startGame minor refactoring
This commit is contained in:
parent
da9e0b188c
commit
235cb7776a
64
sketch.js
64
sketch.js
@ -49,17 +49,32 @@ function setup() {
|
||||
enemy_head_color: color("red"),
|
||||
enemy_body_color: color("red"),
|
||||
};
|
||||
startGame((full_start = true), (update_objects = true));
|
||||
startGame(level_start = true);
|
||||
}
|
||||
function startGame(full_start, update_objects) {
|
||||
function startGame(level_start) {
|
||||
floorPos_y = 432;
|
||||
cameraPosX = 0;
|
||||
// levels of depth where the character, collectable and enemies stand.
|
||||
groundPositions = [
|
||||
floorPos_y + (height - floorPos_y) / 6,
|
||||
floorPos_y + (3 * (height - floorPos_y)) / 6,
|
||||
floorPos_y + (5 * (height - floorPos_y)) / 6,
|
||||
];
|
||||
if (full_start) {
|
||||
gravity = 1;
|
||||
game_score = 0;
|
||||
finish_position_x = 2000;
|
||||
textSize(width / 20);
|
||||
flagpole = {
|
||||
x: finish_position_x,
|
||||
isReached: false,
|
||||
size_vert: 4,
|
||||
size_hor: 7,
|
||||
cell_size: 20,
|
||||
cell_size_v: 20,
|
||||
cell_size_h: 20,
|
||||
};
|
||||
|
||||
if (level_start) {
|
||||
gameChar = {
|
||||
x: width / 2,
|
||||
y: floorPos_y + (height - floorPos_y) / 6,
|
||||
@ -270,23 +285,8 @@ function startGame(full_start, update_objects) {
|
||||
}
|
||||
},
|
||||
};
|
||||
} else {
|
||||
gameChar.x = width / 2;
|
||||
gameChar.y = floorPos_y + (height - floorPos_y) / 6;
|
||||
gameChar.scale = 1;
|
||||
gameChar.curGroundIndex = 0;
|
||||
gameChar.isPlummeting = false;
|
||||
gameChar.isFalling = false;
|
||||
gameChar.isJumping = false;
|
||||
gameChar.isLeft = false;
|
||||
gameChar.isRight = false;
|
||||
}
|
||||
|
||||
gravity = 1;
|
||||
game_score = 0;
|
||||
finish_position_x = 2000;
|
||||
|
||||
if (update_objects || full_start) {
|
||||
// Creating trees, clouds, mountains, canyons, collectables.
|
||||
{
|
||||
// Creating trees, clouds, mountains, canyons, collectables, platforms, enemies.
|
||||
for (i = 0; i < 150; i++) {
|
||||
trees_x[i] = random(-100, 10000);
|
||||
@ -369,17 +369,17 @@ function startGame(full_start, update_objects) {
|
||||
}
|
||||
}
|
||||
}
|
||||
flagpole = {
|
||||
x: finish_position_x,
|
||||
isReached: false,
|
||||
size_vert: 4,
|
||||
size_hor: 7,
|
||||
cell_size: 20,
|
||||
cell_size_v: 20,
|
||||
cell_size_h: 20,
|
||||
};
|
||||
text_size = width / 20;
|
||||
textSize(text_size);
|
||||
} else {
|
||||
gameChar.x = width / 2;
|
||||
gameChar.y = floorPos_y + (height - floorPos_y) / 6;
|
||||
gameChar.scale = 1;
|
||||
gameChar.curGroundIndex = 0;
|
||||
gameChar.isPlummeting = false;
|
||||
gameChar.isFalling = false;
|
||||
gameChar.isJumping = false;
|
||||
gameChar.isLeft = false;
|
||||
gameChar.isRight = false;
|
||||
}
|
||||
}
|
||||
function draw() {
|
||||
// -------- SKY ----------------
|
||||
@ -822,7 +822,7 @@ function keyPressed() {
|
||||
if (gameChar.curLives < 1 || flagpole.isReached) {
|
||||
if (keyCode == 32 /*Space*/) {
|
||||
/*Hard resets the game*/
|
||||
startGame((full_start = true), (update_objects = true));
|
||||
startGame((level_start= true), );
|
||||
}
|
||||
} else if (!gameChar.isPlummeting) {
|
||||
if (keyCode == 65 /*A*/) gameChar.isLeft = true;
|
||||
|
Loading…
Reference in New Issue
Block a user