I want to make lava rise from the ground on every level and if you touch it you lose all you levels. Here is the lava code i have so far void draw() { fill(255, 200, 50); float h.y = height-float(frameCount)/10; rect(0, h.y, width, height-h.y); fill(255); if (h.y<height) { background(255, 0, 0); text("You're dead", 0, height/2); } } And this is the program code i do not know where to put it in order for it to work(some of the code is not here b/c its too long,whats missing is classes and lvl 2 and 3) // Global game variables PImage backgroundpic1, backgroundpic2, backgroundpic3, platform1, coinphot, coin2, hearth, bulletphot, bulletphot2; Hero h; Shooter s; ArrayList c; ArrayList walkers; ArrayList shooters; ArrayList bullets; PImage [] spriteImages, walkerImages, shooterImages; int frames, zombieframes, shooterframes, life, startingcoordx, startingcoordy, counter, bottomPane; ; float heroX, heroY, heroSpeedVert, gravity, lava; boolean runonce, left, right, up, down, space, shift; Platform [] platforms; int activeLevel = 0, coincounter = 0;
import processing.sound.*; SoundFile file;
void setup() { file = new SoundFile(this, "8-bit Game Music Loop.mp3"); file.play(); file.loop(); size(800, 600); //platform tile images. platform1 = loadImage("ui/platform_long.png"); backgroundpic1 = loadImage("ui/bg.png"); //background image for level1 backgroundpic2 = loadImage("ui/bg2.png"); //background image for level2 backgroundpic3 = loadImage("ui/bg3.png"); //background image for level3 coinphot = loadImage("ui/coin.png"); hearth = loadImage("ui/life.png"); bulletphot = loadImage("ui/bullet.png"); bulletphot2 = loadImage("ui/bullet2.png"); coinphot.resize(30, 30); hearth.resize(30, 30); bulletphot.resize(20, 15); bulletphot2.resize(20, 15); startingcoordx = 0; startingcoordy = 575; h = new Hero(startingcoordx, startingcoordy); frames = 24; zombieframes = 2; shooterframes = 2; life = 3;
spriteImages = new PImage[frames]; for (int i = 1; i<frames; i++) { spriteImages[i]=loadImage("hero/person"+i+".png"); spriteImages[i].resize(40, 50); } walkerImages = new PImage[zombieframes]; for (int i = 0; i<zombieframes; i++) { walkerImages[i]=loadImage("zombie/walk"+i+".png"); walkerImages[i].resize(40, 50); } shooterImages = new PImage[shooterframes]; for (int i = 0; i<shooterframes; i++) { shooterImages[i]=loadImage("shooter/shooter"+i+".png"); shooterImages[i].resize(40, 50); } //boolean variables left = false; right = false; up = false; down = false; space = false; shift = false; runonce = true; }
void startMenu() { /-------------------DESIGNING THE MAIN MENU-------------------------/ background(236, 240, 241); textAlign(CENTER); fill(52, 73, 94); textSize(70); text("JUMPER", width/2, height/2); textSize(15); text("Click to start", width/2, height-30); h.x = startingcoordx; h.y = startingcoordy; runonce = true; coincounter = 0; life = 3; /-------------------ENDING OF MAIN MENU---------------------------/ }
void level1ScreenGen() { /* ----------------- DESIGNING THE LEVEL 1----------------------- */ background(backgroundpic1); // how many platforms will be used platforms = new Platform[18];
//ground floor platforms
platforms[0] = new Platform (0, 580, "safe");
platforms[1] = new Platform (120, 580, "coin");
platforms[2] = new Platform (240, 580, "walker");
platforms[3] = new Platform (360, 580, "safe");
platforms[4] = new Platform (480, 580, "coin");
platforms[5] = new Platform (600, 580, "walker");
platforms[6] = new Platform (720, 580, "coin");
// all other platforms to jump on
platforms[7] = new Platform (0, 290, "coin");
platforms[8] = new Platform (360, 490, "safe");
platforms[9] = new Platform (750, 250, "safe");
platforms[10] = new Platform (250, 330, "safe");
platforms[11] = new Platform (0, 120, "safe");
platforms[12] = new Platform (350, 90, "coin");
platforms[13] = new Platform (580, 370, "coin");
platforms[14] = new Platform (460, 250, "safe");
platforms[15] = new Platform (700, 100, "walker");
platforms[16] = new Platform (680, 100, "coin");
platforms[17] = new Platform (560, 370, "walker");
/* ------------------------ END OF LEVEL DESIGNING ---------------*/
if (runonce) { c = new ArrayList(); walkers = new ArrayList(); for (int i = 0; i < platforms.length; ++i) { if (platforms[i].typeof == "coin") { c.add(new Coin(platforms[i].x+50, platforms[i].y-30)); } else if (platforms[i].typeof == "walker") { walkers.add(new Walker(int(platforms[i].x), int(platforms[i].y-50))); } } runonce = false; } }
void CoinCounter()
{
image(coinphot, 700, 5);
fill(52, 73, 94);
textSize(20);
text(coincounter, 770, 25);
if (coincounter == 7)
{
activeLevel+=1;
h.x = startingcoordx;
h.y = startingcoordy;
runonce = true;
coincounter = 0;
System.gc();
}
}
void LifeBar()
{
int distance = 0;
int xcord = 600;
;
for (int i=0; i< life; i++)
{
image(hearth, xcord+distance, 5);
distance+=30;
}
if (life == 0)
{
activeLevel=0;
coincounter = 0;
life=3;
}
}
void commonThings()
{
h.update();
for (int i = 0; i < platforms.length; ++i)
{
rectangleCollisions(h, platforms[i]);
h.checkPlatforms();
}
h.checkBoundaries();
for (int i = 0; i < platforms.length; ++i)
{
platforms[i].display(platform1);
}
for (int k = c.size()-1; k >= 0; k--)
{
CoinCollisions(h, c.get(k));
if (h.CoinCollisionSide != "none")
{
c.remove(k);
coincounter++;
}
}
for (int k = c.size()-1; k >= 0; k--)
{
c.get(k).display(coinphot);
}
if (activeLevel == 1) {
for (int k= walkers.size()-1; k>=0; k--)
{
WalkerCollision(h, walkers.get(k));
walkers.get(k).display();
if (h.WalkerCollisionSide != "none")
{
h.x = startingcoordx;
h.y = startingcoordy;
life--;
}
}
}
else if (activeLevel == 2)
{
for (int k = shooters.size()-1; k >= 0; k--)
{
bullets.get(k).display(bulletphot);
BulletCollisions(h, bullets.get(k));
shooters.get(k).display();
if (h.BulletCollisionSide != "none")
{
h.x = startingcoordx;
h.y = startingcoordy;
life--;
}
}
}
else if (activeLevel == 3)
{
for (int k= walkers.size()-1; k>=0; k--)
{
WalkerCollision(h, walkers.get(k));
walkers.get(k).display();
if (h.WalkerCollisionSide != "none")
{
h.x = startingcoordx;
h.y = startingcoordy;
life--;
}
}
for (int k = shooters.size()-1; k >= 0; k--)
{
bullets.get(k).display(bulletphot);
BulletCollisions(h, bullets.get(k));
shooters.get(k).display();
if (h.BulletCollisionSide != "none")
{
h.x = startingcoordx;
h.y = startingcoordy;
life--;
}
}
}
h.display();
}
void draw()
{
if (activeLevel == 0)
{
startMenu();
}
else if (activeLevel == 1)
{
level1ScreenGen();
commonThings();
CoinCounter();
LifeBar();
}
else if (activeLevel == 2)
{
level2ScreenGen();
commonThings();
CoinCounter();
LifeBar();
}
else if (activeLevel == 3)
{
level3ScreenGen();
commonThings();
CoinCounter();
LifeBar();
}
else if (activeLevel > 3) {
YouWon();
}
}
// If user clicks mouse on main menu, goes to 1st level
void mousePressed()
{
if (activeLevel == 0)
{
activeLevel=1;
}
else if (activeLevel > 3)
{
activeLevel=1;
}
}
// catching the keyboard direction buttons.
void keyPressed()
{
switch (keyCode)
{
case 37://left
left = true;
break;
case 39://right
right = true;
break;
case 38://up
up = true;
break;
case 40://down
down = true;
break;
case 32: //space
space = true;
break;
case 16: //shift
shift = true;
}
}
void keyReleased()
{
switch (keyCode)
{
case 37://left
left = false;
break;
case 39://right
right = false;
break;
case 38://up
up = false;
break;
case 40://down
down = false;
break;
case 32: //space
space = false;
break;
case 16: //shift
shift = false;
}
}
// checking collision between our Hero and platform tiles.
void rectangleCollisions(Hero r1, Platform r2)
{
////r1 is the hero
////r2 is the platform tile
float dx = (r1.x+r1.w/2) - (r2.x+r2.w/2);
float dy = (r1.y+r1.h/2) - (r2.y+r2.h/2);
float combinedHalfWidths = r1.halfWidth + r2.halfWidth; float combinedHalfHeights = r1.halfHeight + r2.halfHeight;
if (abs(dx) < combinedHalfWidths) { ////a collision may be happening ////now check on the y axis if (abs(dy) < combinedHalfHeights) { ////excellent. they are overlapping //determine the overlap on each axis float overlapX = combinedHalfWidths - abs(dx); float overlapY = combinedHalfHeights - abs(dy); ////the collision is on the axis with the ////SMALLEST about of overlap if (overlapX >= overlapY) { if (dy > 0) { r1.collisionSide = "top"; ////move the rectangle back to eliminate overlap ////before calling its display to prevent ////drawing object inside each other r1.y += overlapY; // println("collisionSide: "+r1.collisionSide); } else { r1.collisionSide = "bottom"; r1.y -= overlapY; // println("collisionSide: "+r1.collisionSide); } } else { if (dx > 0) { r1.collisionSide = "left"; r1.x += overlapX; // println("collisionSide: "+r1.collisionSide); } else { r1.collisionSide = "right"; r1.x -= overlapX; // println("collisionSide: "+r1.collisionSide); } } } else { r1.collisionSide = "none"; } } else { r1.collisionSide = "none"; } } void CoinCollisions(Hero r1, Coin r2) { ////r1 is the player ////r2 is the platform rectangle float dx = (r1.x+r1.w/2) - (r2.x+r2.w/2); float dy = (r1.y+r1.h/2) - (r2.y+r2.h/2);
float combinedHalfWidths = r1.halfWidth + r2.halfWidth; float combinedHalfHeights = r1.halfHeight + r2.halfHeight;
if (abs(dx) < combinedHalfWidths)
{
////a collision may be happening
////now check on the y axis
if (abs(dy) < combinedHalfHeights)
{
////excellent. they are overlapping
//determine the overlap on each axis
float overlapX = combinedHalfWidths - abs(dx);
float overlapY = combinedHalfHeights - abs(dy);
////the collision is on the axis with the
////SMALLEST about of overlap
if (overlapX >= overlapY)
{
if (dy > 0)
{
r1.CoinCollisionSide = "top";
////move the rectangle back to eliminate overlap
////before calling its display to prevent
////drawing object inside each other
// r1.y += overlapY;
// println("CoinCollisionSide: "+r1.CoinCollisionSide);
}
else
{
r1.CoinCollisionSide = "bottom";
// r1.y -= overlapY;
// println("CoinCollisionSide: "+r1.CoinCollisionSide);
}
}
else
{
if (dx > 0)
{
r1.CoinCollisionSide = "left";
// r1.x += overlapX;
// println("CoinCollisionSide: "+r1.CoinCollisionSide);
}
else
{
r1.CoinCollisionSide = "right";
// r1.x -= overlapX;
// println("CoinCollisionSide: "+r1.CoinCollisionSide);
}
}
}
else
{
r1.CoinCollisionSide = "none";
}
}
else
{
r1.CoinCollisionSide = "none";
}
// return CoinCollisionSide;
}
void BulletCollisions(Hero r1, Bullet r2)
{
////r1 is the player
////r2 is the platform rectangle
float dx = (r1.x+r1.w/2) - (r2.x4+r2.w4/2);
float dy = (r1.y+r1.h/2) - (r2.y4+r2.h4/2);
float combinedHalfWidths = r1.halfWidth + r2.halfWidth; float combinedHalfHeights = r1.halfHeight + r2.halfHeight;
if (abs(dx) < combinedHalfWidths) { ////a collision may be happening ////now check on the y axis if (abs(dy) < combinedHalfHeights) { ////excellent. they are overlapping //determine the overlap on each axis float overlapX = combinedHalfWidths - abs(dx); float overlapY = combinedHalfHeights - abs(dy); ////the collision is on the axis with the ////SMALLEST about of overlap if (overlapX >= overlapY) { if (dy > 0) { r1.BulletCollisionSide = "top"; ////move the rectangle back to eliminate overlap ////before calling its display to prevent ////drawing object inside each other // r1.y += overlapY; // println("CoinCollisionSide: "+r1.CoinCollisionSide); } else { r1.BulletCollisionSide = "bottom"; // r1.y -= overlapY; // println("CoinCollisionSide: "+r1.CoinCollisionSide); } } else { if (dx > 0) { r1.BulletCollisionSide = "left"; // r1.x += overlapX; // println("CoinCollisionSide: "+r1.CoinCollisionSide); } else { r1.BulletCollisionSide = "right"; // r1.x -= overlapX; // println("CoinCollisionSide: "+r1.CoinCollisionSide); } } } else { r1.BulletCollisionSide = "none"; } } else { r1.BulletCollisionSide = "none"; } // return CoinCollisionSide; } void WalkerCollision(Hero r1, Walker r2) { ////r1 is the player ////r2 is the platform rectangle float dx = (r1.x+r1.w/2) - (r2.x2+r2.w2/2); float dy = (r1.y+r1.h/2) - (r2.y2+r2.h2/2);
float combinedHalfWidths = r1.halfWidth + r2.half_Width; float combinedHalfHeights = r1.halfHeight + r2.half_Height;
if (abs(dx) < combinedHalfWidths) { ////a collision may be happening ////now check on the y axis if (abs(dy) < combinedHalfHeights) { ////excellent. they are overlapping //determine the overlap on each axis float overlapX = combinedHalfWidths - abs(dx); float overlapY = combinedHalfHeights - abs(dy); ////the collision is on the axis with the ////SMALLEST about of overlap if (overlapX >= overlapY) { if (dy > 0) { r1.WalkerCollisionSide = "top"; ////move the rectangle back to eliminate overlap ////before calling its display to prevent ////drawing object inside each other // r1.y += overlapY; // println("CoinCollisionSide: "+r1.CoinCollisionSide); } else { r1.WalkerCollisionSide = "bottom"; // r1.y -= overlapY; // println("CoinCollisionSide: "+r1.CoinCollisionSide); } } else { if (dx > 0) { r1.WalkerCollisionSide = "left"; // r1.x += overlapX; // println("CoinCollisionSide: "+r1.CoinCollisionSide); } else { r1.WalkerCollisionSide = "right"; // r1.x -= overlapX; // println("CoinCollisionSide: "+r1.CoinCollisionSide); } } } else { r1.WalkerCollisionSide = "none"; } } else { r1.WalkerCollisionSide = "none"; } // return CoinCollisionSide; }
void display() { if (h < endcoord) { image(walkerImages[0], x2++, y2); xmax = x2; h++; } else { if (x2+endcoord == xmax) { h=0; } image(walkerImages[1], x2--, y2); } // this thing helps to create moving animation if (x2 != x2-1) { current_Frame = (current_Frame+1)%frame_Sequence; } } }