Compare commits
6 Commits
new
...
007bb67a0d
| Author | SHA1 | Date | |
|---|---|---|---|
| 007bb67a0d | |||
| 967dc93f23 | |||
| 4b2e32591f | |||
|
|
a26432dbdd | ||
| 80a3e06e84 | |||
|
|
497de07028 |
100
#simulation.pde#
Normal file
100
#simulation.pde#
Normal file
@@ -0,0 +1,100 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
.kek2.pde.~undo-tree~
Normal file
10
.kek2.pde.~undo-tree~
Normal file
@@ -0,0 +1,10 @@
|
||||
(undo-tree-save-format-version . 1)
|
||||
"f7678610572151071a75b80e34c3a939accf7c9b"
|
||||
[nil nil nil nil (25974 54439 79887 0) 0 nil]
|
||||
([nil nil ((#("
|
||||
|
||||
" 0 2 (fontified t)) . 1) (undo-tree-id0 . -1) (undo-tree-id1 . -1) (undo-tree-id2 . -1) (undo-tree-id3 . -1) (undo-tree-id4 . -1) (undo-tree-id5 . -1) (undo-tree-id6 . -2) 2 (t 25974 54118 112253 507000)) nil (25974 54439 79883 0) 0 nil])
|
||||
([nil nil ((1471 . 1474) (1469 . 1469) (1469 . 1471) (1463 . 1469) (1461 . 1463) (1460 . 1460) (1460 . 1461) (1459 . 1460) (1458 . 1459) (1456 . 1457) (1455 . 1456) (#("." 0 1 (face font-lock-string-face fontified t)) . -1455) (undo-tree-id7 . -1) (undo-tree-id8 . -1) (undo-tree-id9 . -1) (undo-tree-id10 . -1) (undo-tree-id11 . -1) (undo-tree-id12 . -1) (undo-tree-id13 . -1) (#(" " 0 1 (face font-lock-string-face fontified t)) . -1456) (undo-tree-id14 . -1) (undo-tree-id15 . -1) (undo-tree-id16 . -1) (undo-tree-id17 . -1) (undo-tree-id18 . -1) 1457 (1454 . 1457) (1453 . 1455) (#("\"" 0 1 (fontified nil)) . -1453) (undo-tree-id19 . -1) (undo-tree-id20 . -1) (1452 . 1454) (1451 . 1452) (1448 . 1451) (1447 . 1447) (1447 . 1448) (#("N" 0 1 (fontified t)) . -1447) (undo-tree-id21 . -1) (undo-tree-id22 . -1) (#("e" 0 1 (fontified t)) . -1448) (undo-tree-id23 . -1) (undo-tree-id24 . -1) 1449 (1448 . 1449) (1446 . 1446) (1446 . 1448) (1440 . 1446) (1439 . 1440) (1438 . 1439) (1437 . 1437) (1437 . 1438) (1436 . 1438) (#("(" 0 1 (face font-lock-keyword-face fontified nil)) . -1436) (1436 . 1437) (1430 . 1436) (1429 . 1429) (1429 . 1430) (#("o" 0 1 (fontified t)) . -1429) (undo-tree-id25 . -1) (undo-tree-id26 . -1) 1430 (1429 . 1429) (1429 . 1430) (1427 . 1429) (#(" " 0 2 (fontified nil)) . 1426) (undo-tree-id27 . -2) (1428 . 1429) (1425 . 1428) (t 25974 54439 84243 136000) 1379) nil (25974 55177 491605 0) 0 nil])
|
||||
([nil nil ((1475 . 1476) (t 25974 55177 494845 710000)) nil (25974 55179 791073 0) 0 nil])
|
||||
([nil current ((apply -3 1427 1480 undo--wrap-and-run-primitive-undo 1427 1480 ((1429 . 1432) 1443))) nil (25974 55193 449487 0) 0 nil])
|
||||
nil
|
||||
15
.logs.pde.~undo-tree~
Normal file
15
.logs.pde.~undo-tree~
Normal file
@@ -0,0 +1,15 @@
|
||||
(undo-tree-save-format-version . 1)
|
||||
"aafce57dc9d3ed6c354179a6ca1caa678609b93f"
|
||||
[nil nil nil nil (25974 55370 872343 0) 0 nil]
|
||||
([nil nil ((#("logwidth/2, y+5, 170*0.3, 160*0.3);
|
||||
}
|
||||
}
|
||||
|
||||
void logCollide() " 0 13 (fontified t) 13 14 (prettify-symbols-end 918 prettify-symbols-start 917 composition (0 1 [32 65 57709]) fontified t) 14 20 (fontified t) 20 21 (prettify-symbols-end 925 prettify-symbols-start 924 composition (1 1 [32 65 57711]) fontified t) 21 29 (fontified t) 29 30 (prettify-symbols-end 934 prettify-symbols-start 933 composition (1 1 [32 65 57711]) fontified t) 30 42 (fontified t) 42 45 (fontified t) 45 46 (fontified t) 46 47 (fontified t) 47 49 (fontified t) 49 50 (face font-lock-type-face fontified t) 50 51 (face font-lock-type-face fontified t) 51 52 (face font-lock-type-face fontified t) 52 53 (face font-lock-type-face c-type c-decl-id-start fontified t) 53 54 (fontified t) 54 55 (face font-lock-function-name-face fontified t) 55 56 (face font-lock-function-name-face fontified t) 56 57 (face font-lock-function-name-face fontified t) 57 58 (face font-lock-function-name-face fontified t) 58 59 (face font-lock-function-name-face fontified t) 59 60 (face font-lock-function-name-face fontified t) 60 61 (face font-lock-function-name-face fontified t) 61 62 (face font-lock-function-name-face fontified t) 62 63 (face font-lock-function-name-face fontified t) 63 64 (face font-lock-function-name-face fontified t) 64 65 (fontified t) 65 66 (fontified t) 66 67 (fontified t)) . -904) (undo-tree-id10 . -44) (undo-tree-id11 . -61) (undo-tree-id12 . -67) 971 (970 . 971) (968 . 970) (#("(" 0 1 (face font-lock-variable-name-face fontified nil)) . -968) (968 . 969) (#(" " 0 1 (fontified t)) . -968) (undo-tree-id13 . -1) 969 (965 . 969) (#("o" 0 1 (face font-lock-variable-name-face fontified t)) . -965) (undo-tree-id14 . -1) 966 (965 . 966) (#("ide() " 0 1 (face font-lock-function-name-face fontified t) 1 2 (face font-lock-function-name-face fontified t) 2 3 (face font-lock-function-name-face fontified t) 3 4 (fontified t) 4 5 (fontified t) 5 6 (fontified t)) . -965) (undo-tree-id15 . -4) (undo-tree-id16 . -6) 971 (970 . 971) (#(";" 0 1 (fontified t)) . -970) (undo-tree-id17 . -1) (#("
|
||||
" 0 1 (fontified t)) . -971) (undo-tree-id18 . -1) (#(" " 0 1 (fontified t)) . -972) (undo-tree-id19 . -1) (#(" " 0 1 (fontified t)) . -973) (undo-tree-id20 . -1) 974 (971 . 974) (970 . 971) (#("L" 0 1 (face font-lock-type-face fontified t)) . -969) (undo-tree-id21 . -1) (undo-tree-id22 . -1) (#("o" 0 1 (face font-lock-type-face fontified t)) . -970) (undo-tree-id23 . -1) (undo-tree-id24 . -1) (#("g" 0 1 (face font-lock-type-face fontified t)) . -971) (undo-tree-id25 . -1) (undo-tree-id26 . -1) 972 (970 . 972) (969 . 969) (969 . 970) (968 . 970) (#("(" 0 1 (face font-lock-variable-name-face fontified nil)) . -968) (968 . 969) (959 . 968) (954 . 954) (954 . 959) (953 . 953) (953 . 954) (951 . 953) (#(" " 0 2 (fontified nil)) . 950) (undo-tree-id27 . -2) (952 . 953) (949 . 952) (t 25974 54118 112720 118000) 948) nil (25974 55370 872341 0) 0 nil])
|
||||
([nil nil ((#("
|
||||
" 0 1 (fontified nil) 1 3 (fontified nil)) . 949) (undo-tree-id1 . -3) (#("
|
||||
" 0 1 (fontified nil)) . 952) (undo-tree-id2 . -1) (950 . 952) (#(" " 0 2 (fontified nil)) . 951) (undo-tree-id3 . -2) (#("v" 0 1 (face font-lock-type-face fontified nil)) . 953) (undo-tree-id4 . -1) (#("oid l" 0 1 (face font-lock-type-face fontified nil) 1 2 (face font-lock-type-face fontified nil) 2 3 (face font-lock-type-face fontified nil) 3 4 (fontified nil) 4 5 (face font-lock-function-name-face fontified nil)) . 954) (undo-tree-id5 . -5) (#("ogCollide" 0 1 (face font-lock-function-name-face fontified nil) 1 2 (face font-lock-function-name-face fontified nil) 2 3 (face font-lock-function-name-face fontified nil) 3 4 (face font-lock-function-name-face fontified nil) 4 5 (face font-lock-function-name-face fontified nil) 5 6 (face font-lock-function-name-face fontified nil) 6 7 (face font-lock-function-name-face fontified nil) 7 8 (face font-lock-function-name-face fontified nil) 8 9 (face font-lock-function-name-face fontified nil)) . 959) (undo-tree-id6 . -9) (#("(" 0 1 (face font-lock-variable-name-face fontified nil)) . 968) (968 . 969) (#("()" 0 1 (fontified nil) 1 2 (fontified nil)) . 968) (undo-tree-id7 . -1) (#("L" 0 1 (face font-lock-type-face fontified nil)) . 969) (undo-tree-id8 . -1) (#("og" 0 1 (face font-lock-type-face fontified nil) 1 2 (face font-lock-type-face fontified nil)) . 970) (undo-tree-id9 . -2) (969 . 972) (#(";" 0 1 (fontified nil)) . 970) (#("
|
||||
" 0 1 (fontified nil) 1 2 (fontified nil) 2 3 (fontified nil)) . 971) (970 . 974) (#(" " 0 1 (fontified nil)) . 970) (965 . 971) (#("o" 0 1 (face font-lock-variable-name-face fontified nil)) . 965) (965 . 966) (#("ide " 0 1 (face font-lock-function-name-face fontified nil) 1 2 (face font-lock-function-name-face fontified nil) 2 3 (face font-lock-function-name-face fontified nil) 3 4 (fontified nil)) . 965) (968 . 969) (#("(" 0 1 (face font-lock-variable-name-face fontified nil)) . 968) (968 . 969) (#("()" 0 1 (fontified nil) 1 2 (fontified nil)) . 968) (#(" " 0 1 (fontified nil)) . 970) (904 . 971)) nil (25974 55370 872332 0) 0 nil])
|
||||
([nil current ((970 . 971) (968 . 970) (#("(" 0 1 (face font-lock-variable-name-face fontified nil)) . -968) (968 . 969) (959 . 968) (954 . 954) (954 . 959) (953 . 953) (953 . 954) (951 . 953) (#(" " 0 2 (fontified nil)) . 950) (undo-tree-id0 . -2) (952 . 953) (949 . 952) (t 25974 54118 112720 118000) 948) nil (25974 55370 872323 0) 0 nil])
|
||||
nil
|
||||
11
.ship.pde.~undo-tree~
Normal file
11
.ship.pde.~undo-tree~
Normal file
@@ -0,0 +1,11 @@
|
||||
(undo-tree-save-format-version . 1)
|
||||
"5a0971ca47ac30921e9b713a56e832b4cdda3829"
|
||||
[nil nil nil nil (25974 55084 608787 0) 0 nil]
|
||||
([nil nil ((#("
|
||||
" 0 1 (fontified t)) . -254) (undo-tree-id0 . -1) (undo-tree-id1 . -1) (undo-tree-id2 . -1) (undo-tree-id3 . -1) (undo-tree-id4 . -1) (undo-tree-id5 . -1) (#("
|
||||
" 0 1 (fontified t)) . -255) (undo-tree-id6 . -1) (undo-tree-id7 . -1) (undo-tree-id8 . -1) (undo-tree-id9 . -1) (undo-tree-id10 . -1) (#(" " 0 1 (fontified t)) . -256) (undo-tree-id11 . -1) (undo-tree-id12 . -1) (undo-tree-id13 . -1) (#(" " 0 1 (fontified t)) . -257) (undo-tree-id14 . -1) (undo-tree-id15 . -1) 258 (256 . 258) (#(" " 0 2 (fontified nil)) . 255) (undo-tree-id16 . -2) (257 . 258) (254 . 257) (t 25974 54118 112987 610000) 251) nil (25974 55084 608783 0) 0 nil])
|
||||
([nil nil ((apply 3 484 507 undo--wrap-and-run-primitive-undo 484 507 ((#("// " 0 1 (face font-lock-comment-delimiter-face fontified t c-is-sws t c-in-sws t) 1 3 (face font-lock-comment-delimiter-face fontified t c-in-sws t)) . -488) 507))) nil (25974 55118 133801 0) 0 nil])
|
||||
([nil nil ((484 . 485)) nil (25974 55118 133801 0) 0 nil])
|
||||
([nil nil ((511 . 514) (509 . 509) (509 . 511) (508 . 509) (506 . 507) (505 . 506) (504 . 505) (503 . 505) (#("\"" 0 1 (fontified nil)) . -503) (503 . 504) (#("\"" 0 1 (face font-lock-string-face fontified nil)) . -503) (undo-tree-id17 . -1) (#("\"" 0 1 (face font-lock-string-face fontified t)) . 504) (503 . 505) (#("\"" 0 1 (fontified nil)) . -503) (502 . 504) (501 . 502) (499 . 501) (498 . 498) (498 . 499) (497 . 497) (497 . 498) (#("colliding" 0 9 (fontified t)) . 497) (undo-tree-id18 . -8) (undo-tree-id19 . -8) (undo-tree-id20 . -1) (undo-tree-id21 . -1) (undo-tree-id22 . -1) (undo-tree-id23 . -1) (undo-tree-id24 . -9) (undo-tree-id25 . -9) 498) nil (25974 55118 133798 0) 0 nil])
|
||||
([nil current ((apply -3 485 520 undo--wrap-and-run-primitive-undo 485 520 ((489 . 492) 497))) nil (25974 55141 588556 0) 0 nil])
|
||||
nil
|
||||
8
.simulation.pde.~undo-tree~
Normal file
8
.simulation.pde.~undo-tree~
Normal file
@@ -0,0 +1,8 @@
|
||||
(undo-tree-save-format-version . 1)
|
||||
"6ba7b52093be99eddee500fa2cd073dfd0644cc9"
|
||||
[nil nil nil nil (25965 46461 784103 0) 0 nil]
|
||||
([nil nil ((122 . 123) (120 . 122) (#("#" 0 1 (fontified t)) . -120) (undo-tree-id0 . -1) 121 (120 . 121) (t 25939 34023 800616 55000)) nil (25965 46461 784100 0) 0 nil])
|
||||
([nil nil ((83 . 84) (t 25965 46461 786953 630000) 48) nil (25974 17116 102820 0) 0 nil])
|
||||
([nil current ((#("
|
||||
" 0 1 (fontified t)) . 84) (undo-tree-id0 . 1)) nil (25974 17116 102818 0) 0 nil])
|
||||
nil
|
||||
BIN
assets/Sprite-0001.ase
Normal file
BIN
assets/Sprite-0001.ase
Normal file
Binary file not shown.
BIN
assets/Sprite-0001.png
Normal file
BIN
assets/Sprite-0001.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/Sprite-0002.ase
Normal file
BIN
assets/Sprite-0002.ase
Normal file
Binary file not shown.
BIN
assets/Sprite-bob.png
Normal file
BIN
assets/Sprite-bob.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 507 B |
BIN
assets/Sprite-robi.png
Normal file
BIN
assets/Sprite-robi.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/Sprite-robiwithbob.png
Normal file
BIN
assets/Sprite-robiwithbob.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.5 KiB |
BIN
assets/Sprite-saege.png
Normal file
BIN
assets/Sprite-saege.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 236 B |
17
collect.pde
17
collect.pde
@@ -1,10 +1,11 @@
|
||||
class Collectable {
|
||||
float x, y, cwidth, cheight;
|
||||
float cwidth, cheight;
|
||||
boolean is_attached = false;
|
||||
PVector pos = new PVector();
|
||||
|
||||
Collectable(float xpos, float ypos, float cw, float ch) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
pos.x = xpos;
|
||||
pos.y = ypos;
|
||||
cwidth = cw;
|
||||
cheight = ch;
|
||||
}
|
||||
@@ -18,10 +19,7 @@ class Saw extends Collectable {
|
||||
|
||||
void drawSaw() {
|
||||
if (!is_attached) {
|
||||
stroke(0);
|
||||
fill(210, 210, 0);
|
||||
rect(x, y, cwidth, cheight);
|
||||
fill(0);
|
||||
image(saw_sprite, pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,10 +32,7 @@ class Bob extends Collectable {
|
||||
|
||||
void drawBob() {
|
||||
if (!is_attached) {
|
||||
stroke(0);
|
||||
fill(255, 209, 152);
|
||||
rect(x, y, cwidth, cheight);
|
||||
fill(0);
|
||||
image(bob_sprite, pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
files.pde
Normal file
32
files.pde
Normal file
@@ -0,0 +1,32 @@
|
||||
class Files {
|
||||
|
||||
boolean checkSaveFile(String filepath) {
|
||||
return new File(dataPath(filepath)).exists();
|
||||
}
|
||||
|
||||
void loadJson(String jsonfile) {
|
||||
// if (!checkSaveFile(jsonfile)) {
|
||||
try {
|
||||
JSONArray values = loadJSONArray(jsonfile);
|
||||
|
||||
stats_menu.best_game_time = values.getInt(0);
|
||||
stats_menu.trees_sawed = values.getInt(1);
|
||||
stats_menu.game_time = values.getInt(2);
|
||||
println("Savefile found");
|
||||
|
||||
} catch (Exception e) {
|
||||
println("Savefile not found");
|
||||
}
|
||||
}
|
||||
|
||||
JSONArray json;
|
||||
void savetofile(String filename) {
|
||||
json = new JSONArray();
|
||||
|
||||
json.setInt(0, stats_menu.best_game_time);
|
||||
json.setInt(1, stats_menu.trees_sawed);
|
||||
json.setInt(2, millis() + stats_menu.game_time);
|
||||
saveJSONArray(json,"./saves/" + filename + ".json");
|
||||
}
|
||||
|
||||
}
|
||||
174
kek2.pde
174
kek2.pde
@@ -1,54 +1,30 @@
|
||||
|
||||
|
||||
float checkDistance(Log log, Ship ship) {
|
||||
float testX = ship.x;
|
||||
float testY = ship.y;
|
||||
float testX = ship.pos.x;
|
||||
float testY = ship.pos.y;
|
||||
|
||||
// which edge is closest?
|
||||
if (ship.x < log.x) testX = log.x;
|
||||
else if (ship.x > log.x+log.logwidth) testX = log.x+log.logwidth;
|
||||
if (ship.y < log.y) testY = log.y;
|
||||
else if (ship.y > log.y+log.logheight) testY = log.y+log.logheight;
|
||||
if (ship.pos.x < log.x) testX = log.x;
|
||||
else if (ship.pos.x > log.x+log.logwidth) testX = log.x+log.logwidth;
|
||||
if (ship.pos.y < log.y - log.logheight) testY = log.y - log.logheight;
|
||||
else if (ship.pos.y > log.y) testY = log.y;
|
||||
|
||||
// get distant
|
||||
float distX = ship.x-testX;
|
||||
float distY = ship.y-testY;
|
||||
float distX = ship.pos.x-testX;
|
||||
float distY = ship.pos.y-testY;
|
||||
float distance = sqrt( (distX*distX) + (distY*distY) );
|
||||
|
||||
line(testX, testY, ship_zero.x, ship_zero.y);
|
||||
line(testX, testY, ship.pos.x, ship.pos.y);
|
||||
|
||||
// if the distance is less than the radius, collision!
|
||||
return distance;
|
||||
}
|
||||
|
||||
// -----
|
||||
boolean isColliding = false;
|
||||
// Main Game entry
|
||||
void play() {
|
||||
background(75, 105, 47);
|
||||
|
||||
Ship ship_zero;
|
||||
Saw saw_zero;
|
||||
Bob bob;
|
||||
text(playtime.second(), 20, 20);
|
||||
|
||||
Log[] logs = {new Log(100, 200, 100, 100, false), new Log(500, 200, 200, 100, false), new Log(400, 400, 20, 100, true) };
|
||||
|
||||
void setup() {
|
||||
size(600, 600);
|
||||
ship_zero = new Ship();
|
||||
saw_zero = new Saw(100, 100, 20, 50);
|
||||
bob = new Bob(100, 400, 20, 40);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(50);
|
||||
|
||||
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
logs[i].drawLog(i);
|
||||
}
|
||||
|
||||
|
||||
// for(int i = 0; i < trees.length; i++) {
|
||||
// trees[i].draw();
|
||||
// }
|
||||
|
||||
ship_zero.draw();
|
||||
saw_zero.drawSaw();
|
||||
@@ -56,11 +32,129 @@ void draw() {
|
||||
bob.drawBob();
|
||||
ship_zero.collect(bob);
|
||||
|
||||
// draw wall
|
||||
for(int i = 0; i < walls.length; i++) {
|
||||
walls[i].drawLog(i);
|
||||
}
|
||||
// draw log
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
logs[i].drawLog(i);
|
||||
}
|
||||
// log normal stroke
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
logs[i].strokecolor = logs[i].logcolor;
|
||||
}
|
||||
|
||||
|
||||
// nearest log stroke (debug)
|
||||
logs[ship_zero.nextLog].strokecolor = color(255, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// global state
|
||||
boolean isgame = false;
|
||||
boolean ismenu = true;
|
||||
boolean isend = false;
|
||||
boolean isstats = false;
|
||||
boolean ispause = false;
|
||||
boolean start_slide = true;
|
||||
|
||||
// ----- Objectives
|
||||
MainMenu main_menu = new MainMenu();
|
||||
Stats stats_menu = new Stats();
|
||||
|
||||
Log[] logs;
|
||||
|
||||
// player
|
||||
Ship ship_zero;
|
||||
|
||||
// collectables
|
||||
Saw saw_zero;
|
||||
Bob bob;
|
||||
|
||||
// stopwatch
|
||||
StopWatchTimer playtime = new StopWatchTimer();
|
||||
Files savefile = new Files();
|
||||
|
||||
|
||||
PImage player_sprite;
|
||||
PImage player_sprite_bob;
|
||||
PImage saw_sprite;
|
||||
PImage bob_sprite;
|
||||
|
||||
void setup() {
|
||||
size(600, 600);
|
||||
textAlign(CENTER, CENTER);
|
||||
|
||||
create_level(30);
|
||||
println(logs[1]);
|
||||
|
||||
ship_zero = new Ship();
|
||||
saw_zero = new Saw(-width+100, 100, 20, 50);
|
||||
bob = new Bob(500, 400, 20, 40);
|
||||
|
||||
player_sprite = loadImage("./assets/Sprite-robi.png");
|
||||
player_sprite_bob = loadImage("./assets/Sprite-robiwithbob.png");
|
||||
saw_sprite = loadImage("./assets/Sprite-saege.png");
|
||||
bob_sprite = loadImage("./assets/Sprite-bob.png");
|
||||
|
||||
savefile.loadJson("./saves/save.json");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
// time debug
|
||||
// println(millis(), " start: ", playtime.startTime, " pause: ", playtime.pauseTime);
|
||||
|
||||
// game state
|
||||
if (isgame) {
|
||||
|
||||
// Go to second or first slide
|
||||
if(ship_zero.pos.x > 0) {
|
||||
start_slide = false;
|
||||
} else {
|
||||
start_slide = true;
|
||||
}
|
||||
|
||||
// actually move the camera
|
||||
if(start_slide) {
|
||||
translate(600, 0);
|
||||
} else {
|
||||
translate(0, 0);
|
||||
}
|
||||
|
||||
// Main Entry
|
||||
play();
|
||||
|
||||
// Timer
|
||||
if (playtime.running) {} else playtime.start();
|
||||
if (playtime.pause) playtime.resume();
|
||||
|
||||
// Win
|
||||
if(bob.is_attached && dist(ship_zero.pos.x, ship_zero.pos.y ,-400, 300) < 100) {
|
||||
isgame = false;
|
||||
isend = true;
|
||||
}
|
||||
fill(150, 0, 0, 50);
|
||||
ellipse(-400, 300, 200, 200);
|
||||
|
||||
} else if (ismenu){
|
||||
// menu code
|
||||
// play();
|
||||
main_menu.drawMenu();
|
||||
if (playtime.running) playtime.stop();
|
||||
} else if (isstats) {
|
||||
stats_menu.draw();
|
||||
} else if (isend) {
|
||||
// end screen code
|
||||
|
||||
|
||||
// save
|
||||
if(playtime.second() < stats_menu.best_game_time) stats_menu.best_game_time = playtime.second();
|
||||
savefile.savetofile("save");
|
||||
} else if (ispause) {
|
||||
main_menu.drawMenu();
|
||||
|
||||
if (playtime.running && playtime.pause == false) playtime.pause_start();
|
||||
}
|
||||
|
||||
mouse_released = false;
|
||||
}
|
||||
|
||||
17
keys.pde
17
keys.pde
@@ -12,10 +12,18 @@ void keyPressed() {
|
||||
}
|
||||
} else if (key == 's') { // SAW
|
||||
if (ship_zero.hasSaw) {
|
||||
if(checkDistance(logs[ship_zero.nextLog], ship_zero) < 40) {
|
||||
logs[ship_zero.nextLog].sawed = true;
|
||||
Log target_log = logs[ship_zero.nextLog];
|
||||
if(checkDistance(target_log, ship_zero) < 40) {
|
||||
target_log.sawed = true;
|
||||
stats_menu.trees_sawed = stats_menu.trees_sawed + 1;
|
||||
}
|
||||
}
|
||||
} else if (keyCode == ESC){
|
||||
key = 0;
|
||||
if (isgame) {
|
||||
isgame = false;
|
||||
ispause = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,3 +33,8 @@ void keyReleased() {
|
||||
else if (keyCode == LEFT) {ROTATEL = false; }
|
||||
else if (keyCode == RIGHT) {ROTATER = false; }
|
||||
}
|
||||
|
||||
boolean mouse_released = false;
|
||||
void mouseReleased() {
|
||||
mouse_released = true;
|
||||
}
|
||||
|
||||
15
level.pde
Normal file
15
level.pde
Normal file
@@ -0,0 +1,15 @@
|
||||
// Outside wall
|
||||
Log[] walls = {new Log(-30, 275, 40, 275, false, true), new Log(-30, 600, 40, 275, false, true)};
|
||||
|
||||
void create_level(int logcount) {
|
||||
logs = new Log[logcount];
|
||||
randomSeed((int)random(0, 30));
|
||||
for (int i = 1; i < logs.length; i++) {
|
||||
logs[i] = new Log((int) random(0, width), (int) random(0, height), 20, 60 + random(0, 40), true, false);
|
||||
}
|
||||
// 2nd slide entry
|
||||
logs[0] = new Log(-5, 325, 10, 50, false, true);
|
||||
|
||||
// debug log
|
||||
logs[1] = new Log(-300, 100, 20, 100, true, false);
|
||||
}
|
||||
33
logs.pde
33
logs.pde
@@ -2,54 +2,57 @@ class Log {
|
||||
float x, y, logwidth, logheight;
|
||||
boolean sawed = false;
|
||||
boolean is_tree = false;
|
||||
boolean is_wall = false;
|
||||
float a = 0;
|
||||
boolean render_log = true;
|
||||
|
||||
color logcolor;
|
||||
color strokecolor = logcolor;
|
||||
|
||||
Log (float xpos, float ypos, float logw, float logh, boolean ist) {
|
||||
Log (float xpos, float ypos, float logw, float logh, boolean ist, boolean isw) {
|
||||
x = xpos;
|
||||
y = ypos;
|
||||
logwidth = logw;
|
||||
logheight = logh;
|
||||
is_tree = ist;
|
||||
is_wall = isw;
|
||||
//draw();
|
||||
}
|
||||
|
||||
void drawLog(int logtext) {
|
||||
|
||||
if (sawed) {
|
||||
logcolor = color(128, 88, 60);
|
||||
if (a > -90) a = a - 1;
|
||||
if (a == -90) render_log = false;
|
||||
} else if (is_wall) {
|
||||
logcolor = color(0, 0, 0);
|
||||
} else {
|
||||
logcolor = color(133, 79, 51);
|
||||
}
|
||||
|
||||
if (render_log) {
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
rotate(radians(a));
|
||||
stroke(strokecolor); // Set stroke color for the log
|
||||
strokeWeight(1); // Set stroke weight for the log
|
||||
fill(logcolor); // Set fill color for the log
|
||||
// rectMode(CENTER);
|
||||
rect(x, y, logwidth, logheight); // Draw the log as a rectangle
|
||||
rect(0, 0, logwidth, -logheight); // Draw the log as a rectangle
|
||||
text(logtext, x, y);
|
||||
// rectMode(CORNER);
|
||||
strokeWeight(1);
|
||||
stroke(0);
|
||||
|
||||
// Bush
|
||||
if(is_tree) {
|
||||
color bushes = color(107, 117, 48);
|
||||
fill(bushes);
|
||||
ellipse(x+logwidth/2, y+5, 170*0.3, 160*0.3);
|
||||
}
|
||||
ellipse(0 + logwidth/2, 0 - logheight, 170*0.3, 160*0.3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Tree extends Log {
|
||||
Tree (float x, float y, float logw, float logh, boolean hasC) {
|
||||
super(x, y, logw, logh, hasC);
|
||||
popMatrix();
|
||||
}
|
||||
void draw() {
|
||||
color treecolor = color(133, 79, 51);
|
||||
|
||||
// rectMode(CENTER);
|
||||
drawLog(1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
141
menu.pde
Normal file
141
menu.pde
Normal file
@@ -0,0 +1,141 @@
|
||||
class Menus {
|
||||
|
||||
boolean drawRectWithMouseColission(float x, float y, float rectwidth, float rectheight) {
|
||||
// Draw A Rect
|
||||
rectMode(CENTER);
|
||||
rect(x, y, rectwidth, rectheight);
|
||||
rectMode(CORNER);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MainMenu extends Menus {
|
||||
|
||||
void playButton(float x, float y, float w, float h) {
|
||||
fill(100, 100, 100);
|
||||
if(drawRectWithMouseColission(x, y, w, h) && mousePressed) {
|
||||
ismenu = false;
|
||||
ispause = false;
|
||||
isgame = true;
|
||||
}
|
||||
fill(0);
|
||||
textAlign(CENTER, CENTER);
|
||||
textSize(32);
|
||||
text("Play", x, y);
|
||||
}
|
||||
|
||||
void statsButton(float x, float y, float w, float h) {
|
||||
fill(100, 100, 100);
|
||||
if(drawRectWithMouseColission(x, y, w, h) && mousePressed) {
|
||||
ismenu = false;
|
||||
isstats = true;
|
||||
}
|
||||
fill(0);
|
||||
textAlign(CENTER, CENTER);
|
||||
textSize(32);
|
||||
text("Stats", x, y);
|
||||
}
|
||||
|
||||
void drawMenu() {
|
||||
background(40);
|
||||
// color maincolor = color(100, 100, 100);
|
||||
playButton(300, 300, 150, 50);
|
||||
statsButton(300, 400, 150, 50);
|
||||
|
||||
textSize(100);
|
||||
textAlign(CENTER, CENTER);
|
||||
text("Save Bob", 300, 200);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
println("test");
|
||||
}
|
||||
}
|
||||
|
||||
class Stats extends Menus {
|
||||
int trees_sawed = 0;
|
||||
int best_game_time = 0;
|
||||
int game_time = 0;
|
||||
|
||||
void menuButton() {
|
||||
fill(100, 100, 100);
|
||||
if(drawRectWithMouseColission(300, 300, 150, 50) && mouse_released) {
|
||||
ismenu = true;
|
||||
isgame = false;
|
||||
isstats = false;
|
||||
}
|
||||
fill(0);
|
||||
textSize(32);
|
||||
textAlign(CENTER, CENTER);
|
||||
text("Main Menu", 300, 300);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(50);
|
||||
menuButton();
|
||||
|
||||
textAlign(LEFT);
|
||||
textSize(24);
|
||||
text("Best Game Time", 100, 50);
|
||||
text(best_game_time, 500, 50);
|
||||
text("Trees Sawed: " , 100, 70);
|
||||
text(trees_sawed, 500, 70);
|
||||
text("Insgesamt Spielzeit", 100, 90);
|
||||
text(game_time, 500, 90);
|
||||
}
|
||||
}
|
||||
|
||||
class StopWatchTimer {
|
||||
int startTime = 0, stopTime = 0, pauseTime = 0;
|
||||
boolean running = false;
|
||||
boolean pause = false;
|
||||
|
||||
|
||||
void start() {
|
||||
startTime = millis();
|
||||
running = true;
|
||||
}
|
||||
void stop() {
|
||||
stopTime = millis();
|
||||
running = false;
|
||||
}
|
||||
void pause_start() {
|
||||
if (!pause) {
|
||||
pauseTime = millis();
|
||||
pause = true;
|
||||
}
|
||||
}
|
||||
void resume() {
|
||||
if (pause) {
|
||||
startTime = startTime + (millis() - pauseTime);
|
||||
pauseTime = 0;
|
||||
pause = false;
|
||||
}
|
||||
}
|
||||
int getElapsedTime() {
|
||||
int elapsed;
|
||||
if (running) {
|
||||
elapsed = (millis() - startTime);
|
||||
}
|
||||
else {
|
||||
elapsed = (stopTime - startTime);
|
||||
}
|
||||
return elapsed;
|
||||
}
|
||||
int second() {
|
||||
return (getElapsedTime() / 1000) % 60;
|
||||
}
|
||||
int minute() {
|
||||
return (getElapsedTime() / (1000*60)) % 60;
|
||||
}
|
||||
int hour() {
|
||||
return (getElapsedTime() / (1000*60*60)) % 24;
|
||||
}
|
||||
}
|
||||
17
readme.org
Normal file
17
readme.org
Normal file
@@ -0,0 +1,17 @@
|
||||
** Ingame
|
||||
*** DONE Level mit 2 Bereichen. Erster Bereich Straße und Kettensäge und End/Startpunkt. Zweiter Bereich Wald und Bob
|
||||
*** DONE Robi muss noch beschleunigen können
|
||||
*** TODO Wir brauchen Geräusche
|
||||
*** DONE setze bob auf den Robi
|
||||
*** TODO Richtige Texte am Anfang zum erklären
|
||||
*** TODO Abprallen nicht machen, wenn newx nicht erreicht sein kann, sondern wenn Robi tatsächlich die Wand berührt
|
||||
*** TODO Roboter muss abprallen, kaputt gehen
|
||||
*** BUG sometimes a log gets stuck in sawed = false state
|
||||
** Menu
|
||||
*** DONE Statistikseite: Spielzeit, Bäume gefällt, Zeit gestoppt
|
||||
*** DONE Richtige Texte im Menu
|
||||
*** DONE File loading and saving
|
||||
Wird noch nicht benutzt
|
||||
*** DONE nochmal die statistikseite überarbeiten
|
||||
**** DONE Math for best_game_time
|
||||
**** TODO Why doesnt bestgametime work
|
||||
5
saves/save.json
Normal file
5
saves/save.json
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
0,
|
||||
13,
|
||||
205455
|
||||
]
|
||||
141
ship.pde
141
ship.pde
@@ -1,41 +1,59 @@
|
||||
class Ship {
|
||||
float x, y, a;
|
||||
// Movement
|
||||
PVector pos = new PVector(-width/2, height/2); // position
|
||||
PVector speed = new PVector(0, 0); // The speed of movement
|
||||
PVector acceleration = new PVector();
|
||||
float a; // angle
|
||||
|
||||
// For the collision
|
||||
PVector newPos = new PVector(width/2, height/2);
|
||||
|
||||
float newX, newY;
|
||||
boolean colliding = false;
|
||||
boolean colliding2 = false;
|
||||
boolean colliding_logs = false;
|
||||
boolean hasSaw = false;
|
||||
float rotationSpeed = 4; // The speed of rotation
|
||||
float movementSpeed = 4; // The speed of movement
|
||||
int nextLog;
|
||||
|
||||
int health = 3;
|
||||
|
||||
Ship() {
|
||||
x = width / 2;
|
||||
y = height / 2;
|
||||
a = -90;
|
||||
// pos.x = width/2;
|
||||
// pos.y = height/2;
|
||||
|
||||
a = 0;
|
||||
newX = width/2;
|
||||
newY = height/2;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
nextLog = returnIndexOfNearestLog();
|
||||
|
||||
logCollide(logs);
|
||||
// logCollide(trees);
|
||||
logCollide(walls);
|
||||
|
||||
|
||||
sawIndicator();
|
||||
simulate();
|
||||
render();
|
||||
// println(colliding);
|
||||
|
||||
ship_zero.colliding2 = false;
|
||||
// println(newX, " : ", newY);
|
||||
|
||||
if (health == 0) {
|
||||
exit();
|
||||
}
|
||||
|
||||
colliding_logs = false;
|
||||
}
|
||||
|
||||
void sawIndicator() {
|
||||
if (hasSaw) {
|
||||
if (checkDistance(logs[nextLog], ship_zero) < 40) {
|
||||
fill(204, 102, 0);
|
||||
circle(x, y -20, 20);
|
||||
circle(pos.x, pos.y -20, 20);
|
||||
fill(0);
|
||||
textSize(32);
|
||||
textAlign(CENTER, CENTER);
|
||||
text("s", x, y - 27);
|
||||
text("s", pos.x, pos.y - 27);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,78 +62,105 @@ class Ship {
|
||||
float shortest_distance_log_distance = checkDistance(logs[0], ship_zero);
|
||||
int shortest_distance_log = 0;
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
// only logs that are not sawed already
|
||||
if (!logs[i].sawed) {
|
||||
if(checkDistance(logs[i], ship_zero) < shortest_distance_log_distance) {
|
||||
shortest_distance_log = i;
|
||||
shortest_distance_log_distance = checkDistance(logs[i], ship_zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
return shortest_distance_log;
|
||||
}
|
||||
|
||||
void simulate() {
|
||||
if(newX > 0 && newX < width && newY > 0 && newY < height) {
|
||||
colliding = false;
|
||||
} else {
|
||||
colliding = true;
|
||||
}
|
||||
// First do the Math but dont move something
|
||||
|
||||
// Rotate PLayer
|
||||
if (ROTATEL) {
|
||||
a -= rotationSpeed;
|
||||
a -= 0.03;
|
||||
}
|
||||
if (ROTATER) {
|
||||
a += rotationSpeed;
|
||||
a += 0.03;
|
||||
}
|
||||
PVector direction = new PVector();
|
||||
direction.x = cos(a);
|
||||
direction.y = sin(a);
|
||||
direction.mult(0.07);
|
||||
|
||||
|
||||
acceleration = direction;
|
||||
|
||||
// add speed if pressing NORTH
|
||||
if(NORTH) {
|
||||
speed.add(acceleration);
|
||||
speed.limit(1.3);
|
||||
} else { // decrease it if not
|
||||
speed.mult(0.95);
|
||||
}
|
||||
|
||||
if (NORTH) {
|
||||
newX = x + cos(radians(a)) * movementSpeed;
|
||||
newY = y + sin(radians(a)) * movementSpeed;
|
||||
|
||||
// Check new pos
|
||||
newPos = pos.add(speed);
|
||||
|
||||
// Collide with outside walls
|
||||
if( newPos.x > width || newPos.y < 0 || newPos.y > height) {
|
||||
colliding = true;
|
||||
// println("collide");
|
||||
} else {
|
||||
colliding = false;
|
||||
}
|
||||
|
||||
// Check if the new position is within the bounds of the screen
|
||||
if(colliding == false && colliding2 == false) {
|
||||
x = newX;
|
||||
y = newY;
|
||||
}
|
||||
} else if (SOUTH) {
|
||||
newX = x - cos(radians(a)) * movementSpeed;
|
||||
newY = y - sin(radians(a)) * movementSpeed;
|
||||
|
||||
// Check if the new position is within the bounds of the screen
|
||||
if(colliding == false && colliding2 == false) {
|
||||
x = newX;
|
||||
y = newY;
|
||||
}
|
||||
// - Handle it more like https://processing.org/examples/circlecollision.html
|
||||
if(colliding == false && colliding_logs == false) {
|
||||
pos.add(speed);
|
||||
} else {
|
||||
speed.limit(0);
|
||||
speed.sub(acceleration);
|
||||
pos.add(0, 0);
|
||||
pos.add(speed.mult(2));
|
||||
}
|
||||
// println(speed);
|
||||
}
|
||||
|
||||
void logCollide(Log[] logs) {
|
||||
for(int i = 0; i < logs.length; i++) {
|
||||
if(logs[i].sawed == false) {
|
||||
if (newX+10 > logs[i].x && newX-10 < logs[i].x + logs[i].logwidth && newY+10 > logs[i].y && newY-10 < logs[i].y + logs[i].logheight) {
|
||||
colliding2 = true;
|
||||
void logCollide(Log[] loggers) {
|
||||
for(int i = 0; i < loggers.length; i++) {
|
||||
if(loggers[i].sawed == false) {
|
||||
if (newPos.x+10 > loggers[i].x && newPos.x-10 < loggers[i].x + loggers[i].logwidth && newPos.y+10 > loggers[i].y - loggers[i].logheight && newPos.y-10 < loggers[i].y) {
|
||||
colliding_logs = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void collect(Collectable c) {
|
||||
if (newX > c.x && newX < c.x + c.cwidth && newY > c.y && newY < c.y + c.cheight) {
|
||||
if (pos.dist(c.pos) < 20) {
|
||||
if (c.getClass() == Saw.class ) hasSaw = true;
|
||||
c.is_attached = true;
|
||||
}
|
||||
}
|
||||
|
||||
void render() {
|
||||
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
rotate(radians(a + 90));
|
||||
translate(pos.x, pos.y);
|
||||
rotate(a);
|
||||
stroke(255);
|
||||
noFill();
|
||||
line(0, -10, 10, 10);
|
||||
line(10, 10, 0, 5);
|
||||
line(0, 5, -10, 10);
|
||||
line(-10, 10, 0, -10);
|
||||
// line(0, -10, 10, 10);
|
||||
// line(10, 10, 0, 5);
|
||||
// line(0, 5, -10, 10);
|
||||
// line(-10, 10, 0, -10);
|
||||
// triangle(- 5, - 5, - 5, 5, 10, 0);
|
||||
imageMode(CENTER);
|
||||
if(bob.is_attached) {
|
||||
image(player_sprite_bob, 0, 0);
|
||||
} else {
|
||||
image(player_sprite, 0, 0);
|
||||
}
|
||||
if(hasSaw) {
|
||||
rect(0+2, 0-45, 20, 50);
|
||||
image(saw_sprite, 20, 0);
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user