Li Boyuan / Mbed 2 deprecated PlaneWar

Dependencies:   mbed Gamepad N5110

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers engine.cpp Source File

engine.cpp

00001 #include "engine.h"
00002 
00003 
00004 void engine::init(){
00005 }
00006 
00007 void engine::fire(int x,int y, bullet &b){
00008     b.x = x;
00009     b.y = y;
00010 }
00011 events engine::evet_check(plane &p, bomb &b, Gamepad &pad, bullet &bu){
00012     xy pxy = p.getxy();
00013     int width = p.getwidth();
00014     int height = p.getheight();
00015     if(b.x>-1){
00016         if(((pxy.x - b.width < b.x)&&(pxy.x+width>b.x)) &&((pxy.y-b.height<b.y)&&(pxy.y+height>b.y))){
00017             return DEAD;
00018         }
00019     }
00020     if(pad.check_event(Gamepad::B_PRESSED) == true){
00021         return FIRE;
00022     }
00023     if(bu.x>-1&&b.x>-1){
00024         if(((bu.x - b.width < b.x)&&(bu.x+2>b.x)) &&((bu.y-b.height<b.y)&&(bu.y+2>b.y))){
00025             return ELMININATE;
00026         }
00027     }
00028         return NONE;
00029     }
00030 
00031 
00032 int engine::randombomb(){
00033     int a = 5;
00034     int b = 35;
00035     int y = (rand() % (b-a+1))+ a;
00036     return y;
00037 }