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@12:be491ab6e742, 2020-04-01 (annotated)
- Committer:
- josh_ohara
- Date:
- Wed Apr 01 14:40:29 2020 +0000
- Revision:
- 12:be491ab6e742
- Parent:
- 11:c174d84e4866
- Child:
- 14:e88bcf5c0887
Created armada, need to make ships move in 1 unit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
josh_ohara | 7:06a2558155f0 | 1 | |
josh_ohara | 7:06a2558155f0 | 2 | #include "SpaceInvaderEngine.h" |
josh_ohara | 7:06a2558155f0 | 3 | |
josh_ohara | 8:86cb9a9f8a73 | 4 | // N5110 lcd1; |
josh_ohara | 8:86cb9a9f8a73 | 5 | |
josh_ohara | 7:06a2558155f0 | 6 | SpaceInvaderEngine::SpaceInvaderEngine() |
josh_ohara | 7:06a2558155f0 | 7 | { |
josh_ohara | 7:06a2558155f0 | 8 | |
josh_ohara | 7:06a2558155f0 | 9 | } |
josh_ohara | 7:06a2558155f0 | 10 | |
josh_ohara | 8:86cb9a9f8a73 | 11 | SpaceInvaderEngine::~SpaceInvaderEngine() |
josh_ohara | 8:86cb9a9f8a73 | 12 | { |
josh_ohara | 8:86cb9a9f8a73 | 13 | |
josh_ohara | 8:86cb9a9f8a73 | 14 | } |
josh_ohara | 8:86cb9a9f8a73 | 15 | |
josh_ohara | 12:be491ab6e742 | 16 | void SpaceInvaderEngine::init(int ship_height, int ship_width, int alien_size, int no_aliens, int column_size, int row_size) { |
josh_ohara | 7:06a2558155f0 | 17 | |
josh_ohara | 7:06a2558155f0 | 18 | S1_height = ship_height; |
josh_ohara | 7:06a2558155f0 | 19 | S1_width = ship_width; |
josh_ohara | 9:8e695df3cc36 | 20 | A1_size = alien_size; |
josh_ohara | 8:86cb9a9f8a73 | 21 | |
josh_ohara | 11:c174d84e4866 | 22 | Vector2D ship_pos = S1.get_position(); |
josh_ohara | 11:c174d84e4866 | 23 | BS1x = ship_pos.x; |
josh_ohara | 11:c174d84e4866 | 24 | BS1y = ship_pos.y; |
josh_ohara | 7:06a2558155f0 | 25 | |
josh_ohara | 12:be491ab6e742 | 26 | N = no_aliens; |
josh_ohara | 12:be491ab6e742 | 27 | CS = column_size; |
josh_ohara | 12:be491ab6e742 | 28 | RS = row_size; |
josh_ohara | 12:be491ab6e742 | 29 | |
josh_ohara | 12:be491ab6e742 | 30 | A1.init(N,A1_size,CS,RS); |
josh_ohara | 7:06a2558155f0 | 31 | S1.init(S1_height,S1_width); |
josh_ohara | 11:c174d84e4866 | 32 | BS1.init(); |
josh_ohara | 8:86cb9a9f8a73 | 33 | |
josh_ohara | 7:06a2558155f0 | 34 | } |
josh_ohara | 7:06a2558155f0 | 35 | |
josh_ohara | 7:06a2558155f0 | 36 | void SpaceInvaderEngine::read_input(Gamepad &pad) |
josh_ohara | 7:06a2558155f0 | 37 | { |
josh_ohara | 7:06a2558155f0 | 38 | D = pad.get_direction(); |
josh_ohara | 7:06a2558155f0 | 39 | Mag = pad.get_mag(); |
josh_ohara | 7:06a2558155f0 | 40 | } |
josh_ohara | 8:86cb9a9f8a73 | 41 | |
josh_ohara | 8:86cb9a9f8a73 | 42 | void SpaceInvaderEngine::render(N5110 &lcd) |
josh_ohara | 8:86cb9a9f8a73 | 43 | { |
josh_ohara | 8:86cb9a9f8a73 | 44 | S1.render(lcd); |
josh_ohara | 9:8e695df3cc36 | 45 | A1.render(lcd); |
josh_ohara | 11:c174d84e4866 | 46 | BS1.render(lcd); |
josh_ohara | 8:86cb9a9f8a73 | 47 | } |
josh_ohara | 8:86cb9a9f8a73 | 48 | |
josh_ohara | 10:9189419fda68 | 49 | void SpaceInvaderEngine::update(Gamepad &pad, N5110 &lcd) |
josh_ohara | 8:86cb9a9f8a73 | 50 | { |
josh_ohara | 8:86cb9a9f8a73 | 51 | S1.update(D,Mag); |
josh_ohara | 10:9189419fda68 | 52 | A1.update(lcd); |
josh_ohara | 11:c174d84e4866 | 53 | get_ship_pos(); |
josh_ohara | 12:be491ab6e742 | 54 | BS1.update(pad, lcd, BS1x, BS1y); |
josh_ohara | 8:86cb9a9f8a73 | 55 | } |
josh_ohara | 8:86cb9a9f8a73 | 56 | |
josh_ohara | 11:c174d84e4866 | 57 | void SpaceInvaderEngine::get_ship_pos() |
josh_ohara | 11:c174d84e4866 | 58 | { |
josh_ohara | 11:c174d84e4866 | 59 | Vector2D ship_pos = S1.get_position(); |
josh_ohara | 11:c174d84e4866 | 60 | BS1x = ship_pos.x + 4; |
josh_ohara | 11:c174d84e4866 | 61 | BS1y = ship_pos.y; |
josh_ohara | 11:c174d84e4866 | 62 | } |
josh_ohara | 11:c174d84e4866 | 63 | |
josh_ohara | 11:c174d84e4866 | 64 | |
josh_ohara | 11:c174d84e4866 | 65 |