collectable detection fix; formatting
This commit is contained in:
parent
235cb7776a
commit
c7e5d9bb58
38
sketch.js
38
sketch.js
@ -49,7 +49,7 @@ function setup() {
|
||||
enemy_head_color: color("red"),
|
||||
enemy_body_color: color("red"),
|
||||
};
|
||||
startGame(level_start = true);
|
||||
startGame((level_start = true));
|
||||
}
|
||||
function startGame(level_start) {
|
||||
floorPos_y = 432;
|
||||
@ -307,7 +307,10 @@ function startGame(level_start) {
|
||||
skew: random(-20, 20),
|
||||
};
|
||||
// To prevent spiky mountains which are quite ugly
|
||||
mountains[i].height = max(mountains[i].width, mountains[i].height);
|
||||
mountains[i].height = max(
|
||||
mountains[i].width,
|
||||
mountains[i].height
|
||||
);
|
||||
}
|
||||
// Start mountains.
|
||||
for (i = 0; i < 6; i++) {
|
||||
@ -338,20 +341,25 @@ function startGame(level_start) {
|
||||
if (i == 0) {
|
||||
collectables[0] = {
|
||||
x: 600,
|
||||
y: groundPositions[0],
|
||||
curGroundIndex: 0,
|
||||
y:
|
||||
groundPositions[0] -
|
||||
10 /*taking 10 for better visuals*/,
|
||||
size: 75,
|
||||
isFound: false,
|
||||
};
|
||||
} else {
|
||||
// Skipping generating coins after the finish line
|
||||
if (collectables[i - 1].x + 200 > finish_position_x) {
|
||||
break;
|
||||
}
|
||||
|
||||
r = floor(random(0, groundPositions.length));
|
||||
collectables[i] = {
|
||||
x: collectables[i - 1].x + 50 + 100 * random(0.5, 1),
|
||||
y: groundPositions[
|
||||
floor(random(0, groundPositions.length))
|
||||
],
|
||||
curGroundIndex: r,
|
||||
y:
|
||||
groundPositions[r] -
|
||||
10 /*taking 10 for better visuals*/,
|
||||
size: 75,
|
||||
isFound: false,
|
||||
};
|
||||
@ -361,7 +369,8 @@ function startGame(level_start) {
|
||||
if (
|
||||
canyons[k].x - canyons[k].width / 2 <
|
||||
collectables[i].x &&
|
||||
canyons[k].x + canyons[k].width / 2 > collectables[i].x
|
||||
canyons[k].x + canyons[k].width / 2 >
|
||||
collectables[i].x
|
||||
) {
|
||||
collectables[i].isFound = true;
|
||||
}
|
||||
@ -379,7 +388,7 @@ function startGame(level_start) {
|
||||
gameChar.isJumping = false;
|
||||
gameChar.isLeft = false;
|
||||
gameChar.isRight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
function draw() {
|
||||
// -------- SKY ----------------
|
||||
@ -496,7 +505,7 @@ function checkCanyon(t_canyon) {
|
||||
function checkCollectable(t_collectable) {
|
||||
if (
|
||||
!t_collectable.isFound &&
|
||||
collectable.y == gameChar.getCurGroundY() &&
|
||||
collectable.curGroundIndex == gameChar.curGroundIndex &&
|
||||
dist(
|
||||
t_collectable.x,
|
||||
t_collectable.y,
|
||||
@ -578,11 +587,13 @@ function drawCanyon(t_canyon) {
|
||||
}
|
||||
function drawCollectable(t_collectable) {
|
||||
push();
|
||||
// centering coins a bit upper
|
||||
// animating the coin's jiggle
|
||||
// a - vert. intensity, c - hor. intensity, b - vert. speed, d - hor. speed
|
||||
a = 0.1;
|
||||
b = 3;
|
||||
c = 0.2;
|
||||
d = 2; // a - vert. intensity, c - hor. intensity, b - vert. speed, d - hor. speed
|
||||
d = 2;
|
||||
t_collectable.y -= sin(frameCount * a) * b;
|
||||
t_collectable.x += sin(frameCount * c) * d;
|
||||
stroke(0.2);
|
||||
@ -600,7 +611,8 @@ function drawCollectable(t_collectable) {
|
||||
function drawClouds() {
|
||||
for (i = 0; i < clouds.length; i++) {
|
||||
push();
|
||||
translate((frameCount / clouds[i].y) * 20, 0); // imitating clouds movement, upper ones should go faster
|
||||
// imitating clouds movement, upper ones should go faster
|
||||
translate((frameCount / clouds[i].y) * 20, 0);
|
||||
// Adding counter-translating to implement parallax, the feeling of depth
|
||||
translate(cameraPosX / 1.1, 0);
|
||||
|
||||
@ -822,7 +834,7 @@ function keyPressed() {
|
||||
if (gameChar.curLives < 1 || flagpole.isReached) {
|
||||
if (keyCode == 32 /*Space*/) {
|
||||
/*Hard resets the game*/
|
||||
startGame((level_start= true), );
|
||||
startGame((level_start = true));
|
||||
}
|
||||
} else if (!gameChar.isPlummeting) {
|
||||
if (keyCode == 65 /*A*/) gameChar.isLeft = true;
|
||||
|
Loading…
Reference in New Issue
Block a user