Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. Nave player;
  2. float acel;
  3. float yaw;
  4.  
  5. float univ = 5000;
  6. Star[] stars = new Star[5000];
  7. PVector center;
  8.  
  9. void setup(){
  10. size( 700, 600, FX2D );
  11. player = new Nave( 350, 300, new PImage(), 0.06 );
  12. imageMode( CENTER );
  13. for( int i=0; i<stars.length; i++){
  14. stars[i] = new Star(random(-univ, univ), random(-univ, univ), random( 0.5, 4), color(random(200, 255), random(200, 255), random(200, 255)));
  15. }
  16. center = new PVector(width*0.5, height*0.5);
  17. }
  18. void draw(){
  19. background(#040334);
  20. noStroke();
  21.  
  22. translate(-player.pos.x + center.x, -player.pos.y + center.y);
  23.  
  24. for( int i=0; i<stars.length; i++){
  25. fill(stars[i].col);
  26. stars[i].display();
  27. }
  28. player.move();
  29. player.display();
  30. //println(frameRate);
  31. }
  32.  
  33. class Nave{
  34. PVector pos, vel;
  35. float rot, sca, rotvel, thrust;
  36. PImage img;
  37. Nave( float x, float y, PImage i, float s ){
  38. pos = new PVector( x, y );
  39. vel = new PVector( 0, 0 );
  40. rot = -HALF_PI;
  41. img = i;
  42. sca = s;
  43. rotvel = 0.075;
  44. thrust = 0.1;
  45. }
  46. void move(){
  47. rot += yaw * rotvel;
  48. PVector nvel = new PVector(thrust*acel, 0);
  49. nvel.rotate(rot);
  50. vel.add(nvel);
  51. pos.add( vel );
  52. }
  53. void display(){
  54. pushMatrix();
  55. translate( pos.x, pos.y );
  56. scale( sca );
  57. rotate( rot );
  58. //image( img, 0, 0 );
  59. fill(255,0,0);
  60. ellipse(0, 0, 800, 400);
  61. popMatrix();
  62. }
  63. }
  64.  
  65. class Star {
  66. PVector pos;
  67. float tam;
  68. color col;
  69. Star(float x, float y, float r, color c){
  70. pos = new PVector(x, y);
  71. tam = r;
  72. col = c;
  73. }
  74. void display(){
  75. fill(col);
  76. ellipse(pos.x, pos.y, tam + sin(frameCount * 0.1), tam + sin(frameCount * 0.1));
  77. }
  78. }
  79.  
  80.  
  81.  
  82.  
  83. void keyPressed() {
  84. switch(keyCode) {
  85. case LEFT:
  86. yaw = -1;
  87. break;
  88. case RIGHT:
  89. yaw = 1;
  90. break;
  91. case UP:
  92. acel = 1;
  93. break;
  94. case DOWN:
  95. acel = -1;
  96. break;
  97. }
  98. }
  99.  
  100. void keyReleased() {
  101. switch(keyCode) {
  102. case LEFT:
  103. case RIGHT:
  104. yaw = 0;
  105. break;
  106. case UP:
  107. case DOWN:
  108. acel = 0;
  109. break;
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement