Roberta Smith
/
ELEC2645_Project_el18rs
All there but errors need fixing
Diff: TetrisGame/TetrisGame.cpp
- Revision:
- 3:522c6f850e91
- Child:
- 4:7ddd287a5d28
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TetrisGame/TetrisGame.cpp Sun May 24 11:18:33 2020 +0000 @@ -0,0 +1,90 @@ +#include "TetrisGame.h" + +TetrisGame::TetrisGame() +{ + +} + +TetrisGame::~TetrisGame() +{ + +} + +void TetrisGame::init(int tetromino_width, int tetromino_height, int tetromino_size, int speed) +{ + _tetromino_width = tetromino_width; + _tetromino_height = tetromino_height; + _tetromino_size = tetromino_size; + _speed = speed; + + // CHANGE SO STARTS AT TOP? + _p1x = GAP; + _p1.init(_p1x,_tetromino_height,_tetromino_width); + _tetromino.init(_tetromino_height, _tetromino_width, _tetromino_size,_speed); +} + +void TetrisGame::read_input(Gamepad &pad) +{ + _d = pad.get_direction(); + _mag = pad.getmag(); +} + +void TetrisGame::draw(N5110 &lcd) +{ + + lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); + + _p1.draw(lcd); +} + +void TetrisGame::update(Gamepax &pad) +{ + check_goal(pad); + + _p1.update(_d,_mag); + + check_floor_collision(pad); + check_tetromino_collisions(pad); +} + +void TetrisGame::check_floor_collision(Gamepad &pad) +{ + Vector2D tetromino_pos = _tetromino.get_pos(); + + if (tetromino_pos.y + _tetromino_size >= (HEIGHT-1) ) { + + tetromino_pos.y = (HEIGHT-1) - _tetromino_size; + tetromino_velocity.y = 0; + + pad.tone(750.0,0.1); + } + // update tetromino parameters?? +} + +void TetrisGame::check_tetromino_collisions(Gamepad &pad) +{ + Vector2D tetromino_pos = _tetromino.get_pos(); + Vector2D tetromino_velocity = _tetromino.get_velocity(); + + Vector2D p1_pos = _p1.get_pos(); + + if ( + (tetromino_pos.y >= p1_pos.y) && + (tetromino_pos.y <= p1_pos.y + _tetromino_height) && + (tetromino_pos.x >= _p1x) && + (tetromino_pos.x <= _plx + _tetromino_width) + ) { + tetromino_pos.x = _plx + _tetromino_width; + tetromino_velocity.x = 0; + + pad.tone(1000.0,0.1); + } + + + + + + + + + \ No newline at end of file