Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

You have to installed processor in order to solve this

That's what it looks like and when programming is running

image text in transcribed

image text in transcribed

Now the code will be provided below

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Part 2

image text in transcribed

image text in transcribed

Part 3

image text in transcribed

Part 4

image text in transcribed

image text in transcribed

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 bullets; ArrayList asteroids;

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(0); gameState = INTRO; }

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(); asteroids = new ArrayList(); for(int i = 0; i

// 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 asteroids) { asteroids.remove(this); } //update the asteroid's position and make it spin void update() { position.add(velocity); rotate2D(rotation, radians(spin)); } //display the asteroid void render() { roundBack(); pushMatrix(); translate(position.x,position.y); rotate(heading2D(rotation)+PI/2); image(pic, -radius,-radius,radius*2, radius*2); popMatrix(); } void roundBack() { if (position.x width) position.x = 0; if (position.y > height) position.y = 0; }

/* 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 asteroids) { for(Asteroid a : asteroids) { PVector dist = PVector.sub(position, a.position); if(dist.mag()

}

----------------------------------

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 asteroids) { for(Asteroid a : asteroids) { PVector dist = PVector.sub(a.position, position); if(dist.mag()

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); }*/ }

Untitled board- Coursecontent other Download the file "asteriodsGame.zip" in Black material. Unzip i the software is strictly a toy: there are no goals. Your task will be to design some structure to enhance the game. Try to consider goals does the player have in the game? Choice: what choies does the player make? Resources: what resources are t and try out the skeletal game, There is some basic activity, but the following questions: Goals: what in the game? How will the player spend the resources? How will new resources be acquired? Variety of Encounter: how can you increase the variety of encounter? Based on the above questions, add the following components to this game. 1. The harm of every bullet and the health of every asteroid. For example, if a bullet hits an asteroid, the asteroid will lose 10 points health. If an ast loses all health, it will be destroyed. (30 points) 2. Score and timer, which decide the outcome of the game. For example, only when score is greater than 100 and the elapsed time is less than 30 seconds, you win the game. You need to decide how to relate score with the number of asteroid, the health of an asteroid, and the number of bullets. (40 points) as 3. colsi sion happens (2o poin 3. Add audio effects to the game, such as background music and the sound effect when a collision happens. (20 points) 4. Add a screen of credits. Anytime when the players press a key (e.g c'), the can see an animated credit screen. An Tutorial 6. (10 points) example function is shown in the slides o you have to use: https://processing.org/ Untitled board- Coursecontent other Download the file "asteriodsGame.zip" in Black material. Unzip i the software is strictly a toy: there are no goals. Your task will be to design some structure to enhance the game. Try to consider goals does the player have in the game? Choice: what choies does the player make? Resources: what resources are t and try out the skeletal game, There is some basic activity, but the following questions: Goals: what in the game? How will the player spend the resources? How will new resources be acquired? Variety of Encounter: how can you increase the variety of encounter? Based on the above questions, add the following components to this game. 1. The harm of every bullet and the health of every asteroid. For example, if a bullet hits an asteroid, the asteroid will lose 10 points health. If an ast loses all health, it will be destroyed. (30 points) 2. Score and timer, which decide the outcome of the game. For example, only when score is greater than 100 and the elapsed time is less than 30 seconds, you win the game. You need to decide how to relate score with the number of asteroid, the health of an asteroid, and the number of bullets. (40 points) as 3. colsi sion happens (2o poin 3. Add audio effects to the game, such as background music and the sound effect when a collision happens. (20 points) 4. Add a screen of credits. Anytime when the players press a key (e.g c'), the can see an animated credit screen. An Tutorial 6. (10 points) example function is shown in the slides o you have to use: https://processing.org/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions

Question

What is meant by the hidden curriculum?

Answered: 1 week ago