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.
Map/Map.cpp
- Committer:
- JamesCummins
- Date:
- 2019-05-06
- Revision:
- 37:de1f584bce71
- Parent:
- 36:9f7463a65fe0
- Child:
- 38:a85bc227b907
File content as of revision 37:de1f584bce71:
#include "Map.h" Map::Map(){ } Map::~Map(){ } void Map::init(){ _coord.x = 47; _coord.y = 25; } void Map::read_input(FXOS8700CQ &accelerometer, Ball &ball){ Data values = accelerometer.get_values(); int ball_speed = ball.get_ball_speed(); _map_change.x = -(1+0.5*ball_speed)*values.ay; _map_change.y = -(1+0.5*ball_speed)*values.ax; } void Map::update(){ _coord.x += _map_change.x; _coord.y += _map_change.y; if(_coord.x < 0){ _coord.x = 0;} //boundary conditions to stop the if(_coord.y < 0){ _coord.y = 0;} //the programme trying to display if(_coord.x > 506) {_coord.x = 506;} //undefined region outside the if(_coord.y > 176) {_coord.y = 176;} //gamemap array } void Map::draw(N5110 &lcd){ bool pixelstate = false; for(int y = _coord.y; y < (48+_coord.y); y++){ for(int x = _coord.x; x < (84+_coord.x); x++){ if(gamemap[y][x] == 1){ pixelstate = true;} else{ pixelstate = false;} lcd.setPixel((x-_coord.x), (y-_coord.y), pixelstate); } } } Vector2D Map::get_map_display(){ Vector2D top_left_coord = _coord; return top_left_coord; } void Map::set_map_display(Vector2D coord){ _coord = coord; } bool Map::check_wall_collision(Gamepad &gamepad, Ball &ball){ bool collision = false; /*Vector2D ball_screen_pos = ball.get_position(); Vector2D c; c.x = ball_screen_pos.x + _coord.x; c.y = ball_screen_pos.y + _coord.y; Vector2D ball_pixels[37] = { {c.x,c.y},{c.x+1,c.y},{c.x+2,c.y},{c.x+3,c.y},{c.x-1,c.y},{c.x-2,c.y}, {c.x-3,c.y},{c.x,c.y+1},{c.x+1,c.y+1},{c.x+2,c.y+1},{c.x+3,c.y+1}, {c.x-1,c.y+1},{c.x-2,c.y+1},{c.x-3,c.y+1},{c.x,c.y-1},{c.x+1,c.y-1}, {c.x+2,c.y-1},{c.x+3,c.y-1},{c.x-1,c.y-1},{c.x-2,c.y-1},{c.x-3,c.y-1}, {c.x,c.y+2},{c.x+1,c.y+2},{c.x+2,c.y+2},{c.x-1,c.y+2},{c.x-2,c.y+2}, {c.x,c.y-2},{c.x+1,c.y-2},{c.x+2,c.y-2},{c.x-1,c.y-2},{c.x-2,c.y-2}, {c.x,c.y+3},{c.x+1,c.y+3},{c.x-1,c.y+3},{c.x,c.y-3},{c.x+1,c.y-3}, {c.x-1,c.y-3} }; for(int i = 0; i < 37; i++){ int y = ball_pixels[i].y; int x = ball_pixels[i].x; if(gamemap[y][x] == 1){ collision = true; printf("colliding pixel = %d,%d\n", x, y); break; } else { collision = false; } }*/ return collision; } bool Map::get_coordinate(Vector2D coord){ bool position; if(gamemap[coord.y][coord.x] == 1){ position == true; } else{ position == false; } return position; }