Advertisement
Guest User

Shooty_bird_main

a guest
May 27th, 2014
1,261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. import ddf.minim.*;
  2. import gifAnimation.*;
  3. import processing.serial.*;
  4.  
  5. Minim minim;
  6.  
  7. class State {
  8. void State (){}
  9. void logic(){}
  10. void draw(){}
  11. }
  12.  
  13. State currentState;
  14. GameState gameState;
  15. MenuState menuState;
  16.  
  17.  
  18. // Assets
  19. PImage img, bg, flare;
  20. AudioPlayer shootSound;
  21. PFont font;
  22. Gif heart;
  23.  
  24. // Serial
  25. String serial;
  26. Serial port;
  27.  
  28. // Game variables
  29. int gameStart;
  30. int points;
  31. int lastPoint;
  32. int lives;
  33. int starttime;
  34. int end = 10;
  35. int deadBird = 0;
  36.  
  37. // Mouse variables
  38. float cursorX = 0;
  39. float cursorY = 0;
  40. float skott = 1;
  41.  
  42. boolean joystickEnabled = true;
  43.  
  44.  
  45. void setup() {
  46. size(600,600);
  47. frameRate(60);
  48. minim = new Minim(this);
  49.  
  50. // Setting up serial joystick
  51. try{
  52. port = new Serial(this, Serial.list()[0], 9600);
  53. port.clear();
  54. serial = port.readStringUntil(end);
  55. serial = null;
  56. }
  57. catch (Exception e){
  58. print("Could not initialize serial");
  59. joystickEnabled = false;
  60. }
  61.  
  62. // Loading assets
  63. img = loadImage("sikte.png");
  64. bg = loadImage("landscape.png");
  65. flare = loadImage("flare.png");
  66. shootSound = minim.loadFile("gunshot.wav");
  67.  
  68. font = createFont("Arial",24,true);
  69. textFont(font,24);
  70.  
  71. // Loading states
  72. menuState = new MenuState();
  73. gameState = new GameState();
  74. currentState = menuState;
  75. }
  76.  
  77. void draw () {
  78. background(bg);
  79. fill(0);
  80.  
  81. input();
  82.  
  83. currentState.logic();
  84. currentState.draw();
  85. }
  86.  
  87. void input() {
  88. // Joystick input
  89. if (joystickEnabled){
  90. while (port.available() > 0 ) {
  91. serial = port.readStringUntil(end);
  92. }
  93. String[] a = split(serial, ',');
  94. String x = a[0];
  95. String y = a[1];
  96. String z = a[2];
  97. println(x);
  98. println(y);
  99. println(z);
  100. float xpos = new Float(x);
  101. float ypos = new Float(y);
  102. skott = new Float(z);
  103. cursorX = map(ypos, 0, 1023, 550, 0);
  104. cursorY = map(xpos,0,1023,420,0);
  105. }
  106. else {
  107. cursorX = mouseX-25;
  108. cursorY = mouseY-25;
  109. }
  110. }
  111.  
  112. void mousePressed() {
  113. skott = 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement