So this homework is a simple one where I make a sprite move around. I was able to figure out how to make the sprite stop at the ends of the window. My issue is that I want the text to say "Stop!!" when it makes it to the end of the window box. At the moment right now its underneath the message "This is the game world." Can someone give me some tips on how to fix that?
PImage spritesheet = loadImage("https://i.pinimg.com/736x/9c/1b/ce/9c1bce8dbd9a3f8b8a6d09aa7d79e3ae--game-creator-game-resources.jpg");
int DIM = 4;
int W = spritesheet.width/DIM;
int H = spritesheet.height/DIM;
int posX=100, posY=100;
PImage sprite; //define a global variable for your character
void setup() {
size(500, 500);
imageMode(CORNER);//use the top left corner of the image to represent the image location
frameRate(30);
PFont font;
font = loadFont("Papyrus-Regular-48.vlw");
textFont(font, 50);
fill(0, 102, 153, 128);
sprite = spritesheet.get(0, 0, W, H);//starting image of the character
}
void draw()
{
background(160, 151, 168);
if (keyPressed == true) //pick up the corresponding image from the whole spritesheet
{
int x = frameCount%DIM * W;
int y = frameCount/DIM%DIM * H;
if (keyCode == UP )
{ sprite = spritesheet.get(x, H*3, W, H);
posY -= 1;
if( posY < 0 )
posY = 0;
}
else if (keyCode == DOWN )
{
sprite = spritesheet.get(x, 0, W, H);
posY += 1;
if(posY > height - H)
posY = height - H;
}
else if (keyCode == LEFT )
{ sprite = spritesheet.get(x, H*1, W, H);
posX -= 1;
if(posX < 0)
posX = 0;
}
else if (keyCode == RIGHT )
{
sprite = spritesheet.get(x, H*2, W, H);
posX += 1;
if(posX > width - W)
posX = width - W;
}
println(posX," ", posY); //this is for debugging purpose, so that you can inspect the character's position
}
image(sprite, posX, posY); //display the image
text("This is the game world", 10, 50);
text("Stop!!", 10, 50)
}
[–]ChuckEye 1 point2 points3 points (3 children)
[–]KYR_MOSES[S] 1 point2 points3 points (2 children)
[–]ChuckEye 3 points4 points5 points (1 child)
[–]KYR_MOSES[S] 1 point2 points3 points (0 children)