xxxxxxxxxx
412
var x = 300;
var y = 200;
var gameOver = false;
var direction = 37;
var auto = false;
//comp vars
var comX = 100;
var comY = 200;
var comdirection = 39;
//comp vars 2
var comX2 = 200;
var comY2 = 100;
var comdirection2 = 40;
//comp var 3
var comX3 = 200;
var comY3 = 300;
var comdirection3 = 38;
//kill all the bots
var dead1 = false;
var dead2 = false;
var dead3 = false;
//check for level
var check = 0;
function setup() {
createCanvas(400, 400);
background(0, 0, 255);
fill(0);
rect(10, 10, 380, 380);
textAlign(CENTER);
frameRate(30);
}
function varabiles() {
x = 300;
y = 200;
dead1 = false;
dead2 = false;
dead3 = false;
gameOver = false;
direction = 37;
frameCount = 0;
}
function level0(){
comX = 100;
comY = 200;
comdirection = 39;
comX2 = 200;
comY2 = 100;
comdirection2 = 40;
comX3 = 200;
comY3 = 300;
comdirection3 = 38;
}
function level(){
comX = 300;
comY = 300;
comdirection = 38;
comX2 = 156;
comY2 = 100;
comdirection2 = 37;
comX3 = 342;
comY3 = 123;
comdirection3 = 40;
}
function level2(){
comX = 321;
comY = 145;
comdirection = 37;
comX2 = 315;
comY2 = 45;
comdirection2 = 39;
comX3 = 143;
comY3 = 61;
comdirection3 = 38;
}
function level3(){
comX = 213;
comY = 312;
comdirection = 39;
comX2 = 213;
comY2 = 31;
comdirection2 = 40;
comX3 = 100;
comY3 = 300;
comdirection3 = 38;
}
function level4(){
comX = 103;
comY = 231;
comdirection = 39;
comX2 = 314;
comY2 = 40;
comdirection2 = 40;
comX3 = 76;
comY3 = 31;
comdirection3 = 39;
}
function draw() {
if (gameOver === true) {
return;
}
if (dead1 === true && dead2 === true && dead3 === true) {
stroke(255, 0, 0);
textSize(24);
text("You Win", 200, 100);
gameOver = true;
}
ob();
human();
computer();
computer2();
computer3();
whatLevel();
}
function notBlack(x, y) {
let a = get(x, y);
if (a[0] !== 0) return true;
else if (a[1] !== 0) return true;
else if (a[2] !== 0) return true;
return false;
}
function keyPressed() {
if (keyCode >= 37 && keyCode <= 40) {
direction = keyCode;
}
if (key === "r") {
varabiles();
background("blue");
fill(0);
stroke(0);
rect(10, 10, 380, 380);
check = check + 1;
if(check === 0){
level0();
}else if(check === 1){
level();
}else if(check === 2){
level2();
}else if(check === 3){
level3();
}else if(check >=4){
level4();
level5ob();
}
}
if (key === "a") {
if (auto === true) {
auto = false;
} else if (auto === false) auto = true;
}
}
function ob() {
stroke(255);
fill(95, 36, 213);
rect(190, 190, 20, 20);
}
function selfDrive() {
if (direction === 37 && notBlack(x - 2, y) === true) {
direction = 38;
} else if (direction === 38 && notBlack(x, y - 2) === true) {
direction = 39;
} else if (direction === 39 && notBlack(x + 2, y) === true) {
direction = 40;
} else if (direction === 40 && notBlack(x, y + 2) === true) {
direction = 37;
}
}
function human() {
if (notBlack(x, y) === true) {
gameOver = true;
fill(255, 0, 0);
stroke(235, 162, 134);
fill(255, 0, 0);
ellipse(x, y, 20);
stroke(255, 0, 0);
textSize(24);
text("You lose", 200, 100);
check = -1;
}
stroke(255);
strokeWeight(2);
point(x, y);
if (direction === 37) {
//left
x = x - 2;
}
if (direction === 38) {
//up
y = y - 2;
}
if (direction === 39) {
//right
x = x + 2;
}
if (direction === 40) {
//down
y = y + 2;
}
if (auto === true) {
selfDrive();
}
}
function computer() {
if (comnotBlack(comX, comY) === true) {
dead1 = true;
fill(255, 0, 0);
stroke(235, 162, 134);
fill(255, 0, 0);
ellipse(comX, comY, 20);
return;
}
stroke(152, 56, 123);
strokeWeight(2);
point(comX, comY);
computerSelfDrive();
if (comdirection == 37) {
//left
comX = comX - 2;
}
if (comdirection == 38) {
//up
comY = comY - 2;
}
if (comdirection == 39) {
//right
comX = comX + 2;
}
if (comdirection == 40) {
//down
comY = comY + 2;
}
}
function comnotBlack(comX, comY) {
let a = get(comX, comY);
if (a[0] !== 0) return true;
else if (a[1] !== 0) return true;
else if (a[2] !== 0) return true;
return false;
}
function computerSelfDrive() {
if (comdirection === 37 && comnotBlack(comX - 2, comY) === true) {
comdirection = 38;
} else if (comdirection === 38 && comnotBlack(comX, comY - 2) === true) {
comdirection = 39;
} else if (comdirection === 39 && comnotBlack(comX + 2, comY) === true) {
comdirection = 40;
} else if (comdirection === 40 && comnotBlack(comX, comY + 2) === true) {
comdirection = 37;
}
}
function computer2() {
if (com2notBlack(comX2, comY2) === true) {
dead2 = true;
fill(255, 0, 0);
stroke(235, 162, 134);
fill(255, 0, 0);
ellipse(comX2, comY2, 20);
return;
}
stroke(41, 213, 93);
strokeWeight(2);
point(comX2, comY2);
computerSelfDrive2();
if (comdirection2 == 37) {
//left
comX2 = comX2 - 2;
}
if (comdirection2 == 38) {
//up
comY2 = comY2 - 2;
}
if (comdirection2 == 39) {
//right
comX2 = comX2 + 2;
}
if (comdirection2 == 40) {
//down
comY2 = comY2 + 2;
}
}
function com2notBlack(comX2, comY2) {
let a = get(comX2, comY2);
if (a[0] !== 0) return true;
else if (a[1] !== 0) return true;
else if (a[2] !== 0) return true;
return false;
}
function computerSelfDrive2() {
if (comdirection2 === 37 && com2notBlack(comX2 - 2, comY2) === true) {
comdirection2 = 38;
} else if (comdirection2 === 38 && com2notBlack(comX2, comY2 - 2) === true) {
comdirection2 = 39;
} else if (comdirection2 === 39 && com2notBlack(comX2 + 2, comY2) === true) {
comdirection2 = 40;
} else if (comdirection2 === 40 && com2notBlack(comX2, comY2 + 2) === true) {
comdirection2 = 37;
}
}
function computer3() {
if (com3notBlack(comX3, comY3) === true) {
dead3 = true;
fill(255, 0, 0);
stroke(235, 162, 134);
fill(255, 0, 0);
ellipse(comX3, comY3, 20);
return;
}
stroke(135, 153, 69);
strokeWeight(2);
point(comX3, comY3);
computerSelfDrive3();
if (comdirection3 == 37) {
//left
comX3 = comX3 - 2;
}
if (comdirection3 == 38) {
//up
comY3 = comY3 - 2;
}
if (comdirection3 == 39) {
//right
comX3 = comX3 + 2;
}
if (comdirection3 == 40) {
//down
comY3 = comY3 + 2;
}
}
function com3notBlack(comX3, comY3) {
let a = get(comX3, comY3);
if (a[0] !== 0) return true;
else if (a[1] !== 0) return true;
else if (a[2] !== 0) return true;
return false;
}
function computerSelfDrive3() {
if (comdirection3 === 37 && com3notBlack(comX3 - 2, comY3) === true) {
comdirection3 = 38;
} else if (comdirection3 === 38 && com2notBlack(comX3, comY3 - 2) === true) {
comdirection3 = 39;
} else if (comdirection3 === 39 && com3notBlack(comX3 + 2, comY3) === true) {
comdirection3 = 40;
} else if (comdirection3 === 40 && com3notBlack(comX3, comY3 + 2) === true) {
comdirection3 = 37;
}
}
function whatLevel(){
if(check === 0){
stroke(255);
fill("Green");
rect(0, 0, 75, 25);
fill(255);
text("Level 1", 37, 20);
}else if(check === 1){
stroke(255);
fill("Green");
rect(0, 0, 75, 25);
fill(255);
text("Level 2", 37, 20);
}else if(check === 2){
stroke(255);
fill("Green");
rect(0, 0, 75, 25);
fill(255);
text("Level 3", 37, 20);
}else if(check === 3){
stroke(255);
fill("Green");
rect(0, 0, 75, 25);
fill(255);
text("Level 4", 37, 20);
}else if(check >= 4){
stroke(255);
fill("Green");
rect(0, 0, 75, 25);
fill(255);
text("Level 5", 37, 20);
}
}
function level5ob(){
stroke(255);
fill(125, 12, 2158);
rect(310, 190, 10, 30);
fill(12, 41, 521);
rect(51, 213, 20, 20);
fill(41, 215, 16);
rect(215, 231, 51, 31);
fill(2145,3,25);
rect(200,100,142,51);
fill(412,5126,71);
rect(90,120,51,23);
}