Code edit (1 edits merged)
Please save this source code
User prompt
in the box update method, before checking the alive state, set self.alive to false if the box's y value goes above: `STAGE_HEIGHT + BOX_HEIGHT / 2`
Code edit (3 edits merged)
Please save this source code
User prompt
add an isPaused = false variable to the interface class, which when true prevents non-interface update ticks
User prompt
Add a global TERMINAL_VELOCITY = 20 and make sure boxes and the player never exceeds this value while falling
User prompt
Replace both PLAYER_GRAVITY and BOX_GRAVITY with a single GRAVITY global of 0.5. Make sure to update old references in the box and player class
Code edit (7 edits merged)
Please save this source code
User prompt
remove all console.log commands in the tnt explode function
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
set the player hitbox alpha to 0
Code edit (1 edits merged)
Please save this source code
User prompt
when the player rotates, rotate the player graphics instead
User prompt
when checking box collision, use the player hitbox instead of the player itself
Code edit (13 edits merged)
Please save this source code
User prompt
add a hitbox to the player
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: self is undefined' in this line: 'self.build('basic', .5, .5, 3);' Line Number: 195
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
when a TNT box countdown expires, create an ExplosionEffect centered on the TNT as a child of the game variable, and add it to the effectsList
Code edit (1 edits merged)
Please save this source code
User prompt
create an effectList array in the game class, iterate through it in the on tick calling their update function; if it returns truthy, remove and delete the effect
Code edit (9 edits merged)
Please save this source code
User prompt
create an explosion effect class
===================================================================
--- original.js
+++ change.js
@@ -1,23 +1,4 @@
-var ExplosionEffect = Container.expand(function (x, y) {
- var self = Container.call(this);
- self.x = x;
- self.y = y;
- ;
- var durationMax = 100;
- var duration = durationMax;
- var explosionGraphics = self.createAsset('explosion', 'Explosion graphics', 0.5, 0.5);
- ;
- self.update = update;
- ;
- function update() {
- var progress = duration / durationMax;
- explosionGraphics.alpha = progress;
- explosionGraphics.scale.set(2 - progress);
- return duration--;
- }
- ;
-});
var BorderedText = Container.expand(function (string, settings) {
var self = Container.call(this);
var textList = [];
var defaultFill = '#ffffff';
@@ -112,8 +93,26 @@
moveInstructions.destroy();
jumpInstructions.destroy();
}
});
+var ExplosionEffect = Container.expand(function (x, y) {
+ var self = Container.call(this);
+ self.x = x;
+ self.y = y;
+ ;
+ var durationMax = 10;
+ var duration = durationMax;
+ var explosionGraphics = self.createAsset('explosion', 'Explosion graphics', 0.5, 0.5);
+ ;
+ self.update = update;
+ ;
+ function update() {
+ var progress = duration / durationMax;
+ explosionGraphics.alpha = progress;
+ explosionGraphics.scale.set(2 - progress);
+ return !duration--;
+ }
+});
var Box = Container.expand(function (x, y, args) {
var self = Container.call(this);
var {index, column} = args;
var speed = BOX_SPEED;
@@ -130,26 +129,28 @@
self.collide = collide;
self.touch = touch;
;
function build(name, xAnchor, yAnchor, variations) {
- var imageName = name + (!variations || variations <= 1) ? '' : Math.floor(Math.random() * variations);
- var boxGraphics = self.createAsset(imageName + 'Box', 'Box graphics', xAnchor, yAnchor);
+ var nameVariant = !variations || variations <= 1 ? '' : 1 + Math.floor(Math.random() * variations);
+ var boxGraphics = self.createAsset(name + nameVariant + 'Box', 'Box graphics', xAnchor, yAnchor);
var shadowGraphics = self.createAsset('shadow', 'Shadow image', 0.5, 0.5);
var hitboxGraphics = self.createAsset('hitbox', 'Hitbox graphics', .5, .25);
shadowGraphics.alpha = 0.5;
shadowGraphics.y = -BOX_HEIGHT * 0.5;
hitboxGraphics.width = BOX_WIDTH * 0.9;
hitboxGraphics.height = BOX_HEIGHT * 0.6;
hitboxGraphics.alpha = 0;
+ self.hitbox = hitboxGraphics;
+ self.shadow = shadowGraphics;
}
function update(args) {
var destroyNextTick = false;
var upperBox = column.boxes[self.index + 1];
var shadowVisible = upperBox && upperBox.falling;
- shadowGraphics.visible = shadowVisible;
+ self.shadow.visible = shadowVisible;
if (shadowVisible) {
var scale = 1 - (self.y - upperBox.y) / STAGE_HEIGHT;
- shadowGraphics.scale.set(scale);
+ self.shadow.scale.set(scale);
}
if (self.falling) {
var {player} = args;
speed += BOX_GRAVITY;
@@ -160,12 +161,12 @@
self.x = 0;
self.y = targetHeight;
speed = 0;
column.count++;
- column.squash(self, self.index - 1);
+ column.touch(self, self.index - 1);
column.addChild(self);
- } else if (player.intersects(shadowGraphics)) {
- destroyNextTick = self.collide(player);
+ } else if (player.intersects(self.hitbox)) {
+ destroyNextTick = self.collide(args);
}
}
if (self.active) {
self.activation(args);
@@ -186,24 +187,23 @@
}
return false;
}
function touch(target) {}
+ ;
+ return self;
});
var BasicBox = Box.expand(function (x, y, args) {
- var self = Container.call(this);
- self = Box.call(this, x, y, args);
+ var self = Box.call(this, x, y, args);
;
self.build('basic', .5, .5, 3);
});
var StoneBox = Box.expand(function (x, y, args) {
- var self = Container.call(this);
- self = Box.call(this, x, y, args);
+ var self = Box.call(this, x, y, args);
;
self.build('stone', .5, .5);
});
var PointsBox = Box.expand(function (x, y, args) {
- var self = Container.call(this);
- self = Box.call(this, x, y, args);
+ var self = Box.call(this, x, y, args);
;
self.build('points', .5, .55, 2);
self.activation = activation;
self.collide = collide;
@@ -226,10 +226,10 @@
}
}
});
var GoldBox = Box.expand(function (x, y, args) {
- var self = Container.call(this);
- self = Box.call(this, x, y, args);
+ var self = Box.call(this, x, y, args);
+ var baseCollide = self.collide;
;
self.build('gold', .5, .5);
self.activation = activation;
self.collide = collide;
@@ -252,10 +252,9 @@
}
}
});
var TntBox = Box.expand(function (x, y, args) {
- var self = Container.call(this);
- self = Box.call(this, x, y, args);
+ var self = Box.call(this, x, y, args);
var {column} = args;
var countdown = 0;
;
self.build('tnt', .5, .55);
@@ -263,52 +262,53 @@
self.collide = collide;
self.touch = touch;
;
function activation(args) {
- if (self.countdown !== null) {
- if (--self.countdown <= 0) {
- var {game, columnList, effectList} = args;
- effectList.push(game.addChild(new ExplosionEffect(column.x, self.y)));
- self.alive = false;
- var min = self.y - BOX_HEIGHT * 1.25;
- var max = self.y + BOX_HEIGHT * 1.25;
- for (var i = column.index - 1; i <= column.index + 1; i++) {
- var col = columnList[i];
- if (col) {
- for (var j = 0; j < col.boxes.length; j++) {
- var box = col.boxes[j];
- if (box.y > min) {
- if (box.y < max) {
- if (box !== self) {
- if (box instanceof TntBox) {
- box.active = true;
- } else if (!(box instanceof StoneBox)) {
- box.alive = false;
- }
+ if (--countdown <= 0) {
+ var {game, columnList, effectList} = args;
+ effectList.push(game.addChild(new ExplosionEffect(column.x, self.y)));
+ self.alive = false;
+ var min = self.y - BOX_HEIGHT * 1.25;
+ var max = self.y + BOX_HEIGHT * 1.25;
+ for (var i = column.index - 1; i <= column.index + 1; i++) {
+ var col = columnList[i];
+ if (col) {
+ for (var j = 0; j < col.boxes.length; j++) {
+ var box = col.boxes[j];
+ if (box.y > min) {
+ if (box.y < max) {
+ if (box !== self) {
+ if (box instanceof TntBox) {
+ box.active = true;
+ } else if (!(box instanceof StoneBox)) {
+ box.alive = false;
}
- } else {
- break;
}
+ } else {
+ break;
}
}
}
}
- } else if (self.countdown % 30 === 0) {
- LK.effects.flashObject(self, 0xff0000, 500);
}
+ } else if (countdown % 30 === 0) {
+ LK.effects.flashObject(self, 0xff0000, 500);
}
}
function collide(args) {
+ baseCollide();
+ ;
if (!self.active) {
self.active = true;
countdown = TNT_COUNTDOWN;
}
+ return false;
}
function touch(target) {
if (!self.active) {
if (target instanceof Player) {
self.active = true;
- self.countdown = TNT_COUNTDOWN;
+ countdown = TNT_COUNTDOWN;
} else if (target instanceof StoneBox) {
self.active = true;
}
}
@@ -325,20 +325,20 @@
self.x = x;
self.y = y;
self.boxes = boxes;
self.index = index;
- self.squash = squash;
+ self.touch = touch;
self.remove = remove;
self.update = update;
self.count = 0;
;
function getCountdown() {
return SPAWN_CONST + Math.floor(Math.random() * (SPAWN_VARIANCE + SPAWN_COUNT_VARIANCE * boxes.length));
}
- function squash(target, index) {
+ function touch(target, index) {
var box = self.boxes[index];
if (box) {
- box.squash(target);
+ box.touch(target);
}
}
function remove(box) {
var index = box.index;
@@ -399,8 +399,13 @@
var targetColumn = Math.floor(x / BOX_WIDTH);
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
playerGraphics.width = PLAYER_SIZE;
playerGraphics.height = PLAYER_SIZE;
+ var hitboxGraphics = self.createAsset('hitbox', 'Player hitbox', .5, .5);
+ hitboxGraphics.width = PLAYER_SIZE * 0.6;
+ hitboxGraphics.height = PLAYER_SIZE * 0.8;
+ hitboxGraphics.alpha = 0;
+ self.hitbox = hitboxGraphics;
;
self.heightClimbed = 0;
self.invulnerability = 0;
self.airborne = false;
@@ -467,17 +472,17 @@
if (newColIndex !== colIndex) {
var column = columnList[newColIndex];
var box = column.boxes[newRowIndex];
if (box && !box.falling) {
- box.squash(self);
+ box.touch(self);
self.x = BOX_WIDTH * (0.5 + (newColIndex * 9 + colIndex * 10) / 19);
self.rotation = Math.PI * (self.x - STAGE_WIDTH / 2) / (BOX_WIDTH * 2);
targetColumn = colIndex;
newColIndex = colIndex;
}
}
if (!self.airborne) {
- columnList[newColIndex].squash(self, rowIndex - 1);
+ columnList[newColIndex].touch(self, rowIndex - 1);
if (rowIndex > self.heightClimbed) {
interface.increment((newRowIndex - self.heightClimbed) * POINTS_GAIN_CLIMBING);
self.heightClimbed = rowIndex;
}
Pixel art, side view of a concrete factory floor . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art, square with cute eyes . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art, square with the texture of a tnt . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a crate, side view . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a crate, flat side view . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a crate, flat side view . Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art of a golden christmas present. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art of a green christmas present with red ribbons. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art of an elaborate green christmas present with red ribbons. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a metal background.
pixel art of a crate made of stone with a label of coal on the side, flat side view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a square tnt explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.