User prompt
in set jump force, calculate the movement vector, the limit how big the movement vector can be
User prompt
Limit how much speed can be added to player
User prompt
Factor in platform hight when looking if they should be removed to top screen. Similarly make sure the platform spawn outside the screen at the top
User prompt
Of hero fail player falls of screen call gameover
User prompt
set max platform speed to 5
User prompt
Platform speed code should always run regardless if the player is jumping or not
User prompt
Set initial platform speed to zero
User prompt
Clamp the platform speed to zero on the low end
User prompt
Make platform speed go up if player is above halfway of the screen, otherwise make it go down
User prompt
when setting player.y in tick, factor in that assets have a centered anchor point
User prompt
Factor in that assets have centered anchor points when setting player.y
User prompt
Factor in both platform and player hight when setting player.y
User prompt
If a platform is fully outside the view at the bottom, move it to a random position at the top
User prompt
when moving down platforms also move down the player
User prompt
Remove the platformspeeq variable in the global scope
User prompt
Remove the global platform speed variable
User prompt
Remove the logic that allows a platform to move by itself
User prompt
Fix Bug: 'ReferenceError: Can't find variable: platformSpeed' in this line: 'self.speed = platformSpeed;' Line Number: 38
User prompt
Create a platform movement speed variable
User prompt
Create a variable for how much to move down the platforms inside the tick method
User prompt
If the player is not jumping and the player y position is above half the screen hight move down all platforms
User prompt
don't set onPlatform inside tick, rather set onPlatform to false when jumping
User prompt
Remove the code that sets on platform to false in side the for loop and then simply set on platform after player.update has been caled
User prompt
Only allow jumping if the player is currently standing on a platform'
User prompt
Only allow jumping if the player is not already jumping
var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', .5, .5); self.gravity = 1; self.jumpForce = 20; self.velocityX = 0; self.velocityY = 0; self.setJumpForce = function (x, y) { this.jumpForceX = x / 12.5; this.jumpForceY = y / 12.5; }; self.jumping = false; self.onPlatform = false; self.update = function () { this.x += this.velocityX; this.y += this.velocityY; this.velocityY += this.gravity; this.velocityX *= 0.98; this.velocityY *= 0.98; if (this.y > 2732) { this.y = 2732; this.velocityY = 0; } if (this.x < 0 || this.x > 2048) { this.velocityX *= -1; } if (this.velocityY >= 0) { this.jumping = false; } else if (this.velocityY < 0) { this.jumping = true; } }; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.createAsset('platform', 'Platform', .5, .5); self.speed = 5; self.move = function () { this.y += this.speed; }; }); var Game = Container.expand(function () { var self = Container.call(this); stage.on('up', function (obj) { if (dragStart && player.onPlatform) { var pos = obj.event.getLocalPosition(self); player.setJumpForce(dragStart.x - pos.x, dragStart.y - pos.y); player.velocityX = player.jumpForceX; player.velocityY = player.jumpForceY; dragStart = null; } }); stage.on('move', function (obj) { if (dragStart) { var pos = obj.event.getLocalPosition(self); } }); var platforms = []; var player = self.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - player.height; var firstJump = false; for (var i = 0; i < 6; i++) { var platform = new Platform(); if (i == 0) { platform.x = player.x; platform.y = player.y + player.height; } else { platform.x = Math.random() * 2048; platform.y = i * (2732 / 6); } platforms.push(platform); self.addChild(platform); } LK.on('tick', function () { player.update(); for (var i = 0; i < platforms.length; i++) { if (player.intersects(platforms[i]) && !player.jumping && player.y + player.height / 2 < platforms[i].y) { player.y = platforms[i].y - player.height; player.velocityY = 0; player.velocityX *= 0.8; player.onPlatform = true; } else { player.onPlatform = false; } } }); var dragStart = null; stage.on('down', function (obj) { dragStart = obj.event.getLocalPosition(self); }); });
===================================================================
--- original.js
+++ change.js
@@ -9,8 +9,9 @@
this.jumpForceX = x / 12.5;
this.jumpForceY = y / 12.5;
};
self.jumping = false;
+ self.onPlatform = false;
self.update = function () {
this.x += this.velocityX;
this.y += this.velocityY;
this.velocityY += this.gravity;
@@ -40,9 +41,9 @@
});
var Game = Container.expand(function () {
var self = Container.call(this);
stage.on('up', function (obj) {
- if (dragStart && !player.jumping) {
+ if (dragStart && player.onPlatform) {
var pos = obj.event.getLocalPosition(self);
player.setJumpForce(dragStart.x - pos.x, dragStart.y - pos.y);
player.velocityX = player.jumpForceX;
player.velocityY = player.jumpForceY;
@@ -77,8 +78,11 @@
if (player.intersects(platforms[i]) && !player.jumping && player.y + player.height / 2 < platforms[i].y) {
player.y = platforms[i].y - player.height;
player.velocityY = 0;
player.velocityX *= 0.8;
+ player.onPlatform = true;
+ } else {
+ player.onPlatform = false;
}
}
});
var dragStart = null;
Single cartoon frog sitting. Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Cartoon lillypad seen edge on. No flower Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Cozy cartoon swamp background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.