Laila Al Badwawi 200906179 SpaceInvaders I declare this my own independent work and understand the university rules on plagiarism.
Dependencies: mbed
Alien/Alien.cpp
- Committer:
- fy14lkaa
- Date:
- 2019-04-20
- Revision:
- 28:4786e81ce3e3
- Child:
- 91:f9e2ff484014
File content as of revision 28:4786e81ce3e3:
#include "Alien.h" Alien::Alien() { } Alien::~Alien() { } void Alien::init(int size,int speed) { _size = size; srand(time(NULL)); int direction = rand() % 8; // randomise initial direction. // 4 possibilities. Get random modulo and set velocities accordingly if (direction == 0) { _velocity.x = speed; _velocity.y = speed; } else if (direction == 1) { _velocity.x = speed; _velocity.y = -speed; } else if (direction == 2) { _velocity.x = speed; _velocity.y = speed; } else { _velocity.x = -speed; _velocity.y = -speed; } } void Alien::draw(N5110 &lcd) { lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); } void Alien::update() { _x += _velocity.x; _y += _velocity.y; } void Alien::set_velocity(Vector2D v) { _velocity.x = v.x; _velocity.y = v.y; } Vector2D Alien::get_velocity() { Vector2D v = {_velocity.x,_velocity.y}; return v; } Vector2D Alien::get_pos() { Vector2D p = {_x,_y}; return p; }