Compare commits
2 Commits
ff4d996155
...
ca87f13623
| Author | SHA1 | Date | |
|---|---|---|---|
| ca87f13623 | |||
| b269d39f62 |
0
game/background.pde
Normal file
0
game/background.pde
Normal file
@ -5,6 +5,9 @@
|
||||
// - 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;
|
||||
@ -14,54 +17,75 @@ float jumpcooldown = 12;
|
||||
|
||||
// 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);
|
||||
|
||||
int[][] level;
|
||||
|
||||
int tilesmoved = 0;
|
||||
int tilespeed = 3;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
void collisionTest() {
|
||||
// Collision with baseline
|
||||
if ( pos.y > baseline_y - playerRadius/2 ) {
|
||||
pos.set(pos.x, baseline_y - playerRadius/2);
|
||||
if ( pos.y > 0.850*height - playerRadius/2 ) {
|
||||
pos.set(pos.x, 0.850*height - playerRadius/2);
|
||||
}
|
||||
|
||||
// Collision with all the tiles bottom site
|
||||
@ -79,35 +103,3 @@ 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) {
|
||||
} 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;
|
||||
jumpspeed =+ 30;
|
||||
}
|
||||
} else if (iseditor) {
|
||||
if (key == 's') {
|
||||
@ -39,7 +39,7 @@ void mouseReleased() {
|
||||
if (mouseButton == LEFT) {
|
||||
level[runnerRect][0] = mouseX+screenx;
|
||||
level[runnerRect][1] = mouseY;
|
||||
level[runnerRect][2] = 50;
|
||||
level[runnerRect][2] = 100;
|
||||
level[runnerRect][3] = 50;
|
||||
println("generated");
|
||||
runnerRect = runnerRect + 1;
|
||||
|
||||
@ -2,11 +2,13 @@ void setup() {
|
||||
size(800,800);
|
||||
frameRate(60);
|
||||
smooth(4);
|
||||
// saveFileChecker();
|
||||
|
||||
|
||||
|
||||
level = loadJson("./saves/save.json");
|
||||
}
|
||||
|
||||
// not done yet
|
||||
void saveFileChecker() {
|
||||
File f = dataFile("./saves/save.json");
|
||||
String filePath = f.getPath();
|
||||
@ -16,20 +18,18 @@ void saveFileChecker() {
|
||||
}
|
||||
};
|
||||
|
||||
void draw() {
|
||||
|
||||
// play();
|
||||
// helper();
|
||||
debug();
|
||||
void draw() {
|
||||
// debug();
|
||||
|
||||
if (ismenu) {
|
||||
mainMenu();
|
||||
} else if (isgame) {
|
||||
drawBackground();
|
||||
play();
|
||||
} else if (iseditor) {
|
||||
mapEditor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean ismenu = true;
|
||||
@ -39,40 +39,49 @@ boolean iseditor = false;
|
||||
|
||||
void mainMenu() {
|
||||
background(14, 181, 59);
|
||||
if (drawRectWithColission(width/2, height/2, 100, 100)) {
|
||||
// go to game
|
||||
if (drawRectWithMouseColission(width/2, height/2, 100, 100)) {
|
||||
if (mousePressed) {
|
||||
ismenu = false;
|
||||
isgame = true;
|
||||
}
|
||||
}
|
||||
if (drawRectWithColission(width/2, height/2+200, 100, 100)) {
|
||||
// go to menu
|
||||
if (drawRectWithMouseColission(width/2, height/2+200, 100, 100)) {
|
||||
if (mousePressed) {
|
||||
ismenu = false;
|
||||
iseditor = true;
|
||||
}
|
||||
}
|
||||
// exit game
|
||||
if (drawRectWithMouseColission(50, 100, 80, 40)) {
|
||||
if (mousePressed) {
|
||||
exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void menuButton() {
|
||||
if (drawRectWithColission(50, 50, 80, 40)) {
|
||||
if (drawRectWithMouseColission(50, 50, 80, 40)) {
|
||||
if (mousePressed) {
|
||||
ismenu = true;
|
||||
iseditor = false;
|
||||
isgame = false;
|
||||
moveTilesBack();
|
||||
moveTilesBack(tilespeed);
|
||||
savetofile("save");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mapEditor() {
|
||||
background(255);
|
||||
baseline();
|
||||
baseRect();
|
||||
generate_editor_tiles();
|
||||
// generate_tiles();
|
||||
menuButton();
|
||||
}
|
||||
|
||||
boolean drawRectWithColission(int x, int y, int rectwidth, int rectheight) {
|
||||
boolean drawRectWithMouseColission(int x, int y, int rectwidth, int rectheight) {
|
||||
// Draw A Rect
|
||||
rectMode(CENTER);
|
||||
rect(x, y, rectwidth, rectheight);
|
||||
|
||||
42
game/map.pde
42
game/map.pde
@ -1,5 +1,6 @@
|
||||
int screenx = 0;
|
||||
|
||||
// level generation
|
||||
void generate_tiles() {
|
||||
for (int i = 0; i < level.length; i++ ) {
|
||||
rect(level[i][0]-screenx, level[i][1], level[i][2], level[i][3]);
|
||||
@ -9,7 +10,7 @@ void generate_tiles() {
|
||||
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 (drawRectWithMouseColission(level[i][0]-screenx, level[i][1], level[i][2], level[i][3])) {
|
||||
if (mousePressed && iseditor) {
|
||||
if (mouseButton == RIGHT) {
|
||||
level[i][0] = 0;
|
||||
@ -22,7 +23,46 @@ 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
|
||||
// int[][] level = new int[100][4];
|
||||
JSONArray json;
|
||||
|
||||
26
game/unused.pde
Normal file
26
game/unused.pde
Normal 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 };
|
||||
Loading…
x
Reference in New Issue
Block a user