Game codes for Pokemon Academy Yiu Fai Kwok - 201198802 I have read the University Regulations on Plagiarism and state that the work covered by this declaration is my own and does not contain any unacknowledged work from other sources.

Dependencies:   mbed FXOS8700CQ mbed-rtos

Game_one/Object_files/Object.cpp

Committer:
yfkwok
Date:
2019-05-09
Revision:
34:3ddfaa217eca
Parent:
16:4e49f5cb972e

File content as of revision 34:3ddfaa217eca:

#include "Object.h"

Object::Object()
{

}

Object::~Object()
{

}

void Object::init(int speed)
{
    _speed = speed;
    
    int position = rand() % 3; // randomise initial position. 

    // 3 possibilities. Get random modulo and set initial position accordingly
    if (position == 0) {
        _x = -9;
        _y = 1;
    } else if (position == 1) {
        _x = -9;
        _y = 16;
    } else if (position == 2) {
        _x = -9;
        _y = 32;
    }
}

void Object::draw(N5110 &lcd)
{
    static int Object_data[] = {
        1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
        1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,
        1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,
        1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,
        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
        1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,
        0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1
    };
    // Sprite for the block object
    lcd.drawSprite(_x, _y, 16, 17, Object_data);
}

void Object::update()
{
    _x += _speed;
}

void Object::set_velocity(int speed)
{
    _speed = speed;
}

int Object::get_velocity()
{
    int speed = _speed;
    return speed;
}

Vector2D Object::get_pos()
{
    Vector2D p = {_x,_y};
    return p;
}

void Object::set_pos(Vector2D p)
{
    _x = p.x;
    _y = p.y;
}