Turning a human into a ZOMBIE!!!! (aka collision and if statement issues)
in
Programming Questions
•
6 months ago
Hi there!
I'm trying to create a simple simulation of a zombie appocolypse. There will be more people and zombies and hopefully a "zombie patrol" but I need to work this bug out first.
I want it so that if the "zombie" collides with the "citizen", the "citizen" becomes a zombie. The program won't let me convert one class into another and I tried displaying a new class but that won't work either.
Once I figure this out, this project should be all downhill from here! Any help would be GREATLY appreciated!!!
full code
// For this project, I want to simulate a zombie appocolypse. I will be using three objects to represent the zombies, average people and law enforcement.
//I want to make it so if a zombie touches (bites) a citizen, they will in turn become a zombie
//If a Zombie-Patrol person touches (shoots) a zombie, the zombie will die.
//if everything works properly, the game will end if everyone becomes a zombie or all the zombies die.
Zombie myZombie;
newZombie myNewZombie;
float zombieX;
float zombieXspeed = -.3;
float zombieY;
float zombieYspeed =-.3;
float zombieXspeed2 = -.1;
int zombieSize = 30;
Citizen myCitizen;
float citizenX;
float citizenXspeed = .3;
float citizenY;
float citizenYspeed = .3;
int citizenSize = 30;
void setup() {
size(500, 500);
//frameRate(30);
//randomize zombie location
zombieX = random(200,400);
zombieY = random(200,400);
//randomize citizen location
citizenX = random(20,355);
citizenY = random(20,355);
myZombie = new Zombie(zombieSize);
myCitizen = new Citizen(citizenSize);
//Zombie = ellipse(zombieX,zombieY);
}
void draw(){
background(0);
zombieX += zombieXspeed;
zombieY += zombieYspeed;
myZombie.display(zombieX, zombieY);
myZombie.display(zombieX+40, zombieY+40);
myZombie.display(zombieX+20, zombieY+20);
citizenX += citizenXspeed;
citizenY += citizenYspeed;
myCitizen.display(citizenX, citizenY);
myCitizen.display(citizenX-40, citizenY-60);
//scene wrapping for first zombie
if (zombieX > width + zombieSize/3){
zombieX = 0+ zombieSize/3;
}
if (zombieX < 0){
zombieX = width - zombieSize/3;
}
if (zombieY > height + zombieSize/3){
zombieY = 0+ zombieSize/3;
}
if (zombieY < 0){
zombieX = height - zombieSize/3;
}
if (zombieX+20 == citizenX+20 && zombieY+20 == citizenY+20){
myNewZombie.display(citizenX,citizenY);
citizenXspeed = -zombieXspeed;
citizenYspeed = -zombieYspeed;
}
}
zombie class
class Zombie { //class name
int r; //float zx, zy;
Zombie(int tempR) {
r = tempR;
}
//methods
void display(float zx, float zy) {
//Zombie;
fill(0,200,0);
ellipse(zx, zy, 20, 20); //zombies will be represented by green circles
}
}
citizen class
class Citizen { //class name
int rc; //float zx, zy;
Citizen(int tempRc) {
rc = tempRc;
}
//methods
void display(float cx, float cy) {
//Zombie;
fill(241,217,120);
ellipse(cx, cy, 20, 20); //zombies will be represented by green circles
}
}
attempted "New Zombie" class
class newZombie { //class name
int rnz; //float zx, zy;
newZombie(int tempRnz) {
rnz = tempRnz;
}
//methods
void display(float nzx, float nzy) {
//Zombie;
fill(0,200,0);
ellipse(nzx, nzy, 20, 20); //zombies will be represented by green circles
}
}
1