Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Gamer.h>
- Gamer gamer;
- const int laserY = 7;
- int laserX = 0;
- const int shipY = 0;
- int shipX = 7;
- int bomb1 = 0;
- int bomb2 = 0;
- int bomb1Y = 1;
- int bomb2Y = 1;
- int gunX = 0;
- int gunY = 0;
- boolean newShip = true;
- //setup device
- void setup()
- {
- gamer.begin();
- }
- void setBombs()
- {
- bomb1 = random(8);
- bomb2 = random(8);
- while (bomb2 == bomb1) bomb1 = random(8);
- }
- void drawShip()
- {
- if (shipX > -1 && shipX < 8) gamer.display[shipX][shipY] = 1;
- if (shipX - 1 > -1 && shipX -1 < 8) gamer.display[shipX - 1][shipY] = 1;
- if (shipX - 2 > -1 && shipX -2 < 8)gamer.display[shipX - 2][shipY] = 1;
- }
- void drawBombs()
- {
- gamer.display[bomb1][bomb1Y] = 1;
- gamer.display[bomb2][bomb2Y] = 1;
- }
- void drawLaser()
- {
- gamer.display[laserX][laserY] = 1;
- }
- void readSwitches()
- {
- if (gamer.isHeld(LEFT)) laserX--;
- if (laserX < 0) laserX = 0;
- if (gamer.isHeld(RIGHT)) laserX++;
- if (laserX > 7) laserX = 7;
- if (gamer.isPressed(START)) drawLaser();
- }
- void loop()
- {
- gamer.clear();
- if (newShip)
- {
- shipX = 7;
- newShip = false;
- setBombs();
- }
- else
- {
- shipX--;
- if (shipX < 0) newShip = true;
- }
- if (shipX == bomb1)
- {
- bomb1Y++;
- if (bomb1Y < 0) bomb1Y = 7;
- bomb2Y++;
- if (bomb2Y < 0) bomb2Y = 7;
- }
- readSwitches();
- drawShip();
- drawBombs();
- drawLaser();
- gamer.updateDisplay();
- delay(300);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement