We are about to switch to a new forum software. Until then we have removed the registration on this forum.
float linkX;
float linkY;
int state = 0;
PImage linkUp;
PImage linkDown;
PImage linkLeft;
PImage linkRight;
PImage linkImg;
PImage map;
PImage tile;
void setup () {
size(1024, 704);
linkUp = loadImage("link_Up.png");
linkDown = loadImage("link_Down_Shield.png");
linkImg = loadImage("link_Down_Shield.png");
linkLeft = loadImage("link_Left_Shield.png");
linkRight = loadImage("link_Right_Shield.png");
linkX = width/2;
linkY = height/2;
map = loadImage("map.png");
tile = map.get(1792, 1232, 256, 176);
tile.resize(1024, 704);
}
void draw () {
background(tile);
drawLink();
checkHotSpots();
fill(255);
text("mouseX = " + mouseX, 15, 15); //output mouse values
text("mouseY = " + mouseY, 15, 30);
}
void checkHotSpots() {
if (state == 0) { //Home Tile
fill(184, 134, 11);
ellipse(285, 95, 50, 65);
}
if (dist(linkX, linkY, 10, 350) < 90) { // Left tile
state = 1;
linkX = width - 80;
tile = map.get(1536, 1232, 256, 176);
tile.resize(1024, 704);
} else if (dist(linkX, linkY, 510, 0) < 90) { //Top tile
state = 2;
linkY = height - 80;
linkX = 500;
tile = map.get(1792, 1056, 256, 176);
tile.resize(1024, 704);
} else if (dist(linkX, linkY, 975, 350) < 90) { //Right tile
state = 3;
linkX = 80;
tile = map.get(2048, 1232, 256, 176);
tile.resize(1024, 704);
}
} else if (state == 1) {
fill(184, 134, 11);
rect(40, 130, 20, 445);
if (dist(linkX, linkY, 825, 40) < 90) {
state = 4;
linkY = 624;
tile = map.get(1536, 1056, 256, 176);
tile.resize(1024, 704);
}
} else if (state == 3) {
fill(184, 134, 11);
rect(930, 6, 20, 570);
if (linkY < 2) {
state = 5;
linkY = 685;
tile = map.get(2048, 1056, 256, 176);
tile.resize(1024, 704);
}
} else if (state == 5) {
fill(184, 134, 11);
rect(930, 6, 20, 570);
if (linkX < 2) {
linkX = 955;
state = 6;
tile = map.get(1792, 1056, 256, 176);
tile.resize(1024, 704);
}
}
}
void keyPressed() {
if ( key == CODED) {
if ( keyCode == UP) {
linkImg = linkUp;
linkY -= 15;
}
if ( keyCode == DOWN) {
linkImg = linkDown;
linkY += 15;
}
if ( keyCode == LEFT) {
linkImg = linkLeft;
linkX -= 15;
}
if ( keyCode == RIGHT) {
linkImg = linkRight;
linkX += 15;
}
}
}
void drawLink() {
pushMatrix();
translate(linkX, linkY);
scale(2.7);
image(linkImg, 0, 0);
popMatrix();
}
Answers
Use dist to detect if the guy is near the ellipse
Then set a boolean showText to true
Use if(showText) text("ghggg", 111,222);
to display the text
Also you can either set showText to false when he moves away or after a certain time period:
if(millis()-startTime>5000) showText=false;
Set startTime to millis() where you set showText to true
I'm not very good with boolean, could you type what I should put please!
before
setup()
:in
draw()
:Use
dist()
to detect if the guy is near the ellipse - Then setshowText
to true and set startTime tomillis()
:I made some additions
thanks
this calls for a class or for arrays: !!!!!!
in theory, treat each enemy like a ball and give it a movement vector
xSpeed, ySpeed and move it.
When it bounces into a wall say
xSpeed-=xSpeed;
etc.Check enemy against player with
dist()
please give me an example of what I should do! please!
before setup
in draw
could you write everything I have to do so I can understand completely what I need to do?
Just write all the code
did you get the concept?
you move an enemy by adding something to its position, so it moves...?
you need to add to Enemy3PosXand posY....
for all enemys
But how would I make it move randomly in different directions?
What variables will I have to create?
??
Whatever you like.
Those are all variables: the enemy pos, the speed etc. create them before setup or better make an enemy class