def read_a_ship(lengths,ask = True): shipX = input("give a letter : A-H: ") shipY = input("give a number : 1-8: ") if(ask == True): print("remaining lengths are:") print(lengths.keys()) length = input("enter a length : 2 , 3 or 4: ") direction = input("enter a direction : 1(up), 2(right), 3(down), 4(left): ") return create_ship(shipX,shipY,length,direction) return create_ship(shipX,shipY,1,1)
def computer_hit_2(computerHits, computerMisses, playerDeadShips): letters = { 0: "a", 1: "A", 2: "B", 3: "C", 4: "D", 5: "E", 6: "F", 7: "G", 8: "H", 9: "J" } choises = [[-1, 0], [1, 0], [0, 1], [0, -1]] increment = choises[random.randint(0, 3)] newX = computerHits.objectList[len(computerHits.objectList) - 1][0] + increment[0] newY = computerHits.objectList[len(computerHits.objectList) - 1][1] + increment[1] if (newX == 0 or newX == 9 or newY > 8 or newY < 1): return computer_hit_2(computerHits, computerMisses, playerDeadShips) newTarget = create_ship(letters[newX], newY, 1, 1) if (in_grid(newTarget, {1: 1}) == False or ([newX, newY] in computerMisses.objectList == True) or ([newX, newY] in playerDeadShips.objectList == True) or ([newX, newY] in computerHits.objectList) == True): return computer_hit_2(computerHits, computerMisses, playerDeadShips) newTarget = transform(newTarget) return newTarget
def run_in_event(self, event): if self.config["pos"] == "random": pos_x = self.root.state_manager.states[ "game"].player.rigidbody.x + random.uniform( -self.config["random_within_x"][0], self.config["random_within_x"][1]) pos_y = self.root.state_manager.states[ "game"].player.rigidbody.y + random.uniform( -self.config["random_within_y"][0], self.config["random_within_y"][1]) entity = ship.create_ship(self.root, self.config["ship_id"], pos_x, pos_y) self.root.state_manager.states["game"].entities.append(entity) if "internal_id" in self.config: event.database["ship_mappings"][ self.config["internal_id"]] = entity.hash_id if "add_triggers" in self.config: for group in self.config["add_triggers"]: entity.add_trigger(group["group"], group["primitive"]) if "join_factions" in self.config: for faction_ in self.config["join_factions"]: faction.get_faction(faction_).do_join(entity)
def run_in_dialog(self, dialog, speech): ship_b=ship.create_ship(absroot, "cardassian_freighter_UNI_wreck", *self.config["worldpos"]) ship_b.rigidbody._vector.magnitude=75 ship_b.rigidbody._vector.angle=22 faction.get_faction("cardassianunion").do_join(ship_b) absroot.savegame.database["sector_data"][self.config["secid"]]["packed_entities"].append( ship_b.save_to_config_node() )
def run_in_dialog(self, dialog, speech): ship_b = ship.create_ship(absroot, "cardassian_freighter_UNI_wreck", *self.config["worldpos"]) ship_b.rigidbody._vector.magnitude = 75 ship_b.rigidbody._vector.angle = 22 faction.get_faction("cardassianunion").do_join(ship_b) absroot.savegame.database["sector_data"][ self.config["secid"]]["packed_entities"].append( ship_b.save_to_config_node())
def process_events(self, events): for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.finish() if self.selected_item: if event.key == pygame.K_x: self.selected_item.dequip() self.first_start() if event.key == pygame.K_d: if self.selected_item.equipped == -1: self.root.state_manager.states[ "game"].entities.append( ship.create_ship( self.root, "cargo_pod_generic", self.selected_item.parent.rigidbody.x, self.selected_item.parent.rigidbody.y, 1, 1)) self.root.state_manager.states["game"].entities[ -1].pick_up(self.selected_item) del self.selected_item.parent.inventory[ self.selected_item.parent.inventory.index( self.selected_item)] self.first_start() else: ui_states.interdict_ok( self.root, title="Error", text= "Cannot drop equipped item!%nDequip with X first", button="OK") if event.key == pygame.K_u: self.selected_item.fire() if event.key == pygame.K_e: self.root.state_manager.start_interdicting( "hardpoint_select", { "inv_id": self.sm_id, "item": self.selected_item }) if event.key == pygame.K_s: self.selected_item.parent.try_stack(self.selected_item) self.first_start() if event.key == pygame.K_a: self.selected_item.parent.try_split( self.selected_item, int( inputbox.ask(self.root.screen.screen, "Number to take >> "))) self.first_start() if event.type == pygame.MOUSEBUTTONDOWN: for _, _, rect, item in self.cache_items: if rect.collidepoint(pygame.mouse.get_pos()): self.selected_item = item
def run_in_ship(self, ship): if (len(ship.inventory) > 0) or 1: absroot.state_manager.states["game"].entities.append( ship_module.create_ship(self.root, "cargo_pod_generic", ship.rigidbody.x, ship.rigidbody.y, 1, 1)) for item in ship.inventory: if item.config.get("is_dropped", True): item.reparent(None) absroot.state_manager.states["game"].entities[-1].pick_up( item)
def computer_create_a_ship(lengths): shipX = chr(random.randint(65, 72)) shipY = random.randint(1, 8) ok = False while (ok == False): ok = True shipLength = random.randint(2, 4) if (shipLength not in lengths.values()): ok = False shipDirection = random.randint(1, 4) return create_ship(shipX, shipY, shipLength, shipDirection)
def first_start(self): self.player=ship.create_ship(self.root, "cargo_transport_test", 100, 100) self.ship2=ship.create_ship(self.root, "destroyer_transport_test", 100, 100) self.player.targeted=self.ship2 self.ship2.rigidbody.x=0 self.ship2.rigidbody.y=0 self.stars=pygame.transform.scale(pygame.image.load("stars-1.png").convert_alpha(), (500,500)) nebulae=[ pygame.image.load("extentions/stock/image/bg-elements/nebula-1.png").convert_alpha(), pygame.image.load("extentions/stock/image/bg-elements/nebula-2.png").convert_alpha(), pygame.image.load("extentions/stock/image/bg-elements/nebula-3.png").convert_alpha() ] planets=[ pygame.image.load("extentions/stock/image/planets/planet-1.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-2.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-3.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-4.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-5.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-6.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-7.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-8.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-9.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-10.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-11.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-12.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-13.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-14.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-15.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-16.png").convert_alpha(), ] self.generated=[] random.seed(0) for i in range(random.randint(30,60)): self.generated.append([[random.randint(-8000,8000), random.randint(-6000,6000)],nebulae[random.randint(0,len(nebulae)-1)]]) for i in range(random.randint(5,10)): self.generated.append([[random.randint(-8000,8000), random.randint(-6000,6000)],planets[random.randint(0,len(planets)-1)]]) self.ship2.rigidbody.x=0 self.ship2.rigidbody.y=0
def process_events(self, events): for e in events: if e.type == pygame.KEYDOWN: if e.key == self.root.settings["keybindings"]["prev_item"]: self.player.selected_wep -= 1 if self.player.selected_wep == -1: self.player.selected_wep = len( self.player.hardpoints) - 1 elif e.key == self.root.settings["keybindings"]["next_item"]: self.player.selected_wep += 1 if self.player.selected_wep == len(self.player.hardpoints): self.player.selected_wep = 0 elif e.key == pygame.K_HOME: self.entities.append( ship.create_ship(self.root, "destroyer_transport_test", 1000, 1000)) self.entities[-1].targeted = self.player self.entities[-1].rigidbody.x = 0 self.entities[-1].rigidbody.y = 0 self.player.targeted = self.entities[-1] elif e.key == pygame.K_i: self.root.state_manager.start_interdicting( "inventory", {"ship": self.player}) elif e.key == pygame.K_BACKQUOTE: pass #hiding window elif e.key == pygame.K_ESCAPE: self.root.state_manager.start_interdicting( "generic_ui", self.root.gamedb("sgcui_settings")) elif e.key == pygame.K_F5: serialize.save_game(self.root, "saves/quicksave.sgs") tasks.display_hanging_message("Quicksaving...") elif e.key == pygame.K_F9: serialize.load_game(self.root, "saves/quicksave.sgs") tasks.display_hanging_message("Quickloading...") elif e.type == pygame.VIDEORESIZE: print e print "gsresize" print debug("GameState resize") self.parralax_scroller.bindall(self.root.renderspace_size) elif e.type == pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed( )[0]: for entitiy in self.entities: if entitiy.can_be_targeted: if self.root.screen.get_t_rect( entitiy.rotated_rect).collidepoint( pygame.mouse.get_pos()): self.player.targeted = entitiy for ext in self.root.extentions: self.root.extentions[ext].event_state("game", e)
def new_game(root, start, player_name, ship_name): import extention_loader, sectors root.savegame=SaveGame(root, player_name, ship_name) root.dialog_manager.init_each_game() root.faction_manager=faction.FactionManager(root) root.faction_manager.update_newgame() root.galaxy=sectors.Galaxy(root) root.galaxy.gamestate=root.state_manager.states["game"] root.state_manager.states["game"].entities=[ship.create_ship(root, start["ship"], *start.get("wspos", [0,0]), ai=False)] root.state_manager.states["game"].player=root.state_manager.states["game"].entities[0] root.quest_manager=quests.QuestManager(root, root.state_manager.states["game"].player) sectors.install_galaxy() root.galaxy.preprocess_statics() root.galaxy.goto_sector(*start.get("sector", [0,0])) root.state_manager.goto_state("game") root.state_manager.run_tick()
def run_in_dialog(self, dialog, speech): mapping={ "klingonempire":"klingon_warbird", "federation":"federation_galaxy" } sid=False for faction in absroot.state_manager.states["game"].player.faction_memberships: if faction in mapping: sid=mapping[faction] break ship_b=ship.create_ship(absroot, sid, *self.config["worldpos"]) ship_b.config["dialog_topic"]="UNI_wounded_pheonix_hail" ship_b.rigidbody._vector.magnitude=75 ship_b.rigidbody._vector.angle=22 absroot.savegame.database["sector_data"][self.config["secid"]]["packed_entities"].append( ship_b.save_to_config_node() )
def run_in_dialog(self, dialog, speech): mapping = { "klingonempire": "klingon_warbird", "federation": "federation_galaxy" } sid = False for faction in absroot.state_manager.states[ "game"].player.faction_memberships: if faction in mapping: sid = mapping[faction] break ship_b = ship.create_ship(absroot, sid, *self.config["worldpos"]) ship_b.config["dialog_topic"] = "UNI_wounded_pheonix_hail" ship_b.rigidbody._vector.magnitude = 75 ship_b.rigidbody._vector.angle = 22 absroot.savegame.database["sector_data"][ self.config["secid"]]["packed_entities"].append( ship_b.save_to_config_node())
def process_events(self, events): for e in events: if e.type==pygame.KEYDOWN: if e.key == self.root.settings["keybindings"]["prev_item"]: self.player.selected_wep-=1 if self.player.selected_wep==-1: self.player.selected_wep=len(self.player.hardpoints)-1 elif e.key == self.root.settings["keybindings"]["next_item"]: self.player.selected_wep+=1 if self.player.selected_wep==len(self.player.hardpoints): self.player.selected_wep=0 elif e.key == pygame.K_HOME: self.entities.append(ship.create_ship(self.root, "destroyer_transport_test", 1000, 1000)) self.entities[-1].targeted=self.player self.entities[-1].rigidbody.x=0 self.entities[-1].rigidbody.y=0 self.player.targeted=self.entities[-1] elif e.key == pygame.K_i: self.root.state_manager.start_interdicting("inventory", {"ship":self.player}) elif e.key == pygame.K_BACKQUOTE: pass #hiding window elif e.key == pygame.K_ESCAPE: self.root.state_manager.start_interdicting("generic_ui", self.root.gamedb("sgcui_settings")) elif e.key == pygame.K_F5: serialize.save_game(self.root, "saves/quicksave.sgs") tasks.display_hanging_message("Quicksaving...") elif e.key == pygame.K_F9: serialize.load_game(self.root, "saves/quicksave.sgs") tasks.display_hanging_message("Quickloading...") elif e.type==pygame.VIDEORESIZE: print e print "gsresize" print debug("GameState resize") self.parralax_scroller.bindall(self.root.renderspace_size) elif e.type==pygame.MOUSEBUTTONDOWN and pygame.mouse.get_pressed()[0]: for entitiy in self.entities: if entitiy.can_be_targeted: if self.root.screen.get_t_rect(entitiy.rotated_rect).collidepoint(pygame.mouse.get_pos()): self.player.targeted=entitiy for ext in self.root.extentions: self.root.extentions[ext].event_state("game", e)
def process_events(self, events): for event in events: if event.type==pygame.KEYDOWN: if event.key==pygame.K_ESCAPE: self.finish() if self.selected_item: if event.key==pygame.K_x: self.selected_item.dequip() self.first_start() if event.key==pygame.K_d: if self.selected_item.equipped==-1: self.root.state_manager.states["game"].entities.append( ship.create_ship(self.root, "cargo_pod_generic", self.selected_item.parent.rigidbody.x, self.selected_item.parent.rigidbody.y, 1,1) ) self.root.state_manager.states["game"].entities[-1].pick_up(self.selected_item) del self.selected_item.parent.inventory[self.selected_item.parent.inventory.index(self.selected_item)] self.first_start() else: ui_states.interdict_ok(self.root, title="Error", text="Cannot drop equipped item!%nDequip with X first", button = "OK") if event.key==pygame.K_u: self.selected_item.fire() if event.key==pygame.K_e: self.root.state_manager.start_interdicting("hardpoint_select", { "inv_id":self.sm_id, "item":self.selected_item }) if event.key==pygame.K_s: self.selected_item.parent.try_stack(self.selected_item) self.first_start() if event.key==pygame.K_a: self.selected_item.parent.try_split(self.selected_item, int(inputbox.ask(self.root.screen.screen, "Number to take >> ")) ) self.first_start() if event.type==pygame.MOUSEBUTTONDOWN: for _,_,rect,item in self.cache_items: if rect.collidepoint(pygame.mouse.get_pos()): self.selected_item=item
def new_game(root, start, player_name, ship_name): import extention_loader, sectors root.savegame = SaveGame(root, player_name, ship_name) root.dialog_manager.init_each_game() root.faction_manager = faction.FactionManager(root) root.faction_manager.update_newgame() root.galaxy = sectors.Galaxy(root) root.galaxy.gamestate = root.state_manager.states["game"] root.state_manager.states["game"].entities = [ ship.create_ship(root, start["ship"], *start.get("wspos", [0, 0]), ai=False) ] root.state_manager.states["game"].player = root.state_manager.states[ "game"].entities[0] root.quest_manager = quests.QuestManager( root, root.state_manager.states["game"].player) sectors.install_galaxy() root.galaxy.preprocess_statics() root.galaxy.goto_sector(*start.get("sector", [0, 0])) root.state_manager.goto_state("game") root.state_manager.run_tick()
def run_in_event(self, event): if self.config["pos"]=="random": pos_x=self.root.state_manager.states["game"].player.rigidbody.x+random.uniform(-self.config["random_within_x"][0],self.config["random_within_x"][1]) pos_y=self.root.state_manager.states["game"].player.rigidbody.y+random.uniform(-self.config["random_within_y"][0],self.config["random_within_y"][1]) entity=ship.create_ship( self.root, self.config["ship_id"], pos_x, pos_y ) self.root.state_manager.states["game"].entities.append(entity) if "internal_id" in self.config: event.database["ship_mappings"][self.config["internal_id"]]=entity.hash_id if "add_triggers" in self.config: for group in self.config["add_triggers"]: entity.add_trigger(group["group"], group["primitive"]) if "join_factions" in self.config: for faction_ in self.config["join_factions"]: faction.get_faction(faction_).do_join(entity)
def g_ss(name, a=True, w=True, k=False): g.entities.append( ship.create_ship(root, name, g.player.rigidbody.x, g.player.rigidbody.y, w, a)) g.entities[-1].keep_in_save = k
def process_events(self, events): for event in events: if event.type==pygame.KEYDOWN: if event.key==pygame.K_ESCAPE: self.finish() if self.selected_item: if event.key==pygame.K_x: if self.selected_item_is_owned: self.selected_item.dequip() self.first_start() else: ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button = "OK") if event.key==pygame.K_d: if self.selected_item_is_owned and self.shop_editable: if self.selected_item.equipped==-1: self.root.state_manager.states["game"].entities.append( ship.create_ship(self.root, "cargo_pod_generic", self.selected_item.parent.rigidbody.x, self.selected_item.parent.rigidbody.y, 1,1) ) self.root.state_manager.states["game"].entities[-1].pick_up(self.selected_item) del self.selected_item.parent.inventory[self.selected_item.parent.inventory.index(self.selected_item)] self.first_start() else: ui_states.interdict_ok(self.root, title="Error", text="Cannot drop equipped item!%nDequip with X first", button = "OK") elif not self.shop_editable: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK") else: ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button = "OK") if event.key==pygame.K_u: if self.selected_item_is_owned and self.shop_editable: self.selected_item.fire() elif not self.shop_editable: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK") else: ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button = "OK") if event.key==pygame.K_e: if self.selected_item_is_owned and self.shop_editable: self.root.state_manager.start_interdicting("hardpoint_select", { "inv_id":self.sm_id, "item":self.selected_item }) elif not self.shop_editable: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK") else: ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button = "OK") if event.key==pygame.K_s: if self.shop_editable: if self.selected_item.equipped==-1: self.selected_item.parent.try_stack(self.selected_item) self.first_start() else: ui_states.interdict_ok(self.root, title="Error", text="Dequip first", button = "OK") else: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK") if event.key==pygame.K_a: if self.shop_editable: text=inputbox.ask(self.root.screen.screen, "Number to take >> ") if text=="meme man 2k14" and self.selected_item.id_str=="money": self.ship.inventory.append(item.create_item(absroot, "moneygun", self.ship)) self.first_start() critical("Paul Blart Mode Enabled") try: self.selected_item.parent.try_split(self.selected_item, int(text) ) except AssertionError as e: ui_states.interdict_ok(absroot, title="Failure", text=str(e), button = "OK") self.first_start() else: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK") if event.key==pygame.K_t and self.is_shop: if self.selected_item_is_owned and self.shop_editable: if overlaps(self.selected_item.tags, self.shop_other.config.get("buys", ["_all"])) and self.selected_item.can_sell: cost=self.selected_item.get_cost()*absroot.galaxy.get_sector().get_sell_price(self.selected_item) def _yes(*a,**k): self.shop_other.pick_up(self.selected_item) del self.selected_item.parent.inventory[self.selected_item.parent.inventory.index(self.selected_item)] self.selected_item.reparent(self.shop_other) self.ship.inventory.append(item.create_item(absroot, "money", self.ship)) self.ship.inventory[-1].count=cost self.ship.try_stack(self.ship.inventory[-1]) self.selected_item=None self.first_start() if absroot.settings["gameplay"]["buysell_confirm"]: ui_states.interdict_yn(self.root, title="Confirm", text="Are you sure you want to sell "+str(self.selected_item.count)+" "+self.selected_item.name+" for "+str(cost), button_y = "SELL", button_n="NO", callback_y=_yes) else: _yes() elif not self.selected_item.can_sell: ui_states.interdict_ok(self.root, title="Sorry...", text="You can't sell that", button = "OK") else: ui_states.interdict_ok(self.root, title="Sorry...", text="I don't buy that", button = "OK") elif not self.shop_editable: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button = "OK") else: if self.selected_item.can_buy: if self.ship.get_item("money"): cost=self.selected_item.get_cost()*absroot.galaxy.get_sector().get_buy_price(self.selected_item) if self.ship.get_item("money").count>cost: def _yes(*a, **k): self.ship.pick_up(self.selected_item) del self.selected_item.parent.inventory[self.selected_item.parent.inventory.index(self.selected_item)] self.selected_item.reparent(self.ship) self.ship.get_item("money").consume(cost) self.first_start() self.selected_item=None if absroot.settings["gameplay"]["buysell_confirm"]: ui_states.interdict_yn(self.root, title="Confirm", text="Are you sure you want to buy "+str(self.selected_item.count)+" "+self.selected_item.name+" for "+str(cost), button_y = "BUY", button_n="NO", callback_y=_yes) else: _yes() else: ui_states.interdict_ok(self.root, title="Sorry...", text="You don't have enough money.%nNeed "+str(cost), button = "OK") else: ui_states.interdict_ok(self.root, title="Sorry...", text="You don't even have 1 money!", button = "OK") else: ui_states.interdict_ok(self.root, title="Sorry...", text="You can't buy that", button = "OK") if event.type==pygame.MOUSEBUTTONDOWN: adj_pos=list(pygame.mouse.get_pos()) #adj_pos[1]+=self.OFFSET if event.button==1: for l in self.tiles: if l[1].collidepoint(adj_pos): self.selected_item=l[0] self.selected_item_is_owned=l[3] if event.button==4: for l in self.tiles: l[1].move_ip(0,64) self.initial_offset+=64 if event.button==5: for l in self.tiles: l[1].move_ip(0,-64) self.initial_offset-=64
def computer_choose_a_random_target(): shipX = random.randint(1, 8) shipY = random.randint(1, 8) return create_ship(shipX, shipY, 1, 1)
def process_events(self, events): for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.finish() if self.selected_item: if event.key == pygame.K_x: if self.selected_item_is_owned: self.selected_item.dequip() self.first_start() else: ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button="OK") if event.key == pygame.K_d: if self.selected_item_is_owned and self.shop_editable: if self.selected_item.equipped == -1: self.root.state_manager.states[ "game"].entities.append( ship.create_ship( self.root, "cargo_pod_generic", self.selected_item.parent. rigidbody.x, self.selected_item. parent.rigidbody.y, 1, 1)) self.root.state_manager.states[ "game"].entities[-1].pick_up( self.selected_item) del self.selected_item.parent.inventory[ self.selected_item.parent.inventory.index( self.selected_item)] self.first_start() else: ui_states.interdict_ok( self.root, title="Error", text= "Cannot drop equipped item!%nDequip with X first", button="OK") elif not self.shop_editable: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button="OK") else: ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button="OK") if event.key == pygame.K_u: if self.selected_item_is_owned and self.shop_editable: self.selected_item.fire() elif not self.shop_editable: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button="OK") else: ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button="OK") if event.key == pygame.K_e: if self.selected_item_is_owned and self.shop_editable: self.root.state_manager.start_interdicting( "hardpoint_select", { "inv_id": self.sm_id, "item": self.selected_item }) elif not self.shop_editable: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button="OK") else: ui_states.interdict_ok(self.root, title="Error", text="Not yours!", button="OK") if event.key == pygame.K_s: if self.shop_editable: if self.selected_item.equipped == -1: self.selected_item.parent.try_stack( self.selected_item) self.first_start() else: ui_states.interdict_ok(self.root, title="Error", text="Dequip first", button="OK") else: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button="OK") if event.key == pygame.K_a: if self.shop_editable: text = inputbox.ask(self.root.screen.screen, "Number to take >> ") if text == "meme man 2k14" and self.selected_item.id_str == "money": self.ship.inventory.append( item.create_item(absroot, "moneygun", self.ship)) self.first_start() critical("Paul Blart Mode Enabled") try: self.selected_item.parent.try_split( self.selected_item, int(text)) except AssertionError as e: ui_states.interdict_ok(absroot, title="Failure", text=str(e), button="OK") self.first_start() else: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button="OK") if event.key == pygame.K_t and self.is_shop: if self.selected_item_is_owned and self.shop_editable: if overlaps( self.selected_item.tags, self.shop_other.config.get( "buys", ["_all" ])) and self.selected_item.can_sell: cost = self.selected_item.get_cost( ) * absroot.galaxy.get_sector().get_sell_price( self.selected_item) def _yes(*a, **k): self.shop_other.pick_up(self.selected_item) del self.selected_item.parent.inventory[ self.selected_item.parent.inventory. index(self.selected_item)] self.selected_item.reparent( self.shop_other) self.ship.inventory.append( item.create_item( absroot, "money", self.ship)) self.ship.inventory[-1].count = cost self.ship.try_stack( self.ship.inventory[-1]) self.selected_item = None self.first_start() if absroot.settings["gameplay"][ "buysell_confirm"]: ui_states.interdict_yn( self.root, title="Confirm", text="Are you sure you want to sell " + str(self.selected_item.count) + " " + self.selected_item.name + " for " + str(cost), button_y="SELL", button_n="NO", callback_y=_yes) else: _yes() elif not self.selected_item.can_sell: ui_states.interdict_ok( self.root, title="Sorry...", text="You can't sell that", button="OK") else: ui_states.interdict_ok(self.root, title="Sorry...", text="I don't buy that", button="OK") elif not self.shop_editable: ui_states.interdict_ok(self.root, title="Error", text="Not Editable", button="OK") else: if self.selected_item.can_buy: if self.ship.get_item("money"): cost = self.selected_item.get_cost( ) * absroot.galaxy.get_sector( ).get_buy_price(self.selected_item) if self.ship.get_item( "money").count > cost: def _yes(*a, **k): self.ship.pick_up( self.selected_item) del self.selected_item.parent.inventory[ self.selected_item.parent. inventory.index( self.selected_item)] self.selected_item.reparent( self.ship) self.ship.get_item( "money").consume(cost) self.first_start() self.selected_item = None if absroot.settings["gameplay"][ "buysell_confirm"]: ui_states.interdict_yn( self.root, title="Confirm", text= "Are you sure you want to buy " + str(self.selected_item.count) + " " + self.selected_item.name + " for " + str(cost), button_y="BUY", button_n="NO", callback_y=_yes) else: _yes() else: ui_states.interdict_ok( self.root, title="Sorry...", text= "You don't have enough money.%nNeed " + str(cost), button="OK") else: ui_states.interdict_ok( self.root, title="Sorry...", text="You don't even have 1 money!", button="OK") else: ui_states.interdict_ok( self.root, title="Sorry...", text="You can't buy that", button="OK") if event.type == pygame.MOUSEBUTTONDOWN: adj_pos = list(pygame.mouse.get_pos()) #adj_pos[1]+=self.OFFSET if event.button == 1: for l in self.tiles: if l[1].collidepoint(adj_pos): self.selected_item = l[0] self.selected_item_is_owned = l[3] if event.button == 4: for l in self.tiles: l[1].move_ip(0, 64) self.initial_offset += 64 if event.button == 5: for l in self.tiles: l[1].move_ip(0, -64) self.initial_offset -= 64
p = t.data[1] n = t.data[0] r.screen.draw_line(n["color"], p.get_center(), ship2.rotated_rect.center, n["thickness"]) tasks.add_task(r, "render_last", tasks.Task(_internal, n["duration"], (n, p))) return True primitives.register_primitive(root, "render_laser_beam", test) item.load_dir(root, "extentions/stock/items") ship.load_dir(root, "extentions/stock/ships") player = ship.create_ship(root, "cargo_transport_test", 100, 100) ship2 = ship.create_ship(root, "destroyer_transport_test", 200, 200) ship2.velocity = 3.5 stars = pygame.transform.scale( pygame.image.load("stars-1.png").convert_alpha(), (500, 500)) nebulae = [ pygame.image.load( "extentions/stock/image/bg-elements/nebula-1.png").convert_alpha(), pygame.image.load( "extentions/stock/image/bg-elements/nebula-2.png").convert_alpha(), pygame.image.load( "extentions/stock/image/bg-elements/nebula-3.png").convert_alpha() ] planets = [ pygame.image.load( "extentions/stock/image/planets/planet-1.png").convert_alpha(),
root.font=pygame.font.Font("kenvector_future_thin.ttf", 15) root.screen=scrollingscreen def test(r, n, p): def _internal(t, r): p=t.data[1] n=t.data[0] r.screen.draw_line(n["color"], p.get_center(), ship2.rotated_rect.center, n["thickness"]) tasks.add_task(r, "render_last", tasks.Task(_internal, n["duration"], (n, p))) return True primitives.register_primitive(root, "render_laser_beam", test) item.load_dir(root, "extentions/stock/items") ship.load_dir(root, "extentions/stock/ships") player=ship.create_ship(root, "cargo_transport_test", 100, 100) ship2=ship.create_ship(root, "destroyer_transport_test", 200, 200) ship2.velocity=3.5 stars=pygame.transform.scale(pygame.image.load("stars-1.png").convert_alpha(), (500,500)) nebulae=[ pygame.image.load("extentions/stock/image/bg-elements/nebula-1.png").convert_alpha(), pygame.image.load("extentions/stock/image/bg-elements/nebula-2.png").convert_alpha(), pygame.image.load("extentions/stock/image/bg-elements/nebula-3.png").convert_alpha() ] planets=[ pygame.image.load("extentions/stock/image/planets/planet-1.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-2.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-3.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-4.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-5.png").convert_alpha(), pygame.image.load("extentions/stock/image/planets/planet-6.png").convert_alpha(),