kek
This commit is contained in:
parent
af58958e83
commit
73cb60941d
0
primitives.pde
Normal file
0
primitives.pde
Normal file
175
program.pde
175
program.pde
@ -1,42 +1,185 @@
|
|||||||
int x;
|
//TODO
|
||||||
int y;
|
//- Start Screen
|
||||||
|
//- Level Editor (click with mouse spawns or deletes tiles)
|
||||||
|
// - Hotkey to slide the window right and left
|
||||||
|
|
||||||
|
// 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 movement = new PVector(0,0);
|
||||||
|
PVector direction = new PVector(0,0);
|
||||||
|
PVector pos = new PVector(220, 50);
|
||||||
|
int playerRadius = 25;
|
||||||
|
|
||||||
|
float actualPos;
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(800,800);
|
size(800,800);
|
||||||
rectMode(CENTER);
|
frameRate(60);
|
||||||
|
smooth(4);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
rect(x, y, 50, 50);
|
|
||||||
|
// rectMode(CENTER);
|
||||||
|
// rect(50, 50, 100, 50);
|
||||||
|
// textAlign(CENTER);
|
||||||
|
// fill(0);
|
||||||
|
// text("test", 50, 50);
|
||||||
|
// noFill();
|
||||||
|
|
||||||
|
|
||||||
|
menu();
|
||||||
|
// play();
|
||||||
|
helper();
|
||||||
}
|
}
|
||||||
void keyPressed()
|
|
||||||
{
|
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();
|
||||||
|
collisionTest();
|
||||||
|
cooldown();
|
||||||
|
jumpToJumpheight();
|
||||||
|
|
||||||
|
generate_tiles();
|
||||||
|
|
||||||
|
helper();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 };
|
||||||
|
int[] tiles_y = { 500, 50, 600 };
|
||||||
|
|
||||||
|
void generate_tiles() {
|
||||||
|
for (int i = 0; i < tiles_x.length; i++ ) {
|
||||||
|
rect(tiles_x[i], tiles_y[i], 50, 50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO Collision erweitern wie in https://happycoding.io/tutorials/processing/collision-detection
|
||||||
|
void collisionTest() {
|
||||||
|
// Collision with baseline
|
||||||
|
if ( pos.y > baseline_y - playerRadius ) {
|
||||||
|
pos.set(pos.x, baseline_y - playerRadius);
|
||||||
|
}
|
||||||
|
// Collision with all the tiles top site
|
||||||
|
for (int i = 0; i < tiles_x.length; i++) {
|
||||||
|
if ((pos.x > tiles_x[i]-25 && pos.x < tiles_x[i]+25) && pos.y < tiles_y[i] - playerRadius) {
|
||||||
|
pos.set(pos.x, tiles_y[i] - playerRadius);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int baseline_y = 700;
|
||||||
|
void baseline() {
|
||||||
|
line(0, baseline_y, width, baseline_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ##### Movement related
|
||||||
|
//
|
||||||
|
// all there is to jumping
|
||||||
|
void jumpToJumpheight() {
|
||||||
|
// control gravitation
|
||||||
|
pos.set(pos.x, pos.y + gravitation);
|
||||||
|
// turn gravity of if we are jumping
|
||||||
|
if (actualPos < jumpheight) {
|
||||||
|
gravitation = 0;
|
||||||
|
} else {
|
||||||
|
gravitation = 9.81;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actualPos < jumpheight) {
|
||||||
|
pos.y = pos.y - speed;
|
||||||
|
jumpcooldown = 40;
|
||||||
|
} else {
|
||||||
|
jumpheight = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// count down jumping cooldown
|
||||||
|
void cooldown() {
|
||||||
|
if (jumpcooldown > 0) {
|
||||||
|
jumpcooldown = jumpcooldown-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// actions for moving
|
||||||
|
void keyPressed() {
|
||||||
if (key == CODED)
|
if (key == CODED)
|
||||||
{
|
{
|
||||||
if (keyCode == LEFT)
|
if (keyCode == LEFT)
|
||||||
{
|
{
|
||||||
//if (directionX>0) {
|
direction.x = -1;
|
||||||
x--;
|
pos.x = pos.x + direction.x * speed;
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
else if (keyCode == RIGHT)
|
else if (keyCode == RIGHT)
|
||||||
{
|
{
|
||||||
//if (directionX<0) {
|
//if (directionX<0) {
|
||||||
x++;
|
direction.x = +1;
|
||||||
|
pos.x = pos.x + direction.x * speed;
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
else if (keyCode == UP)
|
if (keyCode == UP && jumpcooldown == 0)
|
||||||
{
|
{
|
||||||
//if (directionY<0) {
|
//if (directionY<0) {
|
||||||
y--;
|
jumpheight += 400;
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
else if (keyCode == DOWN)
|
// else if (keyCode == DOWN)
|
||||||
{
|
// {
|
||||||
//if (directionY<0) {
|
// //if (directionY<0) {
|
||||||
y++;
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user