Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Eng.cpp
- Committer:
- el18jgb
- Date:
- 2020-05-17
- Revision:
- 8:0b9a824c75fe
- Parent:
- 7:04a7826ff7e4
- Child:
- 9:2836fc3d9ede
File content as of revision 8:0b9a824c75fe:
#include "Eng.h" Eng::Eng() { } Eng::~Eng() { } // objects //Gamepad pad; //N5110 lcd; Aim aim; Heston heston; Pup pup; void Eng::init() { aim.init(); heston.init(); pup.init(); pupon = 0; _tok = 0; flag = true; } //void Eng::read_input(Gamepad &pad); void Eng::update(Gamepad &pad, int fire, N5110 &lcd) { int shot = fire; if (shot == 1){ aim.draw(lcd, fire); lcd.refresh(); check_hit(pad); } int c_score = heston.checkscore(); if (c_score%5 == 0 && flag == false){ flag = true; powerup(lcd, pad); } if (c_score%5 == 1){ flag = false; } int strikes = heston.checkstrike(); heston.update(pad); aim.update(pad); } void Eng::draw(N5110 &lcd) { heston.draw(lcd); aim.draw(lcd, 0); if (pupon == 1){ pup.draw(lcd, 0); } print_score(lcd); } void Eng::check_hit(Gamepad &pad) { Vector2D aim_pos = aim.get_pos(); Vector2D h1_pos = heston.get_pos(); Vector2D pup_pos = pup.get_pos(); if ( (aim_pos.y >= h1_pos.y) && //top (aim_pos.y <= h1_pos.y + 12) && //bottom (aim_pos.x >= h1_pos.x) && //left (aim_pos.x <= h1_pos.x + 11) //right ) { heston.hit(pad); } else if ( (pupon == 1) && (aim_pos.y >= pup_pos.y) && //top (aim_pos.y <= pup_pos.y + 8) && //bottom (aim_pos.x >= pup_pos.x) && //left (aim_pos.x <= pup_pos.x + 8) //right ) { pupon = 0; heston.set_speed(0); pad.led(2,1); pad.led(5,1); } else { heston.miss(pad); } wait(0.4); pad.leds_off(); } void Eng::powerup(N5110 &lcd, Gamepad &pad) { Vector2D aim_pos = aim.get_pos(); int x = aim_pos.x; int y = aim_pos.y; pup.position(x, y); pupon = 1; } void Eng::tik() { _tok = _tok + 1; int rem = _tok%50; if (rem == 0){ heston.set_speed(1); } } void Eng::print_score(N5110 &lcd) { // get scores from paddles int g_score = heston.checkstrike(); // print to LCD i char buffer1[14]; sprintf(buffer1,"%2d",g_score); lcd.printString(buffer1,1,1); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits }