Hi, so I’m working on a homework project, with a character shooting fireballs at walls to destroy them. I’ve been doing well with creating the characters and their projectiles, as well as detecting the collision between the projectiles and the walls. But now I want to change the sprite of the wall when it is shot, so that it gradually transform from a normal wall to a broken wall, to dust, and then to nothing. Can anyone help me with this?
Here are my codes for the walls.
import processing.core.PImage;
import processing.core.PApplet;
public abstract class wall {
protected int x;
protected int y;
protected PImage sprite;
protected int size;
public wall(int x, int y){
this.x = x;
this.y = y;
}
public void setSprite(PImage sprite) {
this.sprite = sprite;
}
public void draw(PApplet app){
app.image(this.sprite, this.x, this.y);
}
public int getX(){
return this.x;
}
public int getY(){
return this.y;
}
}
import processing.core.PImage;
import processing.core.PApplet;
public class brickwall extends wall {
public PImage sprite;
public brickwall(int x, int y){
super(x, y);
}
public boolean wallExist(){
return true;
}
}
First thing I noticed is that you declare your classes with a lower case name which might be confusing with other variable names. Instead use the PascalCase convention like Wall and BrickWall.
For that you need some kind of timer. When the wall is touched by a projectile, you trigger a variable to true and start counting time. Then each time you draw the wall, you display a different sprite depending on how close to the “end of life” limit a wall have.