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.
Engine.cpp
- Committer:
- musallambseiso
- Date:
- 2017-04-09
- Revision:
- 8:1c0bc1a08153
- Parent:
- 7:4c19433600c8
- Child:
- 9:0efc8d7cdcf7
File content as of revision 8:1c0bc1a08153:
#include "Engine.h" Engine::Engine() { } Engine::~Engine() { } int collisions = 0; void Engine::init(int friendly_width,int friendly_height,int ship_size,int speed,N5110 &lcd, Gamepad &pad) { _friendly_width = friendly_width; _friendly_height = friendly_height; _ship_size = ship_size; _speed = speed; _friendlyx = GAP; _friendly.init(_friendlyx,_friendly_height,_friendly_width); _ship1.init(_ship_size,_speed); _ship2.init(_ship_size,_speed); _ship3.init(_ship_size,_speed); _ship4.init(_ship_size,_speed); _ship5.init(_ship_size,_speed); _ship6.init(_ship_size,_speed); } void Engine::read_input(Gamepad &pad) { _d = pad.get_direction(); _mag = pad.get_mag(); } void Engine::draw(N5110 &lcd) { lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); lcd.drawLine(0,39,84,39,1); _friendly.draw(lcd); _stats.draw_health(lcd); _stats.check_health(lcd, collisions); } void Engine::ships_gen(N5110 &lcd) { _ship1.draw(lcd); _ship2.draw(lcd); _ship3.draw(lcd); _ship4.draw(lcd); _ship5.draw(lcd); _ship6.draw(lcd); } void Engine::checker(N5110 &lcd, Gamepad &pad) { check_pass(pad); check_death(lcd, pad); //_stats.check_health(lcd); } void Engine::update(N5110 &lcd, Gamepad &pad) { _friendly.update(_d,_mag); _ship1.update(); _ship2.update(); _ship3.update(); _ship4.update(); _ship5.update(); _ship6.update(); } void Engine::shoot(N5110 &lcd, Gamepad &pad, int speed) { _speed = speed; if (pad.check_event(Gamepad::A_PRESSED) == true) { pad.tone(1200.0,0.1); //_bullet.init(lcd, pad, _speed); //_bullet.draw(lcd); //_bullet.update(); } } void Engine::check_pass(Gamepad &pad) { Vector2D ship1_pos = _ship1.get_pos(); if (ship1_pos.x + _ship_size < 0) { _ship1.init(_ship_size,_speed); } Vector2D ship2_pos = _ship2.get_pos(); if (ship2_pos.x + _ship_size < 0) { _ship2.init(_ship_size,_speed); } Vector2D ship3_pos = _ship3.get_pos(); if (ship3_pos.x + _ship_size < 0) { _ship3.init(_ship_size,_speed); } Vector2D ship4_pos = _ship4.get_pos(); if (ship4_pos.x + _ship_size < 0) { _ship4.init(_ship_size,_speed); } Vector2D ship5_pos = _ship5.get_pos(); if (ship5_pos.x + _ship_size < 0) { _ship5.init(_ship_size,_speed); } Vector2D ship6_pos = _ship6.get_pos(); if (ship6_pos.x + _ship_size < 0) { _ship6.init(_ship_size,_speed); } } void Engine::death(N5110 &lcd, Gamepad &pad) { if (dead == true) { lcd.clear(); lcd.printString("lol u ded",0,1); wait(2); dead = false; } } void Engine::check_death1(N5110 &lcd, Gamepad &pad) { Vector2D friendly_pos = _friendly.get_pos(); Vector2D ship1_pos = _ship1.get_pos(); if ( (friendly_pos.y >= ship1_pos.y-5) && // change 5 to friendly size and 6 to ship size (friendly_pos.y <= ship1_pos.y+5) && (friendly_pos.x+6 >= ship1_pos.x) && (friendly_pos.x+6 <= ship1_pos.x+5) ) { pad.tone(800.0,0.1); //collisions = collisions + 1; dead = true; } } void Engine::check_death2(N5110 &lcd, Gamepad &pad) { Vector2D friendly_pos = _friendly.get_pos(); Vector2D ship2_pos = _ship2.get_pos(); if ( (friendly_pos.y >= ship2_pos.y-5) && // change 5 to friendly size and 6 to ship size (friendly_pos.y <= ship2_pos.y+5) && (friendly_pos.x+6 >= ship2_pos.x) && (friendly_pos.x+6 <= ship2_pos.x+5) ) { pad.tone(800.0,0.1); collisions = collisions + 1; } } void Engine::check_death3(N5110 &lcd, Gamepad &pad) { Vector2D friendly_pos = _friendly.get_pos(); Vector2D ship3_pos = _ship3.get_pos(); if ( (friendly_pos.y >= ship3_pos.y-5) && // change 5 to friendly size and 6 to ship size (friendly_pos.y <= ship3_pos.y+5) && (friendly_pos.x+6 >= ship3_pos.x) && (friendly_pos.x+6 <= ship3_pos.x+5) ) { pad.tone(800.0,0.1); collisions = collisions + 1; } } void Engine::check_death4(N5110 &lcd, Gamepad &pad) { Vector2D friendly_pos = _friendly.get_pos(); Vector2D ship4_pos = _ship4.get_pos(); if ( (friendly_pos.y >= ship4_pos.y-5) && // change 5 to friendly size and 6 to ship size (friendly_pos.y <= ship4_pos.y+5) && (friendly_pos.x+6 >= ship4_pos.x) && (friendly_pos.x+6 <= ship4_pos.x+5) ) { pad.tone(800.0,0.1); collisions = collisions + 1; } } void Engine::check_death5(N5110 &lcd, Gamepad &pad) { Vector2D friendly_pos = _friendly.get_pos(); Vector2D ship5_pos = _ship5.get_pos(); if ( (friendly_pos.y >= ship5_pos.y-5) && // change 5 to friendly size and 6 to ship size (friendly_pos.y <= ship5_pos.y+5) && (friendly_pos.x+6 >= ship5_pos.x) && (friendly_pos.x+6 <= ship5_pos.x+5) ) { pad.tone(800.0,0.1); collisions = collisions + 1; } } void Engine::check_death6(N5110 &lcd, Gamepad &pad) { Vector2D friendly_pos = _friendly.get_pos(); Vector2D ship6_pos = _ship6.get_pos(); if ( (friendly_pos.y >= ship6_pos.y-5) && // change 5 to friendly size and 6 to ship size (friendly_pos.y <= ship6_pos.y+5) && (friendly_pos.x+6 >= ship6_pos.x) && (friendly_pos.x+6 <= ship6_pos.x+5) ) { pad.tone(800.0,0.1); collisions = collisions + 1; } } void Engine::check_death(N5110 &lcd, Gamepad &pad) { check_death1(lcd, pad); check_death2(lcd, pad); check_death3(lcd, pad); check_death4(lcd, pad); check_death5(lcd, pad); check_death6(lcd, pad); game_over(lcd, pad); } void Engine::game_over(N5110 &lcd, Gamepad &pad) { if (collisions >= 6) { lcd.drawRect(0,0,84,48,FILL_WHITE); lcd.printString(" You Lose! ",0,1); lcd.printString(" Press Start! ",0,4); lcd.refresh(); while (pad.check_event(Gamepad::START_PRESSED) == false) { wait(0.1); } init(_friendly_width, _friendly_height, _ship_size, _speed, lcd, pad); collisions = 0; } }