How would I be able to make text show up when the player goes on the ellipse in state 0?

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();
}
Tagged:

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!

  • edited March 2017 Answer ✓

    before setup():

    boolean showText = false; 
    int startTime; 
    

    in draw():

    if(showText) text("ghggg", 111,222);
    if(millis()-startTime>5000) showText=false;
    

    Use dist() to detect if the guy is near the ellipse - Then set showText to true and set startTime to millis() :

    if(dist(linkX,linkY,...,....) < 30) {
        showText = true;
        startTime=millis();
    }
    
  • Answer ✓

    I made some additions

  • this calls for a class or for arrays: !!!!!!

    PImage Enemy1Down;
    PImage Enemy1Up;
    PImage Enemy1Right;
    PImage Enemy1Left;
    
    PImage Enemy2Down;
    PImage Enemy2Up;
    PImage Enemy2Right;
    PImage Enemy2Left;
    
    PImage Enemy3Down;
    PImage Enemy3Up;
    PImage Enemy3Right;
    

    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

        Enemy3PosX=55; 
        Enemy3PosY=155; 
    

    in draw

        Enemy3PosX+=Enemy3SpeedX;
    
  • 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?

  • int direction = int(random(4));
    
    switch (direction) {
    
    case 0:
      //north
      Enemy3SpeedX=0;
      Enemy3SpeedY=-1;
      break; 
    
    case 1:
      //east
      Enemy3SpeedX=1;
      Enemy3SpeedY=0;
      break; 
    
    case 2:
      //south
      Enemy3SpeedX=0;
      Enemy3SpeedY=-1;
      break; 
    
    case 3:
      //west
      Enemy3SpeedX=-1;
      Enemy3SpeedY=0;
      break;
    }
    
  • What variables will I have to create?

  • Answer ✓

    ??

    Whatever you like.

    Those are all variables: the enemy pos, the speed etc. create them before setup or better make an enemy class

Sign In or Register to comment.