User prompt
make the obstacle fall down in a sin wave
Code edit (1 edits merged)
Please save this source code
User prompt
add a score. Everytime the player hits the safezone increase the score
User prompt
if the player reaches the safe zone, the safe zone spawns randomly on the game canvas. Make sure the safe zone is not outside the game, but within a 100px margin
User prompt
change that the player movement is like a drag and drop
Initial prompt
Saigon Madness
/**** * Classes ****/ // Define a class for moving obstacles var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = -obstacleGraphics.height; self.x = Math.random() * 2048; } }; }); //<Assets used in the game will automatically appear here> // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Player update logic if needed }; }); // Define a class for the safe zone var SafeZone = Container.expand(function () { var self = Container.call(this); var safeZoneGraphics = self.attachAsset('safeZone', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = new Player(); player.x = 2048 / 2; player.y = 2732 - 150; game.addChild(player); // Initialize obstacles var obstacles = []; for (var i = 0; i < 5; i++) { var obstacle = new Obstacle(); obstacle.x = Math.random() * 2048; obstacle.y = Math.random() * -2732; obstacles.push(obstacle); game.addChild(obstacle); } // Initialize safe zone var safeZone = new SafeZone(); safeZone.x = 2048 / 2; safeZone.y = 150; game.addChild(safeZone); // Handle player movement var dragNode = null; game.down = function (x, y, obj) { dragNode = player; }; game.move = function (x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } }; game.up = function (x, y, obj) { dragNode = null; }; // Update game logic game.update = function () { // Update obstacles for (var i = 0; i < obstacles.length; i++) { obstacles[i].update(); if (player.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Check if player is in the safe zone if (player.intersects(safeZone)) { LK.effects.flashScreen(0x00ff00, 1000); LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -1,91 +1,100 @@
-/****
+/****
* Classes
-****/
+****/
// Define a class for moving obstacles
var Obstacle = Container.expand(function () {
- var self = Container.call(this);
- var obstacleGraphics = self.attachAsset('obstacle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 5;
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732) {
- self.y = -obstacleGraphics.height;
- self.x = Math.random() * 2048;
- }
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.y = -obstacleGraphics.height;
+ self.x = Math.random() * 2048;
+ }
+ };
});
//<Assets used in the game will automatically appear here>
// Define a class for the player character
var Player = Container.expand(function () {
- var self = Container.call(this);
- var playerGraphics = self.attachAsset('player', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.update = function () {
- // Player update logic if needed
- };
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.update = function () {
+ // Player update logic if needed
+ };
});
// Define a class for the safe zone
var SafeZone = Container.expand(function () {
- var self = Container.call(this);
- var safeZoneGraphics = self.attachAsset('safeZone', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var self = Container.call(this);
+ var safeZoneGraphics = self.attachAsset('safeZone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize player
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 - 150;
game.addChild(player);
// Initialize obstacles
var obstacles = [];
for (var i = 0; i < 5; i++) {
- var obstacle = new Obstacle();
- obstacle.x = Math.random() * 2048;
- obstacle.y = Math.random() * -2732;
- obstacles.push(obstacle);
- game.addChild(obstacle);
+ var obstacle = new Obstacle();
+ obstacle.x = Math.random() * 2048;
+ obstacle.y = Math.random() * -2732;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
}
// Initialize safe zone
var safeZone = new SafeZone();
safeZone.x = 2048 / 2;
safeZone.y = 150;
game.addChild(safeZone);
// Handle player movement
+var dragNode = null;
game.down = function (x, y, obj) {
- player.x = x;
- player.y = y;
+ dragNode = player;
};
+game.move = function (x, y, obj) {
+ if (dragNode) {
+ dragNode.x = x;
+ dragNode.y = y;
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
// Update game logic
game.update = function () {
- // Update obstacles
- for (var i = 0; i < obstacles.length; i++) {
- obstacles[i].update();
- if (player.intersects(obstacles[i])) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- }
- // Check if player is in the safe zone
- if (player.intersects(safeZone)) {
- LK.effects.flashScreen(0x00ff00, 1000);
- LK.showGameOver();
- }
+ // Update obstacles
+ for (var i = 0; i < obstacles.length; i++) {
+ obstacles[i].update();
+ if (player.intersects(obstacles[i])) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ }
+ // Check if player is in the safe zone
+ if (player.intersects(safeZone)) {
+ LK.effects.flashScreen(0x00ff00, 1000);
+ LK.showGameOver();
+ }
};
\ No newline at end of file
vietnamese on a bike, top down, from above, flat, 8 bit art, pixel art, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
top down view of a big crossroad, pixelart style, from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round pizza, flat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat