User prompt
player starts with invulnerability equal to INVULNERABILITY_TIME
Code edit (1 edits merged)
Please save this source code
User prompt
flash the player black when invulnerability reaches 60 and 30
User prompt
tint the player gold while it is invulnerable
Code edit (1 edits merged)
Please save this source code
User prompt
decrement player invulnerability in it's update function if it's greater than 0
Code edit (8 edits merged)
Please save this source code
User prompt
Change `invulnerability` from `true` to `0`
User prompt
Rename the player's `invulnerable` variable to `invulnerability` and update checks in other classes
Code edit (7 edits merged)
Please save this source code
User prompt
Increase COLUMN_VOLUME by 1
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Create an interface class that handles the score. It should contain the scoreTxt variable, and should have an increment function that takes in a value
Code edit (1 edits merged)
Please save this source code
User prompt
check if the squash target is a player
Code edit (9 edits merged)
Please save this source code
User prompt
boxes have an empty squash function that takes in a bool
User prompt
boxes have an activate function which takes in a bool
Code edit (1 edits merged)
Please save this source code
User prompt
clamp the new targetColumn value in the player's move function between 0 and NUM_COLUMNS
Code edit (10 edits merged)
Please save this source code
User prompt
remove the debug console.logs in the player
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -1,14 +1,16 @@
var Interface = Container.expand(function (parent) {
var self = Container.call(this);
parent.addChild(self);
+ ;
var score = 0;
+ ;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(.5, 0);
- LK.gui.topCenter.addChild(scoreTxt);
+ self.addChild(scoreTxt);
;
self.increment = increment;
self.gameOver = gameOver;
;
@@ -42,13 +44,15 @@
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 speed = BOX_SPEED;
+ ;
var boxGraphics = self.createAsset(image + 'Box', 'Box graphics', settings.x, settings.y);
var hitboxGraphics = self.createAsset('hitbox', 'Hitbox graphics', .5, .5);
hitboxGraphics.width = BOX_WIDTH;
hitboxGraphics.height = BOX_HEIGHT;
hitboxGraphics.alpha = 0;
+ ;
self.alive = true;
self.active = false;
self.falling = true;
self.type = type;
@@ -78,9 +82,9 @@
break;
case 'tnt':
self.active = true;
default:
- if (!player.invulnerable) {
+ if (!player.invulnerability) {
interface.gameOver();
}
break;
}
@@ -130,44 +134,49 @@
parent.addChild(self);
self.x = x;
self.y = y;
;
- var countdown = SPAWN_CONST + Math.floor(Math.random() * SPAWN_VARIANCE);
+ var boxes = [];
+ var countdown = getCountdown();
;
self.count = 0;
- self.boxes = [];
+ self.boxes = boxes;
self.squash = squash;
self.remove = remove;
self.update = update;
;
+ function getCountdown() {
+ return SPAWN_CONST + Math.floor(Math.random() * (SPAWN_VARIANCE + SPAWN_COUNT_VARIANCE * boxes.length));
+ }
function squash(target, index) {
var box = self.boxes[index];
if (box) {
box.squash(target);
}
}
function remove(box) {
var index = box.index;
- self.boxes.splice(index, 1);
+ boxes.splice(index, 1);
if (!box.falling) {
self.count--;
}
- for (var i = index; i < self.boxes.length; i++) {
- var box = self.boxes[i];
+ for (var i = index; i < boxes.length; i++) {
+ var box = boxes[i];
box.index--;
if (!box.falling) {
self.count--;
box.falling = true;
}
}
}
- function update(boxes) {
+ function update(args) {
if (--countdown <= 0) {
- countdown = SPAWN_CONST + Math.floor(Math.random() * SPAWN_VARIANCE);
+ countdown = getCountdown();
if (self.count < COLUMN_VOLUME) {
- var box = new Box(self, 0, SPAWN_OFFSET, self.boxes.length);
+ var {boxList} = args;
+ var box = new Box(self, 0, SPAWN_OFFSET, boxes.length);
+ boxList.push(box);
boxes.push(box);
- self.boxes.push(box);
}
}
}
});
@@ -184,9 +193,10 @@
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
playerGraphics.width = PLAYER_SIZE;
playerGraphics.height = PLAYER_SIZE;
;
- self.invulnerable = true;
+ self.heightClimbed = 0;
+ self.invulnerability = true;
self.airborne = false;
self.move = move;
self.jump = jump;
self.update = update;
@@ -209,13 +219,13 @@
verticalSpeed = PLAYER_JUMP_SPEED;
}
}
function update(args) {
- var {columns} = args;
+ var {interface, columnList} = args;
var colIndex = getColIndex();
var rowIndex = getRowIndex();
var targetX = (targetColumn + 0.5) * BOX_WIDTH;
- var targetY = floorHeight - columns[colIndex].count * BOX_HEIGHT;
+ var targetY = floorHeight - columnList[colIndex].count * BOX_HEIGHT;
if (self.x !== targetX) {
var moveSpeed = Math.min(Math.abs(targetX - self.x), PLAYER_MOVE_SPEED);
self.x += Math.sign(targetX - self.x) * moveSpeed;
self.rotation = Math.PI * (self.x - STAGE_WIDTH / 2) / (BOX_WIDTH * 2);
@@ -237,32 +247,40 @@
}
if (!self.airborne) {
colIndex = getColIndex();
rowIndex = getRowIndex();
- columns[colIndex].squash(self, rowIndex - 1);
+ columnList[colIndex].squash(self, rowIndex - 1);
+ if (rowIndex > self.heightClimbed) {
+ interface.increment((rowIndex - self.heightClimbed) * POINTS_GAIN_CLIMBING);
+ self.heightClimbed = rowIndex;
+ }
}
}
});
+;
var STAGE_WIDTH = 2048;
var STAGE_HEIGHT = 2732;
+var STAGE_TICKS = 60;
var CONTROL_SWIPE_DIST = 100;
-var CONTROL_TAP_TICKS = 20;
+var CONTROL_TAP_TICKS = STAGE_TICKS / 3;
var NUM_COLUMNS = 9;
var BOX_WIDTH = STAGE_WIDTH / NUM_COLUMNS;
var BOX_HEIGHT = 0.75 * BOX_WIDTH;
var PLAYER_SIZE = 0.8 * BOX_WIDTH;
var PLAYER_GRAVITY = 0.5;
var PLAYER_JUMP_SPEED = 20;
var PLAYER_MOVE_SPEED = 15;
var SPAWN_OFFSET = -100;
-var SPAWN_CONST = 30;
-var SPAWN_VARIANCE = 10 * 60 - SPAWN_CONST;
+var SPAWN_CONST = STAGE_TICKS / 2;
+var SPAWN_VARIANCE = 10 * STAGE_TICKS - SPAWN_CONST;
+var SPAWN_COUNT_VARIANCE = STAGE_TICKS / 4;
var SPAWN_TNT_CHANCE = 0.03;
var SPAWN_GOLD_CHANCE = 0.01;
var SPAWN_POINTS_CHANCE = 0.05;
var SPAWN_STONE_CHANCE = 0.1;
var POINTS_GAIN_CLIMBING = 1;
var POINTS_GAIN_PICKUP = 5;
+var INVULNERABILITY_TIME = 5 * STAGE_TICKS;
var BOX_SPEED = 5;
var BOX_GRAVITY = 0.2;
var FLOOR_OFFSET = 100;
var COLUMN_VOLUME = Math.floor((STAGE_HEIGHT - FLOOR_OFFSET) / BOX_HEIGHT) + 1;
@@ -292,24 +310,24 @@
y: .5,
images: ['stone']
}
};
+;
var Game = Container.expand(function () {
var self = Container.call(this);
;
var lastTouchX = null;
var lastTouchY = null;
var touchTime = null;
- var boxes = [];
- var columns = [];
+ var boxList = [];
+ var columnList = [];
+ ;
var floor = self.addChild(new Floor(self, STAGE_WIDTH / 2, STAGE_HEIGHT));
for (var i = 0; i < NUM_COLUMNS; i++) {
- columns.push(new Column(self, (i + 0.5) * BOX_WIDTH, 0));
+ columnList.push(new Column(self, (i + 0.5) * BOX_WIDTH, 0));
}
var player = self.addChild(new Player(self, STAGE_WIDTH / 2, STAGE_HEIGHT - FLOOR_OFFSET - PLAYER_SIZE / 2));
- var isGameOver = false;
- var tickOffset = 0;
- var interface = new Interface(self);
+ var interface = new Interface(LK.gui.topCenter);
;
stage.on('down', function (obj) {
var event = obj.event;
lastTouchX = event.global.x;
@@ -345,23 +363,30 @@
}
}
});
LK.on('tick', function () {
- if (isGameOver) {}
- player.update({
- columns
- });
- columns.forEach(function (column) {
- column.update(boxes, tickOffset);
- });
- for (var i = boxes.length - 1; i >= 0; i--) {
- var box = boxes[i];
- if (box.update({
- interface,
- player
- })) {
+ var playerArgs = {
+ interface,
+ columnList
+ };
+ player.update(playerArgs);
+ ;
+ var columnArgs = {
+ boxList
+ };
+ for (var i = columnList.length - 1; i >= 0; i--) {
+ columnList[i].update(columnArgs);
+ }
+ ;
+ var boxArgs = {
+ interface,
+ player
+ };
+ for (var i = boxList.length - 1; i >= 0; i--) {
+ var box = boxList[i];
+ if (box.update(boxArgs)) {
box.destroy();
- boxes.splice(i, 1);
+ boxList.splice(i, 1);
}
}
});
});
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.