Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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. final int S = 10;
  5. float bullet_x;
  6. PImage alien_pic;
  7. PImage shooter_pic;
  8.  
  9. class Alien{
  10. float x,y;
  11. float vx,vy;
  12. int i;
  13. int down;
  14.  
  15. Alien(float x_Pos, float y_Pos){
  16. x = x_Pos;
  17. y = y_Pos;
  18. vx = 30;
  19. vy = 30;
  20. down = 0;
  21. }
  22. void move(){
  23. if(down==0){x = x + 30;}
  24. if (x == width){
  25. x = width;
  26. for (int i=0; i<=1;i++){y = y + vy; down=1;}
  27. }
  28. if (down==1){
  29. vy=0;
  30. x = x - 30;
  31. }
  32. if (down==1){
  33. if (x==0){
  34. x = 0; vy=X;
  35. for (int i=0; i<=1;i++){y = y + vy; down=0;}
  36. }
  37. }
  38. }
  39. void display(){
  40. image(alien_pic,x,y);
  41. move();
  42. }
  43. }
  44. class Shooter{
  45. float x,y;
  46.  
  47. Shooter(float x_Pos, float y_Pos){
  48. x = x_Pos;
  49. y = y_Pos;
  50. }
  51. void display(){
  52. image(shooter_pic,x,y);
  53. }
  54. }
  55. //Bullet Class ist noch unter kompletter Bearbeitung!!
  56. class Bullet{
  57. float x,y;
  58. float w,h;
  59. float vy;
  60.  
  61. Bullet(){
  62. x = 8*X;
  63. y = 2*X;
  64. w = 5;
  65. h = 15;
  66. vy = 0;
  67. }
  68. void move(){
  69. y = y - vy;
  70. }
  71. void display(){
  72. rect(x,y,w,h);
  73. println(x);
  74. }
  75. }
  76.  
  77. Alien alien1 = new Alien(X,X);
  78. Alien alien2 = new Alien(3*X,X);
  79. Alien alien3 = new Alien(5*X,X);
  80. Bullet bullet = new Bullet();
  81. Shooter shooter = new Shooter(8*X,18*X);
  82.  
  83. void setup(){
  84. size(17*X,19*X);
  85. background(0);
  86. frameRate(5);
  87. alien_pic = loadImage("alien.jpg");
  88. shooter_pic = loadImage("shooter.jpg");
  89. }
  90. void draw(){
  91. background(0);
  92. alien1.display();
  93. alien2.display();
  94. alien3.display();
  95. shooter.display();
  96. bullet.display();
  97. }
  98. void keyPressed(){ //LEFT und RIGHT funktioniert nicht, keine Ahnung warum
  99. //if (key == CODED){
  100. if (key == 'a'){
  101. shooter.x = shooter.x - 30;
  102. bullet_x = shooter.x;
  103. }
  104. if (key == 'd'){
  105. shooter.x = shooter.x + 30;
  106. bullet_x = shooter.x;
  107. }
  108. /*if (key == 'Space'){
  109. bullet.vy = bullet.vy + S;
  110. }*/
  111. //}
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement