drawing platforms, constructor function for them
This commit is contained in:
parent
d1c0001865
commit
aa0943467f
81
sketch.js
81
sketch.js
@ -5,6 +5,7 @@ var processStop_timer;
|
|||||||
var fps_recent_values = [];
|
var fps_recent_values = [];
|
||||||
var death_timer;
|
var death_timer;
|
||||||
var showDebugData = false;
|
var showDebugData = false;
|
||||||
|
var debug_charTrace = [];
|
||||||
|
|
||||||
var gameChar;
|
var gameChar;
|
||||||
|
|
||||||
@ -21,6 +22,45 @@ var platforms = [];
|
|||||||
var enemies = [];
|
var enemies = [];
|
||||||
var flagpole;
|
var flagpole;
|
||||||
|
|
||||||
|
function Platform(curGroundIndex, x, width, y) {
|
||||||
|
this.curGroundIndex = curGroundIndex;
|
||||||
|
this.x = x;
|
||||||
|
this.width = width;
|
||||||
|
this.y = y || Math.pow(gameChar.baseJumpingStrength, 2) / 2 - 2 * gameChar.baseJumpingStrength;
|
||||||
|
|
||||||
|
this.draw = function () {
|
||||||
|
push();
|
||||||
|
stroke(0);
|
||||||
|
strokeWeight(2);
|
||||||
|
fill(palette.ground_color0);
|
||||||
|
rect(
|
||||||
|
this.x - this.width,
|
||||||
|
floorPos_y - this.y,
|
||||||
|
width*2, height/100,
|
||||||
|
);
|
||||||
|
|
||||||
|
pop();
|
||||||
|
};
|
||||||
|
|
||||||
|
this._isWithinX = function (who) {
|
||||||
|
if (who.x > this.x - this.width && who.x < this.x + this.width) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.isBelow = function (who) {
|
||||||
|
if (this._isWithinX(who) && who.y > this.y) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.isAbove = function (who) {
|
||||||
|
if (this._isWithinX(who) && who.y < this.y) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var text_size;
|
var text_size;
|
||||||
// Variables to set colors. Set in setup()
|
// Variables to set colors. Set in setup()
|
||||||
var palette;
|
var palette;
|
||||||
@ -401,14 +441,13 @@ function startGame(level_start) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (i = 0; i < groundPositions.length; i++) {
|
||||||
|
platforms[i] = [];
|
||||||
|
}
|
||||||
for (i = 0; i < 100; i++) {
|
for (i = 0; i < 100; i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
platforms[0] = {
|
platforms[0][0] = new Platform(0, 700, 50,
|
||||||
curGroundIndex: 0,
|
pow(gameChar.baseJumpingStrength, 2) / 2 - 2*gameChar.baseJumpingStrength);
|
||||||
x: 700,
|
|
||||||
width: 50,
|
|
||||||
y: pow(gameChar.baseJumpingStrength, 2) / 2,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,6 +501,8 @@ function draw() {
|
|||||||
// -------- FLAGPOLE ------------
|
// -------- FLAGPOLE ------------
|
||||||
renderFlagpole();
|
renderFlagpole();
|
||||||
if (!flagpole.isReached) checkFlagpole();
|
if (!flagpole.isReached) checkFlagpole();
|
||||||
|
// -------- PLATFORMS
|
||||||
|
drawPlatforms();
|
||||||
|
|
||||||
// -------- GAME CHARACTER ------
|
// -------- GAME CHARACTER ------
|
||||||
{
|
{
|
||||||
@ -511,12 +552,28 @@ function draw() {
|
|||||||
text("Level complete. Press space to continue...", 0, height / 2);
|
text("Level complete. Press space to continue...", 0, height / 2);
|
||||||
if (showDebugData) {
|
if (showDebugData) {
|
||||||
text(gameChar.curGroundIndex, 99, 99);
|
text(gameChar.curGroundIndex, 99, 99);
|
||||||
text(gameChar.getCurGroundPosY(), 188, 99);
|
text(gameChar.getCurGroundY(), 188, 99);
|
||||||
text(gameChar.sprite, 277, 99);
|
text(gameChar.sprite, 277, 99);
|
||||||
|
|
||||||
|
// draw game character's trajectory
|
||||||
|
drawCharTrace();
|
||||||
drawFps();
|
drawFps();
|
||||||
}
|
}
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
|
function drawCharTrace() {
|
||||||
|
debug_charTrace.push([gameChar.x, gameChar.y]);
|
||||||
|
if (debug_charTrace.length>100) debug_charTrace.shift();
|
||||||
|
push()
|
||||||
|
stroke(255,0,0);
|
||||||
|
strokeWeight(3);
|
||||||
|
translate(-cameraPosX, 0);
|
||||||
|
for (i=0;i<debug_charTrace.length;i++) {
|
||||||
|
point(debug_charTrace[i][0], debug_charTrace[i][1]);
|
||||||
|
}
|
||||||
|
translate(cameraPosX, 0);
|
||||||
|
pop();
|
||||||
|
}
|
||||||
function checkRiver(t_river) {
|
function checkRiver(t_river) {
|
||||||
if (
|
if (
|
||||||
gameChar.x > river.x - river.width / 2 &&
|
gameChar.x > river.x - river.width / 2 &&
|
||||||
@ -610,7 +667,6 @@ function drawRiver(t_river) {
|
|||||||
}
|
}
|
||||||
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 - vert. intensity, c - hor. intensity, b - vert. speed, d - hor. speed
|
||||||
a = 0.1;
|
a = 0.1;
|
||||||
@ -786,6 +842,15 @@ function drawTrees() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function drawPlatforms() {
|
||||||
|
for (i=0; i<groundPositions.length; i++) {
|
||||||
|
for (k=0; k<platforms[i].length;k++) {
|
||||||
|
platforms[i][k].draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function renderFlagpole() {
|
function renderFlagpole() {
|
||||||
// NB - This function is implemented a bit differently than how it was requested in Part 6.
|
// NB - This function is implemented a bit differently than how it was requested in Part 6.
|
||||||
// It has no states to switch between - instead, the flag gradually goes into the opposite direction
|
// It has no states to switch between - instead, the flag gradually goes into the opposite direction
|
||||||
|
Loading…
Reference in New Issue
Block a user