ELEC2645 (2016/17) / Mbed 2 deprecated 2645_Project_el15as

Dependencies:   mbed

Revision:
4:1f7f32f3e017
Child:
5:158e2951654b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Player/Player.cpp	Mon Apr 24 22:32:40 2017 +0000
@@ -0,0 +1,90 @@
+#include "Player.h"
+
+Player::Player()
+{
+
+}
+
+Player::~Player()
+{
+
+}
+
+void Player::init(intVector2D XY)
+{
+    _x = XY.x;
+    _y = XY.y;
+
+    _isDead = false;
+
+    Vector2D velocity = {0.0f, 0.0f};
+    _velocity = velocity;
+
+    intVector2D points[8] = {
+        {0,0}, {2,0}, // top
+        {0,2}, {2,2}, // bottom
+        {0,0}, {0,2}, // left
+        {2,0}, {2,2}, // right
+    };
+
+    for (int i = 0; i < 8; i++) {
+		collisionPoint[i] = points[i];
+    };
+}
+
+void Player::draw(N5110 &lcd)
+{
+    // draw the player
+    lcd.drawRect(_x, _y, 3, 3, FILL_TRANSPARENT);
+}
+
+void Player::update(float jx, Serial &pc)
+{
+    //_velocity.x = jx;
+
+    if (jx < 0) {
+        _velocity.x = int(jx*3.2f); // to make up for mechanical imbalance
+    } else {
+        _velocity.x = int(jx*3.0f);
+    }
+
+    // Jump if not already jumping and the jump key was pressed
+    if (_didReleaseJumpKey && !_isJumping && _didPressJump)
+    {
+        _isJumping = true;
+        _didReleaseJumpKey = false;
+        _velocity.y = JUMPSPEED;
+    }
+
+    // Jump key released
+    if (!_didPressJump)
+        _didReleaseJumpKey = true;
+
+    _velocity.y += GRAVITY; // apply gravity
+}
+
+intVector2D Player::get_pos() {
+    intVector2D p = {_x, _y};
+    return p;
+}
+
+void Player::set_pos(intVector2D p) {
+    _x = p.x;
+    _y = p.y;
+}
+
+Vector2D Player::get_velocity() {
+    Vector2D velocity = {_velocity.x, _velocity.y};
+    return velocity;
+}
+
+void Player::set_velocity(Vector2D v) {
+    _velocity = v;
+}
+
+void Player::reset_velocity()
+{
+    _velocity.x = 0;
+    _velocity.y = 0;
+}
+