Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
place background in the middle of the cone square
User prompt
set width and height on background to playing field size
User prompt
center pivot on background
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
var Arrow = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
// Increase the scale of the arrow by 100%
scaleY: 2 // Increase the scale of the arrow by 100%
});
self.update = function () {
if (game.point) {
var dx = game.point.x - car.x;
var dy = game.point.y - car.y;
self.rotation = Math.atan2(dy, dx) + Math.PI / 4;
}
};
});
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
pivotX: 0.5,
pivotY: 0.5
});
});
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.75,
scaleX: 1.5,
scaleY: 1.5
});
self.noAccelerationUpdates = 0;
self.accelerationUpdates = 0;
self.forceX = self.forceY = 0;
self.acceleration = 0;
self.prevRotation = 0;
});
var Cone = Container.expand(function () {
var self = Container.call(this);
var coneGraphics = self.attachAsset('cone', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
self.addChild(coneGraphics);
});
var Dust = Container.expand(function () {
var self = Container.call(this);
var dustGraphics = self.attachAsset('dirt', {
anchorX: 0.5,
anchorY: 0.75
});
});
var Obstacle = Container.expand(function (asset) {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset(asset, {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {};
});
var Point = Container.expand(function () {
var self = Container.call(this);
var pointGraphics = self.attachAsset('point', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {};
});
var Skidmark = Container.expand(function () {
var self = Container.call(this);
var skidmarkGraphics = self.attachAsset('skidmark', {
anchorX: 0.5,
anchorY: 0.8
});
self.alpha = 1;
self.rotation = 0;
self.width = 210;
self.height = 210;
self.update = function () {
self.alpha -= 0.001;
if (self.alpha <= 0) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFF00
});
/****
* Game Code
****/
var gameLayer = new Container();
game.point = null;
game.down = function (x, y, obj) {
game.isDown = true;
var midScreenX = 2048 / 2;
var distanceFromMid = x - midScreenX;
if (distanceFromMid < 0) {
car.rotation -= 0.1; // Rotate left
} else {
car.rotation += 0.1; // Rotate right
}
};
game.up = function (x, y) {
game.isDown = false;
};
var obstacles = [];
var playingFieldX = -4000;
var playingFieldY = -4000;
game.update = function () {
if (LK.ticks % 100 == 0 && !gameLayer.children.find(function (child) {
return child instanceof Point;
})) {
var newPoint = new Point();
newPoint.x = Math.random() * 2048;
newPoint.y = -50;
gameLayer.addChild(newPoint);
game.point = newPoint;
}
if (Math.abs(car.forceX) > 1.5 || Math.abs(car.forceY) > 1.5 || game.isDown) {
car.acceleration += 0.2;
var distX = 30;
var dAcc = Math.abs(car.rotation - car.prevRotation);
var skidmark = gameLayer.addChildAt(new Skidmark(), 0);
skidmark.rotation = car.rotation;
skidmark.x = car.x;
skidmark.y = car.y;
var alpha = Math.min(10 * dAcc, 1);
if (dAcc == 0) {
alpha = 0.1;
}
if (game.isDown && accelerationUpdates < 100) {
alpha = 1 - accelerationUpdates / 100;
}
skidmark.alpha = alpha;
}
for (var i = gameLayer.children.length - 1; i >= 0; i--) {
var child = gameLayer.children[i];
if (child instanceof Point && child.intersects(car)) {
child.destroy();
LK.setScore(LK.getScore() + 1);
// Update the score text
scoreText.setText(LK.getScore());
} else if (child instanceof Cone && child.intersects(car)) {
// Flash screen red for 1 second (1000ms) to show we are dead.
LK.effects.flashScreen(0xff0000, 1000);
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state.
}
}
if (game.isDown) {
car.noAccelerationUpdates = 0;
accelerationUpdates += 1;
car.forceX += Math.sin(car.rotation) * 0.7;
car.forceY += Math.cos(car.rotation) * 0.7;
} else {
car.noAccelerationUpdates += 1;
accelerationUpdates = 0;
car.noAccelerationUpdates = Math.min(100, car.noAccelerationUpdates);
car.forceX += Math.sin(car.rotation) * (0.5 * 1 / car.noAccelerationUpdates);
car.forceY += Math.cos(car.rotation) * (0.5 * 1 / car.noAccelerationUpdates);
}
car.x += car.forceX;
car.y -= car.forceY;
car.prevRotation = car.rotation;
backgroundLayer.x = gameLayer.x;
backgroundLayer.y = gameLayer.y;
arrow.update();
car.forceX *= 0.98; // Apply friction to slow down the car
car.forceY *= 0.98;
// Make the view follow the car with a delay
gameLayer.x += (2048 / 2 - car.x - gameLayer.x) * 0.05;
gameLayer.y += (2732 / 2 - car.y - gameLayer.y) * 0.05;
};
var backgroundLayer = new Container();
var gameLayer = new Container();
var background = backgroundLayer.addChildAt(new Background(), 0);
background.x = 2048 / 2;
background.y = 2732 / 2;
game.addChild(backgroundLayer);
var arrow = LK.gui.bottom.addChild(new Arrow());
arrow.y = -150;
game.addChild(gameLayer);
var cones = [];
for (var x = playingFieldX; x <= -playingFieldX; x += 400) {
for (var y = playingFieldY; y <= -playingFieldY; y += 400) {
if (x == playingFieldX || x == -playingFieldX || y == playingFieldY || y == -playingFieldY) {
var cone = new Cone();
cone.x = x;
cone.y = y;
cones.push(cone);
gameLayer.addChild(cone);
}
}
}
var car = gameLayer.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 2 + 500;
car.prevRotation = car.rotation;
// Add score text to the GUI layer
var scoreText = new Text2('0', {
size: 150,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var oldX, oldY;
var obstacles = [];
var obstacleTypes = ['obstacle1', 'obstacle2', 'obstacle3', 'obstacle4'];
for (var i = 0; i < obstacleTypes.length; i++) {
var obstacle = new Obstacle(obstacleTypes[i]);
obstacle.x = Math.random() * 4000 - 2000; // Random position between -2000 and 2000
obstacle.y = Math.random() * 4000 - 2000; // Random position between -2000 and 2000
obstacles.push(obstacle);
gameLayer.addChild(obstacle);
}
game.move = function (x, y, obj) {
if (!oldX) {
oldX = x;
}
if (!oldY) {
oldY = y;
}
if (game.isDown) {
var dx = x - oldX;
if (dx < 0) {
dx = Math.max(dx, -4);
}
if (dx > 0) {
dx = Math.min(dx, 4);
}
car.rotation += dx / 100; // Rotate left
oldX = x;
oldY = y;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -20,10 +20,10 @@
});
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
- anchorX: 0.5,
- anchorY: 0.5
+ pivotX: 0.5,
+ pivotY: 0.5
});
});
var Car = Container.expand(function () {
var self = Container.call(this);
@@ -80,10 +80,10 @@
anchorY: 0.8
});
self.alpha = 1;
self.rotation = 0;
- self.width = 200;
- self.height = 300;
+ self.width = 210;
+ self.height = 210;
self.update = function () {
self.alpha -= 0.001;
if (self.alpha <= 0) {
self.destroy();
A cute looking car, facing up, viewed top down. Suitable for a game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
some dust Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An arrow pointing upwards. Should look like it's pointing to something valuable. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a orange road cone. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a coffee cup, viewed from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cinnamon bun, viewed from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a gold coin with a car one it, simple graphics. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cheese sandwich, viewed from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a salt can, viewed from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A checked pattern in nice soft pastel colors. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.