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.
GameEngine/GameEngine.cpp@18:11068b98e261, 2020-05-01 (annotated)
- Committer:
- evanso
- Date:
- Fri May 01 20:37:10 2020 +0000
- Revision:
- 18:11068b98e261
- Parent:
- 17:25d79cca203a
- Child:
- 19:1bc0a2d22054
Added functions so if button A is press the spaceship shoots a bullet.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| evanso | 8:dd1037c5435b | 1 | #include "GameEngine.h" |
| evanso | 8:dd1037c5435b | 2 | |
| evanso | 8:dd1037c5435b | 3 | GameEngine::GameEngine() { |
| evanso | 8:dd1037c5435b | 4 | |
| evanso | 8:dd1037c5435b | 5 | } |
| evanso | 8:dd1037c5435b | 6 | |
| evanso | 8:dd1037c5435b | 7 | GameEngine::~GameEngine() { |
| evanso | 8:dd1037c5435b | 8 | |
| evanso | 8:dd1037c5435b | 9 | } |
| evanso | 8:dd1037c5435b | 10 | |
| evanso | 13:12276eed13ac | 11 | void GameEngine::init() { |
| evanso | 8:dd1037c5435b | 12 | pad.init(); |
| evanso | 8:dd1037c5435b | 13 | lcd.init(); |
| evanso | 8:dd1037c5435b | 14 | spaceship.init(); |
| evanso | 13:12276eed13ac | 15 | map.init(pad); |
| evanso | 8:dd1037c5435b | 16 | move_map_= 0; |
| evanso | 18:11068b98e261 | 17 | is_bullet_firing_ = false; |
| evanso | 8:dd1037c5435b | 18 | } |
| evanso | 8:dd1037c5435b | 19 | |
| evanso | 13:12276eed13ac | 20 | void GameEngine::gameplay_loop() { |
| evanso | 11:ab578a151f67 | 21 | // clear screen |
| evanso | 13:12276eed13ac | 22 | lcd.setContrast(pad.read_pot1()); |
| evanso | 8:dd1037c5435b | 23 | lcd.clear(); |
| evanso | 11:ab578a151f67 | 24 | |
| evanso | 15:90b6821bcf64 | 25 | // Gets movements |
| evanso | 15:90b6821bcf64 | 26 | read_joystick_direction(); |
| evanso | 13:12276eed13ac | 27 | spaceship.movement(d_); |
| evanso | 13:12276eed13ac | 28 | |
| evanso | 18:11068b98e261 | 29 | // Fires bullet |
| evanso | 18:11068b98e261 | 30 | if (pad.A_pressed()) { |
| evanso | 18:11068b98e261 | 31 | is_bullet_firing_ = true; |
| evanso | 18:11068b98e261 | 32 | //printf("is_bullet_firing_ = %d",is_bullet_firing_); |
| evanso | 18:11068b98e261 | 33 | } |
| evanso | 18:11068b98e261 | 34 | if (is_bullet_firing_){ |
| evanso | 18:11068b98e261 | 35 | Weapons new_bullet; |
| evanso | 18:11068b98e261 | 36 | new_bullet.calc_bullets_start_pos(spaceship.get_pos(), spaceship.get_spaceship_sprite_direction()); |
| evanso | 18:11068b98e261 | 37 | bullet_vector.push_back(new_bullet); |
| evanso | 18:11068b98e261 | 38 | is_bullet_firing_ = false; |
| evanso | 18:11068b98e261 | 39 | } |
| evanso | 18:11068b98e261 | 40 | for (int i = 0; i < bullet_vector.size(); i++){ |
| evanso | 18:11068b98e261 | 41 | bullet_vector[i].draw_bullet(lcd); |
| evanso | 15:90b6821bcf64 | 42 | } |
| evanso | 15:90b6821bcf64 | 43 | |
| evanso | 18:11068b98e261 | 44 | // Draws |
| evanso | 18:11068b98e261 | 45 | spaceship.draw(lcd); |
| evanso | 18:11068b98e261 | 46 | map.draw_map(lcd, d_); |
| evanso | 18:11068b98e261 | 47 | |
| evanso | 18:11068b98e261 | 48 | // refresh's screen |
| evanso | 18:11068b98e261 | 49 | lcd.refresh(); |
| evanso | 13:12276eed13ac | 50 | } |
| evanso | 13:12276eed13ac | 51 | |
| evanso | 15:90b6821bcf64 | 52 | void GameEngine::read_joystick_direction(){ |
| evanso | 13:12276eed13ac | 53 | d_ = pad.get_direction(); |
| evanso | 18:11068b98e261 | 54 | } |
| evanso | 18:11068b98e261 | 55 |