Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //GAME
- package game;
- import processing.core.PApplet;
- import processing.core.PImage;
- public class Spaceship extends PApplet
- {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private static final char[] WOOOOOOOSH = null;
- public float distance;
- public float rotationAmount = 0;
- public boolean rotateLeft = false;
- public boolean rotateRight = false;
- public boolean shootBullet = false;
- public float speed = 11;
- public float x = 400;
- public float y = 350;
- public boolean moveForward = false;
- public boolean moving = false;
- public void setup()
- {
- size(800, 700);
- }
- public void draw()
- {
- background(142, 133, 133);
- //Move and control the rocket ship.
- move();
- changeRotation();
- translate(x, y);
- rotate(rotationAmount);
- drawRocketShip();
- shoot();
- }
- //Set up and draw the rocket ship.
- public int rocketX = 0;
- public int rocketY = 0;
- public void drawRocketShip()
- {
- //Body color.
- stroke(0, 149, 185);
- fill(0, 149, 185);
- //Body
- rect(rocketX, rocketY, -75/2, 50/2);
- rect(rocketX, rocketY, 75/2, -50/2);
- rect(rocketX, rocketY, -75/2, -50/2);
- rect(rocketX, rocketY, 75/2, 50/2);
- //GunsRight
- fill(0, 149, 185);
- rect(-2, -2, 10, 45);
- rect(-10, 35, 55, 10);
- fill(180, 0, 0);
- rect(40, 35, 5, 10);
- rect(-15, 35, 5, 10);
- //GunLeft
- fill(0, 149, 185);
- rect(-2, -45, 10, 45);
- fill(0, 149, 185);
- rect(-10, -45, 55, 10);
- fill(180, 0, 0);
- rect(40, -45, 5, 10);
- rect(-15, -45, 5, 10);
- //front
- fill(170, 0, 0);
- rect(10, 0, 2, 2);
- //window color
- fill(255, 255, 255);
- //window
- fill(180, 0, 0);
- ellipse(rocketX + 0, rocketY + 0, 30, 25);
- //wings
- if(moving)
- {
- //Fire trail
- fill(255, 0, 0);
- noStroke();
- //triangle( 0, 0, rocketX - 30, rocketY + 25, rocketX - 10, rocketY + 40);
- }
- }
- public void keyPressed()
- {
- if(key == 'a')
- {
- rotateLeft = true;
- }
- if(key == 'd')
- {
- rotateRight = true;
- }
- if(key == 'w')
- {
- moveForward = true;
- moving = true;
- }
- if(key == ' ')
- {
- shootBullet = true;
- distance += 30;
- }
- }
- public void keyReleased()
- {
- if(key =='a')
- {
- rotateLeft = false;
- }
- if(key == 'd')
- {
- rotateRight = false;
- }
- if(key == 'w')
- {
- moveForward = false;
- moving = false;
- }
- if(key == ' ')
- {
- shootBullet = false;
- distance=0;
- }
- }
- public void move()
- {
- if(moveForward)
- {
- x += speed * cos(rotationAmount);
- y += speed * sin(rotationAmount);
- }
- }
- public void shoot()
- {
- if(shootBullet)
- {
- shot bullet = new shot(rocketX, rocketY);
- bullet.drawShot();
- fill(255, 128, 0);
- ellipse(bullet.getXofShot() +60 + distance, bullet.getYofShot() +40, 10f, 10f);
- ellipse(bullet.getXofShot() +60 + distance, bullet.getYofShot() -40, 10f, 10f);
- if(distance>50)
- {
- ellipse(bullet.getXofShot() +10 + distance, bullet.getYofShot() +40, 10f, 10f);
- ellipse(bullet.getXofShot() +10 + distance, bullet.getYofShot() -40, 10f, 10f);
- }
- }
- }
- public void bullet()
- {
- }
- public void changeRotation()
- {
- if(rotateLeft)
- {
- rotationAmount -= .08;
- if(rotationAmount < 0)
- {
- rotationAmount = 2 * PI;
- }
- }
- if(rotateRight)
- {
- rotationAmount += .08;
- if(rotationAmount > 2 * PI)
- {
- rotationAmount = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement