-
-
Save niiicolai/132af98673f96ea33671593c769ad389 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
// Current position | |
PVector position; | |
// Movement direction | |
float yDir; | |
// Size | |
float w = 10; | |
float h = 25; | |
// Boundaries | |
float b = 15; | |
// Player constructor | |
public Player(float x, float y, float yDir) { | |
this.position = new PVector(x, y); | |
this.yDir = yDir; | |
} | |
// Setter Methods | |
public void setDirection(float yDir) { | |
this.yDir = yDir; | |
} | |
// Getter Methods | |
public PVector getPosition() { | |
return position; | |
} | |
public float getHeight() { | |
return h; | |
} | |
public float getWidth() { | |
return w; | |
} | |
// Update behavior | |
public void update() { | |
// Update player position | |
position.y += yDir; | |
// Have the player reached | |
// the top? | |
if (position.y < b) { | |
// Stop movement at the top | |
position.y = b; | |
// Have the player reached | |
// the bottom? | |
} else if (position.y > height-b-h) { | |
// Stop the movement at the bottom | |
position.y = height-b-h; | |
} | |
// Set player color to white | |
fill(255); | |
// Draw rectangle | |
rect(position.x, position.y, w, h); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment