2023-10-21 00:41:17 +02:00

108 lines
1.9 KiB
Plaintext

void setup() {
size(800,800);
frameRate(60);
smooth(4);
level = loadJson("./saves/save.json");
}
// not done yet
void saveFileChecker() {
File f = dataFile("./saves/save.json");
String filePath = f.getPath();
boolean exist = f.isFile();
println(filePath, exist);
if (!exist) {
}
};
void draw() {
// debug();
if (ismenu) {
mainMenu();
} else if (isgame) {
drawBackground();
play();
} else if (iseditor) {
mapEditor();
}
}
boolean ismenu = true;
boolean isgame = false;
boolean iseditor = false;
void mainMenu() {
background(14, 181, 59);
// go to game
if (drawRectWithMouseColission(width/2, height/2, 100, 100)) {
if (mousePressed) {
ismenu = false;
isgame = true;
}
}
// go to menu
if (drawRectWithMouseColission(width/2, height/2+200, 100, 100)) {
if (mousePressed) {
ismenu = false;
iseditor = true;
}
}
// exit game
if (drawRectWithMouseColission(50, 100, 80, 40)) {
if (mousePressed) {
exit();
}
}
}
void menuButton() {
if (drawRectWithMouseColission(50, 50, 80, 40)) {
if (mousePressed) {
ismenu = true;
iseditor = false;
isgame = false;
moveTilesBack(tilespeed);
savetofile("save");
}
}
}
void mapEditor() {
background(255);
baseRect();
generate_editor_tiles();
// generate_tiles();
menuButton();
}
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;
}
}
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);
}
}