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
@@ -4,15 +4,17 @@
self.x = x;
self.y = y;
;
var typeValue = Math.random();
- var type = typeValue <= SPAWN_TNT_CHANCE ? 'tnt' : 'basic';
+ var type = (typeValue -= SPAWN_GOLD_CHANCE) < 0 ? 'gold' : (typeValue -= SPAWN_TNT_CHANCE) < 0 ? 'tnt' : (typeValue -= POINTS_CHANCE) < 0 ? 'points' : '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(type + 'Box', 'Box graphics', .5, .5);
+ var boxGraphics = self.createAsset(image + 'Box', 'Box graphics', settings.x, settings.y);
var hitboxGraphics = self.createAsset('hitbox', 'Hitbox graphics', .5, .5);
- hitboxGraphics.alpha = 0.5;
- hitboxGraphics.width = BOX_SIZE;
- hitboxGraphics.height = BOX_SIZE;
+ hitboxGraphics.width = BOX_WIDTH;
+ hitboxGraphics.height = BOX_HEIGHT;
+ hitboxGraphics.alpha = 0;
;
self.active = true;
self.hitbox = hitboxGraphics;
self.update = update;
@@ -34,24 +36,24 @@
parent.addChild(self);
self.x = x;
self.y = y;
;
- var floorGraphics = self.createAsset('floor', 'Floor image', 0.5, 1);
- floorGraphics.width = STAGE_WIDTH;
+ var floorGraphics = self.createAsset('floor', 'Floor image', 0.5, 0.95);
+ floorGraphics.width = STAGE_WIDTH * 1.25;
});
var Player = Container.expand(function (parent, x, y) {
var self = Container.call(this);
parent.addChild(self);
self.x = x;
self.y = y;
;
+ var isJumping = false;
+ var verticalSpeed = 0;
+ var floorHeight = y;
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
+ playerGraphics.width = PLAYER_SIZE;
+ playerGraphics.height = PLAYER_SIZE;
;
- self.isJumping = false;
- self.jumpHeight = 150;
- self.jumpSpeed = -15;
- self.gravity = 0.5;
- self.verticalSpeed = 0;
self.move = move;
self.jump = jump;
self.update = update;
;
@@ -61,21 +63,21 @@
self.y = y;
}
}
function jump() {
- if (!self.isJumping) {
- self.isJumping = true;
- self.verticalSpeed = self.jumpSpeed;
+ if (!isJumping) {
+ isJumping = true;
+ verticalSpeed = PLAYER_JUMP_SPEED;
}
}
function update() {
if (self.isJumping) {
- self.verticalSpeed += self.gravity;
- self.y += self.verticalSpeed;
- if (self.y > FLOOR_OFFSET - self.height) {
- self.y = FLOOR_OFFSET - self.height;
- self.isJumping = false;
- self.verticalSpeed = 0;
+ verticalSpeed += PLAYER_GRAVITY;
+ self.y += verticalSpeed;
+ if (self.y >= floorHeight) {
+ self.y = floorHeight;
+ isJumping = false;
+ verticalSpeed = 0;
}
}
}
});
@@ -91,36 +93,68 @@
self.update = update;
;
function update(boxes) {
if (--countdown <= 0) {
- boxes.push(new Box(self, x, y + SPAWN_OFFSET, STAGE_HEIGHT - count++ * BOX_SIZE));
countdown = SPAWN_CONST + Math.floor(Math.random() * SPAWN_VARIANCE);
+ if (count < COLUMN_VOLUME) {
+ var targetHeight = STAGE_HEIGHT - (count + 0.5) * BOX_HEIGHT - FLOOR_OFFSET;
+ boxes.push(new Box(self, 0, SPAWN_OFFSET, targetHeight));
+ count++;
+ }
}
}
});
var STAGE_WIDTH = 2048;
var STAGE_HEIGHT = 2732;
-var NUM_COLUMNS = 15;
-var BOX_SIZE = STAGE_WIDTH / NUM_COLUMNS;
-var PLAYER_SIZE = 0.8 * BOX_SIZE;
+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 = 15;
var SPAWN_OFFSET = -100;
var SPAWN_CONST = 30;
var SPAWN_VARIANCE = 10 * 60 - SPAWN_CONST;
-var SPAWN_TNT_CHANCE = 0.02;
+var SPAWN_TNT_CHANCE = 0.03;
+var SPAWN_GOLD_CHANCE = 0.01;
+var SPAWN_POINTS_CHANCE = 0.05;
var BOX_SPEED = 5;
var BOX_GRAVITY = 0.1;
var FLOOR_OFFSET = 100;
+var COLUMN_VOLUME = Math.floor((STAGE_HEIGHT - FLOOR_OFFSET) / BOX_HEIGHT);
+var BOX_SETTINGS = {
+ basic: {
+ x: .5,
+ y: .5,
+ images: ['basic1', 'basic2', 'basic3, stone']
+ },
+ tnt: {
+ x: .5,
+ y: .55,
+ images: ['tnt']
+ },
+ gold: {
+ x: .5,
+ y: .5,
+ images: ['gold']
+ },
+ points: {
+ x: .5,
+ y: .55,
+ images: ['points1', 'points2']
+ }
+};
var Game = Container.expand(function () {
var self = Container.call(this);
;
var lastTouchX = null;
var boxes = [];
var columns = [];
var floor = self.addChild(new Floor(self, STAGE_WIDTH / 2, STAGE_HEIGHT));
- var player = self.addChild(new Player(self, STAGE_WIDTH / 2, STAGE_HEIGHT - FLOOR_OFFSET - PLAYER_SIZE / 2));
for (var i = 0; i < NUM_COLUMNS; i++) {
- columns.push(new Column(self, i * BOX_SIZE, 0));
+ columns.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 scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
@@ -142,11 +176,11 @@
if (lastTouchX !== null) {
var event = obj.event;
var currentTouchX = event.global.x;
var deltaX = currentTouchX - lastTouchX;
- if (Math.abs(deltaX) > BOX_SIZE / 2) {
+ if (Math.abs(deltaX) > BOX_WIDTH / 2) {
var direction = deltaX > 0 ? 1 : -1;
- var targetX = Math.max(Math.min(player.x + direction * BOX_SIZE, 2048 - BOX_SIZE / 2), BOX_SIZE / 2);
+ var targetX = Math.max(Math.min(player.x + direction * BOX_WIDTH, 2048 - BOX_WIDTH / 2), BOX_WIDTH / 2);
player.targetX = targetX;
player.startX = player.x;
player.tweening = true;
player.tweenStart = LK.ticks;
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.