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