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
User prompt
while counting down, the tnt type box should flash red every 30 ticks (self.countdown % 30)
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Move the column shadow to the box class
Code edit (2 edits merged)
Please save this source code
User prompt
column shadow is only visible if the boxes array size is greater than the count
Code edit (1 edits merged)
Please save this source code
User prompt
Columns should have a sub-container called boxContainer that holds Boxes
Code edit (7 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -2,9 +2,9 @@
var self = Container.call(this);
self.x = x;
self.y = y;
;
- var durationMax = 10;
+ var durationMax = 100;
var duration = durationMax;
var explosionGraphics = self.createAsset('explosion', 'Explosion graphics', 0.5, 0.5);
;
self.update = update;
@@ -74,9 +74,8 @@
var floorGraphics = self.createAsset('floor', 'Floor image', 0.5, 0.5);
});
var Interface = Container.expand(function () {
var self = Container.call(this);
- ;
var score = 0;
var scoreTxt = self.addChild(new BorderedText(score.toString(), {
size: 150,
anchor: {
@@ -113,39 +112,37 @@
moveInstructions.destroy();
jumpInstructions.destroy();
}
});
-var Box = Container.expand(function (x, y, {index, column}) {
+var Box = Container.expand(function (x, y, args) {
var self = Container.call(this);
- self.x = x;
- self.y = y;
- ;
- var typeValue = Math.random();
- var type = (typeValue -= SPAWN_GOLD_CHANCE) < 0 ? 'gold' : (typeValue -= SPAWN_TNT_CHANCE) < 0 ? 'tnt' : (typeValue -= SPAWN_POINTS_CHANCE) < 0 ? 'points' : (typeValue -= SPAWN_STONE_CHANCE) < 0 ? 'stone' : 'basic';
- var settings = BOX_SETTINGS[type];
- var image = settings.images[Math.floor(Math.random() * settings.images.length)];
+ var {index, column} = args;
var speed = BOX_SPEED;
;
- var boxGraphics = self.createAsset(image + 'Box', 'Box graphics', settings.x, settings.y);
- 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.x = x;
+ self.y = y;
self.alive = true;
self.active = false;
self.falling = true;
- self.type = type;
self.index = index;
- self.hitbox = hitboxGraphics;
+ self.build = build;
self.update = update;
- self.squash = squash;
+ self.activation = activation;
+ 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 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;
+ }
function update(args) {
- var {interface, player} = args;
var destroyNextTick = false;
var upperBox = column.boxes[self.index + 1];
var shadowVisible = upperBox && upperBox.falling;
shadowGraphics.visible = shadowVisible;
@@ -153,8 +150,9 @@
var scale = 1 - (self.y - upperBox.y) / STAGE_HEIGHT;
shadowGraphics.scale.set(scale);
}
if (self.falling) {
+ var {player} = args;
speed += BOX_GRAVITY;
self.y += speed;
var targetHeight = STAGE_HEIGHT - (self.index + 0.5) * BOX_HEIGHT - FLOOR_OFFSET;
if (self.y >= targetHeight) {
@@ -164,77 +162,14 @@
speed = 0;
column.count++;
column.squash(self, self.index - 1);
column.addChild(self);
- } else if (player.intersects(self.hitbox)) {
- switch (type) {
- case 'gold':
- case 'points':
- destroyNextTick = true;
- self.active = true;
- break;
- case 'tnt':
- if (!self.active) {
- self.active = true;
- self.countdown = TNT_COUNTDOWN;
- }
- default:
- if (!player.invulnerability) {
- interface.gameOver();
- }
- break;
- }
+ } else if (player.intersects(shadowGraphics)) {
+ destroyNextTick = self.collide(player);
}
}
if (self.active) {
- switch (type) {
- case 'gold':
- player.invulnerability += INVULNERABILITY_TIME;
- break;
- case 'points':
- interface.increment(POINTS_GAIN_PICKUP);
- break;
- case 'tnt':
- if (self.countdown !== undefined) {
- var {game, columnList, effectList} = args;
- if (--self.countdown <= 0) {
- effectList.push(game.addChild(new ExplosionEffect(self.x, self.y)));
- self.alive = false;
- } else if (self.countdown % 30 === 0) {
- LK.effects.flashObject(self, 0xff0000, 500);
- }
- 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) {
- switch (box.type) {
- case 'stone':
- break;
- case 'tnt':
- box.active = true;
- box.countdown = 0;
- break;
- default:
- box.alive = false;
- break;
- }
- }
- } else {
- break;
- }
- }
- }
- }
- }
- }
- break;
- }
+ self.activation(args);
}
if (!self.alive) {
column.remove(self);
return true;
@@ -242,54 +177,160 @@
if (destroyNextTick) {
self.alive = false;
}
}
- function squash(target) {
+ function activation(args) {}
+ function collide(args) {
+ var {player, interface} = args;
+ if (!player.invulnerability) {
+ interface.gameOver();
+ }
+ return false;
+ }
+ function touch(target) {}
+});
+var BasicBox = Box.expand(function (x, y, args) {
+ var self = Container.call(this);
+ 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);
+ 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);
+ var self = Box.call(this, x, y, args);
+ ;
+ self.build('points', .5, .55, 2);
+ self.activation = activation;
+ self.collide = collide;
+ self.touch = touch;
+ ;
+ function activation(args) {
+ var {interface} = args;
+ interface.increment(POINTS_GAIN_PICKUP);
+ }
+ function collide(args) {
+ self.active = true;
+ return true;
+ }
+ function touch(target) {
if (target instanceof Player) {
- switch (type) {
- case 'gold':
- case 'points':
- self.alive = false;
- self.active = true;
- break;
- case 'tnt':
- if (!self.active) {
- self.active = true;
- self.countdown = TNT_COUNTDOWN;
+ self.active = true;
+ self.alive = false;
+ } else if (target instanceof StoneBox) {
+ self.alive = false;
+ }
+ }
+});
+var GoldBox = Box.expand(function (x, y, args) {
+ var self = Container.call(this);
+ var self = Box.call(this, x, y, args);
+ ;
+ self.build('gold', .5, .5);
+ self.activation = activation;
+ self.collide = collide;
+ self.touch = touch;
+ ;
+ function activation(args) {
+ var {player} = args;
+ player.invulnerability += INVULNERABILITY_TIME;
+ }
+ function collide(args) {
+ self.active = true;
+ return true;
+ }
+ function touch(target) {
+ if (target instanceof Player) {
+ self.active = true;
+ self.alive = false;
+ } else if (target instanceof StoneBox) {
+ self.alive = false;
+ }
+ }
+});
+var TntBox = Box.expand(function (x, y, args) {
+ var self = Container.call(this);
+ var self = Box.call(this, x, y, args);
+ var {column} = args;
+ var countdown = 0;
+ ;
+ self.build('tnt', .5, .55);
+ self.activation = activation;
+ 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;
+ }
+ }
+ } else {
+ break;
+ }
+ }
+ }
}
- break;
+ }
+ } else if (self.countdown % 30 === 0) {
+ LK.effects.flashObject(self, 0xff0000, 500);
}
- } else if (target.type === 'stone') {
- switch (type) {
- case 'gold':
- case 'points':
- self.alive = false;
- break;
- case 'tnt':
- self.active = true;
- self.countdown = 0;
- break;
+ }
+ }
+ function collide(args) {
+ if (!self.active) {
+ self.active = true;
+ countdown = TNT_COUNTDOWN;
+ }
+ }
+ function touch(target) {
+ if (!self.active) {
+ if (target instanceof Player) {
+ self.active = true;
+ self.countdown = TNT_COUNTDOWN;
+ } else if (target instanceof StoneBox) {
+ self.active = true;
}
}
}
});
var Column = Container.expand(function (x, y, index) {
var self = Container.call(this);
- self.x = x;
- self.y = y;
- ;
var boxes = [];
var countdown = SPAWN_INITIAL + getCountdown();
var shadowGraphics = self.createAsset('shadow', 'Shadow image', 0.5, 0.5);
shadowGraphics.alpha = 0.5;
shadowGraphics.y = STAGE_HEIGHT - FLOOR_OFFSET;
;
- self.count = 0;
+ self.x = x;
+ self.y = y;
self.boxes = boxes;
self.index = index;
self.squash = squash;
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));
}
@@ -325,9 +366,20 @@
if (--countdown <= 0) {
countdown = getCountdown();
if (self.count < COLUMN_VOLUME) {
var {boxList, game} = args;
- var box = game.addChild(new Box(self.x, SPAWN_OFFSET, {
+ var typeValue = Math.random();
+ var typeInstance = BasicBox;
+ if ((typeValue -= SPAWN_GOLD_CHANCE) < 0) {
+ typeInstance = GoldBox;
+ } else if ((typeValue -= SPAWN_TNT_CHANCE) < 0) {
+ typeInstance = TntBox;
+ } else if ((typeValue -= SPAWN_POINTS_CHANCE) < 0) {
+ typeInstance = PointsBox;
+ } else if ((typeValue -= SPAWN_STONE_CHANCE) < 0) {
+ typeInstance = StoneBox;
+ }
+ var box = game.addChild(new typeInstance(self.x, SPAWN_OFFSET, {
column: self,
index: boxes.length
}));
boxList.push(box);
@@ -462,35 +514,8 @@
var BOX_GRAVITY = 0.2;
var TNT_COUNTDOWN = 2 * STAGE_TICKS;
var FLOOR_OFFSET = 100;
var COLUMN_VOLUME = Math.floor((STAGE_HEIGHT - FLOOR_OFFSET) / BOX_HEIGHT) + 1;
-var BOX_SETTINGS = {
- basic: {
- x: .5,
- y: .5,
- images: ['basic1', 'basic2', 'basic3']
- },
- tnt: {
- x: .5,
- y: .55,
- images: ['tnt']
- },
- gold: {
- x: .5,
- y: .5,
- images: ['gold']
- },
- points: {
- x: .5,
- y: .55,
- images: ['points1', 'points2']
- },
- stone: {
- x: .5,
- y: .5,
- images: ['stone']
- }
-};
;
var Game = Container.expand(function () {
var self = Container.call(this);
;
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.