import processing.sound.*; SoundFile jumpsound; SoundFile deathsound; SoundFile gamesoundtrack; void setup() { jumpsound = new SoundFile(this, "./sounds/jump.mp3"); deathsound = new SoundFile(this, "./sounds/fail.mp3"); gamesoundtrack = new SoundFile(this, "./sounds/maintheme.mp3"); gamesoundtrack.loop(1, 0.2); size(800,800); frameRate(60); smooth(4); level = loadJson("./saves/save.json"); } void draw() { // debug(); if (ismenu) { mainMenu(); } else if (isgame) { drawBackground(); play(); } else if (iseditor) { mapEditor(); } } boolean ismenu = true; boolean isgame = false; boolean iseditor = false; // This is the start screen and main menu. It has a few Buttons void mainMenu() { background(246, 244, 235); fill(116, 155, 194); textSize(128); textAlign(CENTER); text("p4dash", width/2, height/2 - 100); // go to game fill(70, 130, 169); if (drawRectWithMouseColission(width/2, height/2, 300, 100)) { if (mousePressed) { ismenu = false; isgame = true; } } fill(0); textSize(40); text("Play", width/2, height/2); // go to editor fill(70, 130, 169); if (drawRectWithMouseColission(width/2, height/2+200, 300, 100)) { if (mousePressed) { ismenu = false; iseditor = true; } } fill(0); textSize(40); text("Editor", width/2, height/2+200); fill(145, 200, 228); // exit game if (drawRectWithMouseColission(50, 100, 80, 40)) { if (mousePressed) { exit(); } } fill(0); textSize(40); textAlign(CENTER); text("Exit", 50, 110); // Text in corner textAlign(LEFT); fill(0); textSize(20); text("m - mute audio", 10, 700); } void menuButton() { fill(145, 200, 228); if (drawRectWithMouseColission(50, 50, 80, 40)) { if (mousePressed) { ismenu = true; iseditor = false; isgame = false; moveTilesBack(tilespeed); savetofile("save"); screenx = 0; } } fill(0); textSize(40); textAlign(CENTER); text("Exit", 50, 50+10); } // Map Editor Mode void mapEditor() { background(255); baseRect(); generate_editor_tiles(); // generate_tiles(); menuButton(); // Texts at Top textAlign(RIGHT); textSize(20); text("SPACE - Toggle between rect and triangle", 790, 50); text("Left Click - Place block", 790, 70); text("Right Click - Delete Block", 790, 90); text("Arrows - Move right and left", 790, 110); } // Rectangle with editor colission boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) { // Draw A Rect rectMode(CENTER); rect(x, y, rectwidth, rectheight); // Check it for collission if((mouseX > x - rectwidth/2 && mouseX < x + rectwidth/2) && (mouseY > y - rectheight/2 && mouseY < y + rectheight/2)) { return true; } else { return false; } } // Triangle with editor colission boolean drawTriangleWithMouseColission(int x, int y, int rectwidth, int rectheight) { // Draw A Rect rectMode(CENTER); triangle(x - rectwidth/2, y, x + rectwidth/2, y, x, y - rectheight); // Check it for collission if(dist(mouseX, mouseY, x+rectwidth/2, y-rectheight/2) < rectheight/1.5) { return true; } else { return false; } } boolean drawTriangleWithPlayerColission(int x, int y, int rectwidth, int rectheight) { // Draw A Rect rectMode(CENTER); triangle(x - rectwidth/2, y, x + rectwidth/2, y, x, y - rectheight); // Check it for collission if(dist(pos.x, pos.y, x+rectwidth/2, y-rectheight/2) < rectheight/2) { return true; } else { return false; } } // These are my Debugger Functions void debug() { // println(screenoffset); // println(level[0][0]); } // Neat helper function, that gives us coordinates of point while clicking void helper() { if (mousePressed == true){ println(mouseX, mouseY); } }