import processing.sound.*; SoundFile jumpsound; SoundFile deathsound; void setup() { jumpsound = new SoundFile(this, "./sounds/jump.mp3"); deathsound = new SoundFile(this, "./sounds/fail.mp3"); 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); text("Exit", 50, 110); } void menuButton() { fill(145, 200, 228); if (drawRectWithMouseColission(50, 50, 80, 40)) { if (mousePressed) { ismenu = true; iseditor = false; isgame = false; moveTilesBack(tilespeed); savetofile("save"); } } fill(0); textSize(40); text("Exit", 50, 50+10); } // Map Editor Mode void mapEditor() { background(255); baseRect(); generate_editor_tiles(); // generate_tiles(); menuButton(); } // 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); } }