Player Library
Player.cpp
- Committer:
- ll14c4p
- Date:
- 2017-05-03
- Revision:
- 10:43b537436eb5
- Parent:
- 9:002ea306683d
- Child:
- 11:1a8dc3242e13
File content as of revision 10:43b537436eb5:
#include "Player.h" Player::Player() { } Player::~Player() { } int sprite[5][6] = { {0,1,0,0,1,0}, {1,1,0,0,1,1}, {1,1,1,1,1,1}, {1,1,1,1,1,1}, {0,1,1,1,1,0}, }; int m = 0; void Player::init() //Delete Int { _speed = 0.05;// default speed } void Player::draw(N5110 &lcd) { if(m == 0){ _x = WIDTH/2 -1; // Middle of screen // Change these values to change starting position _y = HEIGHT/2 -1; // Near bottom of screen m = m+1; } //printf("SPRITE %d %d \n", _x, _y); lcd.drawSprite(_x,_y,5,6,(int *)sprite); } Vector2D Player::get_pos() { Vector2D playerpos = {_x,_y}; //printf("playerpos from player = %f %f \n", playerpos.x, playerpos.y); return playerpos; } void Player::update(Direction d,float mag) { _speed = int(mag*5.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 > 78) { _x = 78; } if (_y > 43) { _y = 43; } }