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
Fork of el17dg by
Diff: game/player.h
- Revision:
- 33:c623c6d5ed16
- Parent:
- 32:5403bb974294
- Child:
- 34:754915ce9de5
--- a/game/player.h Fri Apr 26 13:09:03 2019 +0000
+++ b/game/player.h Mon Apr 29 08:10:52 2019 +0000
@@ -12,7 +12,7 @@
* @author Dmitrijs Griskovs
* @date 15/04/2019
*/
-class Player{
+class Player : public GameObject {
public:
/**
* @var static const int max_player_blasts variable;
@@ -31,7 +31,6 @@
static const int blast_speed = 5;
GameObject blasts[max_player_blasts];
- GameObject player;
CircleBounds player_bounds;
CircleBounds blast_bounds;
Game force_shield_check;
@@ -64,11 +63,10 @@
if (blasts[i].pos.x >= screen_width){
blasts[i].active = false;
GameGlobals::game_score -= 10;
- GameGlobals::score_count_for_difficulty -= 10;
}
lcd.setPixel(blasts[i].pos.x, blasts[i].pos.y, 1);
- lcd.setPixel(blasts[i].pos.x+1, blasts[i].pos.y, 1);
- lcd.setPixel(blasts[i].pos.x+2, blasts[i].pos.y, 1);
+ lcd.setPixel(blasts[i].pos.x + 1, blasts[i].pos.y, 1);
+ lcd.setPixel(blasts[i].pos.x + 2, blasts[i].pos.y, 1);
}
}
}
@@ -90,8 +88,8 @@
}
if (found != -1) {
blasts[found].active = true;
- blasts[found].pos.x = player.pos.x + spaceship1_width;
- blasts[found].pos.y = player.pos.y + (spaceship1_height/2);
+ blasts[found].pos.x = pos.x + spaceship1_width - 2;
+ blasts[found].pos.y = pos.y + (spaceship1_height/2);
}
}
@@ -103,34 +101,38 @@
* whether the force shield was activated in game.cpp, if it was then the player's
* ship is replaced the exactky the same sip but with the added force shield.
*/
- void playerShipMovement(){
+ void updateAndDraw() {
if(x_dir.read() > joy_threshold_max_x) {
- player.pos.x -= ship_speed;
+ pos.x -= ship_speed;
} else if(x_dir.read() < joy_threshold_min_x) {
- player.pos.x += ship_speed;
+ pos.x += ship_speed;
}
if(y_dir.read() > joy_threshold_max_y) {
- player.pos.y -= ship_speed;
+ pos.y -= ship_speed;
} else if(y_dir.read() < joy_threshold_min_y) {
- player.pos.y += ship_speed;
+ pos.y += ship_speed;
}
shipMovementLimits();
+ draw();
+ }
+
+ void draw() {
if (force_shield_check.forceShildActivate()){
- drawSpriteOnTop(player.pos, player_spaceship1_shield_sprite);
+ drawSpriteOnTop(pos, player_spaceship1_shield_sprite);
} else {
- drawSpriteOnTop(player.pos, player_spaceship1_sprite);
+ drawSpriteOnTop(pos, player_spaceship1_sprite);
}
}
private:
/** Prevents the player's ship to go beyond the playing zone limits.*/
void shipMovementLimits(){
// Limits player ship on screen
- if (player.pos.x < game_area_x){ player.pos.x = game_area_x;}
- if (player.pos.y < game_area_y) { player.pos.y = game_area_y;}
+ if (pos.x < game_area_x){ pos.x = game_area_x;}
+ if (pos.y < game_area_y) { pos.y = game_area_y;}
int max_player_x = game_area_x + game_area_width - spaceship1_width;
int max_player_y = game_area_y + game_area_height - spaceship1_height;
- if (player.pos.x > max_player_x) player.pos.x = max_player_x;
- if (player.pos.y > max_player_y) player.pos.y = max_player_y;
+ if (pos.x > max_player_x) pos.x = max_player_x;
+ if (pos.y > max_player_y) pos.y = max_player_y;
}
};
#endif
\ No newline at end of file
