# High school programming project, (COMPLETE BEGINNER)

**URL:** <https://discourse.processing.org/t/high-school-programming-project-complete-beginner/46500>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [June 3, 2025, 5:06pm UTC](https://discourse.processing.org/t/high-school-programming-project-complete-beginner/46500 "2025-06-03T17:06:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dinomaster123](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dinomaster123](https://discourse.processing.org/u/dinomaster123)\
**Post date:** [June 3, 2025, 5:06pm UTC](https://discourse.processing.org/t/high-school-programming-project-complete-beginner/46500/1 "2025-06-03T17:06:40Z")

</div>

Hello my name is Max, and I am a complete beginner in processing,but am starting to enjoy coding and reading interesting / exciting new codes ! In my code i have an enum,(which i dont know what it means) a Lambda methode (again still don’t know what it means) basically i have an advanced code in comparision for my level,but i am ready to learn everything that my code is doing. My question is: Can somebody either explain to me in detail what my code does or tell me a way where i can programm it through simpler methodes. Thank you for your patience and i am looking forward to anyones response !

---

<div class="post-metadata">

**Author:** ![dinomaster123](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dinomaster123](https://discourse.processing.org/u/dinomaster123)\
**Post date:** [June 3, 2025, 5:08pm UTC](https://discourse.processing.org/t/high-school-programming-project-complete-beginner/46500/2 "2025-06-03T17:08:19Z")

</div>

incase my code isnt visable:

```processing
// Geo-Dash mit Dreiecken, AABB-Kollisionen, Bestenliste mit Namenseingabe

import java.util.Collections;

enum GameState { MENU, GAME, PAUSE, LOSE, WIN, LEADERBOARD, ENTER_NAME }
GameState state = GameState.MENU;

float playerX = 100, playerY = 300;
float playerW = 40, playerH = 40;
float ySpeed = 0, gravity = 0.8;
boolean isJumping = false;

ArrayList<TriangleObstacle> obstacles = new ArrayList<TriangleObstacle>();
ArrayList<ScoreEntry> highScores = new ArrayList<ScoreEntry>();

int score = 0;
String currentName = "";

void setup() {
  size(800, 400);
  frameRate(60);
  textAlign(CENTER, CENTER);
}

void draw() {
  background(30);
  switch(state) {
    case MENU:
      drawMenu();
      break;
    case GAME:
      runGame();
      break;
    case LOSE:
      drawLose();
      break;
    case WIN:
      drawWin();
      break;
    case PAUSE:
      drawPause();
      break;
    case LEADERBOARD:
      drawLeaderboard();
      break;
    case ENTER_NAME:
      drawNameEntry();
      break;
  }
}

void drawMenu() {
  fill(255);
  textSize(40);
  text("GEO-DASH", width/2, height/3);
  textSize(20);
  text("[S] Start | [M] Bestenliste", width/2, height/2);
}

void drawLose() {
  fill(255, 0, 0);
  textSize(32);
  text("YOU LOSE!", width/2, height/2 - 20);
  textSize(16);
  text("Bitte gib deinen Namen ein:", width/2, height/2 + 20);
  state = GameState.ENTER_NAME;
}

void drawNameEntry() {
  fill(255);
  textSize(20);
  text("Name: " + currentName, width/2, height/2);
  text("Drücke [ENTER], um zu speichern", width/2, height/2 + 40);
}

void drawWin() {
  fill(0, 255, 0);
  textSize(32);
  text("CONGRATS, YOU WIN!", width/2, height/2);
}

void drawPause() {
  fill(255);
  textSize(32);
  text("PAUSE", width/2, height/2);
}

void drawLeaderboard() {
  background(0);
  fill(255);
  textSize(32);
  text("Bestenliste", width/2, 50);
  textSize(20);
  if (highScores.size() == 0) {
    text("Keine Einträge.", width/2, height/2);
  } else {
    for (int i = 0; i < min(5, highScores.size()); i++) {
      ScoreEntry entry = highScores.get(i);
      text((i+1) + ". " + entry.name + " – " + entry.score + " Punkte", width/2, 100 + i * 30);
    }
  }
  textSize(16);
  text("[M] zurück zum Menü", width/2, height - 30);
}

void runGame() {
  fill(0, 255, 255);
  rect(playerX, playerY, playerW, playerH);

  ySpeed += gravity;
  playerY += ySpeed;

  if (playerY + playerH > height - 20) {
    playerY = height - 20 - playerH;
    ySpeed = 0;
    isJumping = false;
  }

  if (frameCount % 180 == 0) {
    float s = random(30, 60);
    obstacles.add(new TriangleObstacle(width, height - 20, s));
  }

  if (frameCount % 30 == 0) {
    score++;
  }

  fill(255);
  textSize(16);
  text("Score: " + score, 70, 30);

  for (TriangleObstacle to : obstacles) {
    to.move();
    to.display();
    if (checkAABB(playerX, playerY, playerW, playerH, to.x, to.y - to.size, to.size, to.size)) {
      state = GameState.LOSE;
    }
  }
}

void keyPressed() {
  if (state == GameState.MENU) {
    if (key == 's' || key == 'S') {
      restartGame();
      state = GameState.GAME;
    } else if (key == 'm' || key == 'M') {
      state = GameState.LEADERBOARD;
    }
  }

  else if (state == GameState.GAME) {
    if ((key == ' ' || keyCode == UP) && !isJumping) {
      ySpeed = -12;
      isJumping = true;
    } else if (key == 'p' || key == 'P') {
      state = GameState.PAUSE;
    }
  }

  else if (state == GameState.ENTER_NAME) {
    if (key == ENTER || key == RETURN) {
      highScores.add(new ScoreEntry(currentName, score));
      highScores.sort((a, b) -> b.score - a.score);
      currentName = "";
      state = GameState.LEADERBOARD;
    } else if (key == BACKSPACE && currentName.length() > 0) {
      currentName = currentName.substring(0, currentName.length()-1);
    } else if (key != CODED && key != ENTER && key != RETURN) {
      currentName += key;
    }
  }

  else if (state == GameState.LEADERBOARD && (key == 'm' || key == 'M')) {
    state = GameState.MENU;
  }

  else if (state == GameState.PAUSE && (key == 'p' || key == 'P')) {
    state = GameState.GAME;
  }
}

void restartGame() {
  playerY = 300;
  ySpeed = 0;
  obstacles.clear();
  score = 0;
  isJumping = false;
  currentName = "";
}

class TriangleObstacle {
  float x, y, size;
  TriangleObstacle(float x_, float y_, float size_) {
    x = x_;
    y = y_;
    size = size_;
  }
  void move() {
    x -= 5;
  }
  void display() {
    fill(255, 0, 0);
    triangle(x, y, x + size/2, y - size, x + size, y);
  }
}

class ScoreEntry {
  String name;
  int score;
  ScoreEntry(String n, int s) {
    name = n;
    score = s;
  }
}

boolean checkAABB(float x1, float y1, float w1, float h1,
                  float x2, float y2, float w2, float h2) {
  return x1 < x2 + w2 && x1 + w1 > x2 &&
         y1 < y2 + h2 && y1 + h1 > y2;
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 3, 2025, 5:44pm UTC](https://discourse.processing.org/t/high-school-programming-project-complete-beginner/46500/3 "2025-06-03T17:44:51Z")

</div>

> [@dinomaster123](#):
>
> In my code I have an `enum` (which I don’t know what it means)

> [@dinomaster123](#):
>
> `enum GameState { MENU, GAME, PAUSE, LOSE, WIN, LEADERBOARD, ENTER_NAME }`

In its most basic form, an `enum` is just labels that we can store in a variable:

> [@dinomaster123](#):
>
> `GameState state = GameState.MENU;`

The code above declares a variable called _state_ of datatype GameState and initializes it w/ the “label” MENU.

The idea is that depending on the “label” currently stored in the variable _state_ should determine which “action” the code has to take; for example, the `switch () {}` block within **draw()**.

> [@dinomaster123](#):
>
> … a lambda method (again still don’t know what it means)

> [@dinomaster123](#):
>
> `highScores.sort((a, b) -> b.score - a.score);`

A Java lambda is an alternative syntax to declare a function in the form of an expression.

On the code above, `(a, b) -> b.score - a.score` is a lambda function which is passed as the argument to the method **sort()**.

Method **sort()** will call back that lambda many times as a “rule” on how we want the List _highScores_ to be sorted.

In that case, the “rule” is to sort the List in descending order based on the field _score_ from `class` ScoreEntry.

More precisely within the lambda, its parameter _a_ represents 1 ScoreEntry, which is then compared to the 2nd parameter _b_, which is also a ScoreEntry instance.

By subtracting their corresponding _score_ fields, we’ll get either a positive value, or a negative value or a zero value.

A positive result means that _b_ should be positioned before _a_ within the List.

A negative result means that _b_ should be positioned after _a_ within the List.

While a zero `0` result means both _b_ & _a_ have the same _score_; and thus no changes are needed.

BtW, a Java lambda function automatically returns the result of the expression within its body.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 3, 2025, 7:25pm UTC](https://discourse.processing.org/t/high-school-programming-project-complete-beginner/46500/4 "2025-06-03T19:25:40Z")

</div>

> [@dinomaster123](#):
>
> basically i have an advanced code in comparision for my level

Hello @dinomaster123,

What is the source of the code that was posted?

Please read:  
[Post Only Your Own Stuff](https://discourse.processing.org/faq#stealing)

`:)`

---

<div class="post-metadata">

**Author:** ![dinomaster123](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@dinomaster123](https://discourse.processing.org/u/dinomaster123)\
**Post date:** [June 23, 2025, 12:21pm UTC](https://discourse.processing.org/t/high-school-programming-project-complete-beginner/46500/5 "2025-06-23T12:21:50Z")

</div>

Dear glv, I have read and understood what you are advicing me, for the advanced parts i did use AI, to get the programm rolling, now i am fine tuning it, so that is why i I would like some assistance.

Please answer , as soon as you can because my deadline for my good is unfortunately Tomorrow.

Sincerly

dinomaster123

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 23, 2025, 2:03pm UTC](https://discourse.processing.org/t/high-school-programming-project-complete-beginner/46500/6 "2025-06-23T14:03:25Z")

</div>

Hello @dinomaster123,

> [@dinomaster123](#):
>
> Please answer , as soon as you can because my deadline for my good is unfortunately Tomorrow.

You’ve had 20 days, so asking for help as _“soon as you can”_ the day before the deadline isn’t realistic.

I often recommend taking a break from code, getting a good nights sleep and revisiting it the next day with a fresh perspective.

See here:  
_[Manually import Java library, JDSP, and cannot use JDSP built-in functions - #11 by glv](https://discourse.processing.org/t/manually-import-java-library-jdsp-and-cannot-use-jdsp-built-in-functions/46585/11)_

Please read all the guidelines (these are useful and helpful) at the top of the category:

- [Guidelines - FAQ / Code of Conduct](https://discourse.processing.org/faq)
- [Guidelines - Asking Questions](https://discourse.processing.org/t/guidelines-asking-questions/2147/)
- [Guidelines - Answering Questions](https://discourse.processing.org/t/guidelines-answering-questions/2145/)

> [@dinomaster123](#):
>
> for the advanced parts i did use AI, to get the programm rolling, now i am fine tuning it, so that is why i I would like some assistance.

AI can be a useful tool, but it’s not a substitute for learning, especially if you’re still a beginner. I don’t recommend relying on AI without understanding the basics first.

As an experienced user, I can comfortably navigate programming tools like AI and critically evaluate the output. A beginner usually can’t, and relying on it too early can create more confusion.

If you have a specific question about _ **one part of your code** _ or programming concepts, feel free to ask, but keep it focused (_ **do not post entire project** _) so others can consider helping.

Any code you do need help with should be properly formatted:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

Formatting code helps us help you and a requirement.

`:)`
