Okay so I have a walk method that randomly walks up down left and right but only move to one tile? How would i make it walk say 10 tiles without it spawning to 10 tiles...
Npc class
Please post anything that could help fix this bug and some code if you could would really help. ThanksCode:package org.npc;
import java.awt.Image;
import java.util.Random;
import javax.swing.ImageIcon;
public class Npc {
Image npc;
final ImageIcon frontIcon = new ImageIcon(System.getProperty("user.home") + "/Desktop/GAME/NPC/HOME_FRONT.png");
final ImageIcon backIcon = new ImageIcon(System.getProperty("user.home") + "/Desktop/GAME/NPC/HOME_BACK.png");
final ImageIcon rightIcon = new ImageIcon(System.getProperty("user.home") + "/Desktop/GAME/NPC/HOME_RIGHT.png");
final ImageIcon leftIcon = new ImageIcon(System.getProperty("user.home") + "/Desktop/GAME/NPC/HOME_LEFT.png");
int action = 1;
int x, y;
int dx = 0;
int dy = y;
public Npc() {
x = 230;
y = 187;
npc = state();
}
public Image state() {
if (action == 1) {
return frontIcon.getImage();
} else if (action == 2) {
return backIcon.getImage();
} else if (action == 3) {
return rightIcon.getImage();
} else if (action == 4) {
return leftIcon.getImage();
}
return npc;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public void move() {
x += dx;
y += dy;
}
public void walk() {
Random rand = new Random();
int r = rand.nextInt(201);
if (r <= 25) {
for(int x = 0 ; x < 10 ; x++) {
walkUp();
}
} else if (r <= 50) {
for(int x = 0 ; x < 10 ; x++) {
walkDown();
}
} else if (r <= 75) {
for(int x = 0 ; x < 10 ; x++) {
walkLeft();
}
} else if (r <= 100) {
for(int x = 0 ; x < 10 ; x++) {
walkRight();
}
} else if (r <= 200) {
for(int x = 0 ; x < 10 ; x++) {
rest();
}
}
System.out.println("Random #=" + r);
}
public void walkUp() {
action = 2;
dy = -1;
}
public void walkDown() {
action = 1;
dy = 1;
}
public void walkRight() {
action = 3;
dx = 1;
}
public void walkLeft() {
action = 4;
dx = -1;
}
public void rest() {
dx = 0;
dy = 0;
}
}
