def update_and_draw(self, time): if self.y > 0: self.y -= 20 self.my_game.get_screen().fill(mygame.Colour(0,0,0)) self.menu_background.update_and_draw(time) self.df.draw_text(VERSION_STRING,10,10, self.my_game.get_screen()) self.my_game.get_screen().blit(self.img,(self.x, self.y)) if self.check_for_starting_demo(time): return (Scene.SCENE_DEMO,0) if not self.start_time: self.start_time = time if time - self.start_time > self.initial_skip_delay: self.menu.update(time) self.menu.draw(self.my_game.get_screen()) if self.menu.is_finished(): if self.menu.action == AbstractMenuController.ACTION_START_GAME: return (Scene.SCENE_END_SUCCESS, 0) elif self.menu.action == AbstractMenuController.ACTION_LOAD_GAME: additional_data = self.menu.additional_data return (Scene.SCENE_LOAD_GAME, additional_data) elif self.menu.action == AbstractMenuController.ACTION_CREDITS: return (Scene.SCENE_CREDITS, 0) else: return (Scene.SCENE_END_FAILURE, 0) return (Scene.SCENE_CONTINUE, 0)
def update_and_draw(self, time): if not self.start_time: self.start_time = time keystate = self.my_game.get_key_pressed() proceed = keystate & self.proceed_button > 0 if proceed and time - self.start_time > self.initial_skip_delay: if self.ticker: self.font.set_text(self.text_loader.get_mission_text(), self.font_rect) self.ticker = False self.pause_time = time self.my_game.get_screen().fill(mygame.Colour(0,0,0)) self.my_game.get_screen().blit(self.img,(self.x, self.y)) self.font.update(time) self.font.draw(self.my_game.get_screen()) if self.deck_man: self.deck_man.update(time) self.deck_man.draw(self.my_game.get_screen()) if self.font.finished(): self.menu.update(time) self.menu.draw(self.my_game.get_screen()) if (time - self.pause_time) > self.delay: if self.menu.is_finished(): return (Scene.SCENE_END_SUCCESS, 0) else: #need to clear the finished flag self.menu.start() return (Scene.SCENE_CONTINUE, 0)
def __init__(self, mixer): TickerFont.__init__(self, mixer, True) self.large_font_width = 9 self.large_font_height = 12 self.small_font_width = 7 self.small_font_height = 11 self.small_font_voffset = 1 large_rows = [] large_rows.append(' !,.0123456789') large_rows.append(':<>\'+&?/') large_rows.append('ABCDEFGHIJKLMN') large_rows.append('OPQRSTUVWXYZ-@') self.large_images, self.large_index = CompositeTileLoader.load_indexed_tiles( 0, 0, self.large_font_width, self.large_font_height, large_rows, 'breedfont.bmp', mygame.Colour(0xff, 0, 0xff)) small_rows = [] small_rows.append(' !,.0123456789') small_rows.append(':<>\'+&?/') small_rows.append('abcdefghijklmn') small_rows.append('opqrstuvwxyz-@') self.small_images, self.small_index = CompositeTileLoader.load_indexed_tiles( 0, 48, self.small_font_width, self.small_font_height, small_rows, 'breedfont.bmp', mygame.Colour(0xff, 0, 0xff)) self.x = 0 self.y = 0 self.text = None self.mode = BreedFont.INSTANT self.full_text = None if RESIZE: self.large_font_width = int(self.large_font_width * RESIZE_FACTOR) self.large_font_height = int(self.large_font_height * RESIZE_FACTOR) self.small_font_width = int(self.small_font_width * RESIZE_FACTOR) self.small_font_height = int(self.small_font_height * RESIZE_FACTOR) self.small_font_voffset = int(self.small_font_voffset * RESIZE_FACTOR)
class Star: WHITE = mygame.Colour(255, 255, 255) BLACK = mygame.Colour(20, 20, 40) LIGHTGREY = mygame.Colour(180, 180, 180) DARKGREY = mygame.Colour(120, 120, 120) def __init__(self, x, y, speed, size): self.x = x self.y = y self.speed = speed self.last_update = 0 self.size = size def update(self, time): if time > self.last_update - DELAY: self.x += self.speed[0] self.y += self.speed[1] self.colour = mygame.randint(0, 16) self.last_update = time def draw(self, screen): if self.colour < 4: colour = Star.BLACK elif self.colour < 10: colour = Star.DARKGREY elif self.colour < 13: colour = Star.LIGHTGREY else: colour = Star.WHITE if self.size == 1: screen.set_at((self.x, self.y), colour) if self.size == 2: screen.set_at((self.x, self.y), colour) screen.set_at((self.x + 1, self.y), colour) screen.set_at((self.x, self.y + 1), colour) screen.set_at((self.x + 1, self.y + 1), colour) if self.size > 3: screen.set_at((self.x, self.y), colour) screen.set_at((self.x + 1, self.y), colour) screen.set_at((self.x, self.y + 1), colour) screen.set_at((self.x + 1, self.y + 1), colour) screen.set_at((self.x + 2, self.y), colour) screen.set_at((self.x + 2, self.y + 1), colour)
def load_tiles(self): rows = [] rows.append(' !"`````()`+,-./0123456789:;{=}?`ABCDEFGHIJKLMNOPQR') rows.append('STUVWXYZ[\\]````````````````````````````````` ') self.images, self.index = CompositeTileLoader.load_indexed_tiles( 0, 0, self.font_width, self.font_height, rows, 'tinyfont.bmp', mygame.Colour(0xff, 0, 0xff))
def fade_red_16bit(self): #For bpp >8 we can't use palette switches so must use an alpha overlay s = self.my_game.get_screen() if not self.countdown_overlay: sw,sh = s.get_width(),s.get_height() self.countdown_overlay = self.level.my_game.create_blank((sw,sh)) self.countdown_overlay.fill(mygame.Colour(0xff, 0, 0)) self.countdown_overlay.set_alpha(128) if not Cheats.getNoCountdown(): s.blit(self.countdown_overlay, (0,0))
def load_tiles(self): rows = [] rows.append(' ABCDEFGHIJKLMNO') rows.append('PQRSTUVWXYZ-+ ') rows.append("0123456789:.',& ") self.images, self.index = CompositeTileLoader.load_indexed_tiles( 0, 0, self.font_width, self.font_height, rows, 'greenfont.bmp', mygame.Colour(0xff, 0, 0xff))
def __init__(self): self.tile_width= 12 self.tile_height = 32 self.trans = mygame.Colour(0xff, 0, 0xff) self.load_tiles() self.x = 0 self.y = 0 self.count = 0 if RESIZE: self.tile_width= int(self.tile_width * RESIZE_FACTOR) self.tile_height = int(self.tile_height * RESIZE_FACTOR)
def update_and_draw(self, time): if not self.finished: if time >= self.last_update + GameOverScene.DELAY: self.last_update = time self.current_frame += 1 if self.current_frame > 8: self.current_frame = 8 self.finished = True else: if time >= self.last_update + GameOverScene.FINISHED_DELAY: return (Scene.SCENE_END_SUCCESS, 0) self.my_game.get_screen().fill(mygame.Colour(0,0,0)) self.my_game.get_screen().blit(self.frames[self.current_frame],(self.x, self.y)) return (Scene.SCENE_CONTINUE, 0)
def update_and_draw(self, time): self.my_game.get_screen().fill(mygame.Colour(0,0,0)) finished = self.draw_content(self.my_game.get_screen(), time) self.menu_background.update_and_draw(time) proceed = False if not self.start_time: self.start_time = time if time - self.start_time > self.delay: keystate = self.my_game.get_key_pressed() proceed = keystate & self.proceed_button > 0 if proceed or finished: return (Scene.SCENE_END_SUCCESS, 0) else: return (Scene.SCENE_CONTINUE, 0)
def __init__(self, x, y, mixer): trans = mygame.Colour(255, 0, 255) self.images, self.tile_width, self.tile_height = CompositeTileLoader.load_tiles("deckman.bmp", 64, 96, trans) self.last_flash_update = 0 self.last_move_update = 0 self.increment = DeckMan.INCR if RESIZE: self.increment = int(self.increment * HUD_RESIZE_FACTOR) self.x =x self.y = y - self.tile_height self.lift_sound = mixer.Sound(get_sound_pathname(LIFT_SOUND)) self.lift_sound.set_volume(32) if not Cheats.getNoAudio(): self.lift_sound.play() self.current_frame = 0
def __init__(self, my_game, menu_background): Scene.__init__(self, 'menu') self.my_game = my_game self.menu_background = menu_background self.img = mygame.load_image(get_image_pathname('alienhead.bmp')) if RESIZE: self.img = self.img.scale((int(self.img.get_width()*RESIZE_FACTOR),int(self.img.get_height() *RESIZE_FACTOR))) trans = mygame.Colour(255, 0, 255) self.img.set_colorkey(trans) self.x=(SCREEN_X - self.img.get_height()) /2 self.y= SCREEN_Y +100 key_set = KeySet.load_key_set() self.proceed_button = key_set.fire self.df = DebugFont() self.menu = GameMenu(my_game)
def update_and_draw(self, time): if not self.start_time: self.start_time = time keystate = self.my_game.get_key_pressed() proceed = keystate & self.proceed_button > 0 if proceed: if self.font.finished(): return (Scene.SCENE_END_SUCCESS, 0) self.my_game.get_screen().fill(mygame.Colour(0,0,0)) self.my_game.get_screen().blit(self.img,(self.x, self.y)) self.font.update(time) self.font.draw(self.my_game.get_screen()) return (Scene.SCENE_CONTINUE, 0)
def load_tiles(self): self.trans = mygame.Colour(0xff,0,0xff) self.tile_width = 256 self.tile_height = 128 self.images, self.tile_width, self.tile_height = CompositeTileLoader.load_tiles(WEAPON_IMAGES, self.tile_width, self.tile_height, self.trans, HUD_RESIZE_FACTOR)
def start(self): self.img = mygame.load_image(get_image_pathname('IntexBG.bmp')) self.img.set_colorkey(mygame.Colour(0xff, 0, 0xff)) if RESIZE: self.img = self.img.scale((int(self.img.get_width()*HUD_RESIZE_FACTOR),int(self.img.get_height() *HUD_RESIZE_FACTOR)))
def draw(self, screen): screen.fill(mygame.Colour(0,0,0)) self.menu_background.draw(screen) menu = self.get_current_menu() menu.draw(screen)
def load_units(self, unit_set): print_debug("Unit load units", 5) time = self.my_game.get_ticks() mixer = self.my_game.get_mixer() #Load the alien units (not referenced by level data)... for file in ('enemy1.uni','enemy2.uni','enemy3.uni','enemy4.uni', 'enemy5.uni', 'enemy6.uni', 'enemy7.uni', 'enemy8.uni', 'enemy9.uni', 'firebossworm.uni'): unit = U.UnitFactory.create_unit(file, mygame.Colour(0xff, 0, 0xff), mixer, self, time) unit_set.add_alien_prototype(file, unit) for u in self.level_unit_instances: unit = U.UnitFactory.create_level_unit(u, mygame.Colour(0xff, 0, 0xff), mixer, self, time) #Keep note of the special units... print_debug(u.name, 5) if u.name == 'Player': unit_set.set_player_unit(unit) unit.set_player_stats(self.initial_player_stats) #Use level configured starting health if set if self.initial_player_health: unit.get_player_stats().set_health(self.initial_player_health) #clear the bluepass as you loose this at start of level unit.get_player_stats().blue_pass = False print_debug("Player at %f,%f"%(u.tileposx, u.tileposy),2) elif u.name == 'GunFire' or u.file == 'gunfire.uni': #not all levels have a name configured for gunfire unit_set.set_gun_flare_unit(unit) elif u.name == 'Boss': unit_set.add_alien(unit) #level6 seems to include an enemy so need to check for that here elif u.file == 'enemy5.uni': unit_set.add_alien(unit) elif u.file == 'lift.uni': unit_set.add_lift(unit) elif unit.unit_definition.object_type == 'door': unit_set.add_door(unit) else: #add as a static unit unit_set.add_unit(unit) # keep a count of every dome created if unit.unit_definition.ai_type == 'dome' or unit.unit_definition.ai_type == 'egg' or unit.unit_definition.ai_type == 'hostage': self.level_state.add_dome() #Load the bullet unit (not referenced directly by level data)... for weapon in self.weapons.get_all_weapons(): file = weapon.projectile #pygame.Color("#0000FF") unit = U.UnitFactory.create_unit(file, mygame.Colour(0xff, 0, 0xff), mixer, self, time) unit.set_additional_profile(weapon) unit_set.add_bullet_prototype(file, unit) #Load the small explosions... unit = U.UnitFactory.create_unit('explosionsmall.uni', mygame.Colour(0xff, 0, 0xff), mixer, self, time) unit_set.set_small_explosion_unit(unit) #Load the big explosions.... unit = U.UnitFactory.create_unit('explosionbig.uni', mygame.Colour(0xff, 0, 0xff), mixer, self, time) unit_set.set_big_explosion_unit(unit)
def clear_background(self, s): s.fill(mygame.Colour(0,0,0))
def __init__(self, player_stats, my_game): self.player_stats = player_stats self.my_game = my_game self.hud_img = mygame.load_image(get_image_pathname(HUD_IMAGE)) self.hud_gold = mygame.load_image(get_image_pathname(HUD_GOLD_IMAGE)) self.hud_gold_big_blip = my_game.create_blank( (2, self.hud_gold.get_height())) self.hud_gold_big_blip.blit(self.hud_gold, self.hud_gold_big_blip.get_rect(), self.hud_gold_big_blip.get_rect()) self.hud_gold_plus = mygame.load_image( get_image_pathname(HUD_GOLD_PLUS)) self.hud_gold_plus.set_colorkey(mygame.Colour(0xff, 0, 0xff)) self.hud_gold_small_blip = my_game.create_blank( (1, self.hud_gold.get_height())) self.hud_gold_small_blip.blit(self.hud_gold, self.hud_gold_small_blip.get_rect(), self.hud_gold_small_blip.get_rect()) self.health_bar_x = 32 self.lives_x = 134 self.big_tick_x_increment = 4 self.small_tick_x_increment = 2 self.ammo_x = 206 self.small_ammo_x = 250 self.keys_x = 337 self.health_bars = dict() if RESIZE: self.hud_img = self.hud_img.scale( (int(self.hud_img.get_width() * HUD_RESIZE_FACTOR), int(self.hud_img.get_height() * HUD_RESIZE_FACTOR))) self.hud_gold = self.hud_gold.scale( (int(self.hud_gold.get_width() * HUD_RESIZE_FACTOR), int(self.hud_gold.get_height() * HUD_RESIZE_FACTOR))) self.hud_gold_big_blip = self.hud_gold_big_blip.scale( (int(self.hud_gold_big_blip.get_width() * HUD_RESIZE_FACTOR), int(self.hud_gold_big_blip.get_height() * HUD_RESIZE_FACTOR))) self.hud_gold_small_blip = self.hud_gold_small_blip.scale( (int(self.hud_gold_small_blip.get_width() * HUD_RESIZE_FACTOR), int(self.hud_gold_small_blip.get_height() * HUD_RESIZE_FACTOR))) self.hud_gold_plus = self.hud_gold_plus.scale( (int(self.hud_gold_plus.get_width() * HUD_RESIZE_FACTOR), int(self.hud_gold_plus.get_height() * HUD_RESIZE_FACTOR))) self.health_bar_x = int(self.health_bar_x * HUD_RESIZE_FACTOR) self.lives_x = int(self.lives_x * HUD_RESIZE_FACTOR) self.big_tick_x_increment = int(self.big_tick_x_increment * HUD_RESIZE_FACTOR) self.ammo_x = int(self.ammo_x * HUD_RESIZE_FACTOR) self.keys_x = int(self.keys_x * HUD_RESIZE_FACTOR) self.small_tick_x_increment = int(self.small_tick_x_increment * HUD_RESIZE_FACTOR) self.small_ammo_x = int(self.small_ammo_x * HUD_RESIZE_FACTOR)
def __init__(self): self.trans_set2 = mygame.Colour(0xff,0,0xff)