Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Alien/Alien.cpp
- Committer:
- josh_ohara
- Date:
- 2020-05-12
- Revision:
- 21:970807533b10
- Parent:
- 20:0b6f1cfc5be6
- Child:
- 22:3e978b1d7958
File content as of revision 21:970807533b10:
#include "Alien.h" void Alien::init(int x, int y, int size) { Alive = true; Shoot = false; StartX = x; StartY = y; X = x; Y = y; Size = size; Speed = 3; alien_bullet_vector.init(); } void Alien::render(N5110 &lcd) { if(Alive == true){ lcd.drawRect(X, Y, Size, Size, FILL_BLACK); alien_bullet_vector.render(lcd); } } Vector2D Alien::get_position() { Vector2D p = {X,Y}; return p; } void Alien::update(int step_x, int remainder_x, Gamepad &pad, int counter) { X+=Speed; int c = counter; int _step_x = step_x; int _remainder_x = remainder_x; if (X < 1 + _remainder_x*_step_x) { X = 1 + _remainder_x*_step_x; Speed = -Speed; Y = Y + 2; } if (X > WIDTH - Size - 1 - (4-_remainder_x)*_step_x) { X = WIDTH - Size - 1 - (4-_remainder_x)*_step_x; Speed = -Speed; Y = Y + 2; } flag_set(c); alien_bullet_vector.update(X,Y,Shoot); Shoot = false; } void Alien::set_life(bool x){ Alive = x; } bool Alien::get_life(){ bool x = Alive; return x; } void Alien::flag_set(int counter){ int c = counter; if(c%7 == 12){ int r = rand()%20; if((r < 2)&& (Alive == true)) { Shoot = true; } } } vector<AlienBullet> Alien::get_bullet_vector(){ vector<AlienBullet> v = alien_bullet_vector.get_vector(); return v; } void Alien::set_bullet_hit(int i, bool hit){ alien_bullet_vector.set_hit(i,hit); }