Skip to content

Commit

Permalink
starting final boss work
Browse files Browse the repository at this point in the history
sprite done, spawning functional, behavior #1 started.  Boss room
transition and screen bounds functional.
  • Loading branch information
Will Taplin committed Jun 2, 2014
1 parent 0d6a761 commit 4054995
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 30 deletions.
17 changes: 15 additions & 2 deletions bullets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from engine.system import TIMESTEP
from engine.system import SCREEN_RECT

LAST_LEVEL_SCREEN_RECT = pygame.rect.Rect(0,64,320,144)

class Bullet(pygame.sprite.Sprite):
""" Abstract class for a bullet """
def __init__(self, x, y, angle, image):
Expand All @@ -35,8 +37,10 @@ def __init__(self, x, y, angle, image):
self.hb_offsety = 0
self.destroyable = True

def update(self):
pass
def update(self, *args):
game = args[2]
if game.current_level == 6:
self.bounds = LAST_LEVEL_SCREEN_RECT

class BasicBullet(Bullet):
""" Player bullet class, sub-class of Bullet
Expand Down Expand Up @@ -99,6 +103,9 @@ def __init__(self, x, y, angle, speed, image):
self.dy + self.hb_offsety, 6, 6)

def update(self, *args):
#call Bullet update for last level screen bounds
Bullet.update(self, *args)

# calculate change in x,y
self.dx += (math.cos(self.radians) * self.speed) * TIMESTEP
self.dy += (math.sin(self.radians) * self.speed) * TIMESTEP
Expand Down Expand Up @@ -126,6 +133,9 @@ def __init__(self, x, y, angle, image):
self.dy + self.hb_offsety, 6, 6)

def update(self, *args):
#call Bullet update for last level screen bounds
Bullet.update(self, *args)

# calculate change in x,y
self.dx += (math.cos(self.radians) * self.speed) * TIMESTEP
self.dy += (math.sin(self.radians) * self.speed) * TIMESTEP
Expand Down Expand Up @@ -238,6 +248,9 @@ def __init__(self, x, y, angle, images):
self.speed = 35

def update(self, *args):
#call Bullet update for last level screen bounds
Bullet.update(self, *args)

# calculate change in x,y
self.dx += (math.cos(self.radians) * self.speed) * TIMESTEP
self.dy += (math.sin(self.radians) * self.speed) * TIMESTEP
Expand Down
54 changes: 52 additions & 2 deletions enemies.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __init__(self, game, x, y, has_powerup, images):
self.hitbox = pygame.Rect(self.dx + self.hb_offsetx,
self.dy + self.hb_offsety, 18, 13)
self.points = 175
self.powerup_type = 0
self.powerup_type = 0 # spreader

def update(self, *args):
# call parent classes update method
Expand Down Expand Up @@ -217,6 +217,10 @@ def update(self, *args):
current_time = args[0]
engine.objects.AnimatedSprite.update(self, current_time)

# smaller vertical bounds on the last level
if self.game.current_level == 6:
self.bounds = self.game.game_world_last_level

shot = None

# Move vertically on the screen, reversing direction
Expand Down Expand Up @@ -673,4 +677,50 @@ def update(self, *args):

def spawn(self, current_time):
self.dx = self.bounds.left - self.rect.width
self.last_shift = current_time
self.last_shift = current_time

class Boss(Enemy1):
def __init__(self, game, x, y, has_powerup, images):
Enemy1.__init__(self, game, x, y, has_powerup, images)
self.x = x
self.speed = 50
self.bounds = game.game_world_boss_level
self.hb_offsetx = 26 # offset for hitbox
self.hb_offsety = 24
self.hitbox = pygame.Rect(self.dx + self.hb_offsetx,
self.dy + self.hb_offsety, 10, 8)
self.direction = [0,-1]
self.begin_time = 3000
self.change_pattern = 9000
self.behavior_1 = True
self.behavior_2 = False


def spawn(self, current_time):
self.dx = self.x
self.spawn_time = current_time

def update(self, *args):
current_time = args[0]
engine.objects.AnimatedSprite.update(self, current_time)

if current_time - self.spawn_time > self.begin_time:
if self.direction[1] == -1: # moving up
self.dy -= self.speed * TIMESTEP
if self.dy <= self.bounds.top:
self.dy = self.bounds.top
self.direction[1] = 1
if self.direction[1] == 1: # moving down
self.dy += self.speed * TIMESTEP
if self.dy + self.image.get_height() >= self.bounds.bottom:
self.dy = self.bounds.bottom - self.image.get_height()
self.direction[1] = -1

# update the rect
self.rect.x = self.dx
self.rect.y = self.dy
self.hitbox.x = self.rect.x + self.hb_offsetx
self.hitbox.y = self.rect.y + self.hb_offsety



28 changes: 24 additions & 4 deletions engine/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,34 @@ def __init__(self, game, background, auto_scroll = True):
self.height = 240 # height of screen
self.coordinate = 0 # left edge of viewport
self.last_coordinate = 0
self.level_pos = 0
self.level_pos = 11000
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
self.vp = self.background.subsurface((self.coordinate, 0,
self.width, self.height))
self.boss_level = False
self.call_once = False

def update(self):

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

self.coordinate += self.advance_velocity * system.TIMESTEP
self.level_pos += self.advance_velocity * system.TIMESTEP
self.coordinate += self.advance_velocity * system.TIMESTEP
self.level_pos += self.advance_velocity * system.TIMESTEP

# loop image
if self.coordinate > self.maxScroll:
if not self.game.boss_level_triggered:
self.last_coordinate = 0
self.coordinate = 0
else:
self.coordinate = 640
self.game.paused = True
self.background = self.game.image_manager.get_image('closed')
self.coordinate = 0
self.game.boss_level = True

def draw(self, screen):
# create new subsurface from updated coordinate
Expand All @@ -137,6 +147,16 @@ def draw(self, screen):
self.vp = self.background.subsurface((draw_pos, 0, self.width,
self.height))
screen.blit(self.vp, (0,0))

def transition_to(self, new_background):
if not self.call_once:
surf_width = self.background.get_width() + new_background.get_width()
surface = pygame.Surface((surf_width, self.height)).convert()
surface.blit(self.background, (0,0))
surface.blit(new_background, (self.background.get_width(),0))
self.background = surface
self.maxScroll = 640
self.call_once = True

class FadeAnimation():
""" fade in/fade out screen animation
Expand Down
12 changes: 11 additions & 1 deletion game.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ def __init__(self):
self.text_color = (252,248,252)
self.load_content()
pygame.display.set_icon(self.image_manager.get_image('icon'))
self.current_level = 5
self.current_level = 6
self.boss_level = False
self.boss_level_triggered = False
self.hud = hud.GameHud(self, (320, 32), (0,0,0))
self.game_world = pygame.rect.Rect(0, SCREEN_RECT.top + self.hud.height,
320, SCREEN_RECT.height - self.hud.height)
self.game_world_last_level = pygame.rect.Rect(0,
SCREEN_RECT.top + self.hud.height + 32,
320,
SCREEN_RECT.height - self.hud.height - 64)
self.game_world_boss_level = pygame.rect.Rect(16,SCREEN_RECT.top + self.hud.height + 16,
SCREEN_RECT.right - 32,
SCREEN_RECT.height - self.hud.height - 32)
self.player = player.Player(self, 16, 112,
self.image_manager.get_image('ship'))

Expand Down Expand Up @@ -106,6 +115,7 @@ def load_content(self):
False, -1)
self.image_manager.load_single('smallship.bmp', 'smallship',
(255,0,255))
self.image_manager.load_sheet('boss.bmp', 'boss', 64, 96, False, -1)

# load sounds
self.sound_manager.load_sound('cursor.wav', 'cursor',
Expand Down
6 changes: 6 additions & 0 deletions player.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def __init__(self, game, x, y, images):
def update(self, *args):
current_time = args[0]

if self.game.current_level >= 6:
if self.game.boss_level:
self.bounds = self.game.game_world_boss_level
else:
self.bounds = self.game.game_world_last_level

# show correct frame
self.image = self.images[self.frame]
self.current_weapon = self.weapons[self.current_weapon_index]
Expand Down
Binary file modified res/images/background6.bmp
Binary file not shown.
Binary file added res/images/boss.bmp
Binary file not shown.
Binary file added res/images/closed.bmp
Binary file not shown.
Binary file added res/images/open.bmp
Binary file not shown.
6 changes: 0 additions & 6 deletions res/levels/level_6.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
begin_enemy type enemy_12 x 900 y 64 has_powerup True end_enemy

begin_enemy type enemy_14 x 900 y 140 has_powerup False end_enemy

begin_enemy type enemy_13 x 1300 y 64 has_powerup False end_enemy

begin_enemy type enemy_15 x 1800 y 64 has_powerup False end_enemy
7 changes: 5 additions & 2 deletions sprite_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class SpriteManager(engine.objects.SpriteManager):
""" Container for all game sprite groups and their sprites.
Can update and draw all groups with respective methods.
Also handles the loading of level files and the creation of enemies """
def __init__(self):
def __init__(self, game):
engine.objects.SpriteManager.__init__(self)
# Create all sprite groups and add them to
# self.objects
self.game = game
player_group = pygame.sprite.Group()
enemy_group = pygame.sprite.Group()
player_shots = pygame.sprite.Group()
Expand All @@ -50,7 +51,7 @@ def update(self, current_time, viewport, player_rect):

for key in self.update_order:
for sprite in self.sprites[key]:
enemy_bullet = sprite.update(current_time, player_rect)
enemy_bullet = sprite.update(current_time, player_rect, self.game)
if enemy_bullet is not None:
self.add_sprite(enemy_bullet, 'enemy_shots')

Expand Down Expand Up @@ -233,6 +234,8 @@ def create_enemy(self, game, enemy_type, x, y, has_powerup):
enemy = enemies.Enemy14(game, x, y, has_powerup, images)
elif enemy_type == 'enemy_15':
enemy = enemies.Enemy15(game, x, y, has_powerup, images)
elif enemy_type == 'boss':
enemy = enemies.Boss(game, x, y, has_powerup, images)

# Add enemy to enemy queue
self.enemy_queue.append(enemy)
Expand Down
36 changes: 23 additions & 13 deletions states.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def draw(self, screen):
class GameState(engine.system.State):
def __init__(self, game):
engine.system.State.__init__(self, game)
self.sprite_manager = sprite_manager.SpriteManager()
self.sprite_manager = sprite_manager.SpriteManager(game)
self.font = game.font
self.text_color = game.text_color
self.level = game.current_level
Expand All @@ -85,6 +85,8 @@ def load_content(self):
# load images
background = 'background%d.bmp' % self.level
self.game.image_manager.load_single(background, 'background')
self.game.image_manager.load_single('open.bmp','open')
self.game.image_manager.load_single('closed.bmp','closed')

def unload_content(self):
self.game.image_manager.unload_image('background')
Expand Down Expand Up @@ -123,8 +125,7 @@ def activate(self, transition):
level_string = "LEVEL %d" % self.level
self.message = engine.gui.Message(self.game, level_string, 4000)
self.show_message = True


self.boss_spawned = False

def reactivate(self, transition):
engine.system.State.reactivate(self, transition)
Expand All @@ -141,10 +142,11 @@ def handle_input(self):

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

def update(self):
print (self.viewport.level_pos + self.game.game_world.width) / 16
#print (self.viewport.level_pos + self.game.game_world.width) / 16

engine.system.State.update(self)

Expand Down Expand Up @@ -175,8 +177,9 @@ def update(self):
self.game.push_state(state)

# If player has reached the end of the level, create a
# level complete message, set game over to True.
if self.viewport.level_pos > 11500:
# level complete message
print self.viewport.level_pos
if self.viewport.level_pos > 11500: #1150
end = self.game.next_level()
if not end: # go to next level
text = ["LEVEL %d COMPLETE!" % self.level]
Expand All @@ -186,12 +189,19 @@ def update(self):
self.game.player.reset_pos()
self.game.push_state(state)

else: # show ending
text = ["GAME OVER"]
state = engine.objects.EventState(self.game, text,
None,
TitleScreenState(self.game))
self.game.push_state(state)
else: # trigger boss level
self.game.boss_level_triggered = True
self.viewport.transition_to(self.game.image_manager.get_image('open'))

# boss level fully on screen
if self.game.boss_level == True:
# spawn boss once
if not self.boss_spawned:
self.sprite_manager.create_enemy(self.game,
'boss',235,
59 + self.game.hud.height,
False)
self.boss_spawned = True

def draw(self, screen):
# draw the background and all sprites
Expand Down

0 comments on commit 4054995

Please sign in to comment.