Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. //Wie ändere ich genau in diesem Beispiel die Gametime() und abhängig von der Rendertime()?
  2.  
  3. final int X = 30;
  4. int S = 0;
  5. PImage alien_pic;
  6. PImage shooter_pic;
  7.  
  8. class Alien {
  9. float x, y;
  10. float vx, vy;
  11. int i;
  12. int down;
  13.  
  14. Alien(float x_Pos, float y_Pos) {
  15. x = x_Pos;
  16. y = y_Pos;
  17. vx = 30;
  18. vy = 30;
  19. down = 0;
  20. }
  21. void move() {
  22. if (down==0) {
  23. x = x + 30;
  24. }
  25. if (x == width) {
  26. x = width;
  27. for (int i=0; i<=1; i++) {
  28. y = y + vy;
  29. down=1;
  30. }
  31. }
  32. if (down==1) {
  33. vy=0;
  34. x = x - 30;
  35. }
  36. if (down==1) {
  37. if (x==0) {
  38. x = 0;
  39. vy=X;
  40. for (int i=0; i<=1; i++) {
  41. y = y + vy;
  42. down=0;
  43. }
  44. }
  45. }
  46. }
  47. void display() {
  48. image(alien_pic, x, y);
  49. move();
  50. }
  51. }
  52. class Shooter {
  53. float x, y;
  54.  
  55. Shooter(float x_Pos, float y_Pos) {
  56. x = x_Pos;
  57. y = y_Pos;
  58. }
  59. void display() {
  60. image(shooter_pic, x, y);
  61. }
  62. }
  63. class Bullet {
  64. float x, y;
  65. float w, h;
  66. float vy;
  67.  
  68. Bullet(float x_Pos) {
  69. x = x_Pos;
  70. y = 19*X;
  71. w = 5;
  72. h = 15;
  73. vy = 20;
  74. }
  75. void move() {
  76. y = y - vy;
  77. }
  78. void display() {
  79. rect(x, y, w, h);
  80. move();
  81. }
  82. }
  83.  
  84. Alien alien1 = new Alien(X, X);
  85. Alien alien2 = new Alien(3*X, X);
  86. Alien alien3 = new Alien(5*X, X);
  87. Shooter shooter = new Shooter(8*X, 18*X);
  88. Bullet bullet = new Bullet(shooter.x+12);
  89.  
  90. void setup() {
  91. size(17*X, 19*X);
  92. background(0);
  93. frameRate(5);
  94. alien_pic = loadImage("alien.jpg");
  95. shooter_pic = loadImage("shooter.jpg");
  96. //for-Schhleife zum Erstellen der 4 Reihen Aliens
  97.  
  98. }
  99. void draw() {
  100. background(0);
  101. alien1.display();
  102. alien2.display();
  103. alien3.display();
  104. shooter.display();
  105. if (S >= 1) {
  106. bullet.display();
  107. }
  108. }
  109. void keyPressed() {
  110. if (key == ' ') {
  111. S = 1;
  112. }
  113. if (key == CODED){
  114. if (keyCode == LEFT) {
  115. if (shooter.x>=0+30){
  116. shooter.x = shooter.x - 30;
  117. }
  118. }
  119. if (keyCode == RIGHT) {
  120. if (shooter.x<=15*X){
  121. shooter.x = shooter.x + 30;
  122. }
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement