Advertisement
Guest User

Shooty_bird_game

a guest
May 27th, 2014
1,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1.  
  2. class GameState extends State {
  3. int seconds, starttime;
  4. int points, lastPoint;
  5. int lives;
  6.  
  7. int highscore;
  8.  
  9. Bird bird;
  10.  
  11. GameState() {
  12. // Assets
  13. bird = new Bird();
  14. heart = new Gif(Shooty_Bird.this, "heart.gif");
  15. heart.loop();
  16. highscore = 0;
  17. reset();
  18. }
  19.  
  20. void reset () {
  21. starttime = millis();
  22. gameStart = 1;
  23.  
  24. points = 0;
  25. lives = 3;
  26. }
  27.  
  28. void logic(){
  29. seconds = (millis()-starttime)/1000;
  30.  
  31. if ((seconds % 3) == 0){
  32. bird.move();
  33. }
  34.  
  35. if (skott == 0) {
  36. shoot();
  37. if(dist(bird.x,bird.y,cursorX,cursorY) < 35)
  38. {
  39. points++;
  40. bird.dead = true;
  41. }
  42. else {
  43. lives--;
  44. if (lives == 0){
  45. // Lose
  46. currentState = menuState;
  47. if (points > highscore){
  48. highscore = points;
  49. }
  50. menuState.text = "You lost! Score:" + points + " Highscore: " + highscore;
  51. }
  52. }
  53. }
  54. }
  55.  
  56. void draw() {
  57. // Text
  58. text(points + " points",480,580);
  59. text("Lives left:", 10,580);
  60. text(seconds + " seconds", 10,20);
  61.  
  62. // Graphics
  63. if (!bird.dead){
  64. image(bird.gif,bird.x,bird.y);
  65. }
  66. image(img,cursorX,cursorY);
  67.  
  68. for (int liveCount=0; liveCount<lives; liveCount++){
  69. image(heart, 120+(35*liveCount),555);
  70. }
  71. }
  72.  
  73. void shoot() {
  74. image(flare,0,0);
  75. shootSound.play();
  76. shootSound.rewind();
  77. delay(100);
  78. skott = 1;
  79. }
  80.  
  81. class Bird {
  82. int x, y;
  83. boolean dead = false;
  84. Gif gif;
  85.  
  86. Bird () {
  87. reset();
  88. gif = new Gif(Shooty_Bird.this, "flappy.gif");
  89. gif.loop();
  90. }
  91. void reset () {
  92. x = 700;
  93. y = 700;
  94. }
  95. void move() {
  96. dead = false;
  97. x = int(random(0,420));
  98. y = int(random(50,450));
  99. }
  100. }
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement