/****
* Classes
****/
// Class for Basket
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Basket update logic if needed
};
});
//<Assets used in the game will automatically appear here>
// Class for Rice
var Rice = Container.expand(function (type) {
var self = Container.call(this);
var assetId = 'rice_' + type;
var riceGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000,
//Init game with black background
title: "SAVE YOUR FELLOW RICE"
});
/****
* Game Code
****/
// Add background image
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Initialize arrays and variables
var rices = [];
var basket;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Display the word 'SAME SHAPE & SIZE ONLY' in the center of the screen
var gameInstruction = new Text2('SAME SHAPE & SIZE ONLY', {
size: 100,
fill: "#ffffff"
});
gameInstruction.anchor.set(0.5, 0.5);
gameInstruction.x = 2048 / 2;
gameInstruction.y = 2732 / 2;
game.addChild(gameInstruction);
// Initialize basket
basket = game.addChild(new Basket());
basket.x = 2048 / 2;
basket.y = 2200;
// Function to handle move events
function handleMove(x, y, obj) {
basket.x = x;
}
// Mouse or touch move on game object
game.move = handleMove;
// Function to spawn rice
function spawnRice() {
var types = ['short', 'medium', 'long'];
var type = types[Math.floor(Math.random() * types.length)];
var newRice = new Rice(type);
newRice.x = Math.random() * 2048;
newRice.y = -50;
rices.push(newRice);
game.addChild(newRice);
}
// Initialize timer
var timer = 60 * 60; // 60 seconds * 60 frames per second
var timerTxt = new Text2('60', {
size: 200,
fill: "#ffffff"
});
timerTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timerTxt);
// Update function
game.update = function () {
// Play the gameplay_sound 12 times repeatedly during game play
if (LK.ticks % (60 * 5) == 0) {
// 60 ticks per second * 5 seconds = 300 ticks
var gameplaySound = LK.getSound('gameplay_sound');
for (var i = 0; i < 12; i++) {
gameplaySound.play();
}
}
for (var i = rices.length - 1; i >= 0; i--) {
if (rices[i].intersects(basket)) {
switch (rices[i].type) {
case 'long':
score -= 2;
LK.getSound('game_over_sound').play();
break;
case 'medium':
score -= 1;
LK.getSound('game_over_sound').play();
break;
case 'short':
score += 1;
LK.getSound('rice_hit_short').play();
LK.getSound('rice_hit_short').play();
break;
}
scoreTxt.setText(score);
rices[i].destroy();
rices.splice(i, 1);
}
}
if (timer > 15 * 60) {
if (LK.ticks % 60 == 0) {
spawnRice();
}
} else if (timer > 10 * 60) {
if (LK.ticks % 30 == 0) {
spawnRice();
}
} else if (timer > 5 * 60) {
if (LK.ticks % 15 == 0) {
spawnRice();
}
} else {
if (LK.ticks % 10 == 0) {
spawnRice();
}
}
// Update timer
if (timer > 0) {
timer--;
timerTxt.setText(Math.floor(timer / 60));
// Increase the speed of the falling rice when the timer is less than 30 seconds
if (timer < 30 * 60) {
for (var i = 0; i < rices.length; i++) {
rices[i].speed += 0.1;
}
}
} else {
// End game when timer reaches 0
if (timer == 0) {
LK.setScore(score);
LK.showGameOver();
}
}
}; /****
* Classes
****/
// Class for Basket
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Basket update logic if needed
};
});
//<Assets used in the game will automatically appear here>
// Class for Rice
var Rice = Container.expand(function (type) {
var self = Container.call(this);
var assetId = 'rice_' + type;
var riceGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000,
//Init game with black background
title: "SAVE YOUR FELLOW RICE"
});
/****
* Game Code
****/
// Add background image
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Initialize arrays and variables
var rices = [];
var basket;
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Display the word 'SAME SHAPE & SIZE ONLY' in the center of the screen
var gameInstruction = new Text2('SAME SHAPE & SIZE ONLY', {
size: 100,
fill: "#ffffff"
});
gameInstruction.anchor.set(0.5, 0.5);
gameInstruction.x = 2048 / 2;
gameInstruction.y = 2732 / 2;
game.addChild(gameInstruction);
// Initialize basket
basket = game.addChild(new Basket());
basket.x = 2048 / 2;
basket.y = 2200;
// Function to handle move events
function handleMove(x, y, obj) {
basket.x = x;
}
// Mouse or touch move on game object
game.move = handleMove;
// Function to spawn rice
function spawnRice() {
var types = ['short', 'medium', 'long'];
var type = types[Math.floor(Math.random() * types.length)];
var newRice = new Rice(type);
newRice.x = Math.random() * 2048;
newRice.y = -50;
rices.push(newRice);
game.addChild(newRice);
}
// Initialize timer
var timer = 60 * 60; // 60 seconds * 60 frames per second
var timerTxt = new Text2('60', {
size: 200,
fill: "#ffffff"
});
timerTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timerTxt);
// Update function
game.update = function () {
// Play the gameplay_sound 12 times repeatedly during game play
if (LK.ticks % (60 * 5) == 0) {
// 60 ticks per second * 5 seconds = 300 ticks
var gameplaySound = LK.getSound('gameplay_sound');
for (var i = 0; i < 12; i++) {
gameplaySound.play();
}
}
for (var i = rices.length - 1; i >= 0; i--) {
if (rices[i].intersects(basket)) {
switch (rices[i].type) {
case 'long':
score -= 2;
LK.getSound('game_over_sound').play();
break;
case 'medium':
score -= 1;
LK.getSound('game_over_sound').play();
break;
case 'short':
score += 1;
LK.getSound('rice_hit_short').play();
LK.getSound('rice_hit_short').play();
break;
}
scoreTxt.setText(score);
rices[i].destroy();
rices.splice(i, 1);
}
}
if (timer > 15 * 60) {
if (LK.ticks % 60 == 0) {
spawnRice();
}
} else if (timer > 10 * 60) {
if (LK.ticks % 30 == 0) {
spawnRice();
}
} else if (timer > 5 * 60) {
if (LK.ticks % 15 == 0) {
spawnRice();
}
} else {
if (LK.ticks % 10 == 0) {
spawnRice();
}
}
// Update timer
if (timer > 0) {
timer--;
timerTxt.setText(Math.floor(timer / 60));
// Increase the speed of the falling rice when the timer is less than 30 seconds
if (timer < 30 * 60) {
for (var i = 0; i < rices.length; i++) {
rices[i].speed += 0.1;
}
}
} else {
// End game when timer reaches 0
if (timer == 0) {
LK.setScore(score);
LK.showGameOver();
}
}
};