Skip to content

Commit

Permalink
Bug fixed: Teleporting players back to level if out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellSalmon committed Aug 25, 2018
1 parent 3ffc3f9 commit 9358c07
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions PLAYER.py
Expand Up @@ -26,6 +26,7 @@ def __init__(self, pos):
self.rect.x = self.real_x
self.rect.y = self.real_y
SETTINGS.player_rect = self.rect
self.last_pos_tile = None

self.mouse = pygame.mouse
self.sensitivity = SETTINGS.sensitivity
Expand Down Expand Up @@ -284,6 +285,36 @@ def update(self, x, y):

SETTINGS.player_map_pos = [int(self.rect.centerx / SETTINGS.tile_size), int(self.rect.centery / SETTINGS.tile_size)]

#check if player is out of bounds and teleport them back.
generator_check_list = [x for x in SETTINGS.walkable_area if x.map_pos == SETTINGS.player_map_pos]
if generator_check_list:
pos = generator_check_list[0].map_pos
else:
pos = []

check_list = SETTINGS.walkable_area + SETTINGS.all_solid_tiles
out_generator = [x for x in check_list if x.map_pos == SETTINGS.player_map_pos]
if out_generator:
pos2 = out_generator[0].map_pos
else:
pos2 = []


if SETTINGS.player_map_pos == pos:
SETTINGS.last_player_map_pos = SETTINGS.player_map_pos
self.last_pos_tile = generator_check_list[0]

elif SETTINGS.player_map_pos != pos2 and SETTINGS.last_player_map_pos:
if self.last_pos_tile:
SETTINGS.player_map_pos = SETTINGS.last_player_map_pos
self.rect.center = self.last_pos_tile.rect.center
SETTINGS.player_rect = self.rect
self.real_x = self.rect.x
self.real_y = self.rect.y




def draw(self, canvas):
pointer = self.direction(0, 10)
p1 = pointer[0] + self.rect.center[0]
Expand Down
1 change: 1 addition & 0 deletions SETTINGS.py
Expand Up @@ -105,6 +105,7 @@
'cspeed' : 0,
}
player = None
last_player_map_pos = None


'''Texture settings'''
Expand Down
Binary file modified data/customLevels.dat
Binary file not shown.
Binary file modified data/settings.dat
Binary file not shown.
Binary file modified data/statistics.dat
Binary file not shown.

0 comments on commit 9358c07

Please sign in to comment.