Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GameState extends State {
- int seconds, starttime;
- int points, lastPoint;
- int lives;
- int highscore;
- Bird bird;
- GameState() {
- // Assets
- bird = new Bird();
- heart = new Gif(Shooty_Bird.this, "heart.gif");
- heart.loop();
- highscore = 0;
- reset();
- }
- void reset () {
- starttime = millis();
- gameStart = 1;
- points = 0;
- lives = 3;
- }
- void logic(){
- seconds = (millis()-starttime)/1000;
- if ((seconds % 3) == 0){
- bird.move();
- }
- if (skott == 0) {
- shoot();
- if(dist(bird.x,bird.y,cursorX,cursorY) < 35)
- {
- points++;
- bird.dead = true;
- }
- else {
- lives--;
- if (lives == 0){
- // Lose
- currentState = menuState;
- if (points > highscore){
- highscore = points;
- }
- menuState.text = "You lost! Score:" + points + " Highscore: " + highscore;
- }
- }
- }
- }
- void draw() {
- // Text
- text(points + " points",480,580);
- text("Lives left:", 10,580);
- text(seconds + " seconds", 10,20);
- // Graphics
- if (!bird.dead){
- image(bird.gif,bird.x,bird.y);
- }
- image(img,cursorX,cursorY);
- for (int liveCount=0; liveCount<lives; liveCount++){
- image(heart, 120+(35*liveCount),555);
- }
- }
- void shoot() {
- image(flare,0,0);
- shootSound.play();
- shootSound.rewind();
- delay(100);
- skott = 1;
- }
- class Bird {
- int x, y;
- boolean dead = false;
- Gif gif;
- Bird () {
- reset();
- gif = new Gif(Shooty_Bird.this, "flappy.gif");
- gif.loop();
- }
- void reset () {
- x = 700;
- y = 700;
- }
- void move() {
- dead = false;
- x = int(random(0,420));
- y = int(random(50,450));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement