Code edit (1 edits merged)
Please save this source code
User prompt
create an interval on the player that checks to see which planet node's index is closest to the player's angle every PLAYER_ACTION_INTERVAL ticks
Code edit (16 edits merged)
Please save this source code
User prompt
Rename the globals: PLAYER_PICKUP_DIST and PLAYER_PICKUP_SQRDIST to: PLAYER_ACTION_DIST and PLAYER_ACTION_SQRDIST, and update all old usages of the variables
Code edit (4 edits merged)
Please save this source code
User prompt
destroy and clear the player variable in the launch function if direction > 0
Code edit (1 edits merged)
Please save this source code
User prompt
destroy and clear the player variable on ship launch (in the launch function)
User prompt
destroy and clear the player variable on ship launch
Code edit (1 edits merged)
Please save this source code
User prompt
flip the player's graphic based on the direction it's moving
Code edit (3 edits merged)
Please save this source code
User prompt
rotate the player asset to match it's current angle
Code edit (2 edits merged)
Please save this source code
User prompt
Prevent the player from overshooting the targetAngle when moving
Code edit (2 edits merged)
Please save this source code
User prompt
in the player update method: check if the angle between the player and the targetAngle are unequal and move the player's position around the planet at a radial speed of PLAYER_SPEED until it reaches the angle
User prompt
call the player update function from the no tick callback if the player exists
User prompt
add an update method to the player, which is called every tick if the player exists
Code edit (1 edits merged)
Please save this source code
User prompt
Only perform the on down action if the square distance between the click and the planet is within the planet's radius + PLAYER_BUFFER_DIST squared
Code edit (1 edits merged)
Please save this source code
User prompt
Change the game.on down event to calculate the angle between the click and the planet's position
Code edit (1 edits merged)
Please save this source code
User prompt
Register a listener for the on down event on the stage
===================================================================
--- original.js
+++ change.js
@@ -128,14 +128,18 @@
return self;
});
var Player = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
+ var actionCountdown = PLAYER_ACTION_INTERVAL;
var playerGraphics = self.attachAsset('player', {
rotation: MATH_HALF_PI,
anchorX: 0.5,
anchorY: 0.5
});
- self.update = function () {
+ ;
+ self.update = update;
+ ;
+ function update() {
var currentAngle = Math.atan2(self.y, self.x);
var angleDifference = targetAngle - currentAngle;
angleDifference = mod(angleDifference + Math.PI, MATH_2_PI) - Math.PI;
if (angleDifference < -MATH_APPROX_ZERO || angleDifference > MATH_APPROX_ZERO) {
@@ -145,27 +149,22 @@
self.x = Math.cos(newAngle) * planet.radius;
self.y = Math.sin(newAngle) * planet.radius;
playerGraphics.scale.x = direction < 0 ? -1 : 1;
playerGraphics.rotation = newAngle + MATH_HALF_PI;
- }
- if (LK.ticks % PLAYER_ACTION_INTERVAL === 0) {
- self.checkClosestNode();
- }
- };
- self.checkClosestNode = function () {
- var playerAngle = mod(Math.atan2(self.y, self.x) + planet.rotation, MATH_2_PI);
- var closestNodeIndex = 0;
- var smallestAngleDifference = MATH_2_PI;
- planet.nodes.forEach(function (node, index) {
- var nodeAngle = mod(node.rotation, MATH_2_PI);
- var angleDifference = Math.abs(mod(playerAngle - nodeAngle + Math.PI, MATH_2_PI) - Math.PI);
- if (angleDifference < smallestAngleDifference) {
- smallestAngleDifference = angleDifference;
- closestNodeIndex = index;
+ currentAngle = newAngle;
+ } else if (--actionCountdown <= 0) {
+ var actionNode = checkForActionNode(currentAngle);
+ if (actionNode) {
+ performAction(actionNode);
}
- });
- console.log('Closest node index to player:', closestNodeIndex);
- };
+ }
+ }
+ function performAction(actionNode) {}
+ function checkForActionNode(angle) {
+ var count = planet.nodes.length;
+ var index = Math.round(mod(angle / MATH_2_PI * count, count));
+ console.log(index);
+ }
});
var Ship = Container.expand(function (x, y) {
var self = Container.call(this);
var shipGraphics = self.attachAsset('ship', {
pixel art of a tiny planet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a planet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of an alien currency symbol. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a planet made of gold ore. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
plain black background with stars. 2d repeating Texture.
pixel art of a asteroid. Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a cute alien farmer, side view. Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a rocky explosion.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art flame particle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a large white, empty, rectangular, speech bubble. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a red chevron. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art of yellow grapes. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.