Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ff3d6fe

Browse files
committedApr 14, 2017
Version 0.3.1-alpha edits
Changes: Fixed #2 and #6 (applied #3) Added screen nodes that detect both boxes and triangles; fixed screen node overapping Added left / right push feature to the level editor Fixed level editor mispositioning temporary obstacle when the camera is moved upwards misc. small tweaks
1 parent e5a86d4 commit ff3d6fe

File tree

17 files changed

+591
-205
lines changed

17 files changed

+591
-205
lines changed
 

‎GDE level editor/source/GDE_leveleditor.java

+122-41
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public int[] getTrianglePoints() {
131131
}
132132

133133
public boolean inDrawingRegion () {
134-
return betweenIn(x, camX - obstacleSize / 2, camX + width + obstacleSize / 2) && betweenIn(y, camY - height / 2 - obstacleSize / 2, camY + height / 2 + obstacleSize / 2);
134+
return betweenIn(x, camX - obstacleSize / 2, camX + width + obstacleSize / 2) && betweenIn(y, camY - height / 2 - obstacleSize / 2, camY + height + obstacleSize / 2);
135135
}
136136

137137
public boolean inCollisionRegion() {
@@ -175,6 +175,16 @@ public void keyPressed() {
175175
tempObstacle.triangle = !tempObstacle.triangle;
176176
break;
177177

178+
case 'm':
179+
for (Obstacle o : obstacles)
180+
o.x += 50;
181+
break;
182+
183+
case 'n':
184+
for (Obstacle o : obstacles)
185+
o.x -= 50;
186+
break;
187+
178188
default:
179189
if (key == CODED) {
180190
switch (keyCode) {
@@ -314,7 +324,7 @@ public void draw() {
314324

315325
noStroke();
316326
fill(70, 70, 60);
317-
rect(camX, floorLevel, width, height);
327+
rect(camX, floorLevel, width, height - floorLevel);
318328

319329
if(paused) {
320330
int x = mouseX + camX;
@@ -324,7 +334,7 @@ public void draw() {
324334
tempObstacle.y = max(y + floorLevel - obstacleSize / 2, 0);
325335
} else {
326336
tempObstacle.x = x - (x % obstacleSize) + obstacleSize / 2;
327-
tempObstacle.y = max(y + floorLevel - (y % obstacleSize) - obstacleSize, 0);
337+
tempObstacle.y = max(y + floorLevel - (y % obstacleSize) - (y < 0? obstacleSize : 0), 0);
328338
}
329339
tempObstacle.draw();
330340
}
@@ -405,78 +415,141 @@ public void iterate() {
405415
}
406416
}
407417

408-
public void checkColl() {
418+
public void checkColl () {
409419

410420
if (playerY < 0) {
411421
playerY = 0;
412422
}
413423

414-
ArrayList<Obstacle> triangles = new ArrayList<Obstacle>();
415-
ArrayList<Obstacle> boxes = new ArrayList<Obstacle>();
416-
417-
for (Obstacle o : obstacles) { // First check to raise the player
418-
if(!o.triangle) { // Must contain all boxes, because the player can be raised into another box (previously out of range)
419-
boxes.add(o);
420-
} else {
421-
triangles.add(o);
424+
//Old code revamped for better load (triangles take a bit more computing power) (might be untrue as trigonometric functions are now used for boxes)
425+
/*for (Obstacle o : obstacles) {
426+
if (!o.inDrawingRegion ()) {
422427
continue;
423428
}
424-
425-
if(!o.inCollisionRegion()) {
429+
if (o.triangle) {
430+
int[] points = {o.x - obstacleSize / 2, o.flipped? o.y + obstacleSize : o.y, o.x, o.flipped? o.y : o.y + obstacleSize, o.x + obstacleSize / 2, o.flipped? o.y + obstacleSize : o.y};
431+
if (pointInBox (o.x - obstacleSize / 2, o.y, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY) ||
432+
pointInBox (o.x + obstacleSize / 2, o.y, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY) ||
433+
pointInBox (o.x, o.y + obstacleSize, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY)) { // Player definitely clips the triangle (some point of the triangle is in the player)
434+
435+
kill ();
436+
break;
437+
}
438+
if (pointInTriangle (playerX - playerSize / 2, playerY, points) ||
439+
pointInTriangle (playerX + playerSize / 2, playerY, points) ||
440+
pointInTriangle (playerX - playerSize / 2, playerY + playerSize, points) ||
441+
pointInTriangle (playerX + playerSize / 2, playerY + playerSize, points)) { // Player clips the triangle
442+
443+
kill ();
444+
break;
445+
446+
}
447+
} else {
448+
if (betweenEx (playerX, o.x - obstacleSize / 2 - playerSize / 2, o.x + obstacleSize / 2 + playerSize / 2) && betweenEx (playerY, o.y - obstacleSize / 2 - playerSize / 2, o.y + obstacleSize / 2 + playerSize / 2)) { // Player clips the obstacle
449+
if (abs (playerX - o.x) > abs (playerY - o.y)) { // Player (probably) approached from the side
450+
kill ();
451+
break;
452+
} else { // Player (probably) approached from the Y axis
453+
int sgn = (gravity < 0)? -1 : 1;
454+
if (playerY - o.y > 0 && sgn == 1 || playerY - o.y < 0 && sgn == -1) { // Player collided on the correct side
455+
playerY = o.y + (obstacleSize / 2 + playerSize / 2) * sgn;
456+
} else {
457+
kill ();
458+
break;
459+
}
460+
}
461+
}
462+
}
463+
}*/
464+
465+
ArrayList<Obstacle> triangles = new ArrayList<Obstacle> ();
466+
ArrayList<Obstacle> boxes = new ArrayList<Obstacle> ();
467+
468+
float prevY = playerY - playerVelY, prevX = playerX - playerVelX; // Get previous position
469+
470+
for (Obstacle o : obstacles) {
471+
if (!o.triangle) {
472+
boxes.add (o);
473+
} else {
474+
triangles.add (o);
426475
continue;
427476
}
477+
}
478+
if (playerVelY <= 0f) { // Player can only be raised if it's moving down
479+
480+
int tempY = playerY; // Store Y value to be raised to
428481

429-
// if(betweenEx(playerX, o.x - obstacleSize / 2 - playerSize / 2, o.x + obstacleSize / 2 + playerSize / 2) && betweenEx (playerY, o.y - obstacleSize / 2 - playerSize / 2, o.y + obstacleSize / 2 + playerSize / 2)) { // Player clips the obstacle
430-
if (abs(playerX - o.x) > abs(playerY - o.y)) { // Player (probably) approached from the side (defaults to y axis if equal!!!)
431-
/*kill();
432-
return;*/
433-
} else { // Player (probably) approached from the Y axis
434-
int sgn = (gravity < 0)? -1 : 1;
435-
if (playerY - o.y > 0 && sgn == 1 || playerY - o.y < 0 && sgn == -1) { // Player collided on the correct side
436-
playerY = o.y + (obstacleSize / 2 + playerSize / 2) * sgn;
437-
/*} else {
438-
kill();
439-
return;*/
482+
for (Obstacle o : boxes) { // First check to raise the player
483+
484+
if (!o.inCollisionRegion ()) {
485+
continue;
486+
}
487+
488+
/*
489+
// if (betweenEx (playerX, o.x - obstacleSize / 2 - playerSize / 2, o.x + obstacleSize / 2 + playerSize / 2) && betweenEx (playerY, o.y - obstacleSize / 2 - playerSize / 2, o.y + obstacleSize / 2 + playerSize / 2)) { // Player clips the obstacle
490+
if (abs (playerX - o.x) > abs (playerY - o.y)) { // Player (probably) approached from the side (defaults to y axis if equal!!!)
491+
//kill ();
492+
//return;
493+
} else { // Player (probably) approached from the Y axis
494+
int sgn = (gravity < 0)? -1 : 1;
495+
if (playerY - o.y > 0 && sgn == 1 || playerY - o.y < 0 && sgn == -1) { // Player collided on the correct side
496+
playerY = o.y + (obstacleSize / 2 + playerSize / 2) * sgn;
497+
//} else {
498+
// kill ();
499+
// return;
500+
}
501+
}
502+
*/
503+
504+
if (prevY >= o.y + obstacleSize / 2 + playerSize / 2 && o.y + obstacleSize / 2 + playerSize / 2 > tempY) { // Only raise the player if the player was above the box and the current raise is below that of the obstacle
505+
if (betweenIn(playerVelX * (abs (max(prevY, o.y) - min(prevY, o.y)) - playerSize / 2 - obstacleSize / 2) / playerVelY + prevX, o.x - obstacleSize / 2 - playerSize / 2, o.x + obstacleSize / 2 + playerSize / 2)) { // Check whether the player landed on top of the box
506+
tempY = o.y + obstacleSize / 2 + playerSize / 2; // Raise the player
507+
}
440508
}
441509
}
510+
playerY = tempY; // Apply the raising
442511
}
443512

444513
for (Obstacle o : boxes) { // Second check to kill the player (if needed)
445-
446-
if(!o.inCollisionRegion()) {
514+
if (!o.inCollisionRegion ()) {
447515
continue;
448516
}
449517

450-
if (abs(playerX - o.x) > abs(playerY - o.y)) { // Player (probably) approached from the side (defaults to y axis if equal!!!)
451-
kill();
518+
/*if (abs (playerX - o.x) > abs (playerY - o.y)) { // Player (probably) approached from the side (defaults to y axis if equal!!!)
519+
kill ();
452520
return;
453521
} else { // Player (probably) approached from the Y axis
454522
int sgn = (gravity < 0)? -1 : 1;
455-
if (!(playerY - o.y > 0 && sgn == 1 || playerY - o.y < 0 && sgn == -1)) { // Player collided on the incorrect side
456-
kill();
523+
if (! (playerY - o.y > 0 && sgn == 1 || playerY - o.y < 0 && sgn == -1)) { // Player collided on the incorrect side
524+
kill ();
457525
return;
458526
}
527+
}*/
528+
529+
if (betweenIn(playerY - (playerY - prevY) * (abs (max(o.x, prevX) - min(o.x, prevX)) - obstacleSize / 2 - playerSize / 2) / playerVelX, o.y - obstacleSize / 2 - playerSize / 2, o.y + obstacleSize / 2 + playerSize / 2)) { // Check whether the player landed on the side of the box
530+
kill ();
531+
return;
459532
}
460533
}
461534

462-
for (Obstacle o : triangles) { // Finally check the triangles
535+
for (Obstacle o : triangles) { // Finally check the triangles (most load (??))
463536
int[] points = {o.x - obstacleSize / 2, o.flipped? o.y + obstacleSize : o.y, o.x, o.flipped? o.y : o.y + obstacleSize, o.x + obstacleSize / 2, o.flipped? o.y + obstacleSize : o.y};
464537

465-
if(pointInBoxEx(o.x - obstacleSize / 2, o.y, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY) ||
466-
pointInBoxEx(o.x + obstacleSize / 2, o.y, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY) ||
467-
pointInBoxEx(o.x, o.y + obstacleSize, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY)) { // Player definately clips the triangle (some point of the triangle is in the player)
538+
if (pointInBoxEx (o.x - obstacleSize / 2, o.y, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY) ||
539+
pointInBoxEx (o.x + obstacleSize / 2, o.y, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY) ||
540+
pointInBoxEx (o.x, o.y + obstacleSize, playerX - playerSize / 2, playerY + playerSize, playerX + playerSize / 2, playerY)) { // Player definately clips the triangle (some point of the triangle is in the player)
468541

469-
kill();
542+
kill ();
470543
return;
471544

472545
}
473546

474-
if(pointInTriangle(playerX - playerSize / 2, playerY, points) ||
475-
pointInTriangle(playerX + playerSize / 2, playerY, points) ||
476-
pointInTriangle(playerX - playerSize / 2, playerY + playerSize, points) ||
477-
pointInTriangle(playerX + playerSize / 2, playerY + playerSize, points)) { // Player clips the triangle
547+
if (pointInTriangle (playerX - playerSize / 2, playerY, points) ||
548+
pointInTriangle (playerX + playerSize / 2, playerY, points) ||
549+
pointInTriangle (playerX - playerSize / 2, playerY + playerSize, points) ||
550+
pointInTriangle (playerX + playerSize / 2, playerY + playerSize, points)) { // Player clips the triangle
478551

479-
kill();
552+
kill ();
480553
return;
481554

482555
}
@@ -526,10 +599,18 @@ public boolean betweenEx (int value, int min, int max) {
526599
return value < max && value > min;
527600
}
528601

602+
public boolean betweenEx (float value, int min, int max) {
603+
return value < max && value > min;
604+
}
605+
529606
public boolean betweenIn (int value, int min, int max) {
530607
return value <= max && value >= min;
531608
}
532609

610+
public boolean betweenIn (float value, int min, int max) {
611+
return value <= max && value >= min;
612+
}
613+
533614
public void drawPlayer () {
534615
noStroke();
535616
fill(0, 0, 0);

0 commit comments

Comments
 (0)
Please sign in to comment.