camera movement made fluid
This commit is contained in:
parent
c7e5d9bb58
commit
6ff8a3fd1a
15
sketch.js
15
sketch.js
@ -1,5 +1,6 @@
|
|||||||
var floorPos_y;
|
var floorPos_y;
|
||||||
var cameraPosX;
|
var cameraPosX;
|
||||||
|
var camera_speed;
|
||||||
var processStop_timer;
|
var processStop_timer;
|
||||||
var fps_recent_values = [];
|
var fps_recent_values = [];
|
||||||
var showDebugData = false;
|
var showDebugData = false;
|
||||||
@ -53,13 +54,13 @@ function setup() {
|
|||||||
}
|
}
|
||||||
function startGame(level_start) {
|
function startGame(level_start) {
|
||||||
floorPos_y = 432;
|
floorPos_y = 432;
|
||||||
cameraPosX = 0;
|
|
||||||
// levels of depth where the character, collectable and enemies stand.
|
// levels of depth where the character, collectable and enemies stand.
|
||||||
groundPositions = [
|
groundPositions = [
|
||||||
floorPos_y + (height - floorPos_y) / 6,
|
floorPos_y + (height - floorPos_y) / 6,
|
||||||
floorPos_y + (3 * (height - floorPos_y)) / 6,
|
floorPos_y + (3 * (height - floorPos_y)) / 6,
|
||||||
floorPos_y + (5 * (height - floorPos_y)) / 6,
|
floorPos_y + (5 * (height - floorPos_y)) / 6,
|
||||||
];
|
];
|
||||||
|
camera_speed = 0.9;
|
||||||
gravity = 1;
|
gravity = 1;
|
||||||
game_score = 0;
|
game_score = 0;
|
||||||
finish_position_x = 2000;
|
finish_position_x = 2000;
|
||||||
@ -73,7 +74,6 @@ function startGame(level_start) {
|
|||||||
cell_size_v: 20,
|
cell_size_v: 20,
|
||||||
cell_size_h: 20,
|
cell_size_h: 20,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (level_start) {
|
if (level_start) {
|
||||||
gameChar = {
|
gameChar = {
|
||||||
x: width / 2,
|
x: width / 2,
|
||||||
@ -285,6 +285,7 @@ function startGame(level_start) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
cameraPosX = gameChar.x;
|
||||||
// Creating trees, clouds, mountains, canyons, collectables.
|
// Creating trees, clouds, mountains, canyons, collectables.
|
||||||
{
|
{
|
||||||
// Creating trees, clouds, mountains, canyons, collectables, platforms, enemies.
|
// Creating trees, clouds, mountains, canyons, collectables, platforms, enemies.
|
||||||
@ -397,11 +398,15 @@ function draw() {
|
|||||||
// -------- GROUND -------------
|
// -------- GROUND -------------
|
||||||
drawGround();
|
drawGround();
|
||||||
|
|
||||||
push(); // Scrolling
|
push();
|
||||||
fill(0);
|
fill(0);
|
||||||
|
|
||||||
translate(-cameraPosX, 0); // Scrolling
|
translate(-cameraPosX, 0); // Scrolling everything
|
||||||
if (gameChar.x < finish_position_x) cameraPosX = gameChar.x - width / 2; // Scrolling
|
// Focusing on the character. lerp() ensures fluid camera movement.
|
||||||
|
if (gameChar.x < finish_position_x)
|
||||||
|
cameraPosX = lerp(gameChar.x - width/2, cameraPosX, camera_speed);
|
||||||
|
else
|
||||||
|
cameraPosX = lerp(finish_position_x - width/2, cameraPosX, camera_speed);
|
||||||
|
|
||||||
// -------- CLOUDS --------------
|
// -------- CLOUDS --------------
|
||||||
drawClouds();
|
drawClouds();
|
||||||
|
Loading…
Reference in New Issue
Block a user