Compare commits
No commits in common. "ca87f13623b78f0df0f4a60f447187a43f603696" and "ff4d996155db6f47461e1d274f8a39b148c59a29" have entirely different histories.
ca87f13623
...
ff4d996155
@ -5,9 +5,6 @@
|
|||||||
// - Find a way to make menus
|
// - Find a way to make menus
|
||||||
//- Movement berechnen mit move = gravitation - speed
|
//- Movement berechnen mit move = gravitation - speed
|
||||||
// - Jump als Zahl, die langsam kleiner wird
|
// - Jump als Zahl, die langsam kleiner wird
|
||||||
//
|
|
||||||
// Make Colission better:
|
|
||||||
// - https://happycoding.io/tutorials/processing/collision-detection
|
|
||||||
|
|
||||||
// jumping related
|
// jumping related
|
||||||
float speed = 20;
|
float speed = 20;
|
||||||
@ -17,75 +14,54 @@ float jumpcooldown = 12;
|
|||||||
|
|
||||||
// for moving x-axis (mostly depracted)
|
// for moving x-axis (mostly depracted)
|
||||||
// But dont delete yet!!
|
// But dont delete yet!!
|
||||||
// PVector direction = new PVector(0,0);
|
PVector direction = new PVector(0,0);
|
||||||
PVector pos = new PVector(220, 50);
|
PVector pos = new PVector(220, 50);
|
||||||
int playerRadius = 25;
|
int playerRadius = 25;
|
||||||
|
|
||||||
// float actualPos;
|
float actualPos;
|
||||||
|
|
||||||
PVector tilesize = new PVector(50, 50);
|
PVector tilesize = new PVector(50, 50);
|
||||||
|
|
||||||
int[][] level;
|
int[][] level;
|
||||||
|
|
||||||
int tilesmoved = 0;
|
|
||||||
int tilespeed = 3;
|
|
||||||
|
|
||||||
|
|
||||||
|
int test = 0;
|
||||||
// The actual game
|
// The actual game
|
||||||
void play() {
|
void play() {
|
||||||
// calculate actual position on ground
|
// calculate actual position on ground
|
||||||
// actualPos = height - pos.y;
|
actualPos = height - pos.y;
|
||||||
|
|
||||||
|
background(255);
|
||||||
|
|
||||||
// player
|
// player
|
||||||
rectMode(CENTER);
|
rectMode(CENTER);
|
||||||
rect(pos.x, pos.y, playerRadius, playerRadius);
|
rect(pos.x, pos.y, playerRadius, playerRadius);
|
||||||
|
|
||||||
moveTiles(tilespeed);
|
moveTiles();
|
||||||
baseRect();
|
baseline();
|
||||||
|
// jumpToJumpheight();
|
||||||
newJump();
|
newJump();
|
||||||
collisionTest();
|
collisionTest();
|
||||||
|
|
||||||
generate_tiles();
|
generate_tiles();
|
||||||
|
|
||||||
helper();
|
helper();
|
||||||
|
// moveTiles();
|
||||||
menuButton();
|
menuButton();
|
||||||
|
|
||||||
fill(0);
|
fill(0);
|
||||||
text(tilesmoved, 700, 50);
|
text(test, 700, 50);
|
||||||
tilesmoved = tilesmoved + tilespeed;
|
test = test+3;
|
||||||
fill(255);
|
fill(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void moveTiles(int tilesspeed) {
|
|
||||||
for (int i = 0; i < level.length; i++) {
|
|
||||||
level[i][0] = level[i][0] - tilesspeed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void moveTilesBack(int tilespeed) {
|
|
||||||
for (int i = 0; i < level.length; i++) {
|
|
||||||
level[i][0] = level[i][0] + tilesmoved;
|
|
||||||
}
|
|
||||||
tilesmoved = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handles Jumping
|
|
||||||
float movement;
|
|
||||||
float jumpspeed;
|
|
||||||
void newJump() {
|
|
||||||
movement = gravitation - jumpspeed;
|
|
||||||
pos.set(pos.x, pos.y + movement);
|
|
||||||
if (jumpspeed > 0) {
|
|
||||||
jumpspeed--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is an absolute mess
|
|
||||||
|
|
||||||
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
||||||
void collisionTest() {
|
void collisionTest() {
|
||||||
// Collision with baseline
|
// Collision with baseline
|
||||||
if ( pos.y > 0.850*height - playerRadius/2 ) {
|
if ( pos.y > baseline_y - playerRadius/2 ) {
|
||||||
pos.set(pos.x, 0.850*height - playerRadius/2);
|
pos.set(pos.x, baseline_y - playerRadius/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collision with all the tiles bottom site
|
// Collision with all the tiles bottom site
|
||||||
@ -103,3 +79,35 @@ void collisionTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int screenoffset = 0;
|
||||||
|
|
||||||
|
void moveTiles() {
|
||||||
|
for (int i = 0; i < level.length; i++) {
|
||||||
|
level[i][0] = level[i][0] - 3;
|
||||||
|
screenoffset++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
float movement;
|
||||||
|
float jumpspeed;
|
||||||
|
void newJump() {
|
||||||
|
movement = gravitation - jumpspeed;
|
||||||
|
pos.set(pos.x, pos.y + movement);
|
||||||
|
if (jumpspeed > 0) {
|
||||||
|
jumpspeed--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,15 +5,15 @@ void keyPressed () {
|
|||||||
if (ismenu) {
|
if (ismenu) {
|
||||||
} else if (isgame) {
|
} else if (isgame) {
|
||||||
if (key == CODED) {
|
if (key == CODED) {
|
||||||
// if (keyCode == RIGHT) {
|
if (keyCode == RIGHT) {
|
||||||
// direction.x = +1;
|
direction.x = +1;
|
||||||
// pos.x = pos.x + direction.x * speed;
|
pos.x = pos.x + direction.x * speed;
|
||||||
// } else if (keyCode == LEFT) {
|
} else if (keyCode == LEFT) {
|
||||||
// direction.x = -1;
|
direction.x = -1;
|
||||||
// pos.x = pos.x + direction.x * speed;
|
pos.x = pos.x + direction.x * speed;
|
||||||
// }
|
}
|
||||||
} else if (key == ' ') {
|
} else if (key == ' ') {
|
||||||
jumpspeed =+ 30;
|
jumpspeed =+ 25;
|
||||||
}
|
}
|
||||||
} else if (iseditor) {
|
} else if (iseditor) {
|
||||||
if (key == 's') {
|
if (key == 's') {
|
||||||
@ -39,7 +39,7 @@ void mouseReleased() {
|
|||||||
if (mouseButton == LEFT) {
|
if (mouseButton == LEFT) {
|
||||||
level[runnerRect][0] = mouseX+screenx;
|
level[runnerRect][0] = mouseX+screenx;
|
||||||
level[runnerRect][1] = mouseY;
|
level[runnerRect][1] = mouseY;
|
||||||
level[runnerRect][2] = 100;
|
level[runnerRect][2] = 50;
|
||||||
level[runnerRect][3] = 50;
|
level[runnerRect][3] = 50;
|
||||||
println("generated");
|
println("generated");
|
||||||
runnerRect = runnerRect + 1;
|
runnerRect = runnerRect + 1;
|
||||||
|
|||||||
@ -2,13 +2,11 @@ void setup() {
|
|||||||
size(800,800);
|
size(800,800);
|
||||||
frameRate(60);
|
frameRate(60);
|
||||||
smooth(4);
|
smooth(4);
|
||||||
|
// saveFileChecker();
|
||||||
|
|
||||||
|
|
||||||
level = loadJson("./saves/save.json");
|
level = loadJson("./saves/save.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
// not done yet
|
|
||||||
void saveFileChecker() {
|
void saveFileChecker() {
|
||||||
File f = dataFile("./saves/save.json");
|
File f = dataFile("./saves/save.json");
|
||||||
String filePath = f.getPath();
|
String filePath = f.getPath();
|
||||||
@ -18,18 +16,20 @@ void saveFileChecker() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
// debug();
|
|
||||||
|
// play();
|
||||||
|
// helper();
|
||||||
|
debug();
|
||||||
|
|
||||||
if (ismenu) {
|
if (ismenu) {
|
||||||
mainMenu();
|
mainMenu();
|
||||||
} else if (isgame) {
|
} else if (isgame) {
|
||||||
drawBackground();
|
|
||||||
play();
|
play();
|
||||||
} else if (iseditor) {
|
} else if (iseditor) {
|
||||||
mapEditor();
|
mapEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean ismenu = true;
|
boolean ismenu = true;
|
||||||
@ -39,49 +39,40 @@ boolean iseditor = false;
|
|||||||
|
|
||||||
void mainMenu() {
|
void mainMenu() {
|
||||||
background(14, 181, 59);
|
background(14, 181, 59);
|
||||||
// go to game
|
if (drawRectWithColission(width/2, height/2, 100, 100)) {
|
||||||
if (drawRectWithMouseColission(width/2, height/2, 100, 100)) {
|
|
||||||
if (mousePressed) {
|
if (mousePressed) {
|
||||||
ismenu = false;
|
ismenu = false;
|
||||||
isgame = true;
|
isgame = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// go to menu
|
if (drawRectWithColission(width/2, height/2+200, 100, 100)) {
|
||||||
if (drawRectWithMouseColission(width/2, height/2+200, 100, 100)) {
|
|
||||||
if (mousePressed) {
|
if (mousePressed) {
|
||||||
ismenu = false;
|
ismenu = false;
|
||||||
iseditor = true;
|
iseditor = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// exit game
|
|
||||||
if (drawRectWithMouseColission(50, 100, 80, 40)) {
|
|
||||||
if (mousePressed) {
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void menuButton() {
|
void menuButton() {
|
||||||
if (drawRectWithMouseColission(50, 50, 80, 40)) {
|
if (drawRectWithColission(50, 50, 80, 40)) {
|
||||||
if (mousePressed) {
|
if (mousePressed) {
|
||||||
ismenu = true;
|
ismenu = true;
|
||||||
iseditor = false;
|
iseditor = false;
|
||||||
isgame = false;
|
isgame = false;
|
||||||
moveTilesBack(tilespeed);
|
moveTilesBack();
|
||||||
savetofile("save");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mapEditor() {
|
void mapEditor() {
|
||||||
background(255);
|
background(255);
|
||||||
baseRect();
|
baseline();
|
||||||
generate_editor_tiles();
|
generate_editor_tiles();
|
||||||
// generate_tiles();
|
// generate_tiles();
|
||||||
menuButton();
|
menuButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) {
|
boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) {
|
||||||
// Draw A Rect
|
// Draw A Rect
|
||||||
rectMode(CENTER);
|
rectMode(CENTER);
|
||||||
rect(x, y, rectwidth, rectheight);
|
rect(x, y, rectwidth, rectheight);
|
||||||
|
|||||||
42
game/map.pde
42
game/map.pde
@ -1,6 +1,5 @@
|
|||||||
int screenx = 0;
|
int screenx = 0;
|
||||||
|
|
||||||
// level generation
|
|
||||||
void generate_tiles() {
|
void generate_tiles() {
|
||||||
for (int i = 0; i < level.length; i++ ) {
|
for (int i = 0; i < level.length; i++ ) {
|
||||||
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
||||||
@ -10,7 +9,7 @@ void generate_tiles() {
|
|||||||
void generate_editor_tiles() {
|
void generate_editor_tiles() {
|
||||||
for (int i = 0; i < 100; i++ ) {
|
for (int i = 0; i < 100; i++ ) {
|
||||||
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
||||||
if (drawRectWithMouseColission(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 (mousePressed && iseditor) {
|
||||||
if (mouseButton == RIGHT) {
|
if (mouseButton == RIGHT) {
|
||||||
level[i][0] = 0;
|
level[i][0] = 0;
|
||||||
@ -23,46 +22,7 @@ void generate_editor_tiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void baseRect() {
|
|
||||||
line(0, 0.850*height, width, 0.850*height);
|
|
||||||
fill(255);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Background
|
|
||||||
void drawBackground() {
|
|
||||||
color sky = color(94, 218, 252);
|
|
||||||
color sand = color(235, 218, 174);
|
|
||||||
color darksand = color(232, 177, 120);
|
|
||||||
color sea = color(51, 169, 255);
|
|
||||||
color seaend = color(146, 254, 255);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
// }
|
|
||||||
fill(sea);
|
|
||||||
quad(0, 400, width, 400, width, 650, 0, 650);
|
|
||||||
// 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);
|
|
||||||
fill(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawCloud() {
|
|
||||||
ellipse(224, 184, 220, 220);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//// This Handles loading and saving the level
|
|
||||||
// TODO Check if json is empty. If it is generate level
|
// TODO Check if json is empty. If it is generate level
|
||||||
// int[][] level = new int[100][4];
|
// int[][] level = new int[100][4];
|
||||||
JSONArray json;
|
JSONArray json;
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
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 };
|
|
||||||
Loading…
x
Reference in New Issue
Block a user