Question: Hello, I ' m having issues implementing my animation timer and getting my program to run. This program is suppose to mimic the game asteroids.
Hello, Im having issues implementing my animation timer and getting my program to run. This program is suppose to mimic the game asteroids. Can someone help fix my line of code below so it runs properly? In JAVA.
public abstract class Character
private Polygon character;
private PointD movement;
public CharacterPolygon polygon, int x int y
this.character polygon;
this.character.setTranslateXx;
this.character.setTranslateYy;
this.movement new PointD;
public Polygon getCharacter
return character;
public void turnLeft
this.character.setRotatethischaracter.getRotate;
public void turnRight
this.character.setRotatethischaracter.getRotate;
public void move
this.character.setTranslateXthischaracter.getTranslateX this.movement.getX;
this.character.setTranslateYthischaracter.getTranslateY this.movement.getY;
Wrap around the screen
if thischaracter.getTranslateX
this.character.setTranslateXthischaracter.getTranslateX AsteroidsApplication.LEVEYS;
if thischaracter.getTranslateX AsteroidsApplication.LEVEYS
this.character.setTranslateXthischaracter.getTranslateX AsteroidsApplication.LEVEYS;
if thischaracter.getTranslateY
this.character.setTranslateYthischaracter.getTranslateY AsteroidsApplication.KORKEUS;
if thischaracter.getTranslateY AsteroidsApplication.KORKEUS
this.character.setTranslateYthischaracter.getTranslateY AsteroidsApplication.KORKEUS;
public void accelerate
double changeX Math.cosMathtoRadiansthischaracter.getRotate;
double changeY Math.sinMathtoRadiansthischaracter.getRotate;
changeX ;
changeY ;
this.movement this.movement.addchangeX changeY;
public class AsteroidsApplication extends Application
public static int WIDTH ;
public static int HEIGHT ;
public static int BUFFERSIZE ; Buffer size for animation timer
public static int LEVEYS ; Placeholder value
public static int KORKEUS ; Placeholder value
private List pressedKeys new ArrayList;
private List projectiles new ArrayList;
private List asteroids new ArrayList;
private Ship ship;
@Override
public void startStage stage throws Exception
Pane pane new Pane;
pane.setPrefSizeWIDTH HEIGHT;
ship new ShipWIDTH HEIGHT ;
for int i ; i ; i
Random rnd new Random;
Asteroid asteroid new AsteroidrndnextIntWIDTH rndnextIntHEIGHT;
asteroids.addasteroid;
pane.getChildrenaddshipgetCharacter;
asteroids.forEachasteroid pane.getChildrenaddasteroidgetCharacter;
Scene scene new Scenepane;
scene.setOnKeyPressedevent
KeyCode keyCode event.getCode;
if pressedKeys.containskeyCode
pressedKeys.addkeyCode;
;
scene.setOnKeyReleasedevent pressedKeys.removeeventgetCode;
stage.setScenescene;
stage.show;
new AnimationTimer
@Override
public void handlelong now
if pressedKeyscontainsKeyCodeLEFT
ship.turnLeft;
if pressedKeyscontainsKeyCodeRIGHT
ship.turnRight;
if pressedKeyscontainsKeyCodeUP
ship.accelerate;
ship.move;
asteroids.forEachAsteroid::move;
projectiles.forEachProjectile::move;
asteroids.forEachasteroid
if shipcollideasteroid
stop;
;
start;
public static void mainString args
launchargs;
public class Ship extends Character
public Shipint x int y
supernew Polygon x y;
public class Projectile extends Character
public Projectileint x int y
supernew Polygon x y;
public class PolygonFactory
public Polygon createPolygon
Random rnd new Random;
double size rndnextInt;
Polygon polygon new Polygon;
double c Math.cosMathPI ;
double c Math.cosMathPI ;
double s Math.sinMathPI ;
double s Math.sinMathPI ;
polygon.getPointsaddAll
size,
size c size s
size c size s
size c size s
size c size s;
for int i ; i polygon.getPointssize; i
int change rndnextInt;
polygon.getPointsseti polygon.getPointsgeti change;
return polygon;
public class Asteroid extends Character
private double rotationalMovement;
public Asteroidint x int y
supernew PolygonFactorycreatePolygon x y;
Random rnd new Random;
super.getCharactersetRotaterndnextInt;
int accelerationAmount rndnextInt;
for int i ; i accelerationAmount; i
accelerate;
this.rotationalMovement rndnextDouble;
@Override
public void move
super.move;
super.getCharactersetRotatesupergetCharactergetRotate rotationalMovement;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
