Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Nave player;
- float acel;
- float yaw;
- float univ = 5000;
- Star[] stars = new Star[5000];
- PVector center;
- void setup(){
- size( 700, 600, FX2D );
- player = new Nave( 350, 300, new PImage(), 0.06 );
- imageMode( CENTER );
- for( int i=0; i<stars.length; i++){
- stars[i] = new Star(random(-univ, univ), random(-univ, univ), random( 0.5, 4), color(random(200, 255), random(200, 255), random(200, 255)));
- }
- center = new PVector(width*0.5, height*0.5);
- }
- void draw(){
- background(#040334);
- noStroke();
- translate(-player.pos.x + center.x, -player.pos.y + center.y);
- for( int i=0; i<stars.length; i++){
- fill(stars[i].col);
- stars[i].display();
- }
- player.move();
- player.display();
- //println(frameRate);
- }
- class Nave{
- PVector pos, vel;
- float rot, sca, rotvel, thrust;
- PImage img;
- Nave( float x, float y, PImage i, float s ){
- pos = new PVector( x, y );
- vel = new PVector( 0, 0 );
- rot = -HALF_PI;
- img = i;
- sca = s;
- rotvel = 0.075;
- thrust = 0.1;
- }
- void move(){
- rot += yaw * rotvel;
- PVector nvel = new PVector(thrust*acel, 0);
- nvel.rotate(rot);
- vel.add(nvel);
- pos.add( vel );
- }
- void display(){
- pushMatrix();
- translate( pos.x, pos.y );
- scale( sca );
- rotate( rot );
- //image( img, 0, 0 );
- fill(255,0,0);
- ellipse(0, 0, 800, 400);
- popMatrix();
- }
- }
- class Star {
- PVector pos;
- float tam;
- color col;
- Star(float x, float y, float r, color c){
- pos = new PVector(x, y);
- tam = r;
- col = c;
- }
- void display(){
- fill(col);
- ellipse(pos.x, pos.y, tam + sin(frameCount * 0.1), tam + sin(frameCount * 0.1));
- }
- }
- void keyPressed() {
- switch(keyCode) {
- case LEFT:
- yaw = -1;
- break;
- case RIGHT:
- yaw = 1;
- break;
- case UP:
- acel = 1;
- break;
- case DOWN:
- acel = -1;
- break;
- }
- }
- void keyReleased() {
- switch(keyCode) {
- case LEFT:
- case RIGHT:
- yaw = 0;
- break;
- case UP:
- case DOWN:
- acel = 0;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement