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
- Committer:
- ikenna1
- Date:
- 2019-04-14
- Revision:
- 23:0301effce801
- Parent:
- 22:8cad70085883
- Child:
- 24:ab821bfeb383
File content as of revision 23:0301effce801:
#include "RosenEngine.h" DigitalIn A(PTB9); // Constructor RosenEngine::RosenEngine() { } // Destructor RosenEngine::~RosenEngine() { } void RosenEngine::init(int ship_width,int ship_height,int ship_speed,int ship_xpos,int ship_ypos) { // initialise the game parameters _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos); // place seeker above the ship _enemy.init(48,0); _menu.init(16); _health.init(_shipno); } void RosenEngine::read_input(Gamepad &pad) { Vector2D mapped_coord = pad.get_coord(); _xjoystick = mapped_coord.x; _yjoystick = mapped_coord.y; _d = pad.get_direction(); // printf("_xjoystick ,_yjoystick = %f , %f\n",_xjoystick, _yjoystick); } void RosenEngine::draw(N5110 &lcd, Gamepad &pad) { _health.draw_health(lcd); _health.draw_shields(lcd); _enemy.draw_seeker(lcd); if(_shipno == 0) { _ship.set_dimensions(9,6); _ship.draw_ship(lcd); _weapons.draw(lcd,pad,_shipno); } if(_shipno == 1) { _ship.set_dimensions(7,10); _ship.draw_imperion(lcd); _weapons.draw(lcd,pad,_shipno); } } void RosenEngine::update(Gamepad &pad) { _enemy.update_seeker(ship_xpos, ship_ypos); if(_shipno == 0) { _ship.update_ship(_xjoystick,_yjoystick); _weapons.update(); } if(_shipno == 1 && A == false) { _ship.update_ship(_xjoystick,_yjoystick); _weapons.update(); } // _menu.update(_d); check_enemy_ship_collision(); // printf("collision check complete"); } void RosenEngine::get_pos() { Vector2D ship_pos = _ship.get_pos(); ship_xpos = ship_pos.x; ship_ypos = ship_pos.y; ship_width = 9; _weapons.init(ship_xpos, ship_ypos, ship_width); _ycursor = _menu.get_ycursor(); } void RosenEngine::title(N5110 &lcd) { _menu.title(lcd); _menu.update(_d); } int RosenEngine::get_ycursor() { _ycursor = _menu.get_ycursor(); return _ycursor; } int RosenEngine::get_shipno() { _shipno = _menu.get_xcursor(); return _shipno; } void RosenEngine::ship_select(N5110 &lcd) { _menu.update(_d); _menu.disp_ships(lcd); } void RosenEngine::check_enemy_ship_collision() { Vector2D ship_pos = _ship.get_pos(); Vector2D seeker_pos = _enemy.get_seekerpos(); int ship_x[9]; int ship_y[6]; int seeker_x[9]; int seeker_y[6]; bool xcol = false; bool ycol = false; // create an array of all x positions for the ship sprite i.e along its width (ship_x) for(int countx = 0; countx<=9; countx=countx+1) { ship_x[countx] = ship_pos.x + countx; seeker_x[countx] = seeker_pos.x + countx; // printf("ship_x = %d, seeker_x = %d\n", ship_x[countx], seeker_x[countx]); } // create an array of all y positions for the ship sprite i.e along its height (ship_y) for(int county = 0; county<=6; county=county+1) { ship_y[county] = ship_pos.y + county; seeker_y[county] = seeker_pos.y + county; //printf("ship_y = %d, seeker_y = %d\n", ship_y[county], seeker_y[county]); } // check all values of ship position against all values of seekers x position for(int nx = 0; nx<=9; nx=nx+1) { for(int mx = 0; mx<=9; mx=mx+1) { if(ship_x[nx] == seeker_x[mx]) { xcol = true; } } } for(int ny = 0; ny<=6; ny=ny+1) { for(int my = 0; my<=6; my=my+1) { if(ship_y[ny] == seeker_y[my]) { ycol = true; } } } printf("xcol = %d, ycol = %d\n", xcol, ycol); if(xcol == true && ycol == true) { _health.update(1); _enemy.reset_seeker(); } } void RosenEngine::check_enemy_projectile_collision() { Vector2D seeker_pos = _enemy.get_seekerpos(); if(_shipno == 0){ } }