var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.createAsset('particle', 'Particle Graphics', 0.5, 0.5);
self.lifetime = 180;
self.on('tick', function () {
self.lifetime--;
self.alpha = self.lifetime / 180;
if (self.lifetime <= 0) self.destroy();
});
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.createAsset('obstacle', 'Obstacle Graphics', 0.5, 0.5);
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
});
var RoadBlock = Container.expand(function () {
var self = Container.call(this);
var roadBlockGraphics = self.createAsset('roadBlock', 'Road Block Graphics', 0.5, 0.5);
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
});
var Objective = Container.expand(function () {
var self = Container.call(this);
var objectiveGraphics = self.createAsset('objective', 'Objective Graphics', 0.5, 0.5);
self.setPosition = function (x, y) {
self.x = x;
self.y = y;
};
});
var SteeringWheel = Container.expand(function () {
var self = Container.call(this);
var wheelGraphics = self.createAsset('steeringWheel', 'Steering Wheel Graphics', 0.5, 0.5);
wheelGraphics.scale.set(wheelGraphics.scale.x * 0.995, wheelGraphics.scale.y * 0.995);
self.rotation = 0;
self.interactive = true;
self.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(LK.stage);
self.rotation = (pos.x - self.x) / self.width * Math.PI * 0.2;
});
});
var Bus = Container.expand(function () {
var self = Container.call(this);
self.recoil = function () {
self.speed = -10;
LK.setTimeout(function () {
self.stop();
}, 100);
};
var busGraphics = self.createAsset('bus', 'Bus Graphics', .5, .5);
busGraphics.scale.set(1.5);
busGraphics.rotation = -Math.PI / 2;
self.speed = 0;
self.accelerating = false;
self.accelerate = function () {
self.accelerating = true;
};
self.stop = function () {
self.accelerating = false;
};
self.update = function () {
if (self.accelerating) {
self.speed = Math.min(self.speed + 0.2, 10);
} else {
self.speed = Math.max(self.speed - 0.1, 0);
}
};
self.move = function (wheelRotation) {
var forwardX = Math.cos(self.rotation) * self.speed;
var forwardY = Math.sin(self.rotation) * self.speed;
var newX = self.x + forwardX;
var newY = self.y + forwardY;
if (newX < 0 || newX > LK.stage.width || newY < 0 || newY > LK.stage.height) {
LK.showGameOver();
} else {
self.x = newX;
self.y = newY;
}
var maxRotationSpeed = 0.02;
if (self.speed > 0) {
var rotationChange = wheelRotation;
var rotationSpeed = maxRotationSpeed * Math.abs(wheelRotation) / (Math.PI * 0.2);
self.rotation += Math.max(Math.min(rotationChange, rotationSpeed), -rotationSpeed);
}
};
self.checkCollision = function (obstacles) {
for (var i = 0; i < obstacles.length; i++) {
var busBounds = this.getBounds();
var obstacleBounds = obstacles[i].getBounds();
obstacleBounds.x += obstacleBounds.width * 0.3;
obstacleBounds.y += obstacleBounds.height * 0.3;
obstacleBounds.width *= 0.4;
obstacleBounds.height *= 0.4;
if (self.intersects(obstacles[i])) {
LK.showGameOver();
break;
}
}
};
});
var Game = Container.expand(function () {
stage.on('up', function (obj) {
bus.stop();
});
var self = Container.call(this);
var obstacles = [];
for (var i = 0; i < 1; i++) {
var obstacle = new Obstacle();
var posX = Math.random() * LK.stage.width;
var posY = Math.random() * LK.stage.height;
obstacle.setPosition(posX, posY);
obstacles.push(obstacle);
}
var roadBlocks = [];
var roadLength = 10;
var roadBlockWidth = 200;
var roadBlockHeight = 100;
var background = self.createAsset('background', 'Game Background', 0, 0);
self.addChild(background);
var score = 0;
var background = self.createAsset('background', 'Game Background', 0, 0);
self.addChild(background);
var bus = self.addChild(new Bus());
var objective = self.addChild(new Objective());
objective.setPosition(2048 / 2, 2732 / 4);
var steeringWheel = self.addChild(new SteeringWheel());
steeringWheel.x = 2048 / 2;
steeringWheel.y = 2732 - 100 - steeringWheel.height / 2;
var swipeText = new Text2('Hold, then swipe left and right', {
size: 50,
fill: "#ffffff",
align: 'center'
});
swipeText.anchor.set(0.5, 0.5);
swipeText.x = LK.stage.width / 3;
swipeText.y = 50;
LK.gui.addChild(swipeText);
var passengers = [];
var traffic = [];
bus.x = 2048 / 2;
bus.y = 2732 / 2;
var scoreTxt = new Text2('0', {
size: 75,
fill: "#ffff00"
});
scoreTxt.anchor.set(.5, 0);
scoreTxt.y = 50;
scoreTxt.x = -600;
LK.gui.topCenter.addChild(scoreTxt);
var timerText = new Text2('10', {
size: 75,
fill: "#ff0000"
});
timerText.anchor.set(.5, 0);
timerText.y = scoreTxt.y + 100;
timerText.x = -600;
LK.gui.topCenter.addChild(timerText);
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
stage.on('down', function (obj) {
bus.accelerate();
});
LK.on('tick', function () {
obstacles.forEach(function (obstacle) {
self.addChild(obstacle);
});
bus.update();
bus.move(steeringWheel.rotation);
bus.checkCollision(obstacles);
for (var i = 0; i < passengers.length; i++) {
passengers[i].pickUp();
}
for (var i = 0; i < traffic.length; i++) {
traffic[i].move();
}
if (bus.intersects(objective)) {
score += 1;
scoreTxt.setText(score.toString());
var newObstacle = new Obstacle();
var posX = Math.random() * LK.stage.width;
var posY = Math.random() * LK.stage.height;
newObstacle.setPosition(posX, posY);
obstacles.push(newObstacle);
self.addChild(newObstacle);
var newObjectiveX, newObjectiveY;
do {
newObjectiveX = 100 + Math.random() * (LK.stage.width - 200);
newObjectiveY = 100 + Math.random() * (LK.stage.height - 200);
} while (Math.abs(newObjectiveY - bus.y) < LK.stage.height / 2);
objective.setPosition(newObjectiveX, newObjectiveY);
timerText.setText('15');
var countdown = 15;
var countdownInterval = LK.setInterval(function () {
countdown--;
timerText.setText(countdown.toString());
if (countdown <= 0) {
LK.clearInterval(countdownInterval);
LK.showGameOver();
}
}, 1000);
LK.clearInterval(self.countdownInterval);
self.countdownInterval = countdownInterval;
}
});
});
Simple Car Steering Wheel. In-Game asset. 2d. Blank background. Svg
bomb Single Game Texture. In-Game asset. 2d. No shadows. flat. detailed
yellow bus stop symbol svg Single Game Texture. In-Game asset. 2d. No shadows. flat. detailed
yellow bus symbol svg. roof. top down. Single Game Texture. In-Game asset. 2d. No shadows. flat. detailed
dark transparent dust particle Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.