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
SpaceInvaderEngine/SpaceInvaderEngine.cpp
- Committer:
- josh_ohara
- Date:
- 2020-04-03
- Revision:
- 14:e88bcf5c0887
- Parent:
- 12:be491ab6e742
- Child:
- 15:dde4ce4bf7fe
File content as of revision 14:e88bcf5c0887:
#include "SpaceInvaderEngine.h" // N5110 lcd1; SpaceInvaderEngine::SpaceInvaderEngine() { } SpaceInvaderEngine::~SpaceInvaderEngine() { } void SpaceInvaderEngine::init(int ship_height, int ship_width, int alien_size, int no_aliens, int column_size, int row_size) { S1_height = ship_height; S1_width = ship_width; A1_size = alien_size; Vector2D ship_pos = S1.get_position(); S1x = ship_pos.x; S1y = ship_pos.y; N = no_aliens; CS = column_size; RS = row_size; A1.init(N,A1_size,CS,RS); S1.init(S1_height,S1_width); BS1.init(); } void SpaceInvaderEngine::read_input(Gamepad &pad) { D = pad.get_direction(); Mag = pad.get_mag(); } void SpaceInvaderEngine::render(N5110 &lcd) { S1.render(lcd); A1.render(lcd); BS1.render(lcd); } void SpaceInvaderEngine::update(Gamepad &pad, N5110 &lcd) { get_ship_pos(); S1.update(D,Mag); BS1.update(pad, lcd, S1x+4, S1y); A1.update(pad); ship_bullet_alien_collision(pad, lcd); } void SpaceInvaderEngine::get_ship_pos() { Vector2D ship_pos = S1.get_position(); S1x = ship_pos.x; S1y = ship_pos.y; } void SpaceInvaderEngine::ship_bullet_alien_collision(Gamepad &pad, N5110 &lcd){ vector<Alien> alien_vector = A1.get_vector(); vector<Bullet> bullet_vector = BS1.get_vector(); for(int i = 0; i < alien_vector.size(); i++){ Vector2D alien_position = alien_vector[i].get_position(); int alien_x = alien_position.x; int alien_y = alien_position.y; for (int n = 0; n < bullet_vector.size(); n++){ Vector2D bullet_position = bullet_vector[n].get_position(); int bullet_x = bullet_position.x; int bullet_y = bullet_position.y; if((alien_x < bullet_x) && (bullet_x < alien_x + 4)&& (alien_y < bullet_y) && (bullet_y < alien_y + 4)) { bool T = true; bool F = false; A1.set_life(i,F); BS1.set_hit(n,T); } } } }