Player Library

Player.cpp

Committer:
ll14c4p
Date:
2017-04-24
Revision:
1:933b7aa73bbc
Parent:
0:a88279bdf8c0
Child:
2:108a1fc56c4c

File content as of revision 1:933b7aa73bbc:

#include "Player.h"

Player::Player()
{

}

Player::~Player()
{

}

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)
{
    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;
    }

}