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.
Diff: Player/Player.cpp
- Revision:
- 2:888634fff8ff
- Child:
- 3:aa82968b7a8e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Player/Player.cpp Sat Apr 06 12:08:39 2019 +0000
@@ -0,0 +1,128 @@
+
+#include "Player.h"
+
+// nothing doing in the constructor and destructor
+Player::Player()
+{
+
+}
+
+Player::~Player()
+{
+
+}
+
+
+
+//void Player::PlayerSprite()
+//{
+// // First declare the pixel map data using '1' for black,
+// // or '0' for white pixels
+//
+//}
+// // x origin, y origin, rows, cols, sprite
+// //lcd.drawSprite(20,6,8,5,(int *)sprite);
+// //lcd.refresh();
+// //wait(5.0);
+
+
+
+void Player::init(int player_height,int player_width)
+{
+ // Initialise at the centre
+
+ _x = HEIGHT/2 - player_height/2;
+ _y = WIDTH/2 - player_width/2;
+
+ _player_height = player_height;
+ _player_width = player_width;
+
+ _speed = 1; // default speed
+}
+
+
+
+void Player::draw(N5110 &lcd)
+{
+ int Player_sprite[14][14] = {
+ {1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+ {1,1,1,0,0,0,1,1,0,0,0,1,1,1},
+ {1,1,1,1,0,0,1,1,0,0,1,1,1,1},
+ {1,0,1,1,1,0,1,1,0,1,1,1,0,1},
+ {1,0,0,1,1,1,1,1,1,1,1,0,0,1},
+ {1,0,0,0,1,1,1,1,1,1,0,0,0,1},
+ {1,0,0,0,0,1,1,1,1,0,0,0,0,1},
+ {1,0,0,0,0,1,1,1,1,0,0,0,0,1},
+ {1,0,0,0,1,1,1,1,1,1,0,0,0,1},
+ {1,0,0,1,1,1,1,1,1,1,1,0,0,1},
+ {1,0,1,1,1,0,1,1,0,1,1,1,0,1},
+ {1,1,1,1,0,0,1,1,0,0,1,1,1,1},
+ {1,1,1,0,0,0,1,1,0,0,0,1,1,1},
+ {1,1,1,1,1,1,1,1,1,1,1,1,1,1},
+ };
+
+ // Instantiate the Bitmap object using the data above
+ lcd.drawSprite(_x, _y, _player_height, _player_width,(int *)Player_sprite); //Need a initial position to move from
+}
+
+
+void Player::update(Direction d,float mag)
+{
+ _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
+
+ // update y value depending on direction of movement
+ // North is decrement as origin is at the top-left so decreasing moves up
+ if (d == N) {
+ _y-=_speed; // check for -1.0 angle
+ } else if (d == NE) { // then keep going in 45 degree increments
+ _y-=_speed;
+ _x+=_speed;
+ } else if (d == E) {
+ _x+=_speed;
+ } else if (d == SE) {
+ _y+=_speed;
+ _x+=_speed;
+ } else if (d == S) {
+ _y+=_speed;
+ } else if (d == SW) {
+ _y+=_speed;
+ _x-=_speed;
+ } else if (d == W) {
+ _x-=_speed;
+ } else if (d == NW) {
+ _y-=_speed;
+ _x-=_speed;
+ }
+
+ // check the y origin to ensure that the spacecraft doesn't go off screen
+ if (_y < 1) {
+ _y = 1;
+ }
+ if (_y > HEIGHT - _player_height - 1) {
+ _y = HEIGHT - _player_height - 1;
+ }
+
+ // check the y origin to ensure that the spacecraft doesn't go off screen
+ if (_x < 1) {
+ _x = 1;
+ }
+ if (_x > WIDTH - _player_width - 1) {
+ _x = WIDTH - _player_width - 1;
+ }
+}
+
+
+//void Player::add_score()
+//{
+ // Timer code ------ https://os.mbed.com/forum/mbed/topic/2265/?page=1#comment-11449
+// _score++;
+//}
+//int Player::get_score()
+//{
+// return _score;
+//}
+
+Vector2D Player::get_pos() {
+ Vector2D p = {_x,_y};
+ return p;
+}