def add_entity(self, _ent: Entity): if _ent is None: return # Add static collider if no rigidbody is present ColliderManager_2D.get_singleton().add(_ent) # Add to list of all entities self._entities[_ent.name] = _ent # Add to list of ordered entities _depth: int = _ent.get_layer() if _depth not in self._entities_ordered: # Create empty slot self._entities_ordered[_depth] = [] # Add entity to sorted list self._entities_ordered[_depth].append(_ent) # Sort Dictionary self._entities_ordered = OrderedDict( sorted(self._entities_ordered.items(), key=lambda t: t[0])) else: # Add entity to sorted list self._entities_ordered[_depth].append(_ent) # Add to dynamic entities if _ent.get_component(Rigidbody) is not None: self._dynamic_entities[_ent.name] = _ent
def get_chunks_from_entity_location(self, entity: Entity) -> List[ColliderChunk]: _aabb = entity.get_component(Collider_AABB_2D) if _aabb is not None: return self.get_chunks_from_collider_aabb_2d(_aabb) _circle = entity.get_component(Collider_Circle_2D) if _circle is not None: print('process collision error 101') return list(None)
def remove_entity(self, _ent: Entity): # ENTITY deletion flag _ent.deleted = True # Check for entity existence and delete it from any of the following containers if _ent in self._entities.values(): self._entities.pop(_ent.name, None) _ordered_list: List[Entity] = self._entities_ordered[_ent.get_layer()] if _ent in _ordered_list: self._entities_ordered[_ent.get_layer()].remove(_ent) if _ent.get_component( Rigidbody ) is not None and _ent in self._dynamic_entities.values(): self._dynamic_entities.pop(_ent.name, None)
def process_collision(self, _entity: Entity, _others: List[Entity]): # Rigidbody Check _rigidbody: Rigidbody = _entity.get_component(Rigidbody) # Do nothing if ignoring both colliders if _rigidbody.ignore_static_colliders and _rigidbody.ignore_dynamic_colliders: return # Begin _entity.process_collision_start() # Create list of all possible entities in region _megalist: List[Entity] = [] # Static Collision if not _rigidbody.ignore_static_colliders: _chunks: List[ ColliderChunk] = self.get_chunks_from_entity_location(_entity) for c in _chunks: _megalist += c.get_entities() # Dynamic Collision if not _rigidbody.ignore_dynamic_colliders: _megalist += _others # Process all those entities # print('ent:', _entity.name, ' checking: ', len(_megalist)) _entity.process_collision_list(_megalist) # End _entity.process_collision_end()
def add_entity(self, entity: Entity): # Make sure it has a sprite _spr = entity.get_component(Sprite) if _spr is not None: self._entities.append(entity) self._sprites_ref.append(_spr) else: print( 'cannot add entity to sprite batch because its missing a sprite', entity) return self
def create_house(engine): #add a new room engine.add_room("Kanzas_House", KansasHouse()) #create a new house for the city house = Entity(["house"]) house.add_description( "A small suburban house with a white picket fence (your house)") house.add_examine_description("your parents house") #add command to travel to new room house.add_command(command_travel(engine.get_room("Kanzas_House"))) return house
def add(self, ent: Entity): _rigid = ent.get_component(Rigidbody) # Static Collider if _rigid is None: # Check Types _aabb = ent.get_component(Collider_AABB_2D) _circle = ent.get_component(Collider_Circle_2D) # Add Collider based on type if _aabb is not None: _chunks = self.get_chunks_from_collider_aabb_2d(_aabb) for i in _chunks: i.add_entity(ent) elif _circle is not None: _chunks = self.get_chunks_from_square_region_unsafe( _circle.get_position().get_vec2(), Vector2(_circle.radius * 2.0, _circle.radius * 2.0)) for i in _chunks: i.add_entity(ent)
def createCryptoItem(self, name, description, examine): Item = Entity([name]) Item.add_name(name) stats = getItemStatsBlockchainByName(name) if len(stats) != 8: print("couldn't find item on blockchain") #"equipement" : {"head":"", "torso": "", "hands":"", "feet":"", "auxiliary":"", "weapon":""} equipment = "" if stats[0] == ItemTypes.ONEHAND.value: equipment = "weapon" elif stats[0] == ItemTypes.TWOHAND.value: equipment = "weapon" elif stats[0] == ItemTypes.LEGS.value: equipment = "feet" elif stats[0] == ItemTypes.CHEST.value: equipment = "torso" elif stats[0] == ItemTypes.FEET.value: equipment = "feet" elif stats[0] == ItemTypes.HANDS.value: equipment = "hands" elif stats[0] == ItemTypes.HEAD.value: equipment = "head" elif stats[0] == ItemTypes.AUX.value: equipment = "auxiliary" elif stats[0] == ItemTypes.USE.value: equipment = "item" Item.data = { "equip": equipment, "damage": stats[2], "armor": stats[3], "magicRating": stats[1], "price": getPrice(name) } addr = getItemAddressBlockchain(name) Item.id = addr if getIsPurchasable(name): Item.add_command(command_buy(Item)) add_descriptions(Item, description, examine) return Item
def Tavern(cryptoItemEngine): entity = Entity(["tavern"]) store = Store(cryptoItemEngine) entity.add_entity(store) entity.remove_command("stats") add_descriptions( entity, "The Oily Rat tavern is alive and well! patrons from nearby towns gather to hear what quests the curier has to offer!", "The tavern is sturdily built, its location at the county's crossroads makes it an ideal place meet, there is a ['store'] in the far corner... could be worth checking out" ) return entity
def Tavern(engine): tavern = Entity(["tavern"]) tavern.add_description("The Oily Rat tavern is alive and well! patrons from nearby towns gather to hear what quests the curier has to offer!") tavern.add_examine_description("The tavern is sturdily built, its location at the county's crossroads makes it an ideal place meet") tavern.add_entity(Table("")) return tavern
def dagger(id): dagger = Entity(["dagger"]) dagger.add_description("A small rusty dagger") dagger.add_examine_description("this dagger looks like it could do a little bit of damage") dagger.data = {"equip": "weapon", "damage": 1} dagger.add_name("dagger") dagger.add_command(command_equip(dagger)) dagger.add_command(command_pick_up(dagger)) return dagger
def Table(id): table = Entity(["table"+str(id)]) table.add_name("wooden table") table.add_description("a simple wooden table"+str(id)) table.add_examine_description("a wooden table, it looks like a good place to place things") table.data = {"health" : 1} table.add_entity(Chair(1)) table.add_entity(Chair(2)) table.add_command(command_travel(table)) table.add_entity(dagger("")) table.add_command(command_attack(table)) return table
def Chair(id): chair = Entity(["chair"+str(id)]) chair.data = {"health" : 1} chair.add_description("Wooden chair" + str(id)) chair.add_examine_description("its sturdy, you could 'sit' on it, or maybe 'use' it as a weapon.") chair.add_command(command_pick_up(chair)) chair.add_command(command_attack(chair)) return chair
def Iowa(room_routes): city = Entity(["city", "Iowa"]) city.add_description("It is Iowa city") city.add_examine_description( "You can't be more exited to leave this place") return city
def KansasStore(): store = Entity(["shop", "store"]) store.add_description("Small Shop") store.add_examine_description( "The shop sign reads 'Gary's goods - take as much as you can cary' maybe they have supplies" ) store.add_command(Command(KansasStore, ["go"], [store])) owner = Entity(["gary", "owner", "man"]) owner.add_description( "There is a flamboyant man wearing purple robes and a wizard hat, hes probably the owner" ) owner.add_examine_description( "he's in his 50's maybe, looks like hes had a hard life") owner.add_command( Command(TalkToShopOwner, ["talk", "ask", "converse", "say"], [owner])) store.add_entities([owner]) return store
def KansasHouse(): house = Entity(["house"]) house.add_description( "A small suburban house with a white picket fence (your house)") house.add_examine_description("your parents house") car = Entity(["car"]) car.add_description( "There is a car in your parents driveway, its a 1995 honda civic, it might get you to oregon..." ) car.add_examine_description( "It looks like solid reliable transportation, its old but trusty, can fit a cramped 4, and has a full tank of gas" ) mom = Entity(["mom", "lady", "parents", "woman"]) mom.add_description("There is an older woman standing in your driveway") mom.add_examine_description( "She says to you 'Hey, make sure to pack before you go, '") snacks = Entity(["money"]) snacks.add_description("Maybe she has some money if you ask nicely") snacks.add_examine_description("$100") snacks.add_command(command_pick_up(snacks)) mom.add_entity(snacks) house.add_entity(car) house.add_entity(mom) return house
def Kansas(engine): city = Entity(["city", "kanzas"]) city.add_description( "It is Kanzas city, it smells of barbecue chicken and craft beer") city.add_examine_description( "You can't be more exited to leave this place") nextCity = Entity(["iowa"]) nextCity.add_command(command_travel(engine.get_room("Iowa"))) nextCity.add_description( "There is a highway, and a roadsign that says 'next stop Iowa'") nextCity.add_examine_description("The road looks arduous") city.add_entity(nextCity) city.add_entity(create_house(engine)) city.add_entity(KansasStore()) return city
def Store(cryptoItemEngine): name = "store" entity = Entity([name]) entity.add_entities(cryptoItemEngine.get_crypto_items_list()) entity.add_command(command_travel(entity)) entity.add_command(command_list(entity)) entity.remove_command("stats") entity.add_name(name) add_descriptions( entity, "There is shady man standing in the corner, on his shirt is a large '$' sign", "he has many items for sale, all for crypto!") return entity