def __init__(self, name, image, frames, directions=1, timing=100, sound=None): GameObject.__init__(self) assert isinstance(image, Image) #if sound: # assert(sound, Sound) self.name = name self.image = image self.images = None self.directions = directions self.frames = frames self.timing = timing # TODO: some checking to make sure inputs are the correct length if isinstance(self.frames, int): self.frames = tuple(range(0, self.frames)) else: self.frames = tuple(self.frames) self.real_frames = len(set(self.frames)) if isinstance(self.timing, int): self.timing = tuple([self.timing] * len(self.frames)) else: self.timing = tuple(self.timing)
def __init__(self, tmx, size, **kwargs): GameObject.__init__(self) self.default_image = generateDefaultImage((tmx.tilewidth, tmx.tileheight)) self.tmx = tmx self.setSize(size)
def __init__(self, p, locked=False, blocks=None, *args, **kwargs): GameObject.__init__(self, 'door', location=p, char='+', *args, **kwargs) self.tileindex = (0,0) self.block_move = True self.block_sight = True self.blocks = blocks self.locked = locked
def __init__(self,name,image,frames,directions=1,timing=100,sound=None): GameObject.__init__(self) self.add(image) self.name = name self.image = image self.images = None self.directions = directions self.frames = frames self.timing = timing # TODO: some checking to make sure inputs are the correct length if isinstance(self.frames, int): self.frames = tuple(range(0, self.frames)) else: self.frames = tuple(self.frames) self.real_frames = len(set(self.frames)) if isinstance(self.timing, int): self.timing = tuple([self.timing] * len(self.frames)) else: self.timing = tuple(self.timing) if (self.images is not None) and (not force): return
def __init__(self, tmx, size, **kwargs): GameObject.__init__(self) self.default_image = generateDefaultImage( (tmx.tilewidth, tmx.tileheight)) self.tmx = tmx self.setSize(size)
def __init__(self,name,image,frames,directions=1,timing=100,sound=None): GameObject.__init__(self) assert isinstance(image, Image) #if sound: # assert(sound, Sound) self.name = name self.image = image self.images = None self.directions = directions self.frames = frames self.timing = timing # TODO: some checking to make sure inputs are the correct length if isinstance(self.frames, int): self.frames = tuple(range(0, self.frames)) else: self.frames = tuple(self.frames) self.real_frames = len(set(self.frames)) if isinstance(self.timing, int): self.timing = tuple([self.timing] * len(self.frames)) else: self.timing = tuple(self.timing)
def add(self, other): if isinstance(other, Animation): self.animations[other.name] = other if self.default == None: self.setDefault(other) GameObject.add(self, other)
def __init__(self, unlocks, *args, **kwargs): GameObject.__init__(self, 'key', char='[', *args, **kwargs) self.unlocks = unlocks self.facts.append(Solves(self, unlocks.blocks_fact.obj)) for obj in self.world.player.wants: if obj.location_fact.obj == self.unlocks.blocks: # Todo: player doesn't *want* us until they know about us! self.facts.append(Wants(self.world.player, self))
def __init__(self, filename, name, tile=None, size=None): GameObject.__init__(self) self.filename = filename self.name = name self.tile = tile self.size = size self.image = None
def __init__(self, data): GameObject.__init__(self) self.rect = Rect(data.x, data.y, data.width, data.height) if hasattr(data, 'points'): self.points = data.points else: self.points = None self.name = data.name self.properties = data.properties self.entered = False
def __init__(self, name, image, tile=None, size=None): GameObject.__init__(self) self.image = image self.name = name self.tile = tile self.size = size self.frames = [0] self.timing = [-1]
def __init__(self, data): GameObject.__init__(self) self.extent = Rect(data.x, data.y, data.width, data.height) if hasattr(data, 'points'): self.points = data.points else: self.points = None self.name = data.name self.properties = data.properties self.entered = False
def __init__(self, name, description='', location=None, *args, **kwargs): self.map_memory = {} GameObject.__init__(self, name=name, description=description, location=location, *args, **kwargs) self.tiletype = 2 self.knowledge = set() self.wants = [] self.relationships = None self.hp = 1 self.block_move = True
def __init__(self, filename, size, name=None, directions=1): GameObject.__init__(self) self.filename = filename self.size = size if name == None: self.name = filename self.directions = directions # number of directions for animation self.frames = ([],) * directions
def door(x=None, y=None): tile = Tile('+', "Door", x, y) tile.add_trait(traits.Openable(tile)) tile.add_trait(traits.Destroyable( tile, [ lambda: Tile.floor(tile.x, tile.y), lambda: GameObject.debris(tile.x + random.randint(-2, 2), tile.y + random.randint(-2, 2)), lambda: GameObject.debris(tile.x + random.randint(-2, 2), tile.y + random.randint(-2, 2)), ] )) return tile
def __init__(self, name, image): GameObject.__init__(self) try: assert isinstance(image, Image) or isinstance(image, ImageTile) except AssertionError: print name, image raise self.image = image self.name = name self.frames = [0] self.timing = [-1]
def __init__(self): GameObject.__init__(self) self.exits = {} self.geometry = {} # geometry (for collisions) of each layer self.objects = {} # position and size of objects in 3d space self.orientations = {} # records where the object is facing self.extent = None # absolute boundries of the area self.joins = [] self._oldPositions = {} # used in collision handling self.messages = [] self.time = 0
def wall(x=None, y=None): tile = Tile('#', "Wall", x, y, 100, blocks_movement=True, blocks_light=True) tile.add_trait(traits.Destroyable( tile, [ lambda: Tile.floor(tile.x, tile.y), lambda: GameObject.debris(tile.x + random.randint(-5, 5), tile.y + random.randint(-5, 5)), lambda: GameObject.debris(tile.x + random.randint(-5, 5), tile.y + random.randint(-5, 5)), lambda: GameObject.debris(tile.x + random.randint(-5, 5), tile.y + random.randint(-5, 5)), lambda: GameObject.debris(tile.x + random.randint(-5, 5), tile.y + random.randint(-5, 5)), ] )) return tile
def __init__(self): GameObject.__init__(self) self.default = None self.callback = None # called when animation finishes self.curImage = None # cached for drawing ops self.curFrame = None # current frame number self.curAnimation = None self.animations = {} self.loop_frame = 0 self.looped = 0 self.loop = -1 self.timer = 0 self._prevAngle = None self._prevFrame = None self._is_paused = False
def get_contents(self, coordinates = None): """ Return a list of the contents of a sector at the provided coordinates. """ if not coordinates or not isinstance(coordinates,Coordinates): self.log.warning("%s called without proper coordinates: %s (type %s)" % ( "Game.get_contents()", str(coordinates), str(coordinates.__class__.__name__), )) return [] contents = [] self.log.debug("Building content list for %s..." % str(coordinates)) # GameObject -> ManMade or Natural -> Object we want here for parent in GameObject.__subclasses__(): self.log.debug("Processing %s objects..." % str(parent)) for child in globals()[parent.__name__].__subclasses__(): self.log.debug("Processing %s objects under %s..." % (str(child),str(parent))) # subclasses returns full path, ex: objects.star.Star # child.__name__ returns Star shared_object = getattr(Game,'_' + globals()[child.__name__]().plural()) if shared_object and coordinates in shared_object: contents += shared_object[coordinates] self.log.debug("Added %s to contents: %s" % ( str(globals()[child.__name__]().plural()), str(shared_object[coordinates]), )) self.log.debug("Coordinates %s contents: %s" % (str(coordinates),pprint.pformat(contents))) return contents
def __init__(self, agent_metadata_queue, quit_event, options): super().__init__(agent_metadata_queue, quit_event, options) self.logger.info('Initialised!') self.team: int = -1 # A list of cars for both teammates and opponents self.friends: [CarObject] = [] self.foes: [CarObject] = [] # This holds the carobjects for our agent self.drones: [CarObject] = [] self.ball: BallObject = BallObject() self.game: GameObject = GameObject() # A list of boosts self.boosts: [BoostObject] = [] # goals self.friend_goal: GoalObject = None self.foe_goal: GoalObject = None # Game time self.time: float = 0.0 self.odd_tick = 0 # Whether or not GoslingAgent has run its get_ready() function self.ready: bool = False # a flag that tells us when kickoff is happening self.kickoff_flag: bool = False self.prev_kickoff_flag: bool = False self.conceding: bool = False # If true we will go for more stuff # Initialized as true since we are always desperate self.desperate = False
def __init__(self, filename, name, frames, directions=1, timing=None): GameObject.__init__(self) self.filename = filename self.name = name self.order = None if isinstance(frames, int): self.frames = frames self.real_frames = frames elif isinstance(frames, list): self.frames = len(frames) self.real_frames = max(frames) + 1 self.order = frames self.directions = directions self.timing = timing self.images = []
def remove(self, other): playing = False if isinstance(other, (animation.Animation, animation.StaticAnimation)): if self.isPlaying(other): playing = True del self.animations[other.name] GameObject.remove(self, other) # handle when there are no animations left if len(self.animations) == 0: self.curAnimation = None self.curImage = None self.curFrame = None self.default = None self._is_paused = True elif playing: self.setDefault(self.animations.keys()[0]) self.reset()
def __init__(self, animations): GameObject.__init__(self) self.default = None self.curImage = None # cached for drawing ops self.curFrame = None # current frame number self.curAnimation = None self.animations = {} self.looped = 0 self.loop = -1 self.timer = 0.0 self.ttl = 0 self._prevAngle = None for animation in animations: self.add(animation) self.animations[animation.name] = animation self.setDefault(animations[0]) self.play()
def __init_(self): GameObject.__init__( self, components=[ components.CPosition(), components.CPlayerMovement(), components.CActorAnimParser(self.pathLists), ]) # Create a flipped copy of LEFT_WALK as our RIGHT_WALK animation # -- this will be changed when we have more walking animations. components.CActorAnimParser.animations[ enums.ActorAnim.WALK_RIGHT ] = tools.AnimCreator.createHorizontallyFlippedAnimation( components.CActorAnimParser.animations[WALK_LEFT]) # do the same for STANDING_RIGHT with STANDING_LEFT components.CActorAnimParser.animations[ enums.ActorAnim.STANDING_RIGHT ] = tools.AnimCreator.createHorizontallyFlippedAnimation( components.CActorAnimParser.animations[ STANDING_RIGHT])
def __init__(self, animations, axis_offset=(0,0)): GameObject.__init__(self) self.axis_offset = Vec2d(axis_offset) self.curImage = None # cached for drawing ops self.curFrame = None # current frame number self.curAnimation = None self.animations = {} self.looped = 0 self.timer = 0.0 self.ttl = 0 self.flip = 0 self.speed_mod = 1.0 self._prevAngle = None self._changed = True self.axis = Vec2d(0,0) for animation in animations: self.add(animation) self.animations[animation.name] = animation self.play(self.animations.keys()[0])
def __init__(self, animations, axis_offset=(0, 0)): GameObject.__init__(self) self.axis_offset = Vec2d(axis_offset) self.curImage = None # cached for drawing ops self.curFrame = None # current frame number self.curAnimation = None self.animations = {} self.looped = 0 self.timer = 0.0 self.ttl = 0 self.flip = 0 self.speed_mod = 1.0 self._prevAngle = None self._changed = True self.axis = Vec2d(0, 0) for animation in animations: self.add(animation) self.animations[animation.name] = animation self.play(self.animations.keys()[0])
def __init__(self, world, tree): self.world = world self.id = tree.get('id') self.properties = conv.unpack_properties(tree) self.objects = {} for obj in tree.findall('object'): self.objects[obj.get('id')] = GameObject(obj, self.world) self.events = [] for event in tree.find('events').findall('event'): self.events.append(event.get('id')) self.world.eventhandler.events[event.get('id')] = self.world.eventhandler.parser.parse_xml(event) Room.instances[self.id] = self return
def gen_item_health(coords): x, y = coords item_comp = Item(use_function=gf.cast_heal) item = GameObject(g.settings, "Health Potion", x, y, color=colors.lighter_crimson, img=r.health_potion, item=item_comp) return item
def gen_item_scroll_lightning(coords): x, y = coords item_comp = Item(use_function=gf.cast_lightning) item = GameObject(g.settings, "Scroll of lightning bolt", x, y, color=colors.lightest_sky, img=r.scroll2, item=item_comp) return item
def gen_item_scroll_confuse(coords): x, y = coords item_comp = Item(use_function=gf.cast_confuse) item = GameObject(g.settings, "Scroll of confuse", x, y, color=colors.light_yellow, img=r.scroll, item=item_comp) return item
def gen_equ_shield(coords): x, y = coords bonus = randint(5, 10) equipment_com = Equipment(defense_bonus=bonus, slot='hand2') item = GameObject(g.settings, "Shield" + " +" + str(bonus), x, y, color=colors.light_grey, img=r.shield, equipment=equipment_com) #g.item_group.add(item) return item
def gen_equ_sword(coords): x, y = coords bonus = randint(1, 5) equipment_com = Equipment(attack_bonus=bonus, slot='hand', slot2="hand2") item = GameObject(g.settings, "Sword" + " +" + str(bonus), x, y, color=colors.lighter_grey, img=r.sword, equipment=equipment_com) #g.item_group.add(item) return item
def gen_equ_armor(coords): x, y = coords bonus = randint(1, 5) equipment_com = Equipment(defense_bonus=bonus, slot='body') item = GameObject(g.settings, "Armor" + " +" + str(bonus), x, y, color=colors.grey, img=r.armor, equipment=equipment_com) #g.item_group.add(item) return item
def gen_equ_helmet(coords): x, y = coords bonus = randint(1, 5) equipment_com = Equipment(health_bonus=bonus, slot='head') item = GameObject(g.settings, "Helmet" + " +" + str(bonus), x, y, color=colors.light_grey, img=r.helmet, equipment=equipment_com) #g.item_group.add(item) return item
def gen_equ_two_handed_sword(coords): x, y = coords bonus = randint(5, 10) equipment_com = Equipment(attack_bonus=bonus, slot='hand', slot_block="hand2") item = GameObject(g.settings, "Two-Handed Sword" + " +" + str(bonus), x, y, color=colors.light_grey, img=r.two_handed_sword, equipment=equipment_com) #g.item_group.add(item) return item
def gen_monster_troll(coords): x, y = coords fighter_comp = Fighter(hp=16, defense=1, power=4, death_function=gf.monster_death) ai_comp = BasicMonster() monster = GameObject(g.settings, "Troll", x, y, color=colors.darker_green, blocks=True, fighter=fighter_comp, ai=ai_comp, img=r.troll) return monster
def gen_monster_zombie(coords): x, y = coords fighter_comp = Fighter(hp=10, defense=0, power=3, death_function=gf.monster_death) ai_comp = BasicMonster() monster = GameObject(g.settings, "Zombie", x, y, color=colors.darker_violet, blocks=True, fighter=fighter_comp, ai=ai_comp, img=r.zombie) return monster
def run_game(): #Initialize game and create a screen object. pygame.init() settings = Settings() g.settings = Settings() g.settings_g = Settings() pygame.display.set_caption(settings.title) # Initialize Map grid = Grid(settings) g.tiles = Group() # Map Matrix initialisieren und Tiles hinzufügen tiles_init(settings, g.tiles) #Player fighter_comp = Fighter(hp=30, defense=2, power=5, death_function=gf.player_death) g.player = GameObject(settings, "player", 1, 1, colors.gold, img=r.player, blocks=True, fighter=fighter_comp) # Create Random Map make_map() # Initialize GUI and Inventory g.gui_elements = GUI(settings) g.inventory_menu = InventoryMenu(settings) #Print Welcome Message print_message("Welcome to the BEIDL", colors.black, colors.dark_red) #Initialize groups g.monster_group = Group() g.item_group = Group() g.dead_group = Group() g.inventory = Group() g.graphics_group = Group() """F**K AROUND""" #vvvvvvvvvvv# for i in range(10): testi_place_objects('item') for i in range(50): testi_place_objects('enemy') # """Test: Dummy Walls""" # g.map_matrix[4][5].blocked = True # g.map_matrix[4][5].block_sight = True # g.map_matrix[4][6].blocked = True # g.map_matrix[4][6].block_sight = True # # g.map_matrix[15][21].blocked = True # g.map_matrix[15][21].block_sight = True # g.map_matrix[16][21].blocked = True # g.map_matrix[16][21].block_sight = True #^^^^^^^^^# """F**K AROUND""" # Start the main loop for the game. while True: """MENU""" # Menu Screen #while settings.game_state == "menu": #gf.check_events_menu(settings, all_groups) #gf.update_screen_menu(settings, all_groups) """GAME""" #while g.game_state == "playing": while True: g.clock.tick(FPS) # ticks = pygame.time.get_ticks() gf.update_screen(settings) # Check game_state for Contol Setup # TODO game state control handling like this? if g.game_state == 'inventory': player_action = gf.controls_inventory(settings) else: player_action = gf.controls(settings, g.player) # Let Enemys take turns if g.game_state == 'playing' and player_action != "noturn": for obj in g.monster_group: if obj.ai: obj.ai.take_turn() # TODO Turn for using inventory item, redundant, use in game state? if player_action == "turn": for obj in g.monster_group: if obj.ai: obj.ai.take_turn()
def __init__(self): GameObject.__init__(self)
def gen_game_objects(self): for obj_addr in self.gen_objects_addr(): if self.pm.read_int(obj_addr + Offset.Object.type) == 5: yield GameObject(self, obj_addr)