//--------------------------------------------- // den globala variabeln som innehåller skeppet Ship shuttle; Shot missile; Mine btrap; Beam railgun; Blast explosion; Xeno enemy; int weapon; int timer, score; boolean gameOver, gameOn; //--------------------------------------------- void setup(){ size(300,300); framerate(20); timer = 0; score = 0; weapon = 0; gameOver = false; gameOn = false; shuttle = new Ship(220,220); missile = new Shot(-100,-100,0,0,1); btrap = new Mine(-100,-100); railgun = new Beam(-100,-100,-10,-10); explosion = new Blast(width/2,height/2,3f,50,70,255,20,20); enemy = new Xeno(100,100,1.0); } //--------------------------------------------- void displayIntroText(){ PFont font = loadFont("astroFont.vlw"); textFont(font); textAlign(CENTER); fill(0,255,0); text("Welcome to AstroShuttle",width/2,height/2-40); fill(170,170,170); text("a game by Skanaar 2005",width/2,height/2-20); fill(128,128,128); text("mouse button to fire",width/2,height/2+20); text("[space] to accelerate",width/2,height/2+40); text("[w] to cycle weapons",width/2,height/2+60); } //--------------------------------------------- void draw(){ background(0); //smooth(); if(!gameOn) updateInto(); if(gameOn) updateGame(); } //--------------------------------------------- void updateInto(){ float x = random(width), y = random(height); if(millis() % 500 < 50) explosion.addBlast(x, y, 3f, 30, 40, 255, 255, 255); explosion.update(); displayIntroText(); } //--------------------------------------------- void updateGame(){ background(0); timer++; missile.update(); btrap.update(); railgun.update(); explosion.update(); enemy.update(); if(!gameOver) shuttle.update(); drawHUD(); if(keyPressed && !gameOver && key!='w') shuttle.thrust(); if(mousePressed && shuttle.coolDown == 0 && !gameOver){ float x,y,vx,vy,d; x = shuttle.shipX; y = shuttle.shipY; d = dist(mouseX,mouseY,x,y); vx = (mouseX-x) / d; vy = (mouseY-y) / d; if(weapon == 0){ missile.addShot(x,y,10*vx,10*vy,(int)random(11,14)); shuttle.coolDown = 9; } if(weapon == 1){ railgun.addBeam(x,y,vx,vy); shuttle.coolDown = 50; } if(weapon == 2){ btrap.addMine(x-15*vx,y-15*vy); shuttle.coolDown = 20; } } if(keyPressed && gameOver){ shuttle = new Ship(100,100); score = 0; gameOver = false; } } //--------------------------------------------- void drawHUD(){ // draws the score stroke(128,128,255); for(int i=0; i a*ex + b*ey , a*ey - b*ex float ex = cos(rot); float ey = sin(rot); line(x+a*ex+b*ey, y+a*ey-b*ex, x+c*ex+d*ey, y+c*ey-d*ex); } //--------------------------------------------- void keyReleased(){ // rotates the weapons in the arsenal if(key == 'w') weapon = (weapon + 1) % 3; gameOn = true; } //---------------------------------------------