JianWei Lee
/
project_game
Meteor defense project
GameEngine/GameEngine.cpp@13:38cbce17d7d7, 2017-03-30 (annotated)
- Committer:
- jasper0712
- Date:
- Thu Mar 30 11:13:20 2017 +0000
- Revision:
- 13:38cbce17d7d7
- Parent:
- 11:1c48fe71045c
- Child:
- 14:064b8d7f348d
done with spawn abc. starting energy shield next
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jasper0712 | 4:4145abd09075 | 1 | #include "GameEngine.h" |
jasper0712 | 4:4145abd09075 | 2 | |
jasper0712 | 4:4145abd09075 | 3 | GameEngine::GameEngine() |
jasper0712 | 4:4145abd09075 | 4 | { |
jasper0712 | 4:4145abd09075 | 5 | |
jasper0712 | 4:4145abd09075 | 6 | } |
jasper0712 | 4:4145abd09075 | 7 | |
jasper0712 | 4:4145abd09075 | 8 | GameEngine::~GameEngine() |
jasper0712 | 4:4145abd09075 | 9 | { |
jasper0712 | 4:4145abd09075 | 10 | |
jasper0712 | 4:4145abd09075 | 11 | } |
jasper0712 | 4:4145abd09075 | 12 | |
jasper0712 | 4:4145abd09075 | 13 | void GameEngine::drawSpawn(N5110 &lcd){ |
jasper0712 | 9:4c4d787c7a8b | 14 | //spawning every 2 second, moving every 1 seconds at 15 fps & drawit=15. |
jasper0712 | 9:4c4d787c7a8b | 15 | //It changes depending on the game FPS. |
jasper0712 | 4:4145abd09075 | 16 | if (drawit ==0) { |
jasper0712 | 13:38cbce17d7d7 | 17 | drawit =30; |
jasper0712 | 13:38cbce17d7d7 | 18 | spa.randomizeSpawn(Array2, charArray); |
jasper0712 | 13:38cbce17d7d7 | 19 | spa.moveSpawnABC(Array1, Array2, charArray); |
jasper0712 | 4:4145abd09075 | 20 | } else { |
jasper0712 | 4:4145abd09075 | 21 | drawit -=0.5; |
jasper0712 | 13:38cbce17d7d7 | 22 | spa.moveSpawnB(Array1, Array2, charArray); |
jasper0712 | 4:4145abd09075 | 23 | } |
jasper0712 | 13:38cbce17d7d7 | 24 | spa.updateSpawn(Array1, Array2, charArray, lcd); |
jasper0712 | 13:38cbce17d7d7 | 25 | checkGameRule(lcd); |
jasper0712 | 4:4145abd09075 | 26 | } |
jasper0712 | 5:c74bbdda06f4 | 27 | void GameEngine::drawLaserPlayer(Gamepad &pad, N5110 &lcd) { |
jasper0712 | 9:4c4d787c7a8b | 28 | weap.laserDamage(); |
jasper0712 | 5:c74bbdda06f4 | 29 | weap.drawWeapon(pad, lcd); |
jasper0712 | 9:4c4d787c7a8b | 30 | //draw a line for the laser when button is pressed |
jasper0712 | 10:926b1f89c4f1 | 31 | if (pad.buttonhold_A == 1) { |
jasper0712 | 7:3be4369131c6 | 32 | //printf("hi, button is working \n"); |
jasper0712 | 5:c74bbdda06f4 | 33 | weap.weaponMath(pad); |
jasper0712 | 9:4c4d787c7a8b | 34 | weap.drawLaser(Array1, lcd); |
jasper0712 | 5:c74bbdda06f4 | 35 | } |
jasper0712 | 5:c74bbdda06f4 | 36 | } |
jasper0712 | 9:4c4d787c7a8b | 37 | |
jasper0712 | 10:926b1f89c4f1 | 38 | void GameEngine::checkGameRule(N5110 &lcd) { |
jasper0712 | 9:4c4d787c7a8b | 39 | //the only way to lose is when the spawn reaches y = 46. |
jasper0712 | 10:926b1f89c4f1 | 40 | for ( int x = 0; x < 84; x ++) { |
jasper0712 | 10:926b1f89c4f1 | 41 | if (Array1[x][46] > 0) { |
jasper0712 | 10:926b1f89c4f1 | 42 | while (1) { |
jasper0712 | 10:926b1f89c4f1 | 43 | lcd.clear(); |
jasper0712 | 10:926b1f89c4f1 | 44 | lcd.printString("Game Over",10,3); |
jasper0712 | 10:926b1f89c4f1 | 45 | lcd.refresh(); |
jasper0712 | 10:926b1f89c4f1 | 46 | wait(1.0); |
jasper0712 | 10:926b1f89c4f1 | 47 | } |
jasper0712 | 10:926b1f89c4f1 | 48 | } |
jasper0712 | 10:926b1f89c4f1 | 49 | } |
jasper0712 | 5:c74bbdda06f4 | 50 | } |
jasper0712 | 11:1c48fe71045c | 51 | void GameEngine::bomb(Gamepad &pad, N5110 &lcd) { //cooldown not yet implemented. |
jasper0712 | 13:38cbce17d7d7 | 52 | weap.bombCooldown(Array1, pad, lcd); |
jasper0712 | 13:38cbce17d7d7 | 53 | |
jasper0712 | 10:926b1f89c4f1 | 54 | } |