Code: Select all
void setup() {
size(500, 500);
}
void draw() {
background(255);
player();
baddie();
baddie1();
GameOver();
}
/**void mouseClicked() {
background(255);
}
*/
Code: Select all
float speedX = 1;
float speedY = 1;
float spotX = 50;
float spotY = 50;
void baddie(){
fill(255,0,0);
ellipse(spotX,spotY,50, 50);
// allows ellipse to move
spotX = spotX + speedX;
spotY = spotY + speedY;
// allows Ellipse to change directions when hitting the borders of the draw
if(spotX > width - 25 || spotX < 25){
speedX = speedX * -1;
}
if(spotY > height - 25 || spotY < 25){
speedY = speedY * -1;
}
}
Code: Select all
float speedX1 = 1;
float speedY1 = 1;
float spotX1 = 50;
float spotY1 = 100;
void baddie1(){
fill(255,0,0);
ellipse(spotX1,spotY1,50, 50);
// allows ellipse to move
spotX1 = spotX1 + speedX1;
spotY1 = spotY1 + speedY1;
// allows Ellipse to change directions when hitting the borders of the draw
if(spotX1 > width - 25 || spotX1 < 25){
speedX1 = speedX1 * -1;
}
if(spotY1 > height - 25 || spotY1 < 25){
speedY1 = speedY1 * -1;
}
}
Code: Select all
void GameOver(){
if(spotX2 - 50 < spotX && spotY2 - 50 < spotY && spotX2 + 50 > spotX && spotY2 + 50 > spotY) {
background(0);
}
else if(spotX2 - 50 < spotX1 && spotY2 - 50 < spotY1 && spotX2 + 50 > spotX1 && spotY2 + 50 > spotY1) {
background(0);
println("hi");
}
}
Code: Select all
float speedX2 = 4;
float speedY2 = 4;
float spotX2 = 400;
float spotY2 = 100;
void player() {
fill(255,255,0);
ellipse(spotX2,spotY2,50,50);
// Allows player based movement.
if (keyPressed) {
if (key == 'w' || key == 'W') {
spotY2 = spotY2 - speedY2;
}
if (key == 's' || key == 'S') {
spotY2 = spotY2 + speedY2;
}
if (key == 'a' || key == 'A') {
spotX2 = spotX2 - speedX2;
}
if (key == 'd' || key == 'D') {
spotX2 = spotX2 + speedX2;
}
}
// Prevents player from leaving the map
if(spotX2 > width - 25){
spotX2 = spotX2 - 4;
}
if(spotY2 > height - 25){
spotY2 = spotY2 - 4;
}
if(spotX2 < width - 475){
spotX2 = spotX2 + 4;
}
if(spotY2 < height - 475){
spotY2 = spotY2 + 4 ;
}
}