User prompt
redo player control, when the mouse cursor is to the right of the player, the player should move to the right, when the mouse cursor is to the left of the player, the player should move to the left.
User prompt
Player movement is unsure, redo the inroc control, make it faster
Initial prompt
Newton's game
===================================================================
--- original.js
+++ change.js
@@ -1,42 +1,48 @@
-/****
+/****
* Classes
****/
// Player class
var Player = Container.expand(function () {
- var self = Container.call(this);
- var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1);
- self.speed = 5;
- self.moveLeft = function () {
- if (self.x > 0) {
- self.x -= self.speed;
- }
- };
- self.moveRight = function () {
- if (self.x < 2048 - playerGraphics.width) {
- self.x += self.speed;
- }
- };
+ var self = Container.call(this);
+ var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1);
+ self.speed = 10;
+ self.moveLeft = function () {
+ if (self.x > self.speed) {
+ self.x -= self.speed;
+ } else {
+ self.x = 0;
+ }
+ };
+ self.moveRight = function () {
+ if (self.x < 2048 - playerGraphics.width - self.speed) {
+ self.x += self.speed;
+ } else {
+ self.x = 2048 - playerGraphics.width;
+ }
+ };
});
// Apple class
var Apple = Container.expand(function () {
- var self = Container.call(this);
- var appleGraphics = self.createAsset('apple', 'Falling apple', 0.5, 0.5);
- self.speed = 3;
- self.move = function () {
- self.y += self.speed;
- };
- self.isCaught = function (player) {
- return self.intersects(player);
- };
+ var self = Container.call(this);
+ var appleGraphics = self.createAsset('apple', 'Falling apple', 0.5, 0.5);
+ self.speed = 3;
+ self.move = function () {
+ self.y += self.speed;
+ };
+ self.isCaught = function (player) {
+ return self.intersects(player);
+ };
});
-/****
+
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+
+/****
* Game Code
****/
// Initialize player
var player = game.addChild(new Player());
@@ -47,44 +53,45 @@
var apples = [];
// Handle touch movement
function handleTouchMove(obj) {
- var touchPos = obj.event.getLocalPosition(game);
- if (touchPos.x < player.x) {
- player.moveLeft();
- } else if (touchPos.x > player.x) {
- player.moveRight();
- }
+ var touchPos = obj.event.getLocalPosition(game);
+ var playerCenterX = player.x + player.width / 2;
+ if (touchPos.x < playerCenterX) {
+ player.moveLeft();
+ } else if (touchPos.x > playerCenterX) {
+ player.moveRight();
+ }
}
// Attach touch move event to the game
game.on('move', handleTouchMove);
// Game tick event
LK.on('tick', function () {
- // Move apples
- for (var i = apples.length - 1; i >= 0; i--) {
- apples[i].move();
- // Check if apple is caught by the player
- if (apples[i].isCaught(player)) {
- // Increase score
- LK.setScore(LK.getScore() + 1);
- // Remove caught apple
- apples[i].destroy();
- apples.splice(i, 1);
- } else if (apples[i].y > 2732) {
- // Remove apple if it falls off the screen
- apples[i].destroy();
- apples.splice(i, 1);
- }
- }
+ // Move apples
+ for (var i = apples.length - 1; i >= 0; i--) {
+ apples[i].move();
+ // Check if apple is caught by the player
+ if (apples[i].isCaught(player)) {
+ // Increase score
+ LK.setScore(LK.getScore() + 1);
+ // Remove caught apple
+ apples[i].destroy();
+ apples.splice(i, 1);
+ } else if (apples[i].y > 2732) {
+ // Remove apple if it falls off the screen
+ apples[i].destroy();
+ apples.splice(i, 1);
+ }
+ }
- // Spawn apples
- if (LK.ticks % 60 == 0) {
- // Every second
- var newApple = new Apple();
- newApple.x = Math.random() * 2048;
- newApple.y = -50; // Start off-screen
- apples.push(newApple);
- game.addChild(newApple);
- }
+ // Spawn apples
+ if (LK.ticks % 60 == 0) {
+ // Every second
+ var newApple = new Apple();
+ newApple.x = Math.random() * 2048;
+ newApple.y = -50; // Start off-screen
+ apples.push(newApple);
+ game.addChild(newApple);
+ }
});
\ No newline at end of file
grass
the fields of Britain, cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
green apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
eureka moment, cartoon style, light, no people. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
heart. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
stars flying on an ellipse, cartoon style, side view , no people. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white "=" on a green apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white "F" on a red apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
the "G" sign on the red apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white " (M" on a red apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white sign with a small "m" on a red apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white " /" on a green apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white "R" on a red apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
green
a white " 2" on a red apple.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.