User prompt
move versiontxt a bit lower
User prompt
move versiontxt lower
User prompt
move versiontxt lower
User prompt
there is a black vertical mark that is covering a bit of the right of the screen. Is it possible to remove
User prompt
why is there a black part covering part of the screen on the right
User prompt
move versiontxt lower
User prompt
move versiontxt a lot lower
User prompt
move versiontxt lower
User prompt
move versiontxt lower
User prompt
move versiontxt lower
User prompt
move versiontxt lower
User prompt
move versiontxt lower
User prompt
move versiontxt below high score
User prompt
put versiontxt top center
User prompt
versiontxt is not visible. it does not appear on the screen. make it appear on the screen
User prompt
move versiontxt below the red line
User prompt
move versiontxt to y-axis of -1
User prompt
move versiontxt to y-axis of 0
User prompt
move versiontxt down
User prompt
move versiontxt to the bottom
User prompt
under the high score text, put a text saying: "v0.1"
User prompt
move the v0.1 a bit to the left
User prompt
make a text on the bottom right of the screen saying v.0.1
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: Joystick is not defined' in this line: 'var joystick = new Joystick(200, game.height - 200, function (direction) {' Line Number: 152
===================================================================
--- original.js
+++ change.js
@@ -1,46 +1,82 @@
/****
* Classes
****/
-// Hero class
+// BulletPack class
+var BulletPack = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletPackGraphics = self.attachAsset('bulletPack', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 4;
+ self.direction = Math.random() < 0.5 ? -1 : 1;
+ self.move = function () {
+ var speedIncreaseFactor = 0.1 + LK.ticks * 0.0002;
+ self.y += self.speed + speedIncreaseFactor;
+ self.x += self.direction * (10 + speedIncreaseFactor);
+ if (self.x < 0 || self.x > game.width) {
+ self.direction *= -1;
+ }
+ };
+});
+// Character class
var Hero = Container.expand(function () {
var self = Container.call(this);
- var heroGraphics = self.createAsset('hero', 'Hero character', 0.5, 0.5);
- self.bulletLimit = 5; // Initialize bullet limit
+ var heroGraphics = self.attachAsset('hero', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.bulletLimit = 3; // Initialize bullet limit
+ self.canShoot = true; // Allow shooting initially
self.update = function () {
// Hero update logic
};
- self.on('down', function (obj) {
- self.shoot();
- });
self.shoot = function () {
- if (this.bulletLimit > 0) {
+ if (this.bulletLimit > 0 && this.canShoot) {
var bullet = new Bullet();
bullet.x = this.x;
bullet.y = this.y - this.height / 2;
heroBullets.push(bullet);
game.addChild(bullet);
this.bulletLimit--;
bulletCountTxt.setText('Bullets: ' + this.bulletLimit); // Update bullet count display
+ this.canShoot = false; // Set shooting cooldown
+ LK.setTimeout(function () {
+ self.canShoot = true;
+ }, 500); // Cooldown of 500ms before next shot
}
};
});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
- var bulletGraphics = self.createAsset('purpleBullet', 'Purple Bullet', 0.5, 0.5);
+ var bulletGraphics = self.attachAsset('purpleBullet', {
+ anchorX: 0.0625,
+ anchorY: 0.0625
+ });
self.speed = -10;
self.move = function () {
self.y += self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
- var enemyGraphics = self.createAsset('enemy', 'Enemy character', 0.5, 0.5);
- self.speed = 2;
+ var enemyGraphics = self.attachAsset('enemy', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 4;
+ self.direction = Math.random() < 0.5 ? -1 : 1;
self.move = function () {
self.y += self.speed;
+ var speedIncreaseFactor = 0.1 + LK.ticks * 0.0002; // Increase the speed factor over time
+ self.x += self.direction * (4 + speedIncreaseFactor);
+ if (self.x < 0 || self.x > game.width) {
+ self.direction *= -1;
+ }
+ self.speed += 0.02 + LK.ticks * 0.0001; // Increase speed over time with an accelerating factor
};
});
var Button = Container.expand(function (text, positionX, positionY, onClickCallback) {
var self = Container.call(this);
@@ -63,19 +99,18 @@
});
// JoystickAsset class
var JoystickAsset = Container.expand(function () {
var self = Container.call(this);
- var baseGraphics = self.createAsset('joystickBase', 'Joystick Base', 0.5, 0.5);
- var stickGraphics = self.createAsset('joystickStick', 'Joystick Stick', 0.5, 0.5);
self.interactive = true;
- var stickOrigin = {
- x: stickGraphics.x,
- y: stickGraphics.y
- };
self.isDragging = false;
self.onMoveCallback = null;
self.setMoveCallback = function (callback) {
- self.onMoveCallback = callback;
+ self.onMoveCallback = function (direction) {
+ callback({
+ x: direction.x,
+ y: 0
+ });
+ };
};
self.on('down', function (obj) {
self.isDragging = true;
});
@@ -94,33 +129,33 @@
if (self.isDragging) {
var event = obj.event;
var pos = event.getLocalPosition(self);
var dx = pos.x - stickOrigin.x;
- var dy = pos.y - stickOrigin.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- var maxDistance = baseGraphics.width * 0.5;
- if (distance > maxDistance) {
- var angle = Math.atan2(dy, dx);
- dx = maxDistance * Math.cos(angle);
- dy = maxDistance * Math.sin(angle);
+ var maxDistance = stickGraphics.width * 0.5;
+ if (Math.abs(dx) > maxDistance) {
+ dx = maxDistance * (dx > 0 ? 1 : -1);
}
stickGraphics.x = stickOrigin.x + dx;
- stickGraphics.y = stickOrigin.y + dy;
+ stickGraphics.y = stickOrigin.y;
if (self.onMoveCallback) {
self.onMoveCallback({
x: dx / maxDistance,
- y: dy / maxDistance
+ y: 0
});
}
}
});
+ self.containsPoint = function (point) {
+ return point.x >= self.x - self.width / 2 && point.x <= self.x + self.width / 2 && point.y >= self.y - self.height / 2 && point.y <= self.y + self.height / 2;
+ };
});
/****
* Initialize Game
****/
// Create left movement button
var game = new LK.Game({
+ title: '(WIP)',
backgroundColor: 0x000000 // Init game with black background
});
/****
@@ -128,78 +163,140 @@
****/
// Initialize important asset arrays
var heroBullets = [];
var enemies = [];
-// Create hero
+// Create character
var hero = game.addChild(new Hero());
hero.x = game.width / 2;
hero.y = game.height - 100;
// Create score display
-var scoreTxt = new Text2('0', {
- size: 150,
+var scoreTxt = new Text2('Score: 0', {
+ size: 50,
fill: "#ffffff"
});
-scoreTxt.anchor.set(0.5, 0);
-LK.gui.top.addChild(scoreTxt);
+var highScoreTxt = new Text2('High Score: 0 (WIP)', {
+ size: 50,
+ fill: "#ffffff"
+});
+scoreTxt.anchor.set(1, 0);
+highScoreTxt.anchor.set(1, 0);
+highScoreTxt.y = scoreTxt.height + 20;
+LK.gui.topRight.addChild(scoreTxt);
+LK.gui.topRight.addChild(highScoreTxt);
// Create bullet count display
-var bulletCountTxt = new Text2('Bullets: 5', {
+var bulletCountTxt = new Text2('Bullets: 3', {
size: 100,
fill: "#ffffff"
});
-bulletCountTxt.anchor.set(0.5, 0);
-bulletCountTxt.y = scoreTxt.height + 20; // Position below the score display
-LK.gui.top.addChild(bulletCountTxt);
+bulletCountTxt.anchor.set(0, 0);
+bulletCountTxt.y = scoreTxt.height + 50; // Position below the score display
+LK.gui.topLeft.addChild(bulletCountTxt);
+// Create instructions display
+var instructionsTxt = new Text2('Tap anywhere to shoot', {
+ size: 50,
+ fill: "#ffffff"
+});
+instructionsTxt.anchor.set(0, 0);
+LK.gui.topLeft.addChild(instructionsTxt);
+// Create a red line 3/4 down the screen
+var redLine = LK.getAsset('redLine', {});
+redLine.width = game.width;
+redLine.height = 5;
+redLine.y = game.height * 0.75;
+game.addChild(redLine);
// Create joystick instance
-var joystick = new JoystickAsset(200, game.height - 200, function (direction) {
+var joystick = new JoystickAsset();
+joystick.x = joystick.width / 2 + 150;
+joystick.y = game.height - joystick.height / 2 - 150;
+joystick.setMoveCallback(function (direction) {
hero.x = Math.max(hero.width / 2, Math.min(game.width - hero.width / 2, hero.x + direction.x * 10));
- hero.y = Math.max(hero.height / 2, Math.min(game.height - hero.height / 2, hero.y + direction.y * 10));
});
-LK.gui.left.addChild(joystick);
+game.addChild(joystick);
// Handle hero dragging
var dragNode = null;
+game.on('down', function (obj) {
+ hero.shoot();
+});
+game.on('move', function (obj) {
+ var event = obj.event;
+ var pos = event.getLocalPosition(game);
+ hero.x = pos.x;
+ // hero.y = pos.y; // Removed the line that sets the hero's y position
+});
+// Global event listener for shooting bullets
// Game tick event
LK.on('tick', function () {
- // Update hero
+ // Update character
hero.update();
// Move and check bullets
for (var i = heroBullets.length - 1; i >= 0; i--) {
var bullet = heroBullets[i];
bullet.move();
- // Check for bullet collision with enemies
+ // Check for bullet collision with enemies and bullet packs
for (var j = enemies.length - 1; j >= 0; j--) {
if (bullet.intersects(enemies[j])) {
- // Update score
- LK.setScore(LK.getScore() + 1);
- scoreTxt.setText(LK.getScore());
- // Increment hero's bullet limit
- hero.bulletLimit++;
+ if (enemies[j] instanceof BulletPack) {
+ // If the enemy is a bullet pack
+ // Increment character's bullet limit by 5
+ hero.bulletLimit += 5;
+ } else {
+ // If the enemy is an actual enemy
+ // Update score
+ var newScore = LK.getScore() + 1;
+ LK.setScore(newScore);
+ scoreTxt.setText('Score: ' + newScore);
+ var highScore = Math.max(newScore, Number((typeof localStorage !== 'undefined' ? localStorage.getItem('highScore') : '0') || '0'));
+ highScoreTxt.setText('High Score: ' + highScore + ' (WIP)');
+ if (typeof localStorage !== 'undefined' && newScore > highScore) {
+ localStorage.setItem('highScore', newScore.toString());
+ }
+ // Increment character's bullet limit
+ hero.bulletLimit++;
+ }
bulletCountTxt.setText('Bullets: ' + hero.bulletLimit); // Update bullet count display
- // Destroy enemy and bullet
+ // Destroy enemy/bullet pack and bullet
enemies[j].destroy();
enemies.splice(j, 1);
bullet.destroy();
heroBullets.splice(i, 1);
break;
}
}
// Remove off-screen bullets and end the game if it's the last one
- if (bullet.y < -50) {
+ if (bullet.y < 0) {
bullet.destroy();
heroBullets.splice(i, 1);
if (heroBullets.length === 0 && hero.bulletLimit === 0) {
LK.showGameOver(); // End the game when the last bullet is out of frame
}
}
}
- // Move enemies
+ // Move enemies and check if they pass the red line
for (var k = enemies.length - 1; k >= 0; k--) {
enemies[k].move();
+ if (enemies[k].y > game.height * 0.75) {
+ enemies[k].destroy();
+ enemies[k] = null;
+ enemies.splice(k, 1);
+ }
}
- // Spawn enemies
- if (LK.ticks % 120 == 0) {
+ var enemySpawnRate = 60; // Initialize enemy spawn rate
+ // Spawn enemies and bullet packs
+ if (LK.ticks % enemySpawnRate == 0) {
var enemy = new Enemy();
enemy.x = Math.random() * (game.width - enemy.width) + enemy.width / 2;
enemy.y = -enemy.height;
enemies.push(enemy);
game.addChild(enemy);
+ if (enemySpawnRate > 30) {
+ enemySpawnRate -= 0.5;
+ } // Decrease spawn rate over time to a minimum of 30 ticks
}
+ if (LK.ticks % 600 == 0) {
+ // Spawn a bullet pack every 600 ticks
+ var bulletPack = new BulletPack();
+ bulletPack.x = Math.random() * (game.width - bulletPack.width) + bulletPack.width / 2;
+ bulletPack.y = -bulletPack.height;
+ enemies.push(bulletPack); // Add bullet pack to enemies array for collision detection
+ game.addChild(bulletPack);
+ }
});
\ No newline at end of file
android. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
letter X png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
space background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
galaxy background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
galaxy background. High quality
space background.. High contrast