User prompt
make the first road segment created 3000px long
User prompt
make the first road segment created 3000px long
Code edit (1 edits merged)
Please save this source code
User prompt
in tick calculate if the car center is currently inside or outside any of the road segments
User prompt
when destroying a road segment also call self.addRoadSegment
User prompt
only delete road segments that are twice the height of the screen outside the screen
User prompt
delete initialSegment
User prompt
delete initialSegment
Code edit (8 edits merged)
Please save this source code
User prompt
use self.toLocal for segmentGlobalPosition calc
Code edit (1 edits merged)
Please save this source code
User prompt
in tick, calculate if road segments are outside the screen at the bottom
User prompt
use segmentWidth for road width
User prompt
subtract half the width of the road from segment.height before multiplying it into sin and cos
User prompt
subtract half a road width from the currentX and currentY calculation
User prompt
set the road width to 200
User prompt
set zigzag to true when initializing it
User prompt
for current Y add add cos for current Y subtract sin
Code edit (3 edits merged)
Please save this source code
User prompt
simply modify current X and currentY by cos / sin the rotation * the length of the segment
Code edit (13 edits merged)
Please save this source code
User prompt
when calculating currentY and currentY knowing that the anchor of segment is .5,0, set currentY and currentY to the end of the road segment we just created
User prompt
make rotation switch between -Math.PI - Math.PI / 4 and -Math.PI + Math.PI / 4
Code edit (1 edits merged)
Please save this source code
User prompt
do not subtract car width and height from car x,y when starting game
===================================================================
--- original.js
+++ change.js
@@ -62,10 +62,11 @@
segment.height = Math.floor(Math.random() * (4000 - 500 + 1)) + 500;
segment.rotation = zigzag ? -Math.PI - Math.PI / 4 : -Math.PI + Math.PI / 4;
segment.y = currentY;
segment.x = currentX;
- currentY += segment.height * Math.cos(segment.rotation) - segment.width / 2;
- currentX -= segment.height * Math.sin(segment.rotation) + segment.width / 2;
+ var adjustedHeight = segment.height - segmentWidth / 2;
+ currentY += adjustedHeight * Math.cos(segment.rotation);
+ currentX -= adjustedHeight * Math.sin(segment.rotation);
roadSegments.push(segment);
roadContainer.addChild(segment);
};
LK.stageContainer.setBackgroundColor(0xc39977);