Player Library

Revision:
1:933b7aa73bbc
Parent:
0:a88279bdf8c0
Child:
2:108a1fc56c4c
--- a/Player.cpp	Mon Apr 24 08:51:58 2017 +0000
+++ b/Player.cpp	Mon Apr 24 11:05:42 2017 +0000
@@ -1,4 +1,4 @@
-#include Player.h
+#include "Player.h"
 
 Player::Player()
 {
@@ -10,12 +10,62 @@
 
 }
 
+int sprite[3][3] = {
+    {1,0,1},
+    {1,1,1},
+    {1,1,1},
+    };
+    
+void Player::init(int x, int y)
+{
+    _x = WIDTH/2 - 1;  // Middle of screen
+    _y = HEIGHT/2;  // Near bottom of screen
+    _speed = 1;  // default speed 
+    
+}
+
 
 void Player::draw(N5110 &lcd)
 {
-    int _sprite[3][3] = {
-        {1,0,1},
-        {1,1,1},
-        {1,1,1}};
-    lcd.drawSprite(_x,_y,_rows,_cols,_sprite);
+    lcd.drawSprite(_x,_y,3,3,(int *)sprite);
+}
+
+
+
+
+
+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;
+    }
+    if (d == S) {
+        _y+=_speed;
+    }
+    if (d == E) {
+        _x+=_speed;
+    }
+    if (d ==W) {
+        _x-=_speed;
+    }
+
+    // check the y origin to ensure that the paddle doesn't go off screen
+    if (_y < 1) {
+        _y = 1;
+    }
+    if (_x < 1) {
+        _x = 1;
+    }
+    if (_x > 81) {
+        _x = 81;
+    }
+    if (_y > 45) {
+        _x = 45;
+    }
+
 }
\ No newline at end of file