Skip to content

Commit

Permalink
bug fix for pausing during boss battle
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Taplin committed Jun 3, 2014
1 parent 4054995 commit 05a25b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions engine/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self, game, background, auto_scroll = True):
self.coordinate = 0 # left edge of viewport
self.last_coordinate = 0
self.level_pos = 11000
self.draw_pos = 0
self.minScroll = 0 # max value for left scrolling
self.maxScroll = self.background.get_width() - 320 # max for right
self.advance_velocity = 100 # speed of scroll
Expand All @@ -121,7 +122,7 @@ def __init__(self, game, background, auto_scroll = True):

def update(self):

if not self.game.paused:
if not self.game.paused and not self.game.boss_level:
self.last_coordinate = self.coordinate

self.coordinate += self.advance_velocity * system.TIMESTEP
Expand All @@ -143,7 +144,7 @@ def draw(self, screen):
# create new subsurface from updated coordinate
# draw it to the screen
draw_pos = self.game.interpolate_draw(self.coordinate,
self.last_coordinate)
self.last_coordinate, self.game.boss_level)
self.vp = self.background.subsurface((draw_pos, 0, self.width,
self.height))
screen.blit(self.vp, (0,0))
Expand Down
10 changes: 7 additions & 3 deletions engine/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,15 @@ def change_state(self, state, transition = None):
self.states.append(state)
state.activate(transition)

def interpolate_draw(self, current, last):
def interpolate_draw(self, current, last, boss_level):
# returns an interpolated draw position

if not self.paused:
draw_pos = current * self.alpha + last * (1.0 - self.alpha)
else:
draw_pos = current * self.alpha + last * (1.0 - self.alpha)
# if in boss level, background is not scrolling, always return 0
if boss_level:
draw_pos = 0
else: # if paused return the last coordinate passed in
draw_pos = current
return draw_pos

Expand Down
5 changes: 2 additions & 3 deletions states.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def handle_input(self):

# On start button press, push the pause state
if self.game.input_manager.is_pressed('START'):
if not self.game.boss_level:
self.game.push_state(PauseState(self.game))
self.game.push_state(PauseState(self.game))

def update(self):
#print (self.viewport.level_pos + self.game.game_world.width) / 16
Expand Down Expand Up @@ -178,7 +177,7 @@ def update(self):

# If player has reached the end of the level, create a
# level complete message
print self.viewport.level_pos
#print self.viewport.level_pos
if self.viewport.level_pos > 11500: #1150
end = self.game.next_level()
if not end: # go to next level
Expand Down

0 comments on commit 05a25b9

Please sign in to comment.