JianWei Lee
/
project_game
Meteor defense project
Diff: GameEngine/GameEngine.cpp
- Revision:
- 20:32f115462bbc
- Parent:
- 19:7ccbb19703f9
- Child:
- 21:e5585569a938
--- a/GameEngine/GameEngine.cpp Wed Apr 12 13:53:37 2017 +0000 +++ b/GameEngine/GameEngine.cpp Wed Apr 12 17:02:22 2017 +0000 @@ -17,26 +17,27 @@ //printf("init completed \n"); } void GameEngine::update(Gamepad &pad, N5110 &lcd) { - _d1.drone(Array1, charArray, lcd); - _d2.drone(Array1, charArray, lcd); + //_d1.drone(Array2, charArray2, lcd); + //_d2.drone(Array2, charArray2, lcd); drawSpawn(lcd); drawLaserPlayer(pad, lcd); bombAndShield(pad, lcd); + //whatever(pad, lcd); } void GameEngine::drawSpawn(N5110 &lcd){ //spawning every 2 second, moving spawn at every 1 seconds when fps = 15 & drawit=30. //It changes depending on the game FPS. if (drawit == 0) { drawit = 30; - spa.randomizeSpawn(Array2, charArray); - spa.moveSpawnABC(Array1, Array2, charArray); + spa.randomizeSpawn(Array, charArray); + spa.moveSpawnABC(Array, Array2, charArray, charArray2); } else { drawit -= 0.5; - spa.moveSpawnB(Array1, Array2, charArray); + spa.moveSpawnB(Array, Array2, charArray, charArray2); //printf("moving spawn b \n"); } - spa.updateSpawn(Array1, Array2, charArray, lcd); + spa.updateSpawn(Array, Array2, charArray, charArray2, lcd); //checkGameRule(lcd); } void GameEngine::drawLaserPlayer(Gamepad &pad, N5110 &lcd) { @@ -45,13 +46,13 @@ if (pad.buttonhold_A == 1) { //printf("hi, button is working \n"); weap.weaponMath(pad); - weap.drawLaser(Array1, charArray, lcd); + weap.drawLaser(Array2, charArray2, lcd); } } void GameEngine::checkGameRule(N5110 &lcd) { //the only way to lose is when the spawn reaches y = 46. for ( int x = 0; x < 84; x ++) { - if (Array1[x][46] > 0) { + if (Array[x][46] > 0) { while (1) { lcd.clear(); lcd.printString("Game Over",10,3); @@ -62,13 +63,13 @@ } } void GameEngine::bombAndShield(Gamepad &pad, N5110 &lcd) { - weap.bombCooldown(Array1, pad, lcd); + weap.bombCooldown(Array, pad, lcd); if (pad.check_event(Gamepad::X_PRESSED)) { //to prevent from detonating the bomb at instant when button X is accidentally pressed } if (pad.buttonhold_B == 1) { //if B pressed, generate shield. Shield doesnt have to be fully charged to be activated if (weap._shield > 0) { //shield will only activate if the shield has not depleted. - weap.energyShield(Array1, Array2, charArray, lcd); + weap.energyShield(Array, Array2, charArray, charArray2, lcd); } else { //or else, deactivate the shield and recharge the shield. pad.buttonhold_B = 0; } @@ -83,4 +84,31 @@ } } weap.shieldMeter(lcd); +} +void GameEngine::whatever(Gamepad &pad, N5110 &lcd) { + int r = 10; + int c2 = r * r; + Vector2D coord = pad.get_coord(); + int _y = 24 - coord.y * 24; + int _x = 42 + coord.x * 42; + int x2 = _x + r +1; + int y2 = _y + r +1; + //find all the coordinate in a square depending on the radius of circle. + for (int x1 = _x - r; x1 < x2; x1 ++){ + for (int y1 = _y - r; y1 < y2; y1 ++) { + //this code because when y1 get negative. The game crash. + int x3 = x1; int y3 = y1; + if (y3 < 0) { + y3 = 40; + } if (x3 < 0) { + x3 = 40; + } + int a2 = (x3 - _x) * (x3 - _x); + int b2 = (y3 - _y) * (y3 - _y); + if (a2 + b2 <= c2 +1) { //if the coordinate is within the circle + //draw circle and deal damage to it . + lcd.setPixel(x3,y3); + } + } + } } \ No newline at end of file