Compare commits

...

11 Commits

Author SHA1 Message Date
Maximilian Ruhm
eafd6f3d92 finish 2023-10-23 19:11:26 +02:00
46cb3f22c4 editor fix 2023-10-23 00:42:12 +02:00
98e71893f4 maintheme 2023-10-22 23:20:16 +02:00
b78310728e sounds 2023-10-22 23:07:22 +02:00
82e3afcfe5 all work today 2023-10-22 22:58:49 +02:00
Maximilian Ruhm
a527307ee1 code quality 2023-10-22 14:02:08 +02:00
175c0d238e beautify and prepare for losing 2023-10-22 01:39:39 +02:00
Maximilian Ruhm
0db9e72d8d sun 2023-10-21 13:06:37 +02:00
92a6ace93b old map thing 2023-10-21 00:52:46 +02:00
ca87f13623 yes 2023-10-21 00:41:17 +02:00
b269d39f62 did all the things to prepare 2023-10-20 01:17:13 +02:00
11 changed files with 550 additions and 202 deletions

0
game/background.pde Normal file
View File

View File

@@ -5,101 +5,70 @@
// - Find a way to make menus
//- Movement berechnen mit move = gravitation - speed
// - Jump als Zahl, die langsam kleiner wird
//
// Make Colission better:
// - https://happycoding.io/tutorials/processing/collision-detection
// jumping related
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!!
PVector direction = new PVector(0,0);
// PVector direction = new PVector(0,0);
PVector pos = new PVector(220, 50);
int playerRadius = 25;
float actualPos;
// float actualPos;
PVector tilesize = new PVector(50, 50);
PVector tilesize = new PVector(100, 50);
int[][] level;
int tilesmoved = 0;
int tilespeed = 4;
int test = 0;
// The actual game
void play() {
// calculate actual position on ground
actualPos = height - pos.y;
// actualPos = height - pos.y;
background(255);
// player
rectMode(CENTER);
rect(pos.x, pos.y, playerRadius, playerRadius);
moveTiles();
baseline();
// jumpToJumpheight();
moveTiles(tilespeed);
baseRect();
newJump();
collisionTest();
generate_tiles();
helper();
// moveTiles();
menuButton();
fill(0);
text(test, 700, 50);
test = test+3;
text(tilesmoved, 700, 50);
tilesmoved = tilesmoved + tilespeed;
fill(255);
}
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
void collisionTest() {
// Collision with baseline
if ( pos.y > baseline_y - playerRadius/2 ) {
pos.set(pos.x, baseline_y - playerRadius/2);
}
// Collision with all the tiles bottom site
void moveTiles(int tilesspeed) {
for (int i = 0; i < level.length; i++) {
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;
// 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);
}
level[i][0] = level[i][0] - tilesspeed;
}
}
int screenoffset = 0;
void moveTiles() {
void moveTilesBack(int tilespeed) {
for (int i = 0; i < level.length; i++) {
level[i][0] = level[i][0] - 3;
screenoffset++;
level[i][0] = level[i][0] + tilesmoved;
}
}
void moveTilesBack() {
for (int i = 0; i < level.length; i++) {
level[i][0] = level[i][0] + test;
}
test = 0;
}
int baseline_y = 700;
void baseline() {
line(0, baseline_y, width, baseline_y);
tilesmoved = 0;
}
// Handles Jumping
float movement;
float jumpspeed;
void newJump() {
@@ -110,4 +79,31 @@ void newJump() {
}
}
// This is an absolute mess
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
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
for (int i = 0; i < level.length; i++) {
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);
canjump = true;
}
}
}
}

View File

@@ -1,24 +1,48 @@
// } else if (key == 'l') {
// println(loadJSONArray("../map/map.json"));
// Here are all the keys that are used
boolean iseditorModeRect = true;
boolean iseditorModeSpike = false;
float volume = 0.2;
void keyPressed () {
if (key == 'm') {
if (volume == 0.2) {
volume = 0;
} else {
volume = 0.2;
}
gamesoundtrack.amp(volume);
}
if (ismenu) {
} else if (isgame) {
if (key == CODED) {
if (keyCode == RIGHT) {
direction.x = +1;
pos.x = pos.x + direction.x * speed;
} else if (keyCode == LEFT) {
direction.x = -1;
pos.x = pos.x + direction.x * speed;
}
// if (keyCode == RIGHT) {
// direction.x = +1;
// pos.x = pos.x + direction.x * speed;
// } else if (keyCode == LEFT) {
// direction.x = -1;
// pos.x = pos.x + direction.x * speed;
// }
} else if (key == ' ') {
jumpspeed =+ 25;
if(canjump) {
jumpspeed =+ 31;
canjump = false;
jumpsound.play();
}
}
} else if (iseditor) {
if (key == 's') {
savetofile("save");
println("saved");
} else if (key == ' ') {
if(iseditorModeRect) {
iseditorModeRect = false;
iseditorModeSpike = true;
} else if (iseditorModeSpike) {
iseditorModeRect = true;
iseditorModeSpike = false;
}
println("mode changed");
} else if (key == CODED) {
if (keyCode == RIGHT) {
screenx = screenx + 50;
@@ -33,17 +57,30 @@ void keyPressed () {
}
}
// Add tiles in editor mode
int runnerRect = 0;
void mouseReleased() {
if(iseditor) {
if (mouseButton == LEFT) {
level[runnerRect][0] = mouseX+screenx;
level[runnerRect][1] = mouseY;
level[runnerRect][2] = 50;
level[runnerRect][3] = 50;
println("generated");
runnerRect = runnerRect + 1;
println(runnerRect);
if(iseditorModeRect) {
level[runnerRect][0] = mouseX+screenx;
level[runnerRect][1] = mouseY;
level[runnerRect][2] = 100;
level[runnerRect][3] = 50;
level[runnerRect][4] = 0;
println("generated");
runnerRect = runnerRect + 1;
println(runnerRect);
} else if (iseditorModeSpike) {
level[runnerRect][0] = mouseX+screenx;
level[runnerRect][1] = mouseY;
level[runnerRect][2] = 50;
level[runnerRect][3] = 50;
level[runnerRect][4] = 1;
println("generated");
runnerRect = runnerRect + 1;
println(runnerRect);
}
}
}
}

View File

@@ -1,78 +1,125 @@
import processing.sound.*;
SoundFile jumpsound;
SoundFile deathsound;
SoundFile gamesoundtrack;
void setup() {
jumpsound = new SoundFile(this, "./sounds/jump.mp3");
deathsound = new SoundFile(this, "./sounds/fail.mp3");
gamesoundtrack = new SoundFile(this, "./sounds/maintheme.mp3");
gamesoundtrack.loop(1, 0.2);
size(800,800);
frameRate(60);
smooth(4);
// saveFileChecker();
level = loadJson("./saves/save.json");
}
void saveFileChecker() {
File f = dataFile("./saves/save.json");
String filePath = f.getPath();
boolean exist = f.isFile();
println(filePath, exist);
if (!exist) {
}
};
void draw() {
// play();
// helper();
debug();
// debug();
if (ismenu) {
mainMenu();
} else if (isgame) {
drawBackground();
play();
} else if (iseditor) {
mapEditor();
}
}
boolean ismenu = true;
boolean isgame = false;
boolean iseditor = false;
// This is the start screen and main menu. It has a few Buttons
void mainMenu() {
background(14, 181, 59);
if (drawRectWithColission(width/2, height/2, 100, 100)) {
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;
}
}
if (drawRectWithColission(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);
textAlign(CENTER);
text("Exit", 50, 110);
// Text in corner
textAlign(LEFT);
fill(0);
textSize(20);
text("m - mute audio", 10, 700);
}
void menuButton() {
if (drawRectWithColission(50, 50, 80, 40)) {
fill(145, 200, 228);
if (drawRectWithMouseColission(50, 50, 80, 40)) {
if (mousePressed) {
ismenu = true;
iseditor = false;
isgame = false;
moveTilesBack();
moveTilesBack(tilespeed);
savetofile("save");
screenx = 0;
}
}
fill(0);
textSize(40);
textAlign(CENTER);
text("Exit", 50, 50+10);
}
// Map Editor Mode
void mapEditor() {
background(255);
baseline();
baseRect();
generate_editor_tiles();
// generate_tiles();
menuButton();
// Texts at Top
textAlign(RIGHT);
textSize(20);
text("SPACE - Toggle between rect and triangle", 790, 50);
text("Left Click - Place block", 790, 70);
text("Right Click - Delete Block", 790, 90);
text("Arrows - Move right and left", 790, 110);
}
boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) {
// Rectangle with editor colission
boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) {
// Draw A Rect
rectMode(CENTER);
rect(x, y, rectwidth, rectheight);
@@ -85,6 +132,34 @@ boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) {
}
}
// Triangle with editor colission
boolean drawTriangleWithMouseColission(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(mouseX, mouseY, x+rectwidth/2, y-rectheight/2) < rectheight/1.5) {
return true;
} else {
return false;
}
}
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);
// println(level[0][0]);

View File

@@ -1,32 +1,133 @@
// BUG level editor x position bleibt ingame
// TODO Completly rework colission
// TODO Die when touching triangle
// moveTilesBack() and High Score Tracking
// No Unlimited Jumping
int screenx = 0;
// level generation for playable
void generate_tiles() {
stroke(0);
for (int i = 0; i < level.length; i++ ) {
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
if (level[i][4] == 0) {
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
} else {
if (drawTriangleWithPlayerColission(level[i][0] -screenx, level[i][1], level[i][2], level[i][3])) {
moveTilesBack(tilespeed);
deathsound.play();
}
}
}
}
// Generate the tiles for Editor View (tiles that are deletable with mouse)
void generate_editor_tiles() {
for (int i = 0; i < 100; i++ ) {
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
if (drawRectWithColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) {
if (mousePressed && iseditor) {
if (mouseButton == RIGHT) {
level[i][0] = 0;
level[i][1] = 0;
level[i][2] = 0;
level[i][3] = 0;
// rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
if(level[i][4] == 0) {
if (drawRectWithMouseColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) {
if (mousePressed && iseditor) {
if (mouseButton == RIGHT) {
level[i][0] = 0;
level[i][1] = 0;
level[i][2] = 0;
level[i][3] = 0;
level[i][4] = 0;
}
}
}
} else {
if (drawTriangleWithMouseColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) {
if (mousePressed && iseditor) {
if (mouseButton == RIGHT) {
level[i][0] = 0;
level[i][1] = 0;
level[i][2] = 0;
level[i][3] = 0;
level[i][4] = 0;
}
}
}
}
}
}
void baseRect() {
line(0, 0.850*height, width, 0.850*height);
fill(255);
}
// TODO Check if json is empty. If it is generate level
// int[][] level = new int[100][4];
// Draws all the Background elements like sea and Beach
void drawBackground() {
color sky = color(94, 218, 252);
color sand = color(235, 218, 174);
color darksand = color(232, 177, 120);
color darkersand = color(166, 110, 51);
color sea = color(51, 169, 255);
color seaend = color(146, 254, 255);
color sun = color(247, 178, 2);
// sky
background(sky);
// sea
for(int y = 400; y < 650; y++){
float inter = map(y, 400, 650, 0, 1);
color c = lerpColor(sea, seaend, inter);
stroke(c);
line(0, y, width, y);
noStroke();
}
// Beach
fill(sand);
quad(0, 650, width, 650, width, height, 0, height);
// Player stands on this
fill(darksand);
quad(0, 0.850*height, width, 0.850*height, width, height, 0, height);
//sun
fill(sun);
ellipse(130, 100, 70, 70);
randomSeed(0);
drawPalm(100, 700);
drawPalm(200, 700);
drawPalm(300, 700);
drawPalm(400, 700);
fill(0, 200);
stroke(darkersand);
for (int i = 0; i < 500; i++) {
point(random(0, width), random(700, 800));
}
stroke(0);
fill(0);
}
// No Clouds yet
void drawCloud() {
ellipse(224, 184, 220, 220);
}
// Draws a slightly randomised Palm
void drawPalm(int startingpoint_x, int startingpoint_y) {
fill(108, 88, 51);
float randomnumber = int(random(10, 16));
float schwanken = int(random(-2, 2));
int offset = 8;
PVector endpoint = new PVector(startingpoint_x, startingpoint_y - randomnumber * offset);
for (int i = 0; i <= randomnumber; i++) {
triangle(endpoint.x+i*schwanken, endpoint.y+i*offset, endpoint.x+10+i*schwanken, endpoint.y+10+i*offset, endpoint.x+20+i*schwanken, endpoint.y+i*offset);
}
fill(93, 133, 47);
quad(endpoint.x+10, endpoint.y, endpoint.x - 12, endpoint.y - 8, endpoint.x - 50, endpoint.y + 20, endpoint.x - 5, endpoint.y + 12);
quad(endpoint.x+10, endpoint.y, endpoint.x + 22, endpoint.y - 8, endpoint.x + 60, endpoint.y + 20, endpoint.x + 15, endpoint.y + 12);
}
//// This Handles loading and saving the level
JSONArray json;
// This saves the Current save to file
int savetofile(String filename) {
json = new JSONArray();
@@ -37,6 +138,7 @@ int savetofile(String filename) {
mapsave.setInt(1, level[i][1]);
mapsave.setInt(2, level[i][2]);
mapsave.setInt(3, level[i][3]);
mapsave.setInt(4, level[i][4]);
json.setJSONArray(i, mapsave);
}
@@ -44,27 +146,37 @@ int savetofile(String filename) {
return 1;
}
int[][] loadJson(String jsonfile) {
JSONArray values = loadJSONArray(jsonfile);
// println(values.size());
int[][] arrayfromjson = new int[values.size()][values.size()];
for (int i = 0; i < values.size(); i++) {
JSONArray jsontoarray = values.getJSONArray(i);
int x = jsontoarray.getInt(0);
int y = jsontoarray.getInt(1);
int rectwidth = jsontoarray.getInt(2);
int rectheight = jsontoarray.getInt(3);
// arrayfromjson_x[i] = x;
arrayfromjson[i][0] = x;
arrayfromjson[i][1] = y;
arrayfromjson[i][2] = rectwidth;
arrayfromjson[i][3] = rectheight;
}
return arrayfromjson;
boolean checkSaveFile(String filepath) {
return new File(dataPath(filepath)).exists();
}
// 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")) {
JSONArray values = loadJSONArray(jsonfile);
// println(values.size());
int[][] arrayfromjson = new int[values.size()][values.size()];
for (int i = 0; i < values.size(); i++) {
JSONArray jsontoarray = values.getJSONArray(i);
int x = jsontoarray.getInt(0);
int y = jsontoarray.getInt(1);
int rectwidth = jsontoarray.getInt(2);
int rectheight = jsontoarray.getInt(3);
int isspike = jsontoarray.getInt(4);
arrayfromjson[i][0] = x;
arrayfromjson[i][1] = y;
arrayfromjson[i][2] = rectwidth;
arrayfromjson[i][3] = rectheight;
arrayfromjson[i][4] = isspike;
}
return arrayfromjson;
} else {
int[][] arrayfromjson = new int[100][5];
return arrayfromjson;
}
}

View File

@@ -1,599 +1,699 @@
[
[
405,
595,
50,
50
-28,
0,
0,
0,
0
],
[
823,
337,
50,
50
-28,
0,
0,
0,
0
],
[
1002,
560,
649,
677,
50,
50
50,
1
],
[
885,
678,
50,
50
-28,
0,
0,
0,
0
],
[
1027,
338,
50,
50
-28,
0,
0,
0,
0
],
[
929,
686,
580,
391,
100,
50,
50
0
],
[
925,
322,
265,
310,
100,
50,
50
0
],
[
1024,
717,
543,
479,
50,
50
50,
1
],
[
927,
344,
278,
402,
50,
50
50,
1
],
[
1013,
564,
1394,
429,
100,
50,
50
0
],
[
825,
463,
1469,
574,
100,
50,
50
0
],
[
1012,
454,
1742,
644,
100,
50,
50
0
],
[
1597,
453,
100,
50,
0
],
[
1622,
495,
652,
100,
50,
50
],
[
1687,
130,
50,
50
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,
0
],
[
-109,
0,
0,
0,

BIN
game/sounds/fail.mp3 Normal file

Binary file not shown.

BIN
game/sounds/jump.mp3 Normal file

Binary file not shown.

BIN
game/sounds/maintheme.mp3 Normal file

Binary file not shown.

26
game/unused.pde Normal file
View File

@@ -0,0 +1,26 @@
void rectWithText(float rectX, float rectY, float rectWidth, float rectHeight, String rectText, float ts) {
// rect
rectMode(CENTER);
rect(rectX, rectY, rectWidth, rectHeight);
// text
textSize(ts);
textAlign(CENTER,CENTER);
fill(0);
text(rectText, rectX, rectY);
// stop painting
noFill();
}
void menu() {
rectWithText(width/2, height/2, 100, 50, "test", 40);
}
// This is basically the Level file:
// It consists out of an array, that spawns tiles
// It is also checked in collisionTest()
int[] tiles_x = { 300, 50, 600, 50};
int[] tiles_y = { 500, 50, 600, 200 };

View File

@@ -1,7 +1,6 @@
JSONArray json;
void setup() {
size(800,800);
// void setup() {
// size(800,800);
// json = loadJSONArray("map.json");
// JSONObject values = json.getJSONObject(1);
@@ -9,46 +8,49 @@ void setup() {
// int x = values.getInt("x");
// print(x);
}
// }
void draw() {
background(255);
generate_tiles();
}
PVector tilesize = new PVector(50, 50);
int[] tiles_x = {50};
int[] tiles_y = {50};
void pickTiles() {
}
// void draw() {
// background(255);
// generate_tiles();
// }
void generate_tiles() {
for (int i = 0; i < tiles_x.length; i++ ) {
rect(tiles_x[i], tiles_y[i], tilesize.x, tilesize.y);
for (int i = 0; i < level.length; i++ ) {
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
}
}
void mouseReleased() {
tiles_x = (int[])append(tiles_x, mouseX);
tiles_y = (int[])append(tiles_y, mouseY);
println(tiles_x);
int runnerRect = 0;
void mouseReleased() {
level[runnerRect][0] = mouseX+screenx;
level[runnerRect][1] = mouseY;
level[runnerRect][2] = 50;
level[runnerRect][3] = 50;
println("generated");
runnerRect = runnerRect + 1;
println(runnerRect);
}
void keyPressed() {
if (key == 's') {
println("saved");
int[][] level = new int[100][4];
JSONArray json;
int savetofile(String filename) {
json = new JSONArray();
for (int i = 0; i < tiles_x.length; i++) {
for (int i = 0; i < level.length; i++) {
JSONArray mapsave = new JSONArray();
mapsave.setInt(0, tiles_x[i]);
mapsave.setInt(1, tiles_y[i]);
mapsave.setInt(0, level[i][0]);
mapsave.setInt(1, level[i][1]);
mapsave.setInt(2, level[i][2]);
mapsave.setInt(3, level[i][3]);
json.setJSONArray(i, mapsave);
}
saveJSONArray(json, "map.json");
}
saveJSONArray(json, filename + ".json");
return 1;
}
int screenx = 0;