Player Library
Player.cpp
- Committer:
- ll14c4p
- Date:
- 2017-04-28
- Revision:
- 6:79a9c37a0b80
- Parent:
- 5:cd9699b836c3
- Child:
- 7:6987a8d682a3
File content as of revision 6:79a9c37a0b80:
#include "Player.h" Player::Player() { } Player::~Player() { } int sprite[3][3] = { {1,0,1}, {0,1,0}, {1,0,1}, }; int m = 0; void Player::init(int x, int y) { _speed = 0.3; // default speed } void Player::draw(N5110 &lcd) { if(m == 0){ _x = WIDTH/2; // Middle of screen // Change these values to change starting position _y = HEIGHT/2; // Near bottom of screen m = m+1; } printf("SPRITE %d %d \n", _x, _y); lcd.drawSprite(_x,_y,3,3,(int *)sprite); } Vector2D Player::get_pos() { Vector2D pos = {_x,_y}; return pos; } 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; } }