Question
You have to installed processor in order to solve this That's what it looks like and when programming is running Now the code will be
You have to installed processor in order to solve this
That's what it looks like and when programming is running
Now the code will be provided below
Part 2
Part 3
Part 4
Let me know how you add it on each one please very desperate, please provide email so i can email it to u.
code 1 Ship ship;
boolean upPressed = false;//CHANGE LEFT AND RIGHT TO UP AND DOWN( IN SHIP TOO) boolean downPressed = false; boolean rightPressed = false; boolean leftPressed = false;
float shipSpeed = 2; float bulletSpeed = 10;
int numAsteroids = 2; //the number of asteroids int startingRadius = 50; //the size of an asteroid
PImage asteroidPic; PImage rocket;
ArrayList
PFont font;
// game state variables int gameState; public final int INTRO = 1; public final int PLAY = 2; public final int PAUSE = 3; public final int GAMEOVER = 4;
void setup() { background(0); size(800,500); font = createFont("Cambria", 32); frameRate(24); asteroidPic = loadImage("asteroid.png"); rocket = loadImage("rocket.png"); asteroids = new ArrayList
void draw() { switch(gameState) { case INTRO: drawScreen("Welcome!", "Press s to start"); break; case PAUSE: drawScreen("PAUSED", "Press p to resume"); break; case GAMEOVER: drawScreen("GAME OVER", "Press s to try again"); break; case PLAY: background(0); ship.update(); ship.render(); if(ship.checkCollision(asteroids) || asteroids.size()
//Initialize the game settings. Create ship, bullets, and asteroids void initializeGame() { ship = new Ship(); bullets = new ArrayList // void fireBullet() { println("fire");//this line is for debugging purpose PVector pos = new PVector(0, ship.r*2); rotate2D(pos,heading2D(ship.rotation) + PI/2); pos.add(ship.position); PVector vel = new PVector(0, bulletSpeed); rotate2D(vel, heading2D(ship.rotation) + PI/2); bullets.add(new Bullet(pos, vel)); } void keyPressed() { if(key== 's' && ( gameState==INTRO || gameState==GAMEOVER )) { initializeGame(); gameState=PLAY; } if(key=='p' && gameState==PLAY) gameState=PAUSE; else if(key=='p' && gameState==PAUSE) gameState=PLAY; //when space key is pressed, fire a bullet if(key == ' ' && gameState == PLAY) fireBullet(); if(key==CODED && gameState == PLAY) { if(keyCode==UP) upPressed=true; else if(keyCode==DOWN) downPressed=true; else if(keyCode == LEFT) leftPressed = true; else if(keyCode==RIGHT) rightPressed = true; } } void keyReleased() { if(key==CODED) { if(keyCode==UP) { upPressed=false; ship.acceleration = new PVector(0,0); } else if(keyCode==DOWN) { downPressed=false; ship.acceleration = new PVector(0,0); } else if(keyCode==LEFT) leftPressed = false; else if(keyCode==RIGHT) rightPressed = false; } } void drawScreen(String title, String instructions) { background(0,0,0); // draw title fill(255,100,0); textSize(60); textAlign(CENTER, BOTTOM); text(title, width/2, height/2); // draw instructions fill(255,255,255); textSize(32); textAlign(CENTER, TOP); text(instructions, width/2, height/2); } float heading2D(PVector pvect) { return (float)(Math.atan2(pvect.y, pvect.x)); } void rotate2D(PVector v, float theta) { float xTemp = v.x; v.x = v.x*cos(theta) - v.y*sin(theta); v.y = xTemp*sin(theta) + v.y*cos(theta); } ----------------------------------------- class Asteroid { float radius; float omegaLimit = .05; PVector position; PVector velocity; PVector rotation; float spin; int col = 100; PImage pic; public Asteroid(PVector pos, float radius_, PImage pics_) { radius = radius_; position = pos; float angle = random(2 * PI); velocity = new PVector(cos(angle), sin(angle)); velocity.mult((50*50)/(radius*radius)); angle = random(2 * PI); rotation = new PVector(cos(angle), sin(angle)); spin = random(-5,5); pic = pics_; } void hit(ArrayList /* float heading2D(PVector pvect) { return (float)(Math.atan2(pvect.y, pvect.x)); } void rotate2D(PVector v, float theta) { float xTemp = v.x; v.x = v.x*cos(theta) - v.y*sin(theta); v.y = xTemp*sin(theta) + v.y*cos(theta); }*/ } ----------------------------------- class Bullet { PVector position; PVector velocity; int radius = 5; PImage img = loadImage("bullet.png"); public Bullet(PVector pos, PVector vel) { position = pos; velocity = vel; } //check whether the bullet collide with any asteroid (by examining the distance to each asteroid) boolean checkCollision(ArrayList } ---------------------------------- class Ship { PVector position; PVector velocity; PVector acceleration; PVector rotation; float drag = .9; float r = 15; PImage img = loadImage("rocket.png"); public Ship() { position = new PVector(width/2, height-50); acceleration = new PVector(0,0); velocity = new PVector(0,0); rotation = new PVector(0,1); } void update() { PVector below = new PVector(0, -2*r); rotate2D(below, heading2D(rotation)+PI/2); below.add(position); velocity.add(acceleration); velocity.mult(drag);//adjust the speed to avoid it moving too fast velocity.limit(5);//the maximum speed is 5 position.add(velocity); } void roundBack() { if (position.x width-r) position.x = r; if (position.y > height-r) position.y = r; } boolean checkCollision(ArrayList image(img,-r,-r*1.5,2*r,3*r); popMatrix(); } /*float heading2D(PVector pvect) { return (float)(Math.atan2(pvect.y, pvect.x)); }*/ /* void rotate2D(PVector v, float theta) { float xTemp = v.x; v.x = v.x*cos(theta) - v.y*sin(theta); v.y = xTemp*sin(theta) + v.y*cos(theta); }*/ }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started