User prompt
Implement a method within the Player class that allows shooting lasers.
User prompt
Create a Laser Class
User prompt
Implement a method within the Player class that allows shooting lasers.
User prompt
Create a Laser Class
User prompt
Make the laser go up.
User prompt
Add laser asset that shoots the rocks from the player asset.
User prompt
Make the obstacles a bit smaller and make the player bigger.
Remix started
Copy Quintillion Quadrilaterals
/****
* Classes
****/
// Arrow class
var Arrow = Container.expand(function (direction) {
var self = Container.call(this);
var arrowGraphics = self.createAsset('arrow_' + direction, {
anchorX: 0.5
});
arrowGraphics.height = 2732 * 2;
self.direction = direction;
self.on('down', function () {
self.isHeld = true;
});
self.on('up', function () {
self.isHeld = false;
});
self.on('out', function () {
self.isHeld = false;
});
self.update = function (player) {
if (self.isHeld) {
if (self.direction === 'left') {
player.moveLeft();
} else if (self.direction === 'right') {
player.moveRight();
}
}
// Check if player's y position is less than arrow's y position
self.alpha = 0; // Make arrow completely see-through
};
});
// BlockObstacle class
var BlockObstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('block_obstacle', {
anchorX: 0.5,
anchorY: 1
});
obstacleGraphics.scale.set(0.8); // Scale down the obstacle
self.speed = Math.random() * 3 + 2; // Random speed between 2 and 5
self.speedMultiplier = 1;
self.increaseSpeed = function () {
self.speedMultiplier += 0.001;
};
self.move = function () {
self.speedMultiplier += 0.001;
self.y += self.speed * self.speedMultiplier;
};
});
// GameStats class to keep track of game statistics
var GameStats = Container.expand(function () {
var self = Container.call(this);
self.gamesPlayed = 0;
self.incrementGamesPlayed = function () {
self.gamesPlayed++;
};
self.getGamesPlayed = function () {
return self.gamesPlayed;
};
});
var Laser = Container.expand(function () {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.5,
anchorY: 1
});
laserGraphics.scale.set(0.8); // Scale down the laser
self.speed = 10; // Set speed
self.move = function () {
self.y -= self.speed;
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
playerGraphics.scale.set(1.2); // Scale up the player
self.speed = 5;
self.moveLeft = function () {
self.x = Math.max(self.width / 2, self.x - self.speed);
};
self.moveRight = function () {
self.x = Math.min(2048 - self.width / 2, self.x + self.speed);
};
self.update = function () {
// Player update logic
};
});
// Stopwatch class
var Stopwatch = Container.expand(function () {
var self = Container.call(this);
var timeText = new Text2('00:00', {
size: 100,
fill: '#ffffff'
});
timeText.anchor.set(0.5, 0);
LK.gui.top.addChild(timeText);
var startTime = Date.now();
self.updateTime = function () {
var elapsed = Date.now() - startTime;
var minutes = Math.floor(elapsed / 60000).toString().padStart(2, '0');
var seconds = (Math.floor(elapsed / 1000) % 60).toString().padStart(2, '0');
timeText.setText(minutes + ':' + seconds);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Game variables
var player = game.addChild(new Player());
player.x = 1024; // Center of the screen
player.y = 2732 - 100; // Near the bottom of the screen
var obstacles = [];
var isGameOver = false;
var gameStats = game.addChild(new GameStats());
var stopwatch = game.addChild(new Stopwatch());
// Create left and right arrow objects
var leftArrow = game.addChild(new Arrow('left'));
leftArrow.width = 1024; // Half of the screen width
leftArrow.x = leftArrow.width / 2;
leftArrow.y = player.y - player.height * 3 - leftArrow.height / 2;
var rightArrow = game.addChild(new Arrow('right'));
rightArrow.width = 1024; // Half of the screen width
rightArrow.x = 2048 - rightArrow.width / 2;
rightArrow.y = player.y - player.height * 3 - rightArrow.height / 2;
// Touch event handlers
// Add touch event listener to the game
// Game tick event
LK.on('tick', function () {
if (isGameOver) {
LK.effects.flashScreen(0x00ff00, 1000);
LK.showGameOver();
return;
}
// Update player and arrows
player.update();
leftArrow.update(player);
rightArrow.update(player);
stopwatch.updateTime();
// Generate obstacles
if (LK.ticks % 60 == 0) {
// Every 1 second
var newObstacle = new BlockObstacle();
newObstacle.x = Math.random() * (2048 - newObstacle.width) + newObstacle.width / 2;
newObstacle.y = -newObstacle.height;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Move obstacles and check for collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
obstacles[i].increaseSpeed();
if (obstacles[i].y > 2732) {
obstacles[i].destroy();
obstacles.splice(i, 1);
} else if (player.intersects(obstacles[i])) {
isGameOver = true;
gameStats.incrementGamesPlayed();
}
}
}); ===================================================================
--- original.js
+++ change.js
@@ -64,9 +64,10 @@
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.5,
anchorY: 1
});
- self.speed = -10;
+ laserGraphics.scale.set(0.8); // Scale down the laser
+ self.speed = 10; // Set speed
self.move = function () {
self.y -= self.speed;
};
});
@@ -84,14 +85,8 @@
};
self.moveRight = function () {
self.x = Math.min(2048 - self.width / 2, self.x + self.speed);
};
- self.shoot = function () {
- var laser = new Laser();
- laser.x = self.x;
- laser.y = self.y;
- return laser;
- };
self.update = function () {
// Player update logic
};
});
@@ -162,13 +157,8 @@
newObstacle.y = -newObstacle.height;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
- if (LK.ticks % 30 == 0) {
- // Every 0.5 second
- var laser = player.shoot();
- game.addChild(laser);
- }
// Move obstacles and check for collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
obstacles[i].increaseSpeed();
@@ -177,12 +167,7 @@
obstacles.splice(i, 1);
} else if (player.intersects(obstacles[i])) {
isGameOver = true;
gameStats.incrementGamesPlayed();
- } else if (laser && laser.intersects(obstacles[i])) {
- obstacles[i].destroy();
- obstacles.splice(i, 1);
- laser.destroy();
- laser = null;
}
}
});
\ No newline at end of file
Spaceship 2D Pixel.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Asteroid 2D Pixel.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Galaxy Background 2D Pixel.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.