I’m a beginner in coding and I’m trying to make a game. I only have the very basics right now but I seem to be having a problem. Link (the character I’m using for the game) Isn’t showing up on the screen when I run the program and only shows when I press “a” or “d” to move left and right. I’m probably just forgetting to include some line of code but any help would be much appreciated. Thank you! (My code I have so far is below)
PImage[] rightImages=new PImage[6];
PImage[] leftImages=new PImage[6];
Float frame=0.0;
//x y for link
int[] link={80, 110};
boolean[] keys=new boolean[128];
boolean moveRight=false;
boolean moveLeft=false;
void setup() {
size(300, 300);
frameRate(60);
//loading all "right" images
for (int i=1; i<rightImages.length; i++) {
rightImages[i]=loadImage("linkright"+(i)+".png");
}
//loading all "left" images
for (int i=1; i<leftImages.length; i++) {
leftImages[i]=loadImage("linkleft"+(i)+".png");
}
}//end setup
void draw() {
background(200, 80, 50);
moveLink();
if (moveRight) {
image(rightImages[int(frame)], link[0], link[1]);
} else if (moveLeft) {
image(leftImages[int(frame)], link[0], link[1]);
}
frame+=0.1;
if (frame>6) {
frame=1.0;
}
}//end draw
void moveLink() {
if (keys[65]) {//65 is 'a' - move left
link[0]-=3;
moveLeft=true;
} else {
moveLeft=false;
}
if (keys[68]) {//68 is 'd' - move right
link[0]+=3;
moveRight=true;
} else {
moveRight=false;
}
}//end moveLink
void keyPressed() {
keys[keyCode]=true;
}
void keyReleased() {
keys[keyCode]=false;
}