Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am working on a project on Greenfoot. I am having trouble with Boss projectile

ID: 3837424 • Letter: I

Question

I am working on a project on Greenfoot. I am having trouble with Boss projectile since i need a timer for the Boss to shoot on the Player . I just need the Boss to constantly (timer) be shooting on the Player.

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class BossProjectile here.
*

* @version V1
*/
public class BossProjectile extends PreciseMotion
{
/**
* Act - do whatever the BossProjectile wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private DirectionPhysics velocity;
public static final DirectionPhysics GRAVITY = new DirectionPhysics(0.0,0.2);
private static final int GROUND_HEIGHT = GameManager.GROUND_HEIGHT - 60;
  
public BossProjectile()
{
this(new DirectionPhysics(-45,999));
}
public BossProjectile(DirectionPhysics velocity)
{
super(velocity);
}
public void act()
{
addToVelocity(GameManager.GRAVITY);
move();
checkHitTarget();
checkHit();
}
@Override protected void addedToWorld(World world)
{
setLocation(getX(), getY());
}

public void checkHit()
{
if(isTouching(Platform.class) || isAtEdge())
{
GameManager w = (GameManager) getWorld();
w.removeObject(this);
}
}
public void checkHitTarget()
{
Actor enemy = getOneIntersectingObject(Creature.class);
if (enemy != null)
{
GameManager world = (GameManager) getWorld();
//world.addObject(new Explosion(), target.getX(), target.getY());
world.removeObject(enemy);
//world.removeObject(this);
return; // in case of multiple if statements
}

}
}

Explanation / Answer

this.time = this.time + deltaTime;

// Vertical : Speed * Sine * Angle
double vy = (this.speed * maths.sin(this.angle)) + this.ax*this.time ;
// Horizontal : Speed * cos * Angle
double vx = (this.speed * maths.cos(this.angle)) + this.ay*this.time;

this.x = this.x + vx*this.time;
this.y = this.y + vy*this.time + this.ay*(this.time*this.time);

vx += this.ax * this.time;
vy += this.ay * this.time;
I'm forward I even have created some reasonably maths error in relevance the calculations because it looks the x price is correct, although the y price isn't coming down.

Here ar my initial values just in case you're wondering:

this.time = 0.0;
this.deltaTime = .0001;
this.x = 1.0;
this.y = 10;
this.speed = 60.0;
this.ay = -9.8;
this.angle = 45;
this.ax = 0.0;
this.speed = 60.0;
this.deltaTime = zero.0001;
this.endTime = ten.0;
this.x = 1.0;
this.y = 10;
this.ay = -9.8;
this.ax = 0;
this.angle = 45;
this.vx = this.speed*Math.cos(this.angle*(Math.PI/180.0))
this.vy = this.speed*Math.sin(this.angle*(Math.PI/180.0))

double time = zero.0;
while (time < this.endTime)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote