Created
February 24, 2016 21:36
-
-
Save sabotai/3052b469d50ad8d5a572 to your computer and use it in GitHub Desktop.
GD105 Week 4 - Collisions, Conditionals
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
PImage creep; //make a new image called creep | |
int creepX, creepY; //make 2 new integers to track X and Y of creep | |
PImage newCreep; //second image container for arnold | |
Boolean collision; //is the collision happening? T/F | |
void setup(){ | |
size(1280,720); | |
creep = loadImage("cagey.png"); //make sure your image is in the data folder | |
newCreep = loadImage("arnold.png"); | |
creepX = width/2; //creep should be drawn in the middle | |
creepY = height/2; //same | |
collision = false; //do not collide by default | |
} | |
void draw(){ | |
background(100); //clear the background each frame | |
if ((mouseX >= (creepX - creep.width/2)) && //this condition must be true | |
(mouseX <= (creepX + creep.width/2)) && | |
(mouseY >= (creepY - creep.height/2)) && | |
(mouseY <= (creepY + creep.height/2))){ //and (&&) this must also be true | |
collision = true; | |
} else { //if those things were not true, do this other thing | |
collision = false; //do not do collision things | |
} | |
rectMode(CENTER);//draw it from the center | |
rect(creepX, creepY, creep.width, creep.height); //draw the rect in the same place we will draw the image, with the same width and height | |
imageMode(CENTER); //we are giving the center x and y positions | |
if (collision){ //is our variable, collision, true? | |
//how do i draw a creep? | |
image(newCreep, creepX, creepY); //draw the new creep | |
creepX++; //move the image to the right | |
} else { | |
image(creep, creepX, creepY); //if no collision, draw regular creep | |
} | |
//how can i detect when the player is hovering over cage? | |
//println(creep.width); | |
line(mouseX, 0, mouseX, height); //X crosshair | |
line(0, mouseY, width, mouseY); //Y crosshair | |
text("(" + mouseX + "," + mouseY + ")", mouseX, mouseY); //tell us the position in text form | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment