var Player = Container.expand(function() {
var self = Container.call(this); //{0}
var playerGraphics = XS.getAsset('player', 'Medieval Runner Character');
playerGraphics.anchor.set(0.5, 0.5);
self.addChild(playerGraphics);
this.targetX = null; //{1}
this.speed = 60;
//{2}
this.moveToLane = function(targetX) {
this.targetX = targetX;
}; //{3}
//{4}
this.update = function() { //{5}
if (this.targetX !== null) {
var direction = this.targetX > this.x ? 1 : -1;
this.x += direction * this.speed;
if (direction > 0 && this.x >= this.targetX || direction < 0 && this.x <= this.targetX) {
this.x = this.targetX;
this.targetX = null; //{6}
} //{7}
} //{8}
}; //{9}
}); //{10}
//{11}
var Obstacle = Container.expand(function() {
var self = Container.call(this); //{12}
var obstacleGraphics = XS.getAsset('obstacle', 'Medieval Obstacle');
obstacleGraphics.anchor.set(0.5, 0.5);
self.addChild(obstacleGraphics);
//{13}
this.baseSpeed = 10;
this.speed = this.baseSpeed;
//{14}
this.update = function() { //{15}
this.speed = this.baseSpeed + Math.floor(XS.ticks / 1000);
this.y += this.speed;
}; //{16}
}); //{17}
//{18}
var Game = Container.expand(function() {
var self = Container.call(this); //{19}
var score = 0;
var scoreText = new Text2(score, {
size: 150,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff"
}); //{20}
scoreText.anchor.set(0.5, 0);
XS.gui.top.addChild(scoreText);
var lanes = [512, 1024, 1536]; // Three lanes for the player to move between
var trackGraphics = [];
lanes.forEach(function(lane) {
var track = XS.getAsset('track', 'Medieval Runner Track');
track.anchor.set(0.5, 0);
track.x = lane;
track.y = 0;
trackGraphics.push(track);
self.addChild(track);
}); //{21}
var player = self.addChild(new Player());
player.y = 2732 - player.height; // Position the player at the bottom of the screen
player.x = lanes[1]; // Start the player in the middle lane
var obstacles = [];
//{22}
function spawnObstacle(lane) {
var obstacle = new Obstacle();
obstacle.x = lane;
obstacle.y = -obstacle.height;
obstacles.push(obstacle);
self.addChild(obstacle);
} //{23}
//{24}
var lastSpawnedLane = null;
//{25}
function spawnObstaclePattern() {
var pattern = Math.floor(Math.random() * 2);
switch (pattern) {
case 0:
spawnObstacle(lanes[0]);
XS.setTimeout(() => spawnObstacle(lanes[2]), 1000);
break; //{26}
case 1:
spawnObstacle(lanes[1]);
XS.setTimeout(() => spawnObstacle(lanes[0]), 1000);
break; //{27}
} //{28}
XS.setTimeout(spawnObstaclePattern, 5000);
} //{29}
//{30}
spawnObstaclePattern();
//{31}
function updateGame() {
player.update();
obstacles.forEach(function(obstacle) { //{32}
obstacle.update();
if (obstacle.y > player.y && !obstacle.passed) {
score++;
scoreText.setText(score); //{33}
obstacle.passed = true;
} //{34}
if (player.intersects(obstacle)) {
XS.showGameOver(restartGame);
} //{35}
}); //{36}
} //{37}
//{38}
XS.on('tick', updateGame);
//{39}
var swipeStartX = null;
stage.on('down', function(obj) {
swipeStartX = obj.event.getLocalPosition(stage).x;
}); //{40}
stage.on('up', function(obj) {
var swipeEndX = obj.event.getLocalPosition(stage).x;
var swipeDistance = swipeEndX - swipeStartX;
if (swipeDistance > 100 && player.x < lanes[2]) { // Swipe right
player.moveToLane(lanes[lanes.indexOf(player.x) + 1]);
} else if (swipeDistance < -100 && player.x > lanes[0]) { // Swipe left
player.moveToLane(lanes[lanes.indexOf(player.x) - 1]);
} //{41}
swipeStartX = null;
}); //{42}
//{43}
function restartGame() {
obstacles.forEach(function(obstacle) { //{44}
obstacle.destroy();
}); //{45}
obstacles = [];
player.x = lanes[1];
player.y = 2732 - player.height;
score = 0;
scoreText.setText(score); //{46}
//{47}
} //{48}
}); //{49} var Player = Container.expand(function() {
var self = Container.call(this); //{0}
var playerGraphics = XS.getAsset('player', 'Medieval Runner Character');
playerGraphics.anchor.set(0.5, 0.5);
self.addChild(playerGraphics);
this.targetX = null; //{1}
this.speed = 60;
//{2}
this.moveToLane = function(targetX) {
this.targetX = targetX;
}; //{3}
//{4}
this.update = function() { //{5}
if (this.targetX !== null) {
var direction = this.targetX > this.x ? 1 : -1;
this.x += direction * this.speed;
if (direction > 0 && this.x >= this.targetX || direction < 0 && this.x <= this.targetX) {
this.x = this.targetX;
this.targetX = null; //{6}
} //{7}
} //{8}
}; //{9}
}); //{10}
//{11}
var Obstacle = Container.expand(function() {
var self = Container.call(this); //{12}
var obstacleGraphics = XS.getAsset('obstacle', 'Medieval Obstacle');
obstacleGraphics.anchor.set(0.5, 0.5);
self.addChild(obstacleGraphics);
//{13}
this.baseSpeed = 10;
this.speed = this.baseSpeed;
//{14}
this.update = function() { //{15}
this.speed = this.baseSpeed + Math.floor(XS.ticks / 1000);
this.y += this.speed;
}; //{16}
}); //{17}
//{18}
var Game = Container.expand(function() {
var self = Container.call(this); //{19}
var score = 0;
var scoreText = new Text2(score, {
size: 150,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff"
}); //{20}
scoreText.anchor.set(0.5, 0);
XS.gui.top.addChild(scoreText);
var lanes = [512, 1024, 1536]; // Three lanes for the player to move between
var trackGraphics = [];
lanes.forEach(function(lane) {
var track = XS.getAsset('track', 'Medieval Runner Track');
track.anchor.set(0.5, 0);
track.x = lane;
track.y = 0;
trackGraphics.push(track);
self.addChild(track);
}); //{21}
var player = self.addChild(new Player());
player.y = 2732 - player.height; // Position the player at the bottom of the screen
player.x = lanes[1]; // Start the player in the middle lane
var obstacles = [];
//{22}
function spawnObstacle(lane) {
var obstacle = new Obstacle();
obstacle.x = lane;
obstacle.y = -obstacle.height;
obstacles.push(obstacle);
self.addChild(obstacle);
} //{23}
//{24}
var lastSpawnedLane = null;
//{25}
function spawnObstaclePattern() {
var pattern = Math.floor(Math.random() * 2);
switch (pattern) {
case 0:
spawnObstacle(lanes[0]);
XS.setTimeout(() => spawnObstacle(lanes[2]), 1000);
break; //{26}
case 1:
spawnObstacle(lanes[1]);
XS.setTimeout(() => spawnObstacle(lanes[0]), 1000);
break; //{27}
} //{28}
XS.setTimeout(spawnObstaclePattern, 5000);
} //{29}
//{30}
spawnObstaclePattern();
//{31}
function updateGame() {
player.update();
obstacles.forEach(function(obstacle) { //{32}
obstacle.update();
if (obstacle.y > player.y && !obstacle.passed) {
score++;
scoreText.setText(score); //{33}
obstacle.passed = true;
} //{34}
if (player.intersects(obstacle)) {
XS.showGameOver(restartGame);
} //{35}
}); //{36}
} //{37}
//{38}
XS.on('tick', updateGame);
//{39}
var swipeStartX = null;
stage.on('down', function(obj) {
swipeStartX = obj.event.getLocalPosition(stage).x;
}); //{40}
stage.on('up', function(obj) {
var swipeEndX = obj.event.getLocalPosition(stage).x;
var swipeDistance = swipeEndX - swipeStartX;
if (swipeDistance > 100 && player.x < lanes[2]) { // Swipe right
player.moveToLane(lanes[lanes.indexOf(player.x) + 1]);
} else if (swipeDistance < -100 && player.x > lanes[0]) { // Swipe left
player.moveToLane(lanes[lanes.indexOf(player.x) - 1]);
} //{41}
swipeStartX = null;
}); //{42}
//{43}
function restartGame() {
obstacles.forEach(function(obstacle) { //{44}
obstacle.destroy();
}); //{45}
obstacles = [];
player.x = lanes[1];
player.y = 2732 - player.height;
score = 0;
scoreText.setText(score); //{46}
//{47}
} //{48}
}); //{49}
Single subway surfer character. Running upwards. Camera from right above. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Single train car. Topdown view. Subway surfers. 2d. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.