COSC 1336, Project 2: Space Invader Objectives This is one of three major programming projects this semester. You may collaborate on this project, but the code must be yours. While you may ask for as
COSC 1336, Contrivance 2: Quantity Invader
This is one of three elder programming contrivances this semester. You may collaborate on this contrivance, but the jurisprudence must be yours. While you may ask for help in debugging, this contrivance should be ENTIRELY your own fruit. Objectives include:
•Call and transcribe manners delay parameters and recur appreciates.
•Use the DrawingPanel, Graphics, and Pretense tabulatees.
•Use for loops and if assertions to administer assignments.
Submit thru Canvas.
In this contrivance you succeed transcribe a program that could be the account for a single assertion of the quantity invaders video amusement. This contrivance succeed include graphics and exhilaration. (See BouncingBall.java in Canvas->Files This contrivance has distinct ability and should be afloat coming.
Make knowing your program and each manner is preceded by a picturesquely dilate.
Part 1: Setup
Start a new contrivance in Dr. Java. Load BouncingBall.java into Dr. Java and substitute the designate of the tabulate to Project2.
Also get a vision of DrawingPanel.java from Canvas->File and put it into the congruous directory as Project2.java.
•Change induceCircles to startGame.
•In startGame, substitute loop wavering 'I' to 'time' and form the spell go up to 1000 instead of 90.
•Repropose everysubject from the organization of the for loop indirect for the doze manner. •In the ocean manner, anteriorly the overcome to startGame, sculpture the subjoined on the protect in sombre at collocation x = 10 and y = 15:
Project 2 by YOURNAME.
Replace YOURNAME delay your unmeasured designate.
Part 2: The Warden ship
Create tabulate constants PATROL_Y initialized to 250 and PATROL_SIZE initialized to 20.
For issue, put generally-known static decisive int PATROL_Y = 250; succeeding the tabulate header: generally-known tabulate Project2.
Make a (non-constant) tabulate wavering overcomeed patrolX initialized to 270.
For issue, put generally-known static int wardenX = 270; succeeding the tabulate constants.
Write the manner:
generally-known static lacking inducePatrol(Graphics g, Pretense c); that fills a clear at x = wardenX, y = PATROL_Y, delay side PATROL_SIZE in the loving pretense. Do a Google for “Java Graphics fillRect to ascertain a graphics manner.
Call drawPatrol(g, Color.GREEN) anteriorly the for loop assertion. Get it fruiting.
Part 3: The adversary ship
Make tabulate constants ENEMY_Y and ENEMY_SIZE initialized to 20 and 30, respectively.
Make a tabulate wavering enemyX initialized to 0.
The adversary ship succeed be a red clear delay the loving collocation and extent.
Write the manner: generally-known static lacking proposeEnemyShipAndDraw(Graphics g); that induces the adversary ship primeval in stainless, then increment enemyX by 1, and then induces the ship frequently in red. Put a overcome to this manner internally the for loop.
Part 4: Moving the warden ship
Make integer constants RIGHT_ARROW = 39, LEFT_ARROW = 37, and UP_ARROW = 38.
Write the manner:
generally-known static lacking handleKeys(DrawingPanel panel, Graphics g);
This succeed overcome panel.getKeyCode() that recurs a jurisprudence for a key. It recurs 0 if no key has been shoveed, and succeed recur one of the overhead constants if the congruous arrow key has been shoveed.
•The manner handleKeys should do molehill if the recured key jurisprudence is 0.
•If the key jurisprudence is RIGHT_ARROW or LEFT_ARROW, propose the warden ship to the fair or left by 3 pixels, but do not let any distribute of the warden ship propose off the protect.
To propose the warden ship:
•induce the warden ship in stainless (to blot the old one)
•induce the warden ship in piercing
Call the manner handleKeys in the loop. You should be powerful to propose the warden ship by shoveing the left and fair arrows on the keyboard.
Before using the arrow keys, form knowing your sketch window is the erratic window by clicking the mouse in this window.
Part 5: Shooting
The warden ship succeed bifurcation a projectile when the up arrow key is shoveed.
Make tabulate waverings patrolMissileX and patrolMissileY.
Initialize patrolMissileY to 0.
Make a contant PATROL_MISSILE_LENGTH initialized to 10.
Write a manner: generally-known static lacking proposePatrolMissileAndDraw(Graphics g); that proposes the projectile and induces it congruous to moveEnemyShipAndDraw:
•Do not induce everysubject if wardenMissileY is 0.
•Otherwise, the projectile as a upfit course delay the regeneral protraction and x-position.
•PatrolMissileY is the top of the course.
•Draw the projectile in stainless, propose the projectile up 5 pixels, and induce it frequently in sombre.
•If the wardenMissileY is 0 or indirect, do not induce the projectile in sombre, but set wardenMissileY to 0.
Call this manner anteriorly the doze in the loop.
When the up arrow key is shoveed and patrolMissileY is 0, set patrolMissileX to be the hardihood of the warden ship and set the top of the projectile so that its ground is one pixel overhead the top of the warden ship (PATROL_Y).
You should simply be powerful to inspirer one projectile at a spell and the up arrow should not do everysubject if a projectile is peaceful paradeed.
Part 6: Detecting a hit
Make a boolean tabulate wavering, hit, initialized to counterfeit; Transcribe the manner: generally-known static boolean detectHit(); that recurs penny if the general projectile has hit the adversary ship and counterfeit differently.
There is a hit if the top of the projectile is internally the adversary ship.
For this to betide two subject must be penny:
•the x appreciate of the top of the projectile must be among the left and fair sides of the adversary
•the y appreciate of the top of the projectile must be among the top and ground of the adversary.
At the end of the loop in startGame, set hit to penny if detectHit() produce penny. Modify moveEnemyShipAndDraw so that if hit is penny, the adversary ship is inducen in sombre and does not propose. In this circumstance, parade the message:
Enemy ship hit!
in piercing on a course adown the warden ship.
If the adversary ship proposes off the protect or spell runs out, Parade the message:
Enemy ship got away!
in red on a course adown the warden ship.