def render(self, screen): if self.ship: font = data.font("Pieces-of-Eight.ttf", 18) screen.blit(font.render(objects.ship_types[self.ship.type]["fancy"], 1, (0,0,0)), (105, 380)) screen.blit(self.ship.image, (110, 400)) new = pygame.Surface((300, 100)).convert_alpha() new.fill((0,0,0,0)) overs = [] cur_x = 0 cur_y = 5 for i in ["Hull: %s/%s"%(self.ship.hull, self.ship.hull_max), "Crew: %s/%s"%(self.ship.crew, self.ship.crew_max), "Speed: %s/%s"%(self.ship.speed, self.ship.speed_max), "String: %s"%(self.ship.string), "BR", "Hold:", "Gold: %s"%self.ship.resources.gold, "Crew: %s"%self.ship.resources.crew, "String: %s"%self.ship.resources.string]: if i == "BR": cur_x = max(overs)+15 cur_y = 5 continue v = font.render(i, 1, (0, 0, 0)) overs.append(v.get_rect().width) r = v.get_rect() r.left = cur_x r.top = cur_y cur_y += r.height new.blit(v, r) screen.blit(new, (190, 390))
def __init__(self, state, app): self.state = state self.app = app self.buttons = [] button1 = gui.Button(self.app, (125, 390), "TBBB-junk", "Junk", "topleft", icon="junk.png") button2 = gui.Button(self.app, (125, button1.rect.bottom+5), "TBBB-frigate", "Frigate", "topleft", icon="frigate.png") button3 = gui.Button(self.app, (button1.rect.right+5, 390), "TBBB-juggernaut", "Juggernaut", "topleft", icon="juggernaut.png") button4 = gui.Button(self.app, (button1.rect.right+5, button1.rect.bottom+5), "TBBB-flyingdutchman", "Flying Dutchman", "topleft", icon="flyingdutchman.png") button1.over_width = button4.rect.width button1.make_image() button2.over_width = button4.rect.width button2.make_image() button3.over_width = button4.rect.width button3.make_image() button3.rect.left = button1.rect.right + 5 button4.rect.left = button1.rect.right + 5 self.buttons.append(button1) self.buttons.append(button2) self.buttons.append(button3) self.buttons.append(button4) font = data.font("Pieces-of-Eight.ttf", 18) h = font.get_height() values = ("hull", "crew", "speed", "hold_capacity", "damage_multiplier", "cost") nh = h * (len(values) + 3) surfs = {} for i in objects.ship_types: if i in ["junk", "frigate", "juggernaut", "flyingdutchman"]: #hack, remove once we have all the ships in!!! new = pygame.Surface((250, nh)).convert() cur_i = 5 new.blit(font.render("name: "+objects.ship_types[i]["fancy"], 1, (255, 255, 255)), (5, cur_i)) cur_i += h for x in values: new.blit(font.render(x.replace("_", " ")+": "+str(objects.ship_types[i][x]), 1, (255, 255, 255)), (5, cur_i)) cur_i += h new.blit(font.render("crew cost: "+str(objects.ship_types[i]["crew"]), 1, (255, 255, 255)), (5, cur_i)) new.set_alpha(150) surfs[i] = new self.r = pygame.Rect(0,0,250,nh) self.r.bottom = 380 self.s = surfs self.inactive()
def __init__(self, player, world): self.player = player self.world = world self.font = data.font("Pieces-of-Eight.ttf", 18) self.t = None self.active = False
def main(): pygame.init() screen = pygame.display.set_mode((640, 480)) game_size = (640, 350) map_size = (1600, 1600) # Best as a multiple of 82 (or minimap size) screen_rect = pygame.Rect(0, 30, 640, 350) game_screen = screen.subsurface(screen_rect) import os pygame.mixer.music.load(os.path.join('data', 'music', 'rio_grande.ogg')) pygame.mixer.music.play(-1) world = World(game_size, map_size, screen_rect, screen) state = State(world) state.add_player() state.add_player(AIController) gamehud = hud.Hud(screen, state) font = data.font(None, 30) while 1: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() return None if event.type == KEYDOWN and event.key == K_s: pygame.image.save(screen, "screenie.tga") if event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() return None x = gamehud.event(event) if x: state.event(x) gamehud.update() state.update() x, y = pygame.mouse.get_pos() if x <= 5: world.camera.move(-5, 0) if x >= 635: world.camera.move(5, 0) if y <= 5: world.camera.move(0, -5) if y >= 475: world.camera.move(0, 5) world.render(game_screen) state.render(game_screen) gamehud.render() pygame.display.flip()
def set_to(self, ship1, ship2, window): self.ship1 = ship1 self.ship2 = ship2 self.window = window x, y = self.window.rect.topleft font = data.font("Pieces-of-Eight.ttf", 18) h = font.get_height() values = ("hull", "crew", "speed", "damage_multiplier") nh = h * 6 cur_i = 75 self.l1_shipt = gui.Label(self.window, (5, cur_i), "L1_shipt", ship1.type) self.l1_shipt.theme.label["text-color"] = (255, 255, 255) self.l1_shipt.make_image() cur_i += h self.l1_hull = gui.Label(self.window, (5, cur_i), "L1_hull", "hull:"+str(ship1.hull)+"/"+str(ship1.hull_max)) cur_i += h self.l1_crew = gui.Label(self.window, (5, cur_i), "L1_crew", "crew:"+str(ship1.crew)+"/"+str(ship1.crew_max)) cur_i += h self.l1_speed = gui.Label(self.window, (5, cur_i), "L1_speed", "speed:"+str(ship1.speed)+"/"+str(ship1.speed_max)) cur_i += h self.l1_dm = gui.Label(self.window, (5, cur_i), "L1_dm", "damage multiplier:"+str(ship1.damage_multiplier)) cur_i = 75 self.l2_shipt = gui.Label(self.window, (165, cur_i), "L1_shipt", ship2.type) self.l2_shipt.make_image() cur_i += h self.l2_hull = gui.Label(self.window, (165, cur_i), "L1_hull", "hull:"+str(ship2.hull)+"/"+str(ship2.hull_max)) cur_i += h self.l2_crew = gui.Label(self.window, (165, cur_i), "L1_crew", "crew:"+str(ship2.crew)+"/"+str(ship2.crew_max)) cur_i += h self.l2_speed = gui.Label(self.window, (165, cur_i), "L1_speed", "speed:"+str(ship2.speed)+"/"+str(ship2.speed_max)) cur_i += h self.l2_dm = gui.Label(self.window, (165, cur_i), "L1_dm", "damage multiplier:"+str(ship2.damage_multiplier)) self.select_type_msg = gui.Label(self.window, (75, 190), "attack_type", "Select attack type!") self.widgets = [self.l1_shipt, self.l1_hull, self.l1_crew, self.l1_speed, self.l1_dm, self.l2_shipt, self.l2_hull, self.l2_crew, self.l2_speed, self.l2_dm, self.select_type_msg]
def __init__(self, pos): self.pos = pos self.image = random.choice([data.image("island.png"), data.image("island2.png"), data.image("island3.png")]) self.rect = self.image.get_rect() self.rect.center = self.pos self.capitol = False self.capitol_image = data.image("island_capitol-test.png") self.cap_rect = self.capitol_image.get_rect() self.cap_rect.midbottom = self.rect.center self.resources = [] # can be gold, crew and string self.font = data.font(None, 20)
def __init__(self, screen_size=(640, 480), world_size = (5000, 5000), screen_rect=(640, 480), screen=None): self.ssize = screen_size self.wsize = world_size self.mo = MapObject(self.wsize, self) self.tile_image = data.image("water.png") self.rock = data.image("rock.png") self.cur_timer = 0 self.cur_cycle = 0 self.camera = Camera(self.ssize, self.wsize, screen_rect) self.islands = [] self.make_islands() self.font = data.font(None, 30) self.font2 = data.font("Pieces-of-Eight.ttf", 25) self.screen = screen
def set_to(self, ship1, ship2, battle, window): #attack_print((ship1, ship2), battle) # For debugging self.ship1 = ship1 self.ship2 = ship2 self.battle = battle self.window = window d1 = battle.results['damage'][ship1] d2 = battle.results['damage'][ship2] x, y = self.window.rect.topleft font = data.font("Pieces-of-Eight.ttf", 18) h = font.get_height() values = ("hull", "crew", "speed") nh = h * 9 cur_i = 5 surf1 = pygame.Surface((150, nh)).convert_alpha() surf1.fill((0,0,0,0)) surf1.blit(font.render("Attacker", 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf1.blit(font.render(ship1.type, 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf1.blit(font.render("hull damage:"+str(d1[0]), 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf1.blit(font.render("hull:"+self._fix_zero(str(ship1.hull)+"/"+str(ship1.hull_max)), 1, (255, 255, 255)), (5, cur_i)) cur_i += h+5 surf1.blit(font.render("crew lost:"+str(d1[1]), 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf1.blit(font.render("crew: "+self._fix_zero(str(ship1.crew)+"/"+str(ship1.crew_max)), 1, (255, 255, 255)), (5, cur_i)) cur_i += h+5 surf1.blit(font.render("speed penalty:"+str(d1[2]), 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf1.blit(font.render("speed:"+self._fix_zero(str(ship1.speed)+"/"+str(ship1.speed_max)), 1, (255, 255, 255)), (5, cur_i)) self.surf1 = surf1 self.rect1 = surf1.get_rect() self.rect1.topleft = (3+x, 50+y) cur_i = 5 surf2 = pygame.Surface((150, nh)).convert_alpha() surf2.fill((0,0,0,0)) surf2.blit(font.render("Defender", 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf2.blit(font.render(ship2.type, 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf2.blit(font.render("hull damage:"+str(d2[0]), 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf2.blit(font.render("hull:"+self._fix_zero(str(ship2.hull)+"/"+str(ship2.hull_max)), 1, (255, 255, 255)), (5, cur_i)) cur_i += h+5 surf2.blit(font.render("crew lost:"+str(d2[1]), 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf2.blit(font.render("crew:"+self._fix_zero(str(ship2.crew)+"/"+str(ship2.crew_max)), 1, (255, 255, 255)), (5, cur_i)) cur_i += h+5 surf2.blit(font.render("speed penalty:"+str(d2[2]), 1, (255, 255, 255)), (5, cur_i)) cur_i += h surf2.blit(font.render("speed:"+self._fix_zero(str(ship2.speed)+"/"+str(ship2.speed_max)), 1, (255, 255, 255)), (5, cur_i)) self.surf2 = surf2 self.rect2 = surf2.get_rect() self.rect2.topright = (307+x, 50+y) surf3 = pygame.Surface((250, 50)).convert_alpha() surf3.fill((0,0,0,0)) if battle.results['captured'] == 0: ship1.sink() ship2.sink() surf3 = font.render("Both ships were sent to Davey Jones' Locker!", 1, (255, 255, 255)) elif not ship1.is_alive() and not ship2.is_alive(): ship1.sink() ship2.sink() surf3 = font.render("Both ships were sent to Davey Jones' Locker!", 1, (255, 255, 255)) elif "winner" in battle.results: if not ship1.is_alive(): ship1.sink() surf3 = font.render("Attacker was sent to Davey Jones' Locker!", 1, (255, 255, 255)) elif not ship2.is_alive(): ship2.sink() surf3 = font.render("Defender was sent to Davey Jones' Locker!", 1, (255, 255, 255)) elif battle.results['captured'] != None: captured_ship = battle.results['captured'] if captured_ship == ship1: w = "attacking" ship2.take_ship(ship1) elif captured_ship == ship2: w = "defending" ship1.take_ship(ship2) surf3 = font.render(("The "+w+" ship was captured!"), 1, (255, 255, 255)) else: pass #print 'battle results screwed' else: surf3 = font.render(("The battle was inconclusive."), 1, (255, 255, 255)) self.surf3 = surf3 self.rect3 = surf3.get_rect() self.rect3.center = (150+x, 260+y)
def __init__(self, parent, mode="easy"): GameState.__init__(self, parent) self.screen = self.get_root().screen self.audio = sound.SoundManager('data') pygame.mixer.music.load("data/ants_on_my_lawn.ogg") pygame.mixer.music.set_volume(0.6) pygame.mixer.music.play(-1) #self.audio.sounds['ants_on_my_lawn.ogg'].set_volume(0.6) #self.audio.sounds['ants_on_my_lawn.ogg'].play(loops=-1) self.background = data.image("data/background1.png") self.ui_background = data.image("data/porch_ui.png") self.main_group = objects.GameGroup() self.flying_group = objects.GameGroup() self.hero_group = objects.GameGroup() self.hive_group = objects.GameGroup() self.build_tower_group = objects.GameGroup() self.bot_group = objects.GameGroup() self.tower_group = objects.GameGroup() self.insect_group = objects.GameGroup() self.scraps_group = objects.GameGroup() self.blocking_group = objects.GameGroup() self.bullet_group = objects.GameGroup() self.trap_group = objects.GameGroup() self.special_group = objects.GameGroup() self.damage_notes_group = objects.GameGroup() if mode == "easy": level = 1 scraps = 10 self.money = 500 self.scraps = 500 elif mode=="medium": level = 4 scraps = 6 self.money = 425 self.scraps = 425 else: level = 7 scraps = 3 self.money = 350 self.scraps = 350 self.hive = objects.Hive(self) self.hive.level = level self.hive.max_hp += level self.hive.hp += level self.kills = 0 self.font = data.font("data/font.ttf", 24) self.money_ui = self.font.render("money: %s"%self.money, 1, (255,255,255)) self.money_ui_pos = (0, 530) self.scraps_ui = self.font.render("scraps: %s"%self.scraps, 1, (255,255,255)) self.scraps_ui_pos = (0, 550) self.kills_ui = self.font.render("kills: %s"%self.kills, 1, (255,255,255)) self.kills_ui_pos = (0, 570) self.map_grid = map_grid.MapGrid(self) self.hero = objects.Hero(self) self.map_grid.make_random(random.randint(40, 60), scraps) self.build_active = None self.building = None self.build_overlay = None self.selected_object = None self.selected_ui = None #UI here, so it has access to all the data above! self.app = ui.App(self.screen) ui.Button(self.app, "Quit Game", pos=(0,500), callback=self.goback, status_message="Quit game...?") #Make build objects gui #TODO: implement multiple kinds of warriors/traps!!! l = ui.Label(self.app, "Basic", pos=(180, 500)) ui.LinesGroup(self.app, l) b = ui.Button(self.app, image=objects.TowerBase.ui_icon, pos=l.rect.inflate(0,2).bottomleft, callback=self.build_tower, status_message=("Build a Tower\ncost:\n money: %s\n scraps: %s"+\ "\n----------\nattack: %s\nrange: %s\nspeed: %s")%(objects.TowerBase.money_cost, objects.TowerBase.scrap_cost, objects.TowerBase.base_attack, objects.TowerBase.base_range, objects.TowerBase.base_shoot_speed), anchor="topleft") b = ui.Button(self.app, image=objects.Worker.ui_icon, pos=b.rect.inflate(8,0).topright, callback=self.build_worker, status_message=("Build a Worker\ncost:\n money: %s\n scraps: %s"+\ "\n----------\nattack: %s\nhp: %s\nspeed: %s")%(objects.Worker.money_cost, objects.Worker.scrap_cost, objects.Worker.base_damage, objects.Worker.base_hp, objects.Worker.base_speed), anchor="topleft") self.build_worker_button = b l = ui.Label(self.app, "Warriors ", pos=(250, 500)) ui.LinesGroup(self.app, l) b = ui.Button(self.app, image=objects.BattleBot.ui_icon, pos=l.rect.inflate(0,2).bottomleft, callback=self.build_warrior, status_message=("Build a Warrior\ncost:\n money: %s\n scraps: %s"+\ "\n----------\nattack: %s\nhp: %s\nspeed: %s\nspecial: %s")%(objects.BattleBot.money_cost, objects.BattleBot.scrap_cost, objects.BattleBot.base_damage, objects.BattleBot.base_hp, objects.BattleBot.base_speed, objects.BattleBot.special), anchor="topleft") self.build_warrior_button = b b = ui.Button(self.app, image=objects.TrapperBot.ui_icon, pos=b.rect.inflate(8,0).topright, callback=self.build_trapper, status_message=("Build a Trapper\ncost:\n money: %s\n scraps: %s"+\ "\n----------\nattack: %s\nhp: %s\nspeed: %s\nspecial: %s")%(objects.TrapperBot.money_cost, objects.TrapperBot.scrap_cost, objects.TrapperBot.base_damage, objects.TrapperBot.base_hp, objects.TrapperBot.base_speed, objects.TrapperBot.special), anchor="topleft") self.build_trapper_button = b b = ui.Button(self.app, image=objects.GuardBot.ui_icon, pos=b.rect.inflate(8,0).topright, callback=self.build_guard, status_message=("Build a Guard\ncost:\n money: %s\n scraps: %s"+\ "\n----------\nattack: %s\nhp: %s\nspeed: %s\nspecial: %s")%(objects.GuardBot.money_cost, objects.GuardBot.scrap_cost, objects.GuardBot.base_damage, objects.GuardBot.base_hp, objects.GuardBot.base_speed, objects.GuardBot.special), anchor="topleft") self.build_guard_button = b l = ui.Label(self.app, " Traps ", pos=(370, 500)) ui.LinesGroup(self.app, l) b = ui.Button(self.app, image=objects.SpikeTrap.ui_icon, pos=l.rect.inflate(0,2).bottomleft, callback=self.build_spike_trap, status_message=("Build a Spike Trap\ncost:\n money: %s\n scraps: %s"+\ "\n----------\nattack: %s\nuses: %s\nspecial: %s")%(objects.SpikeTrap.money_cost, objects.SpikeTrap.scrap_cost, objects.SpikeTrap.base_damage, objects.SpikeTrap.base_usage_count, objects.SpikeTrap.special), anchor="topleft") self.build_spike_trap_button = b b = ui.Button(self.app, image=objects.CageTrap.ui_icon, pos=b.rect.inflate(8,0).topright, callback=self.build_cage_trap, status_message=("Build a Cage Trap\ncost:\n money: %s\n scraps: %s"+\ "\n----------\nattack: %s\nuses: %s\nspecial: %s")%(objects.CageTrap.money_cost, objects.CageTrap.scrap_cost, objects.CageTrap.base_damage, objects.CageTrap.base_usage_count, objects.CageTrap.special), anchor="topleft") self.build_cage_trap_button = b b = ui.Button(self.app, image=objects.BombTrap.ui_icon, pos=b.rect.inflate(8,0).topright, callback=self.build_bomb_trap, status_message=("Build a Bomb Trap\ncost:\n money: %s\n scraps: %s"+\ "\n----------\nattack: %s\nuses: %s\nspecial: %s")%(objects.BombTrap.money_cost, objects.BombTrap.scrap_cost, objects.BombTrap.base_damage, objects.BombTrap.base_usage_count, objects.BombTrap.special), anchor="topleft") self.build_bomb_trap_button = b #Ooh, techs, gotta love them! l = ui.Label(self.app, " Techs ", pos=(470, 500)) ui.LinesGroup(self.app, l) i = pygame.Surface((30,30)).convert_alpha() i.fill((0,0,0,0)) i.blit(data.image("data/worker-1.png"), (10,10)) i.blit(data.image("data/arrow.png"), (0,0)) self.upg_worker = ui.Button(self.app, image=i, pos=l.rect.inflate(0,2).bottomleft, callback=self.upgrade_worker, status_message="Upgrade Workers\ncurrent level: %s\ncost:\n money: %s"%(self.hero.worker_level, self.hero.tech_worker_upgrade_cost), anchor="topleft") i = pygame.Surface((40,40)).convert_alpha() i.fill((0,0,0,0)) i.blit(data.image("data/warrior-1.png"), (10,10)) i.blit(data.image("data/arrow.png"), (0,0)) self.upg_warrior = ui.Button(self.app, image=i, pos=self.upg_worker.rect.inflate(8,0).topright, callback=self.upgrade_warrior, status_message="Upgrade Warriors\ncurrent level: %s\ncost:\n money: %s"%(self.hero.warrior_level, self.hero.tech_warrior_upgrade_cost), anchor="topleft") i = pygame.Surface((30,30)).convert_alpha() i.fill((0,0,0,0)) i.blit(data.image("data/spikes.png"), (10,10)) i.blit(data.image("data/arrow.png"), (0,0)) self.upg_traps = ui.Button(self.app, image=i, pos=self.upg_warrior.rect.inflate(8,0).topright, callback=self.upgrade_traps, status_message="Upgrade Traps\ncurrent level: %s\ncost:\n money: %s"%(self.hero.trap_level, self.hero.tech_trap_upgrade_cost), anchor="topleft") l = ui.Label(self.app, "Specials ", pos=(610, 500)) ui.LinesGroup(self.app, l) i = pygame.transform.scale(data.image("data/spray_can.png"), (35, 60)) self.special_spray = ui.Button(self.app, image=i, pos=l.rect.inflate(0,2).bottomleft, callback=self.use_spray_special, status_message="Insects whooping on you?\nUse your spray can - kills all baddies!", anchor="topleft") i = pygame.transform.scale(data.image("data/broom.png"), (35, 60)) self.special_broom = ui.Button(self.app, image=i, pos=self.special_spray.rect.inflate(8,0).topright, callback=self.use_broom_special, status_message="Wah! They are too strong!\nCall down some major beatdown\nfrom your mom's broom!", anchor="topleft") i = pygame.transform.scale(data.image("data/mower.png"), (50, 50)) self.special_mower = ui.Button(self.app, image=i, pos=self.special_broom.rect.inflate(8,0).topright, callback=self.use_mower_special, status_message="Get off my lawn already!!\nFine. I can do some major damage to you, ya punks!\nVrrrrm!", anchor="topleft") self.status_message = ui.PopupManager(self.app) self.status_message.set("Testing, 1,2,3") if mode == "easy": self.money += self.hero.tech_worker_upgrade_cost self.upgrade_worker()