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
User prompt
set initial currentX and currentY to the same as car x and y init position
User prompt
do not calculate current x and y at the top of addRoadSegment
User prompt
set segment height to a random value between 500 and 4000
User prompt
set segment height to a random value between 500 and 400
User prompt
update road width to 20px
Code edit (1 edits merged)
Please save this source code
User prompt
rotation should be reversed when we zig
User prompt
add particles with z-index 1
Code edit (1 edits merged)
Please save this source code
User prompt
add road segments to roadContainer
Code edit (1 edits merged)
Please save this source code
User prompt
add a simple container to mainContainer for road segments
User prompt
calculate currentX and currentY at the bottom of addRoadSegment
User prompt
have both a current x and current y variable to determine where to insert the next road segment
===================================================================
--- original.js
+++ change.js
@@ -62,10 +62,10 @@
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);
- currentX -= segment.height * Math.sin(segment.rotation);
+ currentY += segment.height * Math.cos(segment.rotation) - segment.width / 2;
+ currentX -= segment.height * Math.sin(segment.rotation) + segment.width / 2;
roadSegments.push(segment);
roadContainer.addChild(segment);
};
LK.stageContainer.setBackgroundColor(0xc39977);