Restored coins visibility, added coins jiggle

This commit is contained in:
Mottributo 2023-03-23 16:31:39 +03:00
parent d3bd49b861
commit 8eab7faf27

View File

@ -165,17 +165,17 @@ function startGame(full_start, update_objects) {
if (i == 0) {
collectables[0] = {
x: 600,
y_pos: floorPos_y,
size: 50,
y: floorPos_y,
size: 75,
isFound: false,
};
} else
collectables[i] = {
x: collectables[i - 1].x + 50 + 150 * random(0.5, 1),
y_pos: gameChar.possibleGroundPosY[
random(0, gameChar.possibleGroundPosY.length)
y: gameChar.possibleGroundPosY[
ceil(random(0, gameChar.possibleGroundPosY.length))
],
size: 50,
size: 75,
isFound: false,
};
}
@ -473,10 +473,10 @@ function checkCanyon(t_canyon) {
function checkCollectable(t_collectable) {
if (
!t_collectable.isFound &&
collectable.y_pos == gameChar.getCurGroundPosY() &&
collectable.y == gameChar.getCurGroundPosY() &&
dist(
t_collectable.x,
t_collectable.y_pos,
t_collectable.y,
gameChar.x,
gameChar.y - gameChar.x_step * 4
) <
@ -528,7 +528,8 @@ function drawCanyon(t_canyon) {
fill(palette.canyon_river_color);
rect(t_canyon.x - t_canyon.width / 2, floorPos_y, t_canyon.width, height);
if ((frameCount % 2) == 0) {
// Waves animation.
if (frameCount % 2 == 0) {
PointX = random(
t_canyon.x - t_canyon.width / 2 + 5,
t_canyon.x + t_canyon.width / 2 - 5
@ -553,13 +554,22 @@ function drawCanyon(t_canyon) {
pop();
}
function drawCollectable(t_collectable) {
push();
// animating the coin's jiggle
a = 0.1; b = 3; c = 0.2; d = 2; // a - vert. intensity, c - hor. intensity, b - vert. speed, d - hor. speed
t_collectable.y -= sin(frameCount*a)*b;
t_collectable.x += sin(frameCount*c)*d;
stroke(0.2);
fill(palette.coin_outer);
ellipse(t_collectable.x, t_collectable.y_pos, 0.7 * t_collectable.size);
ellipse(t_collectable.x, t_collectable.y, 0.7 * t_collectable.size);
fill(palette.coin_middle);
ellipse(t_collectable.x, t_collectable.y_pos, 0.6 * t_collectable.size);
ellipse(t_collectable.x, t_collectable.y, 0.6 * t_collectable.size);
fill(palette.coin_inner);
ellipse(t_collectable.x, t_collectable.y_pos, 0.5 * t_collectable.size);
ellipse(t_collectable.x, t_collectable.y, 0.5 * t_collectable.size);
// restoring coin's coordinates to preserve game logic
t_collectable.y += sin(frameCount*a)*b;
t_collectable.x -= sin(frameCount*c)*d;
pop();
}
function drawClouds() {
for (i = 0; i < clouds.length; i++) {