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
Diff: Imposs/ImpossEngine.cpp
- Revision:
- 4:a9d5fca3b7ba
- Parent:
- 3:4494e6928194
- Child:
- 5:5c132202b642
--- a/Imposs/ImpossEngine.cpp Sat May 16 15:51:02 2020 +0000 +++ b/Imposs/ImpossEngine.cpp Sun May 17 15:55:47 2020 +0000 @@ -1,11 +1,5 @@ #include "ImpossEngine.h" -#include "Zero.h" -#include "One.h" -#include "mbed.h" -#include "N5110.h" -#include "Gamepad.h" -#include "Ball.h" -#include "StartMenu.h" + ImpossEngine::ImpossEngine() { @@ -17,9 +11,11 @@ } -void ImpossEngine::complete(Gamepad &pad,N5110 &lcd,int level) +StartMenu _start; + +void ImpossEngine::complete(Gamepad &pad,N5110 &lcd) { - _start.complete(pad,lcd,level); + _start.complete(pad,lcd); } void ImpossEngine::read_input(Gamepad &pad) @@ -42,24 +38,33 @@ if (level == 1){ _one.draw(lcd); } - } -void ImpossEngine::update(Gamepad &pad,N5110 &lcd, int ball_x_pos, int ball_y_pos) +void ImpossEngine::update(Gamepad &pad,N5110 &lcd,int level) { _ball.update(_d); - check_collision(pad,lcd,ball_x_pos,ball_y_pos); + check_collision(pad,lcd); - check_finish(pad,ball_x_pos,ball_y_pos,level); + check_finish(level); } -void check_collision(Gamepad &pad,N5110 &lcd, int ball_x_pos, int ball_y_pos) +void ImpossEngine::set_level_zero(){ + level = 0; + } + +void ImpossEngine::set_level_one(){ + level = 1; + } + +void ImpossEngine::check_collision(Gamepad &pad,N5110 &lcd) { int _x = 0; int _y = 0; int i = 0; + int x_pos = _ball.get_ball_x_pos(); + int y_pos = _ball.get_ball_y_pos(); bool collision = false; //check around ball to see if it has made contact with anything @@ -67,7 +72,7 @@ i++; - if(lcd.getPixel(ball_x_pos + _x,ball_y_pos + _y) == 1){ + if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){ collision = true; } @@ -81,7 +86,7 @@ i++; - if(lcd.getPixel(ball_x_pos + _x,ball_y_pos + _y) == 1){ + if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){ collision = true; } @@ -95,7 +100,7 @@ i++; - if(lcd.getPixel(ball_x_pos + _x,ball_y_pos + _y) == 1){ + if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){ collision = true; } @@ -109,27 +114,28 @@ i++; - if(lcd.getPixel(ball_x_pos + _x,ball_y_pos + _y) == 1){ + if(lcd.getPixel(x_pos + _x,y_pos + _y) == 1){ collision = true; } _y --; if(collision == true){ - ball_x_pos = 0; - ball_y_pos = 21; + _ball.level_finish(); } } } -void check_finish(Gamepad &pad, int ball_x_pos, int ball_y_pos, int level) +void ImpossEngine::check_finish(int level) { - if(ball_x_pos == 82){ + int x_pos = _ball.get_ball_x_pos(); + + if(x_pos == 82){ level++; - ball_x_pos = 0; - ball_y_pos = 21; + _ball.level_finish(); } } +