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
/**** * 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 = 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); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 - 50; // Positioned at the bottom of the screen // Initialize apples array 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(); } } // 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); } } // 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); } });
===================================================================
--- original.js
+++ change.js
@@ -54,12 +54,11 @@
// Handle touch movement
function handleTouchMove(obj) {
var touchPos = obj.event.getLocalPosition(game);
- var playerCenterX = player.x + player.width / 2;
- if (touchPos.x < playerCenterX) {
+ if (touchPos.x < player.x) {
player.moveLeft();
- } else if (touchPos.x > playerCenterX) {
+ } else if (touchPos.x > player.x) {
player.moveRight();
}
}
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.