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
RosenEngine/RosenEngine.cpp@15:009ccc07bb57, 2019-04-11 (annotated)
- Committer:
- ikenna1
- Date:
- Thu Apr 11 06:48:52 2019 +0000
- Revision:
- 15:009ccc07bb57
- Parent:
- 14:88ca5b1a111a
- Child:
- 17:e65a9f981834
Added an enemy : seeker
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ikenna1 | 3:f9cd1a38d5c6 | 1 | #include "RosenEngine.h" |
ikenna1 | 3:f9cd1a38d5c6 | 2 | |
ikenna1 | 14:88ca5b1a111a | 3 | DigitalIn A_button(PTB9); |
ikenna1 | 2:66a4e5d7a7cd | 4 | // Constructor |
ikenna1 | 2:66a4e5d7a7cd | 5 | RosenEngine::RosenEngine() |
ikenna1 | 2:66a4e5d7a7cd | 6 | { |
ikenna1 | 2:66a4e5d7a7cd | 7 | |
ikenna1 | 2:66a4e5d7a7cd | 8 | } |
ikenna1 | 2:66a4e5d7a7cd | 9 | // Destructor |
ikenna1 | 2:66a4e5d7a7cd | 10 | RosenEngine::~RosenEngine() |
ikenna1 | 2:66a4e5d7a7cd | 11 | { |
ikenna1 | 2:66a4e5d7a7cd | 12 | |
ikenna1 | 2:66a4e5d7a7cd | 13 | } |
ikenna1 | 3:f9cd1a38d5c6 | 14 | |
ikenna1 | 4:740e14ebbc97 | 15 | |
ikenna1 | 9:241a1a7d8527 | 16 | void RosenEngine::init(int ship_width,int ship_height,int ship_speed,int ship_xpos,int ship_ypos) |
ikenna1 | 2:66a4e5d7a7cd | 17 | { |
ikenna1 | 4:740e14ebbc97 | 18 | // initialise the game parameters |
ikenna1 | 9:241a1a7d8527 | 19 | _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos); |
ikenna1 | 15:009ccc07bb57 | 20 | // place seeker above the ship |
ikenna1 | 15:009ccc07bb57 | 21 | _enemy.init(ship_xpos, 0); |
ikenna1 | 9:241a1a7d8527 | 22 | _menu.init(16); |
ikenna1 | 13:e114d362186d | 23 | |
ikenna1 | 3:f9cd1a38d5c6 | 24 | } |
ikenna1 | 4:740e14ebbc97 | 25 | |
ikenna1 | 5:bb6edc5b5be3 | 26 | void RosenEngine::read_input(Gamepad &pad) |
ikenna1 | 4:740e14ebbc97 | 27 | { |
ikenna1 | 4:740e14ebbc97 | 28 | Vector2D mapped_coord = pad.get_coord(); |
ikenna1 | 8:87a845b8575e | 29 | _xjoystick = mapped_coord.x; |
ikenna1 | 8:87a845b8575e | 30 | _yjoystick = mapped_coord.y; |
ikenna1 | 9:241a1a7d8527 | 31 | _d = pad.get_direction(); |
ikenna1 | 14:88ca5b1a111a | 32 | // printf("_xjoystick ,_yjoystick = %f , %f\n",_xjoystick, _yjoystick); |
ikenna1 | 4:740e14ebbc97 | 33 | } |
ikenna1 | 4:740e14ebbc97 | 34 | |
ikenna1 | 14:88ca5b1a111a | 35 | void RosenEngine::draw(N5110 &lcd, Gamepad &pad) |
ikenna1 | 7:ed5870cfb3e0 | 36 | { |
ikenna1 | 15:009ccc07bb57 | 37 | _enemy.draw_seeker(lcd); |
ikenna1 | 14:88ca5b1a111a | 38 | if(_xcursor == 0) { |
ikenna1 | 14:88ca5b1a111a | 39 | _ship.set_dimensions(9,6); |
ikenna1 | 13:e114d362186d | 40 | _ship.draw_ship(lcd); |
ikenna1 | 13:e114d362186d | 41 | _weapons.draw(lcd); |
ikenna1 | 13:e114d362186d | 42 | } |
ikenna1 | 14:88ca5b1a111a | 43 | if(_xcursor == 1) { |
ikenna1 | 14:88ca5b1a111a | 44 | _ship.set_dimensions(7,10); |
ikenna1 | 13:e114d362186d | 45 | _ship.draw_imperion(lcd); |
ikenna1 | 14:88ca5b1a111a | 46 | |
ikenna1 | 14:88ca5b1a111a | 47 | if((A_button) == true) { |
ikenna1 | 14:88ca5b1a111a | 48 | pad.tone(500,0.5); |
ikenna1 | 14:88ca5b1a111a | 49 | wait(0.5); |
ikenna1 | 14:88ca5b1a111a | 50 | pad.tone(1000,0.3); |
ikenna1 | 14:88ca5b1a111a | 51 | wait(0.3); |
ikenna1 | 14:88ca5b1a111a | 52 | pad.tone(1500,0.2); |
ikenna1 | 14:88ca5b1a111a | 53 | wait(0.2); |
ikenna1 | 14:88ca5b1a111a | 54 | pad.tone(1700,0.15); |
ikenna1 | 14:88ca5b1a111a | 55 | wait(0.15); |
ikenna1 | 14:88ca5b1a111a | 56 | while((A_button) == true) { |
ikenna1 | 14:88ca5b1a111a | 57 | _weapons.draw_i(lcd); |
ikenna1 | 14:88ca5b1a111a | 58 | pad.tone(2000,0.1); |
ikenna1 | 14:88ca5b1a111a | 59 | wait(0.1); |
ikenna1 | 14:88ca5b1a111a | 60 | } |
ikenna1 | 14:88ca5b1a111a | 61 | } |
ikenna1 | 13:e114d362186d | 62 | } |
ikenna1 | 11:73cd744ffa80 | 63 | } |
ikenna1 | 7:ed5870cfb3e0 | 64 | |
ikenna1 | 7:ed5870cfb3e0 | 65 | void RosenEngine::update(Gamepad &pad) |
ikenna1 | 7:ed5870cfb3e0 | 66 | { |
ikenna1 | 15:009ccc07bb57 | 67 | _enemy.update_seeker(ship_xpos, ship_ypos); |
ikenna1 | 14:88ca5b1a111a | 68 | if(_xcursor == 0) { |
ikenna1 | 14:88ca5b1a111a | 69 | _ship.update_ship(_xjoystick,_yjoystick); |
ikenna1 | 14:88ca5b1a111a | 70 | _weapons.update(); |
ikenna1 | 14:88ca5b1a111a | 71 | } |
ikenna1 | 14:88ca5b1a111a | 72 | if(_xcursor == 1 && A_button == false) { |
ikenna1 | 14:88ca5b1a111a | 73 | _ship.update_ship(_xjoystick,_yjoystick); |
ikenna1 | 14:88ca5b1a111a | 74 | _weapons.update(); |
ikenna1 | 14:88ca5b1a111a | 75 | } |
ikenna1 | 14:88ca5b1a111a | 76 | // _menu.update(_d); |
ikenna1 | 7:ed5870cfb3e0 | 77 | } |
ikenna1 | 9:241a1a7d8527 | 78 | void RosenEngine::get_pos() |
ikenna1 | 9:241a1a7d8527 | 79 | { |
ikenna1 | 9:241a1a7d8527 | 80 | |
ikenna1 | 9:241a1a7d8527 | 81 | Vector2D ship_pos = _ship.get_pos(); |
ikenna1 | 9:241a1a7d8527 | 82 | ship_xpos = ship_pos.x; |
ikenna1 | 9:241a1a7d8527 | 83 | ship_ypos = ship_pos.y; |
ikenna1 | 9:241a1a7d8527 | 84 | ship_width = 9; |
ikenna1 | 9:241a1a7d8527 | 85 | _weapons.init(ship_xpos, ship_ypos, ship_width); |
ikenna1 | 13:e114d362186d | 86 | _ycursor = _menu.get_ycursor(); |
ikenna1 | 9:241a1a7d8527 | 87 | } |
ikenna1 | 9:241a1a7d8527 | 88 | void RosenEngine::title(N5110 &lcd) |
ikenna1 | 9:241a1a7d8527 | 89 | { |
ikenna1 | 14:88ca5b1a111a | 90 | _menu.title(lcd); |
ikenna1 | 10:c33d7593a275 | 91 | _menu.update(_d); |
ikenna1 | 10:c33d7593a275 | 92 | } |
ikenna1 | 13:e114d362186d | 93 | int RosenEngine::get_ycursor() |
ikenna1 | 10:c33d7593a275 | 94 | { |
ikenna1 | 13:e114d362186d | 95 | _ycursor = _menu.get_ycursor(); |
ikenna1 | 10:c33d7593a275 | 96 | return _ycursor; |
ikenna1 | 12:47578eb9ea73 | 97 | } |
ikenna1 | 13:e114d362186d | 98 | int RosenEngine::get_xcursor() |
ikenna1 | 13:e114d362186d | 99 | { |
ikenna1 | 13:e114d362186d | 100 | _xcursor = _menu.get_xcursor(); |
ikenna1 | 13:e114d362186d | 101 | return _xcursor; |
ikenna1 | 13:e114d362186d | 102 | } |
ikenna1 | 12:47578eb9ea73 | 103 | void RosenEngine::ship_select(N5110 &lcd) |
ikenna1 | 12:47578eb9ea73 | 104 | { |
ikenna1 | 12:47578eb9ea73 | 105 | _menu.update(_d); |
ikenna1 | 12:47578eb9ea73 | 106 | _menu.disp_ships(lcd); |
ikenna1 | 9:241a1a7d8527 | 107 | } |