User prompt
Draw at the exact same time of click
User prompt
click player to move
User prompt
Don'tmake player follow currsor make corsor holdplayer to moving anywhere
User prompt
Make the draw line follow the player on the screen
User prompt
Make the line follow the player
User prompt
Don't draw by click draw only by moving the player on the background
User prompt
Make the player drawing by moving not by holding
User prompt
If the mouse button still holded keep drawing the line
User prompt
Make player draw by movment too
User prompt
Make a continiue line not point
User prompt
Please fix the bug: 'TypeError: Graphics is not a constructor' in or related to this line: 'var lineSegment = new Graphics();' Line Number: 26
User prompt
Make infinity draw line not just points
User prompt
when click mouse button dra line
User prompt
Add draw object to the game and set it as the line that the player draw it
User prompt
Add up and down for player
User prompt
Please fix the bug: 'ReferenceError: dragNode is not defined' in or related to this line: 'if (dragNode === self && (self.x !== oldX || self.y !== oldY)) {' Line Number: 41
User prompt
Make the Asset Draw the color line that drawed down the player when its moving
User prompt
make the player moving and drawing
User prompt
Add object draw to the game and make it the draw of the player when mouse button is clicked
User prompt
player still not drawing
User prompt
Fix drawing not drawing by player
User prompt
Start draw on the screen
User prompt
Add asset draw to the game make it the draw of player when mouse button is holded
User prompt
Draw if click on player
User prompt
Please fix the bug: 'ReferenceError: dragNode is not defined' in or related to this line: 'if (dragNode === self && (self.x !== oldX || self.y !== oldY)) {' Line Number: 41
/**** * Classes ****/ // Create a DrawLine class to represent the line drawn by the player var DrawLine = Container.expand(function () { var self = Container.call(this); var drawLineGraphics = self.attachAsset('Draw', { anchorX: 0.5, anchorY: 0.5 }); // Store the previous position to draw a continuous line self.previousX = null; self.previousY = null; // Update method to draw a line segment self.update = function (currentX, currentY) { if (self.previousX !== null && self.previousY !== null) { // Draw a line segment from previous position to current position var lineSegment = LK.getAsset('Draw', { anchorX: 0.5, anchorY: 0.5 }); lineSegment.x = (self.previousX + currentX) / 2; lineSegment.y = (self.previousY + currentY) / 2; lineSegment.width = Math.sqrt(Math.pow(currentX - self.previousX, 2) + Math.pow(currentY - self.previousY, 2)); lineSegment.rotation = Math.atan2(currentY - self.previousY, currentX - self.previousX); game.addChild(lineSegment); } // Update previous position self.previousX = currentX; self.previousY = currentY; }; }); // Create a Drawing class for the player var Drawing = Container.expand(function () { var self = Container.call(this); var drawingGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5, width: blockSize * 0.8, // Make the drawing smaller than the player height: blockSize * 0.8 // Make the drawing smaller than the player }); }); // Create a Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5, width: blockSize, height: blockSize }); self.speed = 8; self.vx = 0; self.vy = 0; self.update = function () { var oldX = self.x; var oldY = self.y; self.x += self.vx; self.y += self.vy; // Draw a line if the player has moved if (self.x !== oldX || self.y !== oldY) { if (!self.drawLine) { self.drawLine = new DrawLine(); } self.drawLine.update(self.x, self.y); } if (self.x < 0) { self.x = 0; } if (self.y < 0) { self.y = 0; } if (self.x > game.width) { self.x = game.width; } if (self.y > game.height) { self.y = 0; statusText.timeLeft = 60; // Reset the time left } }; }); // Create a Wall class var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('Wall', { anchorX: 0.5, anchorY: 0.5, width: blockSize, height: blockSize }); }); //<Assets used in the game will automatically appear here> // Create a StatusText class var StatusText = Text2.expand(function () { var self = Text2.call(this, 'Time left: 60', { size: 50, fill: 0xFFFFFF }); self.timeLeft = 60; self.update = function () { if (LK.ticks % 60 == 0) { self.timeLeft--; self.setText('Time left: ' + self.timeLeft); } }; }); /**** * Initialize Game ****/ // Check for collision with wall // Function to generate a random maze var game = new LK.Game({ width: 2048, height: 2732, backgroundColor: 0x000000 }); /**** * Game Code ****/ var background = game.attachAsset('Background1', { anchorX: 0.5, anchorY: 0.5, width: game.width, height: game.height }); background.x = game.width / 2; background.y = game.height / 2; game.addChild(background); // Add move event to the game game.move = function (x, y, obj) { // Move the player to the y position of the touch or mouse event player.y = y - player.height / 2; // Move the player to the x position of the touch or mouse event player.x = x - player.width / 2; }; var blockSize = 100; // Add player to the bottom middle of the screen var player = game.addChild(new Player()); player.x = game.width / 2; player.y = game.height - player.height / 2; // Add status text to the top left of the screen var statusText = game.addChild(new StatusText()); statusText.x = 20; statusText.y = 20; game.down = function (x, y, obj) { // Start moving the player when touch or mouse down game.move(x, y, obj); // Check if the player touched the object if (player.intersects(obj)) { console.log("Player touched the object!"); } // Draw a line at the player's current position var drawLine = new DrawLine(); drawLine.x = player.x; drawLine.y = player.y; game.addChild(drawLine); }; game.up = function (x, y, obj) { // Change the direction of the player when touch or mouse up player.vx = -player.vx; player.vy = -player.vy; }; // Add an update function to the game game.update = function () {};
===================================================================
--- original.js
+++ change.js
@@ -18,12 +18,12 @@
var lineSegment = LK.getAsset('Draw', {
anchorX: 0.5,
anchorY: 0.5
});
- lineSegment.x = self.previousX;
- lineSegment.y = self.previousY;
- lineSegment.width = currentX - self.previousX;
- lineSegment.height = currentY - self.previousY;
+ lineSegment.x = (self.previousX + currentX) / 2;
+ lineSegment.y = (self.previousY + currentY) / 2;
+ lineSegment.width = Math.sqrt(Math.pow(currentX - self.previousX, 2) + Math.pow(currentY - self.previousY, 2));
+ lineSegment.rotation = Math.atan2(currentY - self.previousY, currentX - self.previousX);
game.addChild(lineSegment);
}
// Update previous position
self.previousX = currentX;