From a527307ee1a585f54ce7991268ddf17b6bb82345 Mon Sep 17 00:00:00 2001 From: Maximilian Ruhm Date: Sun, 22 Oct 2023 14:02:08 +0200 Subject: [PATCH] code quality --- game/keys.pde | 10 +++++----- game/main.pde | 23 +++++++---------------- game/map.pde | 23 ++++++++++++----------- 3 files changed, 24 insertions(+), 32 deletions(-) diff --git a/game/keys.pde b/game/keys.pde index 28fd16f..1c64130 100644 --- a/game/keys.pde +++ b/game/keys.pde @@ -1,5 +1,4 @@ - // } else if (key == 'l') { - // println(loadJSONArray("../map/map.json")); +// Here are all the keys that are used boolean iseditorModeRect = true; boolean iseditorModeSpike = false; @@ -45,11 +44,12 @@ void keyPressed () { } } +// Add tiles in editor mode int runnerRect = 0; void mouseReleased() { if(iseditor) { - if(iseditorModeRect) { - if (mouseButton == LEFT) { + if (mouseButton == LEFT) { + if(iseditorModeRect) { level[runnerRect][0] = mouseX+screenx; level[runnerRect][1] = mouseY; level[runnerRect][2] = 100; @@ -58,7 +58,6 @@ void mouseReleased() { println("generated"); runnerRect = runnerRect + 1; println(runnerRect); - } } else if (iseditorModeSpike) { level[runnerRect][0] = mouseX+screenx; level[runnerRect][1] = mouseY; @@ -68,6 +67,7 @@ void mouseReleased() { println("generated"); runnerRect = runnerRect + 1; println(runnerRect); + } } } } diff --git a/game/main.pde b/game/main.pde index 07e0577..9001119 100644 --- a/game/main.pde +++ b/game/main.pde @@ -3,22 +3,9 @@ void setup() { 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(); @@ -36,7 +23,7 @@ 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(14, 181, 59); // go to game @@ -73,6 +60,7 @@ void menuButton() { } } +// Map Editor Mode void mapEditor() { background(255); baseRect(); @@ -81,6 +69,7 @@ void mapEditor() { menuButton(); } +// Rectangle with editor colission boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) { // Draw A Rect rectMode(CENTER); @@ -94,19 +83,21 @@ boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) } } +// Triangle with editor colission boolean drawTriangleWithMouseColission(int x, int y, int rectwidth, int rectheight) { // Draw A Rect rectMode(CENTER); - triangle(); + 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/2) { + if(dist(mouseX, mouseY, x+rectwidth/2, y-rectheight/2) < rectheight/1.5) { return true; } else { return false; } } +// These are my Debugger Functions void debug() { // println(screenoffset); // println(level[0][0]); diff --git a/game/map.pde b/game/map.pde index 1c94c20..52bb870 100644 --- a/game/map.pde +++ b/game/map.pde @@ -1,8 +1,12 @@ // BUG level editor x position bleibt ingame +// TODO Completly rework colission +// TODO Die when touching triangle +// moveTilesBack() and High Score Tracking +// No Unlimited Jumping int screenx = 0; -// level generation +// level generation for playable void generate_tiles() { stroke(0); for (int i = 0; i < level.length; i++ ) { @@ -14,13 +18,10 @@ void generate_tiles() { } } -void generate_spikes() { - -} - +// Generate the tiles for Editor View (tiles that are deletable with mouse) void generate_editor_tiles() { for (int i = 0; i < 100; i++ ) { - rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]); + // rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]); if(level[i][4] == 0) { if (drawRectWithMouseColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) { if (mousePressed && iseditor) { @@ -54,7 +55,7 @@ void baseRect() { fill(255); } -// Background +// Draws all the Background elements like sea and Beach void drawBackground() { color sky = color(94, 218, 252); color sand = color(235, 218, 174); @@ -93,11 +94,12 @@ void drawBackground() { drawPalm(400, 700); } +// No Clouds yet void drawCloud() { ellipse(224, 184, 220, 220); } - +// Draws a slightly randomised Palm void drawPalm(int startingpoint_x, int startingpoint_y) { fill(108, 88, 51); float randomnumber = int(random(10, 16)); @@ -115,10 +117,9 @@ void drawPalm(int startingpoint_x, int startingpoint_y) { //// This Handles loading and saving the level -// TODO Check if json is empty. If it is generate level -// int[][] level = new int[100][4]; JSONArray json; +// This saves the Current save to file int savetofile(String filename) { json = new JSONArray(); @@ -141,6 +142,7 @@ boolean checkSaveFile(String filepath) { return new File(dataPath(filepath)).exists(); } +// Check if there already is a safefile and load it if it is possible. If not load empty array int[][] loadJson(String jsonfile) { if (checkSaveFile("./saves/save.json")) { JSONArray values = loadJSONArray(jsonfile); @@ -158,7 +160,6 @@ int[][] loadJson(String jsonfile) { int rectheight = jsontoarray.getInt(3); int isspike = jsontoarray.getInt(4); - // arrayfromjson_x[i] = x; arrayfromjson[i][0] = x; arrayfromjson[i][1] = y; arrayfromjson[i][2] = rectwidth;