Skip to content

Commit

Permalink
fix: fix ground
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasfremming committed Nov 12, 2024
1 parent 87418ec commit 80b74b1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ground.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ def __init__(self, start_x: int, end_x: int, space: pymunk.space) -> None:
self.points = []
self.add_points(start_x, end_x)

self.body = pymunk.Body(0, 0, 1)
self.body = pymunk.Body(body_type=pymunk.Body.KINEMATIC)
self.poly = pymunk.Poly(self.body, self.points, radius=0.0)
self.poly.friction = 0.5
space.add(self.body, self.poly)

def add_points(self, start_x: int, end_x: int) -> None:
for x in range(int(start_x), int(end_x) + 1, 1):
for x in range(int(self.start_x), int(self.end_x) + 1, 1):
y = int(SCREEN_HEIGHT - FLOOR_HEIGHT + AMPLITUDE * math.sin(FREQUENCY * x))
self.points.append((x, y))

Expand Down Expand Up @@ -191,7 +191,7 @@ def generate_floor_segment(self, start_x: int) -> list:
"""

segment = BasicSegment(start_x, start_x + self.segment_width, self.space)
return segment
return segment

def generate_new_floor_segment(self) -> None:
"""_summary_ Generate a new floor segment
Expand Down Expand Up @@ -237,13 +237,14 @@ def render(self) -> None:
shifted_points.append((shifted_points[-1][0], SCREEN_HEIGHT))
shifted_points.append((shifted_points[0][0], SCREEN_HEIGHT))
pg.draw.polygon(self.screen, (34, 139, 34), shifted_points)

def move_segments(self, scroll_offset: float) -> None:
for segment in self.terrain_segments:
segment.body.position = (
segment.body.position[0] - scroll_offset,
segment.body.position[1],
)
self.space.reindex_shapes_for_body(segment.body)

def init_pymunk_polygon(self, space) -> None:
for segment in self.terrain_segments:
Expand Down Expand Up @@ -429,4 +430,4 @@ def generate_y(self, x: int) -> int:

def __cosine_interp(self, a, b, x) -> float:
x2 = (1 - math.cos(x * math.pi)) / 2
return a * (1 - x2) + b * x2
return a * (1 - x2) + b * x2

0 comments on commit 80b74b1

Please sign in to comment.