How do i calculate the mouseX mouseY to track a shield around the player?

I've done tons of things and as far as i know this goes briefly into calculus. I am way out of my depth with this. How do i calculate the mouseX mouseY to make a shield around P1X and P1Y tied lets say 20 pixels away from the center of the player. The problem isn't the shield itself, it's making the movement work.

Tagged:

Answers

  • The problem isn't the shield itself, it's making the movement work.

    What do you mean by "the movement"? Do you mean you are trying to align the shield each draw, e.g.

    ellipse(P1X, P1Y, 20, 20)
    

    Or do you mean you are trying to calculate collision detection of some object class against the shield?

    You may need to share your code. If so, please format it correctly:

    https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text#latest

  • For now, i am just trying to get the shield to display around the circle. The code right there is exactly right jeremy and i can't figure out how to display it correctly

  • edited January 2017

    @Darthbray --

    You need to share your code for specific advice and describe what it is doing, and what you want it to be doing instead -- I don't know what "getting it to work" or "how to display it correctly" means -- it could mean anything!

    Here is my best based on what you have described thus far:

    int playerSize = 10;
    int shieldSize = 30;
    
    void setup(){
      stroke(255);
    }
    void draw() {
      int P1X = mouseX;
      int P1Y = mouseY;
      background(0);
    
      fill(255,0,0); // make the player red
      ellipse(P1X, P1Y, playerSize, playerSize); // player  
    
      noFill(); // make the shield hollow so it doesn't cover the player
      ellipse(P1X, P1Y, playerSize + shieldSize, playerSize + shieldSize); // shield
    }
    
  • edited January 2017 Answer ✓

    this puts a triangular shield between the player and mouse

    The shield protects the player against an attack from the mouse

    Did you mean this?

    float angle;
    PVector d = new PVector();
    
    void setup() {
      size(600, 600);
    }
    
    void draw()
    {  
      background(0);
    
      translate(width/2, height/2);
    
      d.x = mouseX - width/2;
      d.y = mouseY - height/2;
    
      angle = atan2(d.y, d.x);
    
      triangle_(angle);
    }
    
    void triangle_(float ang)
    {
      pushMatrix();
    
      rotate(ang);
    
      fill(255); // white shield 
      triangle(60, 0, 
        80, -30, 
        80, 30);
    
      fill(255, 0, 0); // red  
      ellipse(0, 0, 
        30, 30);
    
      popMatrix();
    }
    
  • You have given too little information to possibly answer your question. We just end up guessing and double guessing what you want.

Sign In or Register to comment.