let terrainVariation = 1;
let blocks=[{x:2750,y:100, type:"stone", durability:10},
{x:2775,y:100,type:"leaf", durability:10},
{x:2800,y:100,type:"wood", durability:10},
{x:2825,y:125,type:"stone", durability:10},
{x:2850,y:150,type:"leaf", durability:10},
{x:2875,y:175,type:"wood", durability:10},
{x:2900,y:200,type:"stone", durability:10},
{x:2925,y:225,type:"leaf", durability:10},
{x:2950,y:250,type:"wood", durability:10},
{x:2975,y:275,type:"stone", durability:10},
{x:2725,y:125,type:"leaf", durability:10},
{x:2700,y:150,type:"wood", durability:10},
{x:2675,y:175,type:"stone", durability:10},
{x:2650,y:200,type:"leaf", durability:10},
{x:2625,y:225,type:"wood", durability:10},
{x:2600,y:250,type:"stone", durability:10},
{x:2575,y:275,type:"leaf", durability:10}];
let newTime={accDeltaTime:0, deltaTime:0,lastTime:0,allTime:0,secondsSinceStart:0}
let bullets=[{x:0,y:0,dir:"LEFT", bulletLife:0}]
let Inventory=[{name:"gun", quantity:1}, {name:"empty", quantity:0}, {name:"empty", quantity:0}, {name:"empty", quantity:0}, {name:"empty", quantity:0}]
let ticksSinceLastHeal=0;
let enemy=[{health:5, speed:5, x:2600, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}]
overlayImg = loadImage('imga.png');
brickImg = loadImage('stone2.png');
walkRightImg = loadImage('UPDT - CHR WALK RIGHT.png');
walkLeftImg = loadImage('UPDT - CHR WALK LEFT.png');
standStillRight = loadImage('CHR-StandingStillRight.png');
standStillLeft = loadImage('CHR-StandingStillLeft.png')
woodImg = loadImage('Wood.png')
leafImg = loadImage('Leaf.png')
grassImg = loadImage('Untitled(2).png')
gunImg = loadImage('gun2.png')
gunLeftImg = loadImage('gunleft.png')
sandImg = loadImage('sand.png')
evilBiomeImg = loadImage('evil.png')
inActiveInvSquare = loadImage('InventorySquareUnactive.png')
activeInvSquare = loadImage('ActiveInvSquare.png')
ZombieLeftWalk = loadImage('Zombie-Walking-Left.png')
ZombieRightWalk = loadImage('Zombie-Walking-Right.png')
ZombieLeftStand = loadImage('Zombie-Standing-Left.png')
ZombieRightStand = loadImage('Zombie-Standing-Right.png')
let sd = round(random(0,999999));
print("More customization options, such as your own seed, are availible in the code at https://openprocessing.org/sketch/1539966 on line 7")
print("RNG Seed: " + customSeed)
print("More customization options, such as your own seed, are availible in the code at https://openprocessing.org/sketch/1539966 on line 7")
document.addEventListener('contextmenu', event => event.preventDefault());
text("Loading...", 300, 300)
print("Generating terrain...")
let currentBiomeGen="overworld";
let currentBiomeGenBlocks=0;
let currentBiomeGenBlocksGoal=20;
let currentForestGenBlocks=0;
let currentForestGenGoal=20;
for (let i = 0; i < worldSize; i = i + 1) {
currentBiomeGenBlocks=currentBiomeGenBlocks+1;
if (currentBiomeGenBlocks >= currentBiomeGenBlocksGoal) {
currentBiomeGenBlocks = 0;
currentBiomeGenBlocksGoal=round(random(10,50));
let rand1=round(random(0,1))
currentBiomeGen="overworld";
currentForestGenBlocks=currentForestGenBlocks+1;
if (currentForestGenBlocks >= currentForestGenGoal) {
currentForestGenBlocks = 0;
currentForestGenGoal = round(random(10,50));
let rand3=round(random(0,1))
terrain.length=terrain.length+1;
biomeList.length=biomeList.length+1;
rand2=round(random(0,4));
rand2=round(random(0,15));
let rand4=round(random(0,30));
terrain[terrain.length-1]=terrain[terrain.length-2]+(round(random(-1.8*terrainVariation, 1.7*terrainVariation))*25);
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25,y:terrain[terrain.length-1]-25,type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25,y:terrain[terrain.length-1]-50,type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25+25,y:terrain[terrain.length-1]-25,type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25+25,y:terrain[terrain.length-1],type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25,y:terrain[terrain.length-1]-25,type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25,y:terrain[terrain.length-1]-50,type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25,y:terrain[terrain.length-1]-75,type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25-25,y:terrain[terrain.length-1]-50,type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25-25,y:terrain[terrain.length-1]-25,type:"stone", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:(terrain.length-1)*25+25,y:terrain[terrain.length-1]-25,type:"stone", durability:10}
if (rand2==1 && terrain[terrain.length-1] < 325) {
treesToGenerate.length=treesToGenerate.length+1;
treesToGenerate[treesToGenerate.length-1]=terrain.length-1
if (currentBiomeGen=="overworld") {
biomeList[biomeList.length-1]="overworld"
biomeList[biomeList.length-1]="evil"
if (terrainVariation < 1) {
if (terrain[terrain.length-1]>500) {
terrain[terrain.length-1]=500
} else if (terrain[terrain.length-1]<100) {
terrain[terrain.length-1]=100;
print("Generating background...")
for (let i = 0; i < 150; i = i + 1) {
stars.length=stars.length+1;
stars[stars.length-1]={x:round(random(0,900)), y:round(random(0,900)), sm:random(0.5,1)}
print("Generating trees!")
for (let i = 0; i < treesToGenerate.length; i = i + 1) {
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25,y:terrain[treesToGenerate[i]]-25,type:"trans-wood", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25,y:terrain[treesToGenerate[i]]-50,type:"trans-wood", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25,y:terrain[treesToGenerate[i]]-75,type:"trans-wood", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25,y:terrain[treesToGenerate[i]]-100,type:"trans-wood", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25,y:terrain[treesToGenerate[i]]-125,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25,y:terrain[treesToGenerate[i]]-150,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25,y:terrain[treesToGenerate[i]]-175,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25-25,y:terrain[treesToGenerate[i]]-150,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25-25,y:terrain[treesToGenerate[i]]-125,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25-25,y:terrain[treesToGenerate[i]]-100,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25+25,y:terrain[treesToGenerate[i]]-150,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25+25,y:terrain[treesToGenerate[i]]-125,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25-50,y:terrain[treesToGenerate[i]]-125,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25+50,y:terrain[treesToGenerate[i]]-125,type:"trans-leaf", durability:10}
blocks.length=blocks.length+1;
blocks[blocks.length-1]={x:treesToGenerate[i]*25+25,y:terrain[treesToGenerate[i]]-100,type:"trans-leaf", durability:10}
newTime.accDeltaTime=newTime.allTime-newTime.lastTime
newTime.deltaTime=newTime.accDeltaTime*2.3
newTime.secondsSinceStart=newTime.secondsSinceStart+(newTime.deltaTime/1000)
if (frTicker <= newTime.secondsSinceStart) {
frTicker=newTime.secondsSinceStart+1;
if (pausedLoaded==false) {
for (let i = 0; i < terrain.length; i = i + 1) {
line(i*3+1.5, 337, i*3+1.5, (terrain[i]/(25/3))+300)
rect(i*3, (terrain[i]/(25/3))+300, 3, 24);
if (biomeList[i]=="overworld") {
rect(i*3, (terrain[i]/(25/3))+300, 3, 6);
rect(i*3, (terrain[i]/(25/3))+300,3,6)
point((-1*(relCenX+2500))/(25/3)+336, (10-(relCenY-240)/(25/3))+300);
for (let i = 0; i < blocks.length; i = i + 1) {
if (blocks[i].type.replace('trans-','')=="leaf")
image(leafImg, blocks[i].x/(25/3), (blocks[i].y/(25/3))+300, 3, 3)
if (blocks[i].type.replace('trans-','')=="stone")
image(brickImg, blocks[i].x/(25/3), (blocks[i].y/(25/3))+300, 3, 3)
if (blocks[i].type.replace('trans-','')=="wood")
image(woodImg, blocks[i].x/(25/3), (blocks[i].y/(25/3))+300, 3, 3)
} else if (pausedLoaded==true) {
text("Nolenopo", 300, 150)
text("By Evan Shekhar", 300, 200)
if (mouseX < 375 && mouseX > 225 && mouseY < 475 && mouseY > 425) {
if (mouseX < 375 && mouseX > 225 && mouseY < 550 && mouseY > 500) {
if (mouseIsPressed && pL==false) {
text("How to Play", 300, 530)
rect(0,555,600,50,5,5,5,5);
text("Press 'e' to pause at any time.", 300, 565)
text("Enemies spawn about every " + (round((EnemySpawnRate*1.7)/3)/10) + " seconds. Press p and m to add or subtract from it!", 300, 580)
text("Max frame rate is " + cfr + " frames per second. Press u and d to add or subtract from it!", 300, 595)
text("How to play Nolenopo - page " + howToPlay, 300, 50)
text("The goal of the game is to kill as many monsters as you can", 50, 140);
text("Controls", 30, 160);
text("Use A and D to move left or right, and press spacebar to jump.", 50, 180);
text("Press 1, 2, 3, 4, and 5 to select an inventory slot.", 50, 200);
text("Left click to use or place whatever is in your active inventory slot.", 50, 220);
text("Right click to break and collect blocks. You cannot break terrain.", 50, 240);
text("Inventory", 30, 260);
text("At the top of the screen, there are 5 inventory slots.", 50, 280);
text("Anything you have collected shows up there.", 50, 300);
text("You can carry an infinite amount of blocks.", 50, 320);
text("Character and enemies", 30, 340);
text("Your character is a human, always located in the center of the screen.", 50, 360)
text("Zombies are a green colored monster which spawn randomly.", 70, 400)
text("Zombies will walk towards you, and deal damage when they collide.", 70, 420)
text("Zombies can break blocks in front of them.", 70, 440)
if (mouseX < 375 && mouseX > 225 && mouseY < 575 && mouseY > 525) {
if (mouseIsPressed && pL==false) {
text("Next Page", 300, 555)
} else if (howToPlay == 2) {
text("The World", 10, 120);
text("Overworld", 50, 160);
text("The Overworld is represented by green grass & a black background.", 70, 180)
text("There are no special effects in the overworld.", 70, 200)
text("Evil Biome", 50, 220)
text("The Evil Biome is represented by purple grass and a red background.", 70, 240)
text("In the evil biome, monsters spawn more frequently.", 70, 260)
text("Forests can generate on top of Evil or Overworld. More trees spawn here.", 70, 300)
text("The Ocean is represented by blue water all around you.", 70, 340)
text("If you stay in the ocean for too long, you begin to drown.", 70, 360)
text("When in the ocean, things that happened last frame will not be fully", 70, 380)
text("covered up.", 70, 400)
text("Be careful, as resources are finite!", 50, 440)
text("Stone spawns in random rocks around the map. Stone is gray.", 50, 460)
text("Trees spawn more in forests, and cannot spawn underwater.", 50, 480)
text("Leaves & wood spawn in trees. Wood is brown & leaves are", 50, 500)
text("transparent green.", 50, 520)
if (mouseX < 375 && mouseX > 225 && mouseY < 575 && mouseY > 525) {
if (mouseIsPressed && pL==false) {
text("Back to Menu", 300, 555)
} else if (mode=='game') {
EnemySpawnRate=EnemySpawnRate-0.05;
for (let i = 0; i < blocks.length; i = i + 1) {
if (blocks[i].type.replace('trans-', '') == blocks[i].type && blocks[i].x+relCenX+25 > 278+(5*playerSpeed) && blocks[i].x+relCenX < 278+(5*playerSpeed)) {
if (blocks[i].y+relCenY+12.5 > 265 && blocks[i].y+relCenY+12.5 < 335) {
for (let i = 0; i < terrain.length; i = i + 1) {
if (i*25+relCenX+25 > 278+(5*playerSpeed) && i*25+relCenX < 278+(5*playerSpeed)) {
if (terrain[i]+relCenY+12.5 > 265 && terrain[i]+relCenY+12.5 < 335) {
if (lSideCollider==false) {
relCenX=relCenX+(5*playerSpeed);
for (let i = 0; i < blocks.length; i = i + 1) {
let newpos=-(5*playerSpeed)
if (blocks[i].type.replace('trans-', '') == blocks[i].type && blocks[i].x+relCenX+25 > 322+newpos && blocks[i].x+relCenX < 322+newpos) {
if (blocks[i].y+relCenY+12.5 > 265 && blocks[i].y+relCenY+12.5 < 335) {
for (let i = 0; i < terrain.length; i = i + 1) {
if (i*25+relCenX+25 > 322-(5*playerSpeed) && i*25+relCenX < 322-(5*playerSpeed)) {
if (terrain[i]+relCenY+12.5 > 265 && terrain[i]+relCenY+12.5 < 335) {
if (lSideCollider==false) {
relCenX=relCenX-(5*playerSpeed);
relCenY=relCenY+(10*playerSpeed)
let groundCollider = false;
for (let i = 0; i < blocks.length; i = i + 1) {
if (blocks[i].type.replace('trans-', '') == blocks[i].type && blocks[i].x+relCenX-1 < 300 && blocks[i].x+relCenX+26 > 300 && 335>=(blocks[i].y+relCenY) && 335<=(blocks[i].y+relCenY+25)) {
for (let i = 0; i < terrain.length; i = i + 1) {
if (i*25+relCenX-1 < 300 && i*25+relCenX+26 > 300 && 335>=terrain[i]+relCenY) {
if (groundCollider==false) {
if (falling==false && jumping==false) {
relCenY=relCenY-(5*playerSpeed*((timeInAir)/100));
} else if (groundCollider==true) {
if (timeInAir > 600 && 334 < 280+relCenY && falling==false) {
playerHealth=playerHealth-round((timeInAir-500)/100)
} else if (timeInAir > 325 && 334 < 280+relCenY && falling==true) {
playerHealth=playerHealth-(1+round((timeInAir-250)/100))
if (millis()>currentTick) {
currentTick=millis()+tickSpeed;
ticksSinceLastHeal=ticksSinceLastHeal+1;
if (ticksSinceLastHeal >= 10 && playerHealth < maxPlayerHealth) {
playerHealth=playerHealth+1;
if (underwater && breath >= 10) {
playerHealth=playerHealth-1;
if (bulletShot == true && Inventory[activeSlot] != null && Inventory[activeSlot].name == "gun") {
bullets.length=bullets.length+1;
bullets[bullets.length-1] = {x: 300-relCenX, y: 307-relCenY, dir: "LEFT", bulletLife:0}
bullets[bullets.length-1] = {x: 300-relCenX, y: 307-relCenY, dir: "RIGHT", bulletLife:0}
breath=breath+(newTime.deltaTime/750);
if (round(random(0,EnemySpawnRate*1.7))==1) {
if (round(random(0,2)) == 1) {
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)+800, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)-200, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
for (let i = 0; i < biomeList.length; i = i + 1) {
if (i*25+relCenX==round((300-12.5-relCenX)/25)*25+relCenX) {
if (biomeList[i] == "evil") {
if (round(random(0,EnemySpawnRate))==1) {
if (round(random(0,2)) == 1) {
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)+800, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)-200, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
if (round(random(0,EnemySpawnRate*1.7))==1) {
if (round(random(0,2)) == 1) {
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)+800, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)-200, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
for (let i = 0; i < stars.length; i = i + 1) {
point(stars[i].x+(relCenX/(16/stars[i].sm)), stars[i].y+(relCenY/(16/stars[i].sm)));
for (let i = 0; i < blocks.length; i = i + 1) {
if (blocks[i].x !=99999 && blocks[i].x+relCenX < 600 && blocks[i].x+relCenX > -25 && blocks[i].y+relCenY < 600 && blocks[i].y+relCenY > -25) {
let ces=blocks[i].type.replace('trans-', '')
image(brickImg, blocks[i].x+relCenX, blocks[i].y+relCenY, 25, 25)
} else if (ces=="leaf") {
image(leafImg, blocks[i].x+relCenX, blocks[i].y+relCenY, 25, 25)
} else if (ces=="wood") {
image(woodImg, blocks[i].x+relCenX, blocks[i].y+relCenY, 25, 25)
rect(0,300+relCenY,600,5000)
for (let i = 0; i < terrain.length; i = i + 1) {
image(sandImg, (i*25+relCenX), terrain[i]+relCenY, 25, 50)
if (biomeList[i]=="overworld") {
image(grassImg, (i*25+relCenX), terrain[i]+relCenY, 25, 50)
image(evilBiomeImg, (i*25+relCenX), terrain[i]+relCenY, 25, 50)
rect((i*25+relCenX)-1, terrain[i]+relCenY+50, 27, 600)
if (mouseX>0&&mouseX<600&&mouseY>0&&mouseY<600) {
for (let i = 0; i < blocks.length; i = i + 1) {
if (blocks[i].x+relCenX==round((mouseX-12.5-relCenX)/25)*25+relCenX && blocks[i].y+relCenY==round((mouseY-12.5-relCenY)/25)*25+relCenY) {
for (let i = 0; i < terrain.length; i = i + 1) {
if (i*25+relCenX==round((mouseX-12.5-relCenX)/25)*25+relCenX && round((mouseY-12.5-relCenY)/25)*25+relCenY >= terrain[i]+relCenY) {
if (noCopy==true && aboveY==true) {
if (Inventory[activeSlot]!=null && Inventory[activeSlot].name=="woodBlock" && Inventory[activeSlot].quantity>0) {
blocks.length=blocks.length+1
blocks[blocks.length-1]={x: round((mouseX-12.5-relCenX)/25)*25, y: round((mouseY-12.5-relCenY)/25)*25, type:"wood", durability:10}
Inventory[activeSlot].quantity = Inventory[activeSlot].quantity-1;
} else if (Inventory[activeSlot]!=null && Inventory[activeSlot].name=="stoneBlock" && Inventory[activeSlot].quantity>0) {
blocks.length=blocks.length+1
blocks[blocks.length-1]={x: round((mouseX-12.5-relCenX)/25)*25, y: round((mouseY-12.5-relCenY)/25)*25, type:"stone", durability:10}
Inventory[activeSlot].quantity = Inventory[activeSlot].quantity-1;
} else if (Inventory[activeSlot]!=null && Inventory[activeSlot].name=="leafBlock" && Inventory[activeSlot].quantity>0) {
blocks.length=blocks.length+1
Inventory[activeSlot].quantity = Inventory[activeSlot].quantity-1;
blocks[blocks.length-1]={x: round((mouseX-12.5-relCenX)/25)*25, y: round((mouseY-12.5-relCenY)/25)*25, type:"leaf", durability:10}
} else if (mouseButton==RIGHT) {
for (let i = 0; i < blocks.length; i = i + 1) {
if (blocks[i].x+relCenX == round((mouseX-12.5-relCenX)/25)*25+relCenX && blocks[i].y+relCenY == round((mouseY-12.5-relCenY)/25)*25+relCenY) {
let ownsBlockClicked=false;
for (let ie=0; ie<Inventory.length; ie=ie+1) {
if (Inventory[ie].name==blocks[i].type.replace('trans-','') + "Block") {
Inventory[ie].quantity=Inventory[ie].quantity+1;
if (ownsBlockClicked==false) {
let foundEmptySlot=false;
for (let ie=0; ie<Inventory.length; ie=ie+1) {
if (Inventory[ie].name=="empty" && foundEmptySlot==false) {
let ce = blocks[i].type.replace('trans-', '')
Inventory[ie].name=ce + "Block"
if (mouseX>0 && mouseX<600 && mouseY>0 && mouseY<600) {
rect(round((mouseX-12.5-relCenX)/25)*25+relCenX, round((mouseY-12.5-relCenY)/25)*25+relCenY, 25, 25)
for (let i = 0; i < enemy.length; i = i +1) {
enemy[i].attCD=enemy[i].attCD-1;
if (enemy[i].attCD<=0 && enemy[i].x+relCenX<322 && enemy[i].x+relCenX>278 && enemy[i].y+relCenY > (300-35) && enemy[i].y+relCenY < 335) {
playerHealth=playerHealth-1;
enemy[i].framesSinceSwitch=enemy[i].framesSinceSwitch+1;
if (enemy[i].framesSinceSwitch >= 8) {
if (enemy[i].currentFrame=="WALK") {
enemy[i].currentFrame="STAND";
enemy[i].currentFrame="WALK"
enemy[i].framesSinceSwitch=0;
if (enemy[i].currentFrame=="WALK") {
if (enemy[i].x+relCenX > 300) {
image(ZombieLeftWalk, enemy[i].x+relCenX, enemy[i].y+relCenY, 44, 70)
image(ZombieRightWalk, enemy[i].x+relCenX, enemy[i].y+relCenY, 44, 70)
if (enemy[i].x+relCenX > 300) {
image(ZombieLeftStand, enemy[i].x+relCenX, enemy[i].y+relCenY, 44, 70)
image(ZombieRightStand, enemy[i].x+relCenX, enemy[i].y+relCenY, 44, 70)
rect(enemy[i].x+relCenX-25, enemy[i].y+relCenY-50, enemy[i].health*10, 10)
for (let q = 1; q <= 5; q = q + 1) {
rect((enemy[i].x+relCenX-25)+(q*10), enemy[i].y+relCenY-50, 1, 10)
for (let e = 0; e < bullets.length; e = e + 1) {
if (bullets[e] != null) {
if (dist(bullets[e].x+relCenX,bullets[e].y+relCenY,enemy[i].x+relCenX,enemy[i].y+relCenY) < 35) {
enemy[i].health=enemy[i].health-1;
let eLeftSideCollider=false;
let eRightSideCollider=false;
for (let e = 0; e < blocks.length; e = e + 1) {
if (blocks[e].type.replace('trans-', '') == blocks[e].type && blocks[e].x+relCenX+25 > relCenX+newpos && blocks[e].x+relCenX < relCenX+newpos) {
if (blocks[e].y+relCenY+12.5 > (enemy[i].y+relCenY-35) && blocks[e].y+relCenY+12.5 < enemy[i].y+relCenY+35) {
if (enemy[i].attCD <= 0) {
if (blocks[e].type.replace('trans-', '') == blocks[e].type && blocks[e].x+relCenX+25 > relCenX+newpos && blocks[e].x+relCenX < newpos+relCenX) {
if (blocks[e].y+relCenY+12.5 > (enemy[i].y+relCenY-35) && blocks[e].y+relCenY+12.5 < (enemy[i].y+relCenY+35)) {
if (enemy[i].attCD <= 0) {
if (eRightSideCollider == false && enemy[i].x+relCenX < 300) {
if (eLeftSideCollider == false && enemy[i].x+relCenX > 300) {
for (let e = 0; e < terrain.length; e = e + 1) {
if (enemy[i].y+(5*((enemy[i].timeInAir)/100)) < terrain[e]-25 && round(enemy[i].x/25)*25 == e*25) {
enemy[i].y=enemy[i].y+(5*((enemy[i].timeInAir)/100));
enemy[i].timeInAir=enemy[i].timeInAir+25
} else if (round(enemy[i].x/25)*25 == e*25) {
if (enemy[i] != null && enemy[i].health < 1) {
monsterskilled=monsterskilled+1;
if (round(random(0,8))==1) {
if (round(random(0,2)) == 1) {
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)+800, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)-200, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
if (round(random(0,8))==1) {
if (round(random(0,2)) == 1) {
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)+800, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
enemy.length=enemy.length+1;
enemy[enemy.length-1]={health:5, speed:5, x:(-1*relCenX)-200, y:200, attCD:0, timeInAir:0, jumping:false, attackCooldown:0, framesSinceSwitch:0, currentFrame:"WALK", falling:true}
for (let i = 0; i < bullets.length; i = i + 1) {
if (bullets[i] != null) {
bullets[i].bulletLife=bullets[i].bulletLife+1;
if (bullets[i].x+relCenX > -25 && bullets[i].x+relCenX<625 && bullets[i].y+relCenY > -25 && bullets[i].y+relCenY < 625)
if (bullets[i].dir == "LEFT") {
bullets[i].x=bullets[i].x-(10)
bullets[i].x=bullets[i].x+(10)
rect(bullets[i].x+relCenX, bullets[i].y+relCenY, 15, 7, 5, 5, 5, 5)
if (bullets[i].bulletLife>80) {
image(overlayImg, 0, 0, 600, 600)
rect(0,25,60*(10-(round(breath))),25)
for (let i = 0; i <= 10; i = i + 1) {
if (mouseX>0 && mouseX<600 && mouseY>0 && mouseY<600) {
line(mouseX-10, mouseY, mouseX+10, mouseY)
line(mouseX, mouseY-10, mouseX, mouseY+10)
rect(0,0,600*(playerHealth/maxPlayerHealth), 25)
for (let i = 0; i < (30); i=i+1) {
rect(i*(600/maxPlayerHealth), 0, 2, 25)
image(standStillLeft,300,300,44,70)
if (Inventory[activeSlot] != null) {
if (Inventory[activeSlot].name == "gun") {
image(gunLeftImg,300,310,50,25)
image(standStillRight,300,300,44,70)
if (Inventory[activeSlot] != null) {
if (Inventory[activeSlot].name == "gun") {
image(gunImg,300,310,50,25)
image(walkLeftImg,300,300,44,70)
if (Inventory[activeSlot] != null) {
if (Inventory[activeSlot].name == "gun") {
image(gunLeftImg,300,310,50,25)
image(walkRightImg,300,300,44,70)
if (Inventory[activeSlot] != null) {
if (Inventory[activeSlot].name == "gun") {
image(gunImg,300,310,50,25)
image(standStillLeft,300,300,44,70)
if (Inventory[activeSlot] != null) {
if (Inventory[activeSlot].name == "gun") {
image(gunLeftImg,300,310,50,25)
image(standStillRight,300,300,44,70)
if (Inventory[activeSlot] != null) {
if (Inventory[activeSlot].name == "gun") {
image(gunImg,300,310,50,25)
for (let i = 0; i < enemy.length; i = i + 1) {
newTime.lastTime=millis()
for (let i = 0; i < Inventory.length; i=i+1) {
image(activeInvSquare, 100+(i*100), 75, 41, 41)
image(inActiveInvSquare, 100+(i*100), 75, 41, 41)
if (Inventory[i].name=="gun") {
image(gunImg, 98+(i*100), 75, 33, 16)
} else if (Inventory[i].name=="woodBlock") {
image(woodImg, 100+(i*100), 75, 24, 24)
} else if (Inventory[i].name=="stoneBlock") {
image(brickImg, 100+(i*100), 75, 24, 24)
} else if (Inventory[i].name=="leafBlock") {
image(leafImg, 100+(i*100), 75, 24, 24)
if (Inventory[i].quantity==0) {
Inventory[i].name="empty";
if (Inventory[i].name != "empty") {
text(Inventory[i].quantity, 105+(i*100), 85, 40, 40)
text("X: " + round(-1*relCenX)/25, 20, 85)
text("Y: " + round(relCenY)/25, 20, 95)
if (round(-1*relCenX)/25 > terrain.length) {
} else if (gameOver==true) {
text("You Died!", 300,300)
text("You were " + round(totalTimeT/1000) + " seconds old!", 300, 350)
text("You defeated " + monsterskilled + " monsters!", 300, 400)
image(overlayImg, 0, 0, 600, 600)
function mousePressed() {
if (Inventory[activeSlot] != null && Inventory[activeSlot].name == "gun" && bulletShot==false){
bullets.length=bullets.length+1;
bullets[bullets.length-1] = {x: 300-relCenX, y: 307-relCenY, dir: "LEFT", bulletLife:0}
bullets[bullets.length-1] = {x: 300-relCenX, y: 307-relCenY, dir: "RIGHT", bulletLife:0}
function mouseReleased() {
if (howToPlay==0 && mode=="paused") {
EnemySpawnRate=EnemySpawnRate+2;
EnemySpawnRate=EnemySpawnRate-2;
if (EnemySpawnRate < 1) {
if (EnemySpawnRate > 600) {
if (key=='a' && mode=='game') {
if (key=='d' && mode=='game') {
if (key==' ' && mode=='game') {