188 lines
3.8 KiB
Plaintext
188 lines
3.8 KiB
Plaintext
//TODO
|
|
//- Start Screen
|
|
//- Level Editor (click with mouse spawns or deletes tiles)
|
|
// - Hotkey to slide the window right and left
|
|
// - Find a way to make menus
|
|
//- Movement berechnen mit move = gravitation - speed
|
|
// - Jump als Zahl, die langsam kleiner wird
|
|
|
|
// jumping related
|
|
float speed = 20;
|
|
float gravitation = 9.81;
|
|
float jumpheight;
|
|
float jumpcooldown = 12;
|
|
|
|
// for moving x-axis (mostly depracted)
|
|
// But dont delete yet!!
|
|
PVector direction = new PVector(0,0);
|
|
PVector pos = new PVector(220, 50);
|
|
int playerRadius = 25;
|
|
|
|
float actualPos;
|
|
|
|
PVector tilesize = new PVector(50, 50);
|
|
|
|
void setup() {
|
|
size(800,800);
|
|
frameRate(60);
|
|
smooth(4);
|
|
|
|
}
|
|
|
|
void draw() {
|
|
|
|
// rectMode(CENTER);
|
|
// rect(50, 50, 100, 50);
|
|
// textAlign(CENTER);
|
|
// fill(0);
|
|
// text("test", 50, 50);
|
|
// noFill();
|
|
|
|
|
|
// menu();
|
|
play();
|
|
helper();
|
|
}
|
|
|
|
boolean ismenu;
|
|
void menu() {
|
|
rectWithText(width/2, height/2, 100, 50, "test", 40);
|
|
}
|
|
|
|
|
|
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 mouseClicked() {
|
|
}
|
|
|
|
// The actual game
|
|
void play() {
|
|
// calculate actual position on ground
|
|
actualPos = height - pos.y;
|
|
|
|
background(255);
|
|
|
|
// player
|
|
rectMode(CENTER);
|
|
rect(pos.x, pos.y, playerRadius, playerRadius);
|
|
|
|
baseline();
|
|
// jumpToJumpheight();
|
|
newJump();
|
|
collisionTest();
|
|
|
|
generate_tiles();
|
|
|
|
helper();
|
|
// moveTiles();
|
|
}
|
|
|
|
// 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 };
|
|
|
|
void generate_tiles() {
|
|
for (int i = 0; i < tiles_x.length; i++ ) {
|
|
rect(tiles_x[i], tiles_y[i], tilesize.x, tilesize.y);
|
|
}
|
|
}
|
|
// 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
|
|
for (int i = 0; i < tiles_x.length; i++) {
|
|
boolean xSideEdges = pos.x > tiles_x[i] - tilesize.x/2 && pos.x < tiles_x[i] + tilesize.x/2;
|
|
boolean ySideEdges = pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] - tilesize.y/2;
|
|
|
|
// Bottom
|
|
if ( (xSideEdges) && (ySideEdges)) {
|
|
pos.set(pos.x, tiles_y[i] + tilesize.y/2);
|
|
}
|
|
// Top
|
|
if ( (xSideEdges) && (pos.y < tiles_y[i] + tilesize.y/2 && pos.y > tiles_y[i] - tilesize.y/2 - playerRadius)) {
|
|
pos.set(pos.x, tiles_y[i] - tilesize.y/2 - 15);
|
|
}
|
|
}
|
|
}
|
|
|
|
void moveTiles() {
|
|
for (int i = 0; i < tiles_x.length; i++) {
|
|
tiles_x[i] = tiles_x[i] - 1;
|
|
}
|
|
}
|
|
|
|
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--;
|
|
}
|
|
}
|
|
|
|
// actions for moving
|
|
void keyPressed() {
|
|
if (key == CODED)
|
|
{
|
|
if (keyCode == LEFT)
|
|
{
|
|
direction.x = -1;
|
|
pos.x = pos.x + direction.x * speed;
|
|
}
|
|
else if (keyCode == RIGHT)
|
|
{
|
|
//if (directionX<0) {
|
|
direction.x = +1;
|
|
pos.x = pos.x + direction.x * speed;
|
|
//}
|
|
}
|
|
if (keyCode == UP)
|
|
{
|
|
//if (directionY<0) {
|
|
jumpspeed =+ 25;
|
|
//}
|
|
}
|
|
// else if (keyCode == DOWN)
|
|
// {
|
|
// //if (directionY<0) {
|
|
// direction.y = +1;
|
|
// pos.y = pos.y + direction.y * speed;
|
|
// //}
|
|
// }
|
|
}
|
|
}
|
|
|
|
// Neat helper function, that gives us coordinates of point while clicking
|
|
void helper() {
|
|
if (mousePressed == true){
|
|
println(mouseX, mouseY);
|
|
}
|
|
|
|
}
|