User prompt
Add a circle asset to the road class with a width and height of 500, black tint, and anchor of 0.5,0.5
User prompt
change the background colour to sky blue
User prompt
segment.rotation should be in radians
User prompt
create two new classes: A RoadSegment class that contains the roadSegment asset (with anchor of 0,1), and a Road class containing 30 RoadSegments equally rotated around the origin. Then create and show a Road instance in the middle of the screen
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: alpha is undefined' in or related to this line: 'numberText.setText(alpha.toFixed(1));' Line Number: 67
Code edit (2 edits merged)
Please save this source code
User prompt
display a number text in the top center of the screen
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: character.update is not a function' in or related to this line: 'character.update();' Line Number: 167
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: body is not defined' in or related to this line: 'armLeft.x = -body.width / 2 + armOffsetX;' Line Number: 120
User prompt
rename the "body" asset to "torso" and rename any usages
Code edit (3 edits merged)
Please save this source code
User prompt
after creating the body asset in the character class, add a head asset with an anchor of 0.35, 0.95
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.getAsset is not a function' in or related to this line: 'var body = self.getAsset('body', {});' Line Number: 99
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: cyclic object value' in or related to this line: 'self.attachAsset(body, {});' Line Number: 106
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ var Character = Container.expand(function () { var self = Container.call(this); // Create and attach body parts var body = self.attachAsset('body', { anchorX: 0.5, anchorY: 0.5 }); var armLeft = self.addChild(new CharacterArm()); var armRight = self.addChild(new CharacterArm()); var legLeft = self.addChild(new CharacterLeg()); var legRight = self.addChild(new CharacterLeg()); // Position body parts body.x = 0; body.y = 0; armLeft.x = -body.width / 2; armLeft.y = -body.height / 2; armRight.x = body.width / 2; armRight.y = -body.height / 2; legLeft.x = -body.width / 4; legLeft.y = body.height / 2; legRight.x = body.width / 4; legRight.y = body.height / 2; // Add an empty update function to the Character class self.runAlpha = 0; self.update = function () { this.runAlpha += 0.001; armLeft.update(this.runAlpha); armRight.update(this.runAlpha - 0.5); }; }); var CharacterArm = Container.expand(function () { var self = Container.call(this); // Arm settings var upperBaseAngle = -Math.PI * 3 / 8; var lowerBaseAngle = -Math.PI / 4; var lowerHoldAngle = -Math.PI * 5 / 8; var lowerBaseOffset = 90; // Create and attach arm parts var upper = self.attachAsset('upperArm', { rotation: upperBaseAngle, anchorX: 0.85, anchorY: 0.25 }); var lower = self.attachAsset('lowerArm', { y: lowerBaseOffset, rotation: lowerBaseAngle + lowerHoldAngle, anchorX: 0.95, anchorY: 0.05 }); var upperDebug = self.attachAsset('blank', { anchorX: 0.5, scaleX: 0.05, scaleY: lowerBaseOffset / 100, tint: 0xFF0000 }); var lowerDebug = self.attachAsset('blank', { y: lowerBaseOffset, rotation: lowerHoldAngle, anchorX: 0.5, scaleX: 0.05, tint: 0xFF0000 }); // Add an empty update function to the CharacterArm class that takes in an alpha value self.update = function (alpha) { // Swing the arm using a sinusoidal equation based on alpha var upperSwing = Math.sin(alpha * Math.PI * 2) * Math.PI / 4; // Swing between -45 and 45 degrees var lowerSwing = upperSwing / 2; self.rotation = -upperSwing; lower.rotation = lowerBaseAngle + lowerHoldAngle + lowerSwing; // Debugging lowerDebug.rotation = lower.rotation - lowerBaseAngle; }; }); var CharacterLeg = Container.expand(function () { var self = Container.call(this); // Create and attach leg parts var upperLeg = self.attachAsset('upperLeg', { anchorX: 0.5, anchorY: 0.5 }); var lowerLeg = self.attachAsset('lowerLeg', { anchorX: 0.5, anchorY: 0.5 }); // Position leg parts upperLeg.x = 0; upperLeg.y = 0; lowerLeg.x = upperLeg.x; lowerLeg.y = upperLeg.y + upperLeg.height; // Add an empty update function to the CharacterLeg class that takes in an alpha value self.update = function (alpha) {}; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var character = game.addChild(new Character()); // Position character at the center of the screen character.x = 2048 / 2; character.y = 2732 / 2; // Add an ontick event to the game which calls the character's update method LK.on('tick', function () { character.update(); });
/****
* Classes
****/
var Character = Container.expand(function () {
var self = Container.call(this);
// Create and attach body parts
var body = self.attachAsset('body', {
anchorX: 0.5,
anchorY: 0.5
});
var armLeft = self.addChild(new CharacterArm());
var armRight = self.addChild(new CharacterArm());
var legLeft = self.addChild(new CharacterLeg());
var legRight = self.addChild(new CharacterLeg());
// Position body parts
body.x = 0;
body.y = 0;
armLeft.x = -body.width / 2;
armLeft.y = -body.height / 2;
armRight.x = body.width / 2;
armRight.y = -body.height / 2;
legLeft.x = -body.width / 4;
legLeft.y = body.height / 2;
legRight.x = body.width / 4;
legRight.y = body.height / 2;
// Add an empty update function to the Character class
self.runAlpha = 0;
self.update = function () {
this.runAlpha += 0.001;
armLeft.update(this.runAlpha);
armRight.update(this.runAlpha - 0.5);
};
});
var CharacterArm = Container.expand(function () {
var self = Container.call(this);
// Arm settings
var upperBaseAngle = -Math.PI * 3 / 8;
var lowerBaseAngle = -Math.PI / 4;
var lowerHoldAngle = -Math.PI * 5 / 8;
var lowerBaseOffset = 90;
// Create and attach arm parts
var upper = self.attachAsset('upperArm', {
rotation: upperBaseAngle,
anchorX: 0.85,
anchorY: 0.25
});
var lower = self.attachAsset('lowerArm', {
y: lowerBaseOffset,
rotation: lowerBaseAngle + lowerHoldAngle,
anchorX: 0.95,
anchorY: 0.05
});
var upperDebug = self.attachAsset('blank', {
anchorX: 0.5,
scaleX: 0.05,
scaleY: lowerBaseOffset / 100,
tint: 0xFF0000
});
var lowerDebug = self.attachAsset('blank', {
y: lowerBaseOffset,
rotation: lowerHoldAngle,
anchorX: 0.5,
scaleX: 0.05,
tint: 0xFF0000
});
// Add an empty update function to the CharacterArm class that takes in an alpha value
self.update = function (alpha) {
// Swing the arm using a sinusoidal equation based on alpha
var upperSwing = Math.sin(alpha * Math.PI * 2) * Math.PI / 4; // Swing between -45 and 45 degrees
var lowerSwing = upperSwing / 2;
self.rotation = -upperSwing;
lower.rotation = lowerBaseAngle + lowerHoldAngle + lowerSwing;
// Debugging
lowerDebug.rotation = lower.rotation - lowerBaseAngle;
};
});
var CharacterLeg = Container.expand(function () {
var self = Container.call(this);
// Create and attach leg parts
var upperLeg = self.attachAsset('upperLeg', {
anchorX: 0.5,
anchorY: 0.5
});
var lowerLeg = self.attachAsset('lowerLeg', {
anchorX: 0.5,
anchorY: 0.5
});
// Position leg parts
upperLeg.x = 0;
upperLeg.y = 0;
lowerLeg.x = upperLeg.x;
lowerLeg.y = upperLeg.y + upperLeg.height;
// Add an empty update function to the CharacterLeg class that takes in an alpha value
self.update = function (alpha) {};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var character = game.addChild(new Character());
// Position character at the center of the screen
character.x = 2048 / 2;
character.y = 2732 / 2;
// Add an ontick event to the game which calls the character's update method
LK.on('tick', function () {
character.update();
});
white
white
circle sliced into many pieces, flat image. 2d, white background, shadowless.
pixel art of a tall, tree. game asset, 2d, white background, shadowless.
Pixel art street lamp. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art sun. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.