User prompt
add a sun asset in the sun class after the circles for-loop, with an alpha of 0.5
User prompt
In the sun class, create 10 circle assets at the origin, each one 100 units larger than the last, with the first having a width and height of 500. They should be also tinted yellow and have an alpha of 0.05
User prompt
Please fix the bug: 'TypeError: self is undefined' in or related to this line: 'self.attachAsset('circle', {' Line Number: 455
User prompt
In the sun class, create 10 circle assets at the origin, each one 100 units larger than the last, with the first having a width and height of 500. They should be also tinted yellow and have an alpha of 0.05. Make sure to keep the sun asset
User prompt
add the sun asset back
User prompt
In the sun class, create 10 circle assets at the origin, each one 100 units larger than the last, with the first having a width and height of 500. They should be also tinted yellow and have an alpha of 0.05
Code edit (3 edits merged)
Please save this source code
User prompt
Create a new Sun class to replace the sun asset
Code edit (9 edits merged)
Please save this source code
User prompt
show a sun asset at the top (slightly off screen), center of the screen
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: alpha is not defined' in or related to this line: 'if (alpha -= 0.1 < 0) {' Line Number: 164
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: fadeout is not defined' in or related to this line: 'if (fadeout && self.alpha > 0) {' Line Number: 163
Code edit (18 edits merged)
Please save this source code
User prompt
The first line of the generateBackground function should clear the background Container of any children
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 (21 edits merged)
Please save this source code
User prompt
before attaching the roadSegment asset to the RoadSegment class, attach an empty Container class
User prompt
rename the sign0 asset to tree0
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
/**** * Classes ****/ /** * config { * x : Number || 0, * y : Number || 0, * rotation : Number || 0, * } **/ var ConfigContainer = Container.expand(function (config) { var self = Container.call(this); config = config || {}; ; self.x = config.x || 0; self.y = config.y || 0; self.rotation = config.rotation || 0; if (config.scale !== undefined || config.scaleX !== undefined || config.scaleY !== undefined) { var scaleX = config.scaleX !== undefined ? config.scaleX : config.scale !== undefined ? config.scale : 1; var scaleY = config.scaleY !== undefined ? config.scaleY : config.scale !== undefined ? config.scale : 1; self.scale.set(scaleX, scaleY); } ; return self; }); var RoadSegment = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); self.attachAsset('roadSegment', { anchorX: 1, anchorY: 1 }); ; self.scaling = config.scale; self.stepChance = config.stepChance; self.transition = transition; self.previous = config.previous; ; function transition(instant) { var stepChance = self.previous.stepChance; var stepUp = self.previous.scaling < ROAD_SCALE_MAX ? Math.random() < self.stepChance : false; var stepDown = self.previous.scaling > ROAD_SCALE_MIN ? Math.random() < self.stepChance : false; if (stepUp && stepDown) { if (Math.random() < 0.5) { stepDown = false; } else { stepUp = false; } } if (stepUp || stepDown) { self.scaling = self.previous.scaling += ROAD_SCALE_STEP * (stepUp ? 1 : -1); self.stepChance = ROAD_STEP_CHANCE_BASE; } else { self.scaling = self.previous.scaling; self.stepChance = self.previous.stepChance + ROAD_STEP_CHANCE_INCREMENT; } self.scale.set(self.scaling); } }); var Road = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); var segments = []; var segmentAngle = 2 * Math.PI / ROAD_SEGMENT_COUNT; for (var i = 0; i < ROAD_SEGMENT_COUNT; i++) { var segment = segments[i] = self.addChild(new RoadSegment({ previous: i > 0 ? segments[i - 1] : undefined, rotation: i * segmentAngle, stepChance: ROAD_STEP_CHANCE_BASE, scale: ROAD_SCALE_BASE })); if (i === ROAD_SEGMENT_COUNT - 1) { segments[0].previous = segment; } if (i >= ROAD_FREE_RUN_COUNT) { segment.transition(true); } } var circle = self.attachAsset('circle', { width: 500, height: 500, tint: 0x000000, anchorX: 0.5, anchorY: 0.5 }); }); var CharacterLeg = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); // Leg settings var upperBaseAngle = Math.PI * 3 / 8; var lowerBaseOffset = 135; var lowerHoldAngle = Math.PI / 8; var footBaseOffset = 100; // Create and attach leg parts var upper = self.attachAsset('upperLeg', { rotation: upperBaseAngle, anchorY: 0.1, tint: config.tint || 0xFFFFFF }); var lower = self.addChild(new ConfigContainer({ y: lowerBaseOffset, tint: config.tint || 0xFFFFFF })); lower.attachAsset('lowerLeg', { anchorX: 0.65, tint: config.tint || 0xFFFFFF }); var foot = lower.attachAsset('foot', { y: footBaseOffset, anchorX: 0.2, anchorY: 0.05, tint: config.tint || 0xFFFFFF }); self.update = function (alpha) { var sinusoidal = Math.cos(alpha * Math.PI * 2); var upperSwing = sinusoidal * Math.PI / 3; self.rotation = upperSwing; lower.rotation = lowerHoldAngle + (alpha <= 0.5 ? Math.PI / 3 + (1 - Math.abs(sinusoidal)) * Math.PI / 6 : Math.abs(-upperSwing)); foot.rotation = Math.max(0, upperSwing * 2 / 3) - lowerHoldAngle; }; }); var CharacterBody = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); // Body settings var armOffsetX = 15; var armOffsetY = 30; var pelvisOffsetX = -15; var legOffsetX = 5; // Create and attach body parts var armRight = self.addChild(new CharacterArm({ y: armOffsetY, tint: 0x777777 })); var legRight = self.addChild(new CharacterLeg({ x: pelvisOffsetX + legOffsetX, tint: 0x777777 })); var torso = self.attachAsset('torso', { anchorX: 0.5 }); var head = self.attachAsset('head', { anchorX: 0.15, anchorY: 0.95 }); var pelvis = self.attachAsset('pelvis', { x: pelvisOffsetX, y: torso.height, anchorX: 0.5, anchorY: 0.2, tint: 0xAAAAAA }); var legLeft = self.addChild(new CharacterLeg({ x: pelvisOffsetX - legOffsetX })); var armLeft = self.addChild(new CharacterArm({ y: armOffsetY })); // Position body parts armLeft.x = -torso.width / 2 + armOffsetX; armRight.x = torso.width / 2 - armOffsetX; legLeft.y = torso.height + pelvis.height / 3; legRight.y = torso.height + pelvis.height / 3; // Add an empty update function to the Character class self.runAlpha = 0; self.update = function () { this.runAlpha += 0.0075; var sinusoidal = Math.cos(this.runAlpha * Math.PI * 4); armLeft.update(this.runAlpha % 1); armRight.update((this.runAlpha - 0.5) % 1); legLeft.update(this.runAlpha % 1); legRight.update((this.runAlpha - 0.5) % 1); self.y = sinusoidal * 10; head.rotation = (1 + sinusoidal) * Math.PI / 32; }; }); var CharacterArm = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); // Arm settings var upperBaseAngle = -Math.PI * 3 / 8; var upperOffsetAngle = Math.PI / 5; 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, tint: config.tint || 0xFFFFFF }); var lower = self.attachAsset('lowerArm', { y: lowerBaseOffset, rotation: lowerBaseAngle + lowerHoldAngle, anchorX: 0.95, anchorY: 0.05, tint: config.tint || 0xFFFFFF }); self.update = function (alpha) { var upperSwing = Math.cos(alpha * Math.PI * 2) * Math.PI / 4; // Swing between -45 and 45 degrees var lowerSwing = -upperSwing / 2; self.rotation = -upperSwing + upperOffsetAngle; lower.rotation = lowerBaseAngle + lowerHoldAngle + lowerSwing; }; }); var Character = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); var body = self.addChild(new CharacterBody()); self.update = function () { body.update(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue color }); /**** * Game Code ****/ // Global Constants & Settings // Game Constants var GAME_TICKS = 60; // Math Constants var MATH_2_PI = Math.PI * 2; // Road Constants var ROAD_SEGMENT_COUNT = 30; var ROAD_FREE_RUN_COUNT = 5; var ROAD_SCALE_BASE = 0.7; var ROAD_SCALE_STEP = 0.1; var ROAD_SCALE_MAX = 1.0; var ROAD_SCALE_MIN = 0.4; var ROAD_STEP_CHANCE_BASE = 0.1; var ROAD_STEP_CHANCE_INCREMENT = 0.5; // Player Constants var PLAYER_ROTATIONAL_SPEED = MATH_2_PI / (GAME_TICKS * 10); // 10s to complete a revolution ; // Game Instances var road = game.addChild(new Road({ x: 2048 / 2, y: 2732 / 2 })); var character = game.addChild(new Character({ x: 2048 / 2, y: 2732 / 2 })); ; // Events LK.on('tick', function () { road.rotation += PLAYER_ROTATIONAL_SPEED; character.update(); }); ; // Animations function animationRun(alpha) { return {}; } function animationJump(alpha) { return {}; } function animationStand(alpha) { return {}; }
/****
* Classes
****/
/**
* config {
* x : Number || 0,
* y : Number || 0,
* rotation : Number || 0,
* }
**/
var ConfigContainer = Container.expand(function (config) {
var self = Container.call(this);
config = config || {};
;
self.x = config.x || 0;
self.y = config.y || 0;
self.rotation = config.rotation || 0;
if (config.scale !== undefined || config.scaleX !== undefined || config.scaleY !== undefined) {
var scaleX = config.scaleX !== undefined ? config.scaleX : config.scale !== undefined ? config.scale : 1;
var scaleY = config.scaleY !== undefined ? config.scaleY : config.scale !== undefined ? config.scale : 1;
self.scale.set(scaleX, scaleY);
}
;
return self;
});
var RoadSegment = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
self.attachAsset('roadSegment', {
anchorX: 1,
anchorY: 1
});
;
self.scaling = config.scale;
self.stepChance = config.stepChance;
self.transition = transition;
self.previous = config.previous;
;
function transition(instant) {
var stepChance = self.previous.stepChance;
var stepUp = self.previous.scaling < ROAD_SCALE_MAX ? Math.random() < self.stepChance : false;
var stepDown = self.previous.scaling > ROAD_SCALE_MIN ? Math.random() < self.stepChance : false;
if (stepUp && stepDown) {
if (Math.random() < 0.5) {
stepDown = false;
} else {
stepUp = false;
}
}
if (stepUp || stepDown) {
self.scaling = self.previous.scaling += ROAD_SCALE_STEP * (stepUp ? 1 : -1);
self.stepChance = ROAD_STEP_CHANCE_BASE;
} else {
self.scaling = self.previous.scaling;
self.stepChance = self.previous.stepChance + ROAD_STEP_CHANCE_INCREMENT;
}
self.scale.set(self.scaling);
}
});
var Road = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var segments = [];
var segmentAngle = 2 * Math.PI / ROAD_SEGMENT_COUNT;
for (var i = 0; i < ROAD_SEGMENT_COUNT; i++) {
var segment = segments[i] = self.addChild(new RoadSegment({
previous: i > 0 ? segments[i - 1] : undefined,
rotation: i * segmentAngle,
stepChance: ROAD_STEP_CHANCE_BASE,
scale: ROAD_SCALE_BASE
}));
if (i === ROAD_SEGMENT_COUNT - 1) {
segments[0].previous = segment;
}
if (i >= ROAD_FREE_RUN_COUNT) {
segment.transition(true);
}
}
var circle = self.attachAsset('circle', {
width: 500,
height: 500,
tint: 0x000000,
anchorX: 0.5,
anchorY: 0.5
});
});
var CharacterLeg = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
// Leg settings
var upperBaseAngle = Math.PI * 3 / 8;
var lowerBaseOffset = 135;
var lowerHoldAngle = Math.PI / 8;
var footBaseOffset = 100;
// Create and attach leg parts
var upper = self.attachAsset('upperLeg', {
rotation: upperBaseAngle,
anchorY: 0.1,
tint: config.tint || 0xFFFFFF
});
var lower = self.addChild(new ConfigContainer({
y: lowerBaseOffset,
tint: config.tint || 0xFFFFFF
}));
lower.attachAsset('lowerLeg', {
anchorX: 0.65,
tint: config.tint || 0xFFFFFF
});
var foot = lower.attachAsset('foot', {
y: footBaseOffset,
anchorX: 0.2,
anchorY: 0.05,
tint: config.tint || 0xFFFFFF
});
self.update = function (alpha) {
var sinusoidal = Math.cos(alpha * Math.PI * 2);
var upperSwing = sinusoidal * Math.PI / 3;
self.rotation = upperSwing;
lower.rotation = lowerHoldAngle + (alpha <= 0.5 ? Math.PI / 3 + (1 - Math.abs(sinusoidal)) * Math.PI / 6 : Math.abs(-upperSwing));
foot.rotation = Math.max(0, upperSwing * 2 / 3) - lowerHoldAngle;
};
});
var CharacterBody = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
// Body settings
var armOffsetX = 15;
var armOffsetY = 30;
var pelvisOffsetX = -15;
var legOffsetX = 5;
// Create and attach body parts
var armRight = self.addChild(new CharacterArm({
y: armOffsetY,
tint: 0x777777
}));
var legRight = self.addChild(new CharacterLeg({
x: pelvisOffsetX + legOffsetX,
tint: 0x777777
}));
var torso = self.attachAsset('torso', {
anchorX: 0.5
});
var head = self.attachAsset('head', {
anchorX: 0.15,
anchorY: 0.95
});
var pelvis = self.attachAsset('pelvis', {
x: pelvisOffsetX,
y: torso.height,
anchorX: 0.5,
anchorY: 0.2,
tint: 0xAAAAAA
});
var legLeft = self.addChild(new CharacterLeg({
x: pelvisOffsetX - legOffsetX
}));
var armLeft = self.addChild(new CharacterArm({
y: armOffsetY
}));
// Position body parts
armLeft.x = -torso.width / 2 + armOffsetX;
armRight.x = torso.width / 2 - armOffsetX;
legLeft.y = torso.height + pelvis.height / 3;
legRight.y = torso.height + pelvis.height / 3;
// Add an empty update function to the Character class
self.runAlpha = 0;
self.update = function () {
this.runAlpha += 0.0075;
var sinusoidal = Math.cos(this.runAlpha * Math.PI * 4);
armLeft.update(this.runAlpha % 1);
armRight.update((this.runAlpha - 0.5) % 1);
legLeft.update(this.runAlpha % 1);
legRight.update((this.runAlpha - 0.5) % 1);
self.y = sinusoidal * 10;
head.rotation = (1 + sinusoidal) * Math.PI / 32;
};
});
var CharacterArm = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
// Arm settings
var upperBaseAngle = -Math.PI * 3 / 8;
var upperOffsetAngle = Math.PI / 5;
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,
tint: config.tint || 0xFFFFFF
});
var lower = self.attachAsset('lowerArm', {
y: lowerBaseOffset,
rotation: lowerBaseAngle + lowerHoldAngle,
anchorX: 0.95,
anchorY: 0.05,
tint: config.tint || 0xFFFFFF
});
self.update = function (alpha) {
var upperSwing = Math.cos(alpha * Math.PI * 2) * Math.PI / 4; // Swing between -45 and 45 degrees
var lowerSwing = -upperSwing / 2;
self.rotation = -upperSwing + upperOffsetAngle;
lower.rotation = lowerBaseAngle + lowerHoldAngle + lowerSwing;
};
});
var Character = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var body = self.addChild(new CharacterBody());
self.update = function () {
body.update();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue color
});
/****
* Game Code
****/
// Global Constants & Settings
// Game Constants
var GAME_TICKS = 60;
// Math Constants
var MATH_2_PI = Math.PI * 2;
// Road Constants
var ROAD_SEGMENT_COUNT = 30;
var ROAD_FREE_RUN_COUNT = 5;
var ROAD_SCALE_BASE = 0.7;
var ROAD_SCALE_STEP = 0.1;
var ROAD_SCALE_MAX = 1.0;
var ROAD_SCALE_MIN = 0.4;
var ROAD_STEP_CHANCE_BASE = 0.1;
var ROAD_STEP_CHANCE_INCREMENT = 0.5;
// Player Constants
var PLAYER_ROTATIONAL_SPEED = MATH_2_PI / (GAME_TICKS * 10); // 10s to complete a revolution
;
// Game Instances
var road = game.addChild(new Road({
x: 2048 / 2,
y: 2732 / 2
}));
var character = game.addChild(new Character({
x: 2048 / 2,
y: 2732 / 2
}));
;
// Events
LK.on('tick', function () {
road.rotation += PLAYER_ROTATIONAL_SPEED;
character.update();
});
;
// Animations
function animationRun(alpha) {
return {};
}
function animationJump(alpha) {
return {};
}
function animationStand(alpha) {
return {};
}
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.