player health and movement

This commit is contained in:
Maximilian Ruhm 2023-12-18 18:17:43 +01:00
parent 80a3e06e84
commit a26432dbdd
4 changed files with 19 additions and 5 deletions

View File

@ -30,7 +30,7 @@ void play() {
background(50); background(50);
text(playtime.second(), 20, 20); text(playtime.second(), 20, 20);
println(playtime.second()); // println(playtime.second());
// for(int i = 0; i < trees.length; i++) { // for(int i = 0; i < trees.length; i++) {
@ -58,6 +58,7 @@ void play() {
// println(ship_zero.newX, " : ", ship_zero.newY); // println(ship_zero.newX, " : ", ship_zero.newY);
// println("x: ", ship_zero.x, " : ", ship_zero.y); // println("x: ", ship_zero.x, " : ", ship_zero.y);
println(stats_menu.trees_sawed);
} }
// ----- // -----

View File

@ -14,8 +14,13 @@ void keyPressed() {
if (ship_zero.hasSaw) { if (ship_zero.hasSaw) {
if(checkDistance(logs[ship_zero.nextLog], ship_zero) < 40) { if(checkDistance(logs[ship_zero.nextLog], ship_zero) < 40) {
logs[ship_zero.nextLog].sawed = true; logs[ship_zero.nextLog].sawed = true;
stats_menu.trees_sawed = stats_menu.trees_sawed + 1;
} }
} }
} else if (keyCode == ESC && isgame){
key = 0;
isgame = false;
ismenu = true;
} }
} }

View File

@ -37,6 +37,7 @@ class MainMenu extends Menus {
} }
void drawMenu() { void drawMenu() {
background(40);
// color maincolor = color(100, 100, 100); // color maincolor = color(100, 100, 100);
playButton(300, 300, 150, 50); playButton(300, 300, 150, 50);
statsButton(300, 400, 150, 50); statsButton(300, 400, 150, 50);
@ -64,9 +65,10 @@ class Stats extends Menus {
void draw() { void draw() {
background(50); background(50);
menuButton(); menuButton();
String trees = "Trees Sawed: ", trees_sawed;
text("Best Game Time", 50, 50); text("Best Game Time", 50, 50);
text("Trees Sawed", 50, 70); text(trees , 50, 70);
text("Insgesamt Spielzeit", 50, 90); text("Insgesamt Spielzeit", 50, 90);
} }
} }

View File

@ -1,4 +1,5 @@
// Roboter muss abprallen, kaputt gehen // Roboter muss abprallen, kaputt gehen
// TODO Abprallen nicht machen, wenn newx nicht erreicht sein kann, sondern wenn Robi tatsächlich die Wand berührt
class Ship { class Ship {
float x, y, a; float x, y, a;
@ -10,14 +11,14 @@ class Ship {
float movementSpeed = 2; // The speed of movement float movementSpeed = 2; // The speed of movement
int nextLog; int nextLog;
int health; int health = 3;
Ship() { Ship() {
x = width / 2; x = width / 2;
y = height / 2; y = height / 2;
a = -90; a = -90;
// newX = width/2; newX = width/2;
// newY = height/2; newY = height/2;
} }
void draw() { void draw() {
@ -31,6 +32,10 @@ class Ship {
// println(newX, " : ", newY); // println(newX, " : ", newY);
if (health == 0) {
exit();
}
colliding2 = false; colliding2 = false;
} }
@ -86,6 +91,7 @@ class Ship {
float richtungY = y-newY; float richtungY = y-newY;
x = (7*richtungX) + x; x = (7*richtungX) + x;
y = (7*richtungY) + y; y = (7*richtungY) + y;
health = health - 1;
} }
} else if (SOUTH) { } else if (SOUTH) {
newX = x - cos(radians(a)) * movementSpeed; newX = x - cos(radians(a)) * movementSpeed;