commit 935bccd987dab66d2f3b19af1757560abc825ce2 Author: Maximilian Ruhm Date: Fri Nov 24 22:28:51 2023 +0100 first diff --git a/simulation.pde b/simulation.pde new file mode 100644 index 0000000..428155f --- /dev/null +++ b/simulation.pde @@ -0,0 +1,99 @@ +boolean ismenu = true; +boolean isgame = false; +PVector pos = new PVector(220, 50); + +void setup() { + size(800,800); +} + +https://forum.processing.org/two/discussion/19925/rotating-an-object-and-making-it-move-with-a-variable.html +void draw() { + // debug(); + + if (ismenu) { + mainMenu(); + } else if (isgame) { + play(); + } +} + +int rotation; +void play() { + background(255); + + rotate(radians(rotation)); + translate(pos.x, pos.y); + rect(0, 0, 20, 20); +} + +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; + } + } + 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); +} + +// 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; + } +} + +void keyPressed() { + if (ismenu) { + } else if (isgame) { + if (key == CODED) { + if (keyCode == UP) { + pos.x = pos.x + 1; + } else if (keyCode == DOWN) { + pos.x = pos.x - 1; + } else if (keyCode == LEFT) { + rotation = rotation +1; + } else if (keyCode == RIGHT) { + rotation = rotation -1; + } + } + } +}