From 82e3afcfe5e1d3020b3bd05b958ada6e443cab0f Mon Sep 17 00:00:00 2001 From: Makussu Date: Sun, 22 Oct 2023 22:58:49 +0200 Subject: [PATCH] all work today --- game/game.pde | 22 +++++++++++++--------- game/keys.pde | 5 ++++- game/main.pde | 46 ++++++++++++++++++++++++++++++++++++++++++---- game/map.pde | 14 +++++++++----- 4 files changed, 68 insertions(+), 19 deletions(-) diff --git a/game/game.pde b/game/game.pde index 74e9df3..22ee058 100644 --- a/game/game.pde +++ b/game/game.pde @@ -13,7 +13,7 @@ float speed = 20; float gravitation = 9.81; float jumpheight; -float jumpcooldown = 12; +boolean canjump = true; // for moving x-axis (mostly depracted) // But dont delete yet!! @@ -23,12 +23,12 @@ int playerRadius = 25; // float actualPos; -PVector tilesize = new PVector(50, 50); +PVector tilesize = new PVector(100, 50); int[][] level; int tilesmoved = 0; -int tilespeed = 3; +int tilespeed = 4; // The actual game void play() { @@ -86,6 +86,7 @@ void collisionTest() { // Collision with baseline if ( pos.y > 0.850*height - playerRadius/2 ) { pos.set(pos.x, 0.850*height - playerRadius/2); + canjump = true; } // Collision with all the tiles bottom site @@ -93,13 +94,16 @@ void collisionTest() { boolean xSideEdges = pos.x > level[i][0] - tilesize.x/2 && pos.x < level[i][0] + tilesize.x/2; boolean ySideEdges = pos.y < level[i][1] + tilesize.y/2 && pos.y > level[i][1] - tilesize.y/2; + if (level[i][4] == 0) { // Bottom - if ( (xSideEdges) && (ySideEdges)) { - pos.set(pos.x, level[i][1] + tilesize.y/2); - } - // Top - if ( (xSideEdges) && (pos.y < level[i][1] + tilesize.y/2 && pos.y > level[i][1] - tilesize.y/2 - playerRadius)) { - pos.set(pos.x, level[i][1] - tilesize.y/2 - 15); + if ( (xSideEdges) && (ySideEdges)) { + pos.set(pos.x, level[i][1] + tilesize.y/2); + } + // Top + if ( (xSideEdges) && (pos.y < level[i][1] + tilesize.y/2 && pos.y > level[i][1] - tilesize.y/2 - playerRadius)) { + pos.set(pos.x, level[i][1] - tilesize.y/2 - 15); + canjump = true; + } } } } diff --git a/game/keys.pde b/game/keys.pde index 1c64130..5bcb548 100644 --- a/game/keys.pde +++ b/game/keys.pde @@ -15,7 +15,10 @@ void keyPressed () { // pos.x = pos.x + direction.x * speed; // } } else if (key == ' ') { - jumpspeed =+ 30; + if(canjump) { + jumpspeed =+ 31; + canjump = false; + } } } else if (iseditor) { if (key == 's') { diff --git a/game/main.pde b/game/main.pde index 9001119..77bc4c6 100644 --- a/game/main.pde +++ b/game/main.pde @@ -1,3 +1,7 @@ +import processing.sound.*; +SoundFile jumpsound; +SoundFile deathsound; + void setup() { size(800,800); frameRate(60); @@ -25,30 +29,48 @@ boolean iseditor = false; // This is the start screen and main menu. It has a few Buttons void mainMenu() { - background(14, 181, 59); + background(246, 244, 235); + + fill(116, 155, 194); + textSize(128); + textAlign(CENTER); + text("p4dash", width/2, height/2 - 100); // go to game - if (drawRectWithMouseColission(width/2, height/2, 100, 100)) { + fill(70, 130, 169); + if (drawRectWithMouseColission(width/2, height/2, 300, 100)) { if (mousePressed) { ismenu = false; isgame = true; } } - // go to menu - if (drawRectWithMouseColission(width/2, height/2+200, 100, 100)) { + 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; @@ -58,6 +80,9 @@ void menuButton() { savetofile("save"); } } + fill(0); + textSize(40); + text("Exit", 50, 50+10); } // Map Editor Mode @@ -97,6 +122,19 @@ boolean drawTriangleWithMouseColission(int x, int y, int rectwidth, int rectheig } } +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); diff --git a/game/map.pde b/game/map.pde index 52bb870..6c0a575 100644 --- a/game/map.pde +++ b/game/map.pde @@ -13,7 +13,9 @@ void generate_tiles() { if (level[i][4] == 0) { rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]); } else { - triangle(level[i][0]-level[i][2]/2 -screenx, level[i][1], level[i][0]+level[i][2]/2, level[i][1], level[i][0], level[i][1]-level[i][3]); + if (drawTriangleWithPlayerColission(level[i][0] -screenx, level[i][1], level[i][2], level[i][3])) { + moveTilesBack(tilespeed); + } } } } @@ -84,14 +86,16 @@ void drawBackground() { fill(sun); ellipse(130, 100, 70, 70); - - fill(0); - randomSeed(0); drawPalm(100, 700); drawPalm(200, 700); drawPalm(300, 700); drawPalm(400, 700); + + fill(darksand); + point(500, 770); + + fill(0); } // No Clouds yet @@ -144,7 +148,7 @@ boolean checkSaveFile(String filepath) { // 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")) { + if (!checkSaveFile("./saves/save.json")) { JSONArray values = loadJSONArray(jsonfile); // println(values.size());