began work on platforms; moved setting sprite code
This commit is contained in:
parent
34dfd67a50
commit
d1c0001865
62
sketch.js
62
sketch.js
@ -17,6 +17,8 @@ var clouds = [];
|
||||
var mountains = [];
|
||||
var collectables = [];
|
||||
var rivers = [];
|
||||
var platforms = [];
|
||||
var enemies = [];
|
||||
var flagpole;
|
||||
|
||||
var text_size;
|
||||
@ -86,14 +88,34 @@ function startGame(level_start) {
|
||||
speed: 5,
|
||||
baseLives: 3,
|
||||
curLives: 3,
|
||||
baseJumpingStrength: 15,
|
||||
curJumpingStrength: 0,
|
||||
isRight: false,
|
||||
isLeft: false,
|
||||
isFalling: false,
|
||||
isJumping: false,
|
||||
isPlummeting: false,
|
||||
curGroundIndex: 0,
|
||||
|
||||
|
||||
_updateSprite: function()
|
||||
{
|
||||
if (gameChar.isPlummeting) {
|
||||
gameChar.sprite = 2;
|
||||
} else if (gameChar.isFalling) {
|
||||
gameChar.sprite = 2;
|
||||
if (gameChar.isLeft && !gameChar.isRight) gameChar.sprite = 5;
|
||||
else if (gameChar.isRight && !gameChar.isLeft)
|
||||
gameChar.sprite = 6;
|
||||
} else {
|
||||
if (gameChar.isLeft && !gameChar.isRight) gameChar.sprite = 4;
|
||||
else if (gameChar.isRight && !gameChar.isLeft)
|
||||
gameChar.sprite = 3;
|
||||
else gameChar.sprite = 1;
|
||||
}
|
||||
},
|
||||
|
||||
draw: function () {
|
||||
this._updateSprite();
|
||||
push();
|
||||
strokeWeight(1);
|
||||
stroke(1);
|
||||
@ -379,6 +401,16 @@ function startGame(level_start) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 100; i++) {
|
||||
if (i == 0) {
|
||||
platforms[0] = {
|
||||
curGroundIndex: 0,
|
||||
x: 700,
|
||||
width: 50,
|
||||
y: pow(gameChar.baseJumpingStrength, 2) / 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gameChar.x = width / 2;
|
||||
@ -442,15 +474,15 @@ function draw() {
|
||||
}
|
||||
|
||||
if (gameChar.isJumping) {
|
||||
gameChar.y -= gameChar.jumpingStrength;
|
||||
gameChar.jumpingStrength -= gravity;
|
||||
if (gameChar.jumpingStrength <= 0) {
|
||||
gameChar.y -= gameChar.curJumpingStrength;
|
||||
gameChar.curJumpingStrength -= gravity;
|
||||
if (gameChar.curJumpingStrength <= 0) {
|
||||
gameChar.isFalling = true;
|
||||
gameChar.isJumping = false;
|
||||
}
|
||||
} else if (gameChar.isFalling) {
|
||||
gameChar.y -= gameChar.jumpingStrength;
|
||||
gameChar.jumpingStrength -= gravity;
|
||||
gameChar.y -= gameChar.curJumpingStrength;
|
||||
gameChar.curJumpingStrength -= gravity;
|
||||
if (gameChar.y >= gameChar.getCurGroundY()) {
|
||||
gameChar.y = gameChar.getCurGroundY();
|
||||
gameChar.isFalling = false;
|
||||
@ -459,22 +491,6 @@ function draw() {
|
||||
}
|
||||
}
|
||||
checkPlayerDie();
|
||||
// Setting sprite
|
||||
{
|
||||
if (gameChar.isPlummeting) {
|
||||
gameChar.sprite = 2;
|
||||
} else if (gameChar.isFalling) {
|
||||
gameChar.sprite = 2;
|
||||
if (gameChar.isLeft && !gameChar.isRight) gameChar.sprite = 5;
|
||||
else if (gameChar.isRight && !gameChar.isLeft)
|
||||
gameChar.sprite = 6;
|
||||
} else {
|
||||
if (gameChar.isLeft && !gameChar.isRight) gameChar.sprite = 4;
|
||||
else if (gameChar.isRight && !gameChar.isLeft)
|
||||
gameChar.sprite = 3;
|
||||
else gameChar.sprite = 1;
|
||||
}
|
||||
}
|
||||
// Doing plummeting
|
||||
if (gameChar.isPlummeting) {
|
||||
if (death_timer == undefined) death_timer = frameCount;
|
||||
@ -857,7 +873,7 @@ function keyPressed() {
|
||||
!gameChar.isJumping
|
||||
) {
|
||||
gameChar.isJumping = true;
|
||||
gameChar.jumpingStrength = 15;
|
||||
gameChar.curJumpingStrength = gameChar.baseJumpingStrength;
|
||||
}
|
||||
}
|
||||
if (keyCode == 77 /*M*/) showDebugData = !showDebugData;
|
||||
|
Loading…
Reference in New Issue
Block a user