User prompt
player clicks and drags the left mouse button in the direction they want to throw a shuriken. when the player releases left mouse button, the shuriken is released
User prompt
Rats move toward the bottom of the screen
User prompt
player = "id player_hands"
User prompt
Fix Bug: 'ReferenceError: player is not defined' in this line: 'var dx = self.x - player.x;' Line Number: 20
User prompt
rats move toward player_hands
User prompt
rats move toward player
User prompt
set player as id player_hands
User prompt
asset "id player_hands" is the player
User prompt
rats move toward player_hands
User prompt
rats move toward the player
User prompt
the player does not move. the player's position is in the middle of the bottom of screen, represented by a pair of hands
User prompt
rats move toward player
User prompt
player position is middle of the bottom of screen
User prompt
Rats move toward the player
User prompt
rats spawn at the top of the screen at random times. when a player hits a rat with a shuriken, the rat dies and the player gets a point. when a rat reaches the player at the bottom of the screen, the player loses and the game starts over.
User prompt
make background image asset full screen
User prompt
set image asset "id wooden_floor" as level background, 1080 px wide 1920 px tall
User prompt
generate a wooden floor texture for the background
User prompt
play
Initial prompt
Rat Shuriken
var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player_hands', 'Player Hands Graphics', .5, 1); self.x = 2048 / 2; self.y = 2732; }); var Shuriken = Container.expand(function () { var self = Container.call(this); var shurikenGraphics = self.createAsset('shuriken', 'Shuriken Graphics', .5, .5); self.speed = 5; self.move = function () {}; self.destroy = function () {}; }); var Rat = Container.expand(function () { var self = Container.call(this); var ratGraphics = self.createAsset('rat', 'Rat Graphics', .5, .5); self.speed = -2; self.move = function () { self.y -= self.speed; }; self.destroy = function () {}; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.createAsset('powerUp', 'PowerUp Graphics', .5, .5); self.activate = function () {}; }); var Game = Container.expand(function () { var self = Container.call(this); var background = self.createAsset('wooden_floor', 'Level Background', 0, 0); background.width = 2048; background.height = 2732; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreTxt); var player = new Player(); self.addChild(player); var shurikens = []; var rats = []; var powerUps = []; var isGameOver = false; var tickOffset = 0; var score = 0; var isDragging = false; var dragStartPos = { x: 0, y: 0 }; function init() { LK.setInterval(function () { var rat = new Rat(); rat.x = Math.random() * 2048; rat.y = 0; rats.push(rat); self.addChild(rat); }, Math.random() * 2000 + 1000); } function update() { for (var i = 0; i < rats.length; i++) { rats[i].move(); if (rats[i].y >= 2732) { isGameOver = true; break; } } } function gameOver() { LK.showGameOver(); } function checkCollision() { for (var i = 0; i < shurikens.length; i++) { for (var j = 0; j < rats.length; j++) { if (shurikens[i].intersects(rats[j])) { shurikens[i].destroy(); shurikens.splice(i, 1); rats[j].destroy(); rats.splice(j, 1); score++; break; } } } } function updateScore() { scoreTxt.setText(score); } stage.on('down', function (obj) { isDragging = true; dragStartPos = obj.event.getLocalPosition(self); }); stage.on('move', function (obj) {}); stage.on('up', function (obj) { if (isDragging) { isDragging = false; var dragEndPos = obj.event.getLocalPosition(self); var direction = { x: dragEndPos.x - dragStartPos.x, y: dragEndPos.y - dragStartPos.y }; var shuriken = new Shuriken(); shuriken.x = player.x; shuriken.y = player.y; shuriken.move = function () { this.x += direction.x * this.speed; this.y += direction.y * this.speed; }; shurikens.push(shuriken); self.addChild(shuriken); } }); LK.on('tick', function () { update(); checkCollision(); updateScore(); if (isGameOver) { gameOver(); } }); init(); });
===================================================================
--- original.js
+++ change.js
@@ -43,8 +43,13 @@
var powerUps = [];
var isGameOver = false;
var tickOffset = 0;
var score = 0;
+ var isDragging = false;
+ var dragStartPos = {
+ x: 0,
+ y: 0
+ };
function init() {
LK.setInterval(function () {
var rat = new Rat();
rat.x = Math.random() * 2048;
@@ -81,11 +86,32 @@
}
function updateScore() {
scoreTxt.setText(score);
}
- stage.on('down', function (obj) {});
+ stage.on('down', function (obj) {
+ isDragging = true;
+ dragStartPos = obj.event.getLocalPosition(self);
+ });
stage.on('move', function (obj) {});
- stage.on('up', function (obj) {});
+ stage.on('up', function (obj) {
+ if (isDragging) {
+ isDragging = false;
+ var dragEndPos = obj.event.getLocalPosition(self);
+ var direction = {
+ x: dragEndPos.x - dragStartPos.x,
+ y: dragEndPos.y - dragStartPos.y
+ };
+ var shuriken = new Shuriken();
+ shuriken.x = player.x;
+ shuriken.y = player.y;
+ shuriken.move = function () {
+ this.x += direction.x * this.speed;
+ this.y += direction.y * this.speed;
+ };
+ shurikens.push(shuriken);
+ self.addChild(shuriken);
+ }
+ });
LK.on('tick', function () {
update();
checkCollision();
updateScore();