Player Library
Player.cpp
- Committer:
- ll14c4p
- Date:
- 2017-04-24
- Revision:
- 4:6d5ea29f83b0
- Parent:
- 3:60a09496c839
- Child:
- 5:cd9699b836c3
File content as of revision 4:6d5ea29f83b0:
#include "Player.h" Player::Player() { } Player::~Player() { } int sprite[3][3] = { {1,0,1}, {0,1,0}, {1,0,1}, }; void Player::init(int x, int y) { _x = WIDTH/2; // Middle of screen // DOESNT FUCKING CAHNGE STARTING LOCATION _y = HEIGHT/2; // Near bottom of screen _speed = 0.3; // default speed } void Player::draw(N5110 &lcd) { lcd.drawSprite(_x,_y,3,3,(int *)sprite); } Vector2D Player::get_pos() { Vector2D p = {_x,_y}; return p; } 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; } if (d == NE) { _y-=_speed/2; _x+=_speed/2; } if (d == NW) { _y-=_speed/2; _x-=_speed/2; } if (d == SE) { _y+=_speed/2; _x+=_speed/2; } if (d == SW) { _y+=_speed/2; _x-=_speed/2; } // check the y origin to ensure that the paddle doesn't go off screen if (_y <= 0) { _y = 0; } if (_x <= 0) { _x = 0; } if (_x > 81) { _x = 81; } if (_y > 45) { _y = 45; } }