Brief history,
Been working on a project for college and had manage to get the setImage() to work no problems in displaying an explosion if the players car and another collided, i then progressed on to try and create a damage bar that showed increasing damage for every collision detected as opposed to the game consisting of one impact and the game over screen being displayed, as it turned out the code i used somehow competed negated the checkcollision method and long story short i deleted everything back to before is started to create the damage bar, on problem now is the setImage does not seem to display the explosion when collision is detected, everything works fine, it compiles fine with no errors and runs as it should stopping the game when colliding with another car, playing an explosion sound and then displaying a game over screen, however as stated previously the explosion.png no longer displays in game as it used to before i tried to create a damage bar, any help on this matter would be appreciated, the file name is definitely spelled corrected and is located in the images folder of the project.
please find below my code for the Car class of which the checkCollision method is part of.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* This is the class of enemy car that the player has to avoid.
*
* @author (D. Green)
* @version (1.0)
*/
public class Car extends Actor
{
/*
* Constructor.
*/
public Car()
{
}
/*
* Act - do whatever the Car wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moveRight();
moveLeft();
moveUp();
moveDown();
checkCollision();
}
/*
* This method controls the movement of the car to the right.
*/
public void moveRight()
{
int x = getX();
int y = getY();
if (Greenfoot.isKeyDown("right"))
{
setLocation(x +2, y);
}
}
/*
* This method controls the players movement left.
*/
public void moveLeft()
{
int x = getX();
int y = getY();
if (Greenfoot.isKeyDown("left"))
{
setLocation(x -2, y);
}
}
/*
* This method controls the players movement left.
*/
public void moveUp()
{
int x = getX();
int y = getY();
if (Greenfoot.isKeyDown("up"))
{
setLocation(x , y -2);
}
}
/*
* This method controls the players movement left.
*/
public void moveDown()
{
int x = getX();
int y = getY();
if (Greenfoot.isKeyDown("down"))
{
setLocation(x , y +2);
}
}
public void checkCollision()
{
Actor crash = getOneIntersectingObject(Enemycar.class);
if(crash != null)
{
World myWorld = getWorld();
myWorld.removeObject(this);
Greenfoot.playSound("Explosion.wav");
setImage("explosion.png");
Greenfoot.stop();
Gameover gameover = new Gameover();
myWorld.addObject(gameover, myWorld.getWidth() / 2, myWorld.getHeight() / 2);
}
}
}

