logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

These questions involve the java based Processing language, used for visual design.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

These questions involve the java based Processing language, used for visual design.

Examine the attached java based Processing code that fires 3 "bullets" in the direction of where the mouse is clicked. Make the following alterations: 1. Change it so that only 1 "bullet" fires per mouseclick instead of 3. 2. Make the number of "bullets" finite rather than infinite, so that only 30 "bullets" can be fired in total. Print the number of "bullets" to the screen, so that the count can be seen as they decline from 30 to 0. 3. Challenge task: instead of the "bullets" disappearing offscreen, have each one stop at the exact location of the mouseclick that "fired it", disappear and in the same location that it disappeared a circle appears which expands from a small to a larger diameter and then contracts to nothing within a span of about 3 seconds. Make sure to include comments to justify the necessary changes.

The jave processing code is as follows: //Objects Player player = new Player(); //Bullet arraylist ArrayList bullets; //Vars to regulate shooting speed boolean canShoot = true; float canShootCounter; int i; void setup() { size(600, 600); //standard array setup bullets = new ArrayList(); player = new Player(); } void draw() { player.update(); background(100); //since we are adding and removing objects so often, we need to do the forloop backwards preventing any nullPointer errors for (i = bullets.size()-1; i >= 0; i--)

{ //you need a seperate var to get the object from the bullets arraylist then use that variable to call the functions Bullet bullet = bullets.get(i); bullet.update(); } } class Player { PVector location; Player() { location = new PVector(width/2, height/2); } void update() { if (mousePressed == true) { // this regulates the shooting speed if (canShoot == true) { bullets.add( new Bullet()); canShoot = false; canShootCounter = 0; } } // this checks if the right amount of time has passed before canShoot can = true again if (canShoot == false) { canShootCounter ++; //if the right amount of time has passed. make canShoot true if (canShootCounter == 5)/*change this number to change the duration*/{ canShoot = true; } } } } class Bullet { //standard PVector used for the location of the bullet PVector location;

//vars used to check the angle between location and the mouse float oldPosX, oldPosY, rotation, speed; Bullet() { //places the bullet at the mouth of battery location= new PVector(width/2, height-100); //this checks the angle oldPosX = mouseX; oldPosY = mouseY; rotation = atan2(oldPosY - location.y, oldPosX - location.x) / PI * 180; //bullet speed speed = 5;//change this number to change the speed } void update() { //move the bullet location.x = location.x + cos(rotation/180*PI)*speed; location.y = location.y + sin(rotation/180*PI)*speed; ellipse(location.x, location.y, 10, 10); //removes the bullet from the arrayList if it is off the room if (location.x > 0 && location.x < width && location.y > 0 && location.x < height) { } else { bullets.remove(i); } } }

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

923 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

679 Answers

Hire Me
expert
Husnain SaeedComputer science

632 Answers

Hire Me
expert
Atharva PatilComputer science

693 Answers

Hire Me

Get Free Quote!

312 Experts Online