Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KeTr committed Jan 28, 2024
2 parents 1296784 + 909a9f9 commit a1467ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
20 changes: 13 additions & 7 deletions Feather.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,23 @@ def update_phys(self, dt, fluid):

def updatePosition(self, dt):
potential_pos = self.pos + self.v * dt
nbr_wall = self.detectWall(potential_pos)

# NOTE TO FUTURE SELF: ALWAYS CHECK HORIZ/VERT SEPERATELY!!

# horizontal check
nbr_wall = self.detectWall((potential_pos[0], self.pos[1]))
if nbr_wall is not None:
if nbr_wall[0] != 0: # left/right wall
self.v[0] = -self.v[0] /10 # fudge v to not get stuck in wall

# vertical check
nbr_wall = self.detectWall((self.pos[0], potential_pos[1]))
if nbr_wall is not None:
if nbr_wall[1] != 0: # top/bottom wall
self.v[1] = -self.v[1] /10 # fudge v to not get stuck in wall

corrected_pos = self.pos + self.v * dt
self.pos = corrected_pos
else:
self.pos = potential_pos
corrected_pos = self.pos + self.v * dt
self.pos = corrected_pos

def render(self, screen):
feather = self.feather_sprites[self.anim_cnt]
Expand All @@ -85,12 +91,12 @@ def getBoundingBox(self, pos=None):

def detectWall(self, potential_pos):

# 1 3
# 0 2
# o----o
# | |
# | |
# o----o
# 2 4
# 1 3

collision_point = np.copy(potential_pos)
bbox = self.getBoundingBox(collision_point)
Expand Down
7 changes: 6 additions & 1 deletion __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,12 @@ def updateStreamLines(self):
if len(points) > 1:
points = [(self.cam.gridToScreen(x_, y_), v) for (x_, y_, v) in points]
points = [p[0] for p in points]
pygame.draw.lines(self.streamLines, pygame.Color(80, 110, 140, 255), False, points)

r = int(min(255, self.backgroundColor[0] + len(points) * 1.25))
g = int(min(255, self.backgroundColor[1] + len(points) * 1.25))
b = int(min(255, self.backgroundColor[2] + len(points) * 1.25))

pygame.draw.lines(self.streamLines, pygame.Color(r, g, b, 255), False, points)

def showStreamLines(self):
self.updateStreamLines()
Expand Down
12 changes: 6 additions & 6 deletions levels/3.lvl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
d------------------------------b
l d----------------b3 * l
q---p d-----------b ne l
# d-p ///l 3 Y l
# u l //l e Y l
# l l /l E Yd--p
q---p d-----------b ne X l
# d-p ///l 3 c#Y l
# u l //l e ## l
# l l /l E ##d--p
# l l d--+-b l c##l
# l l l l l u ##l
# q--p n T l q+p ##l
#T ww l l
## u ww l ww d-p
do----oop ww n ww q----b
n ww ww l
ww ww l
F ww mmmmm ww l
Y T ww ww l
F ### ww mmmmm ww l
-------------------------------p

0 comments on commit a1467ba

Please sign in to comment.