In my class we are trying to design a video game, and I’m trying to use code a laser beam that an enemy shoots. The laser is meant to start at the eye, and rotate 90 degrees in the direction of of player. In my code, I’ve been able to make the laser rotate like I want to, but the hit box of the image stays in place. This is the code I’ve gotten so far.
abstract class Projectile extends GameObject
{
Projectile(float x, float y, float w, float h, float xSpeed, float ySpeed)
{
super(x, y, w, h);
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
}
}
abstract class EnemyProjectile extends Projectile
{
EnemyProjectile(float x, float y, float w, float h, float xSpeed, float ySpeed)
{
super(x, y, w, h, xSpeed, ySpeed);
}
void reactions()
{
for (int x = 0; x < collisions.size (); x++)
{
GameObject o = collisions.get(x);
if (o instanceof Player)
{
die();
}
if (x<0 || x > width || y < 0 || y > height)
{
die();
}
}
}
void act()
{
super.act();
if (x<0 || x > width || y < 0 || y > height)
{
die();
}
}
}
class IceBeam extends EnemyProjectile
{
private float cx;
private float cy;
private float r;
private int beamTimer;
private float rotate;
IceBeam(float x, float y)
{
super(x, y, iceBeam.width, iceBeam.height, 0, 0);
image = iceBeam;
beamTimer = 0;
rotate = 0;
cx = x;
cy = y;
}
void act()
{
super.act();
}
void render()
{
if (beamTimer < 75)
{
pushMatrix();
for (GameObject o : objects)
{
if (o instanceof IceCreature)
{
translate(o.x+(iceCreature.width/2), o.y+(iceCreature.height/2) - 45);
}
}
for (GameObject b : objects)
{
if (b instanceof Player)
{
if (b.x >= x)
{
rotate-=.02;
} else if (b.x < x)
{
rotate+=.02;
}
}
}
rotate(rotate);
image(iceBeam, x +(iceBeam.width/2), y + (iceCreature.height/2));
popMatrix();
}
if (beamTimer >= 75)
{
die();
}
beamTimer++;
}
void reactions()
{
super.reactions();
}
}