Beispiel #1
0
    def __init__(self, current_ship, special=False):
        """
        :param ._location_x: the vertical location of the torpedo.
        :param ._location_y: the horizontal location of the torpedo.
        :param ._speed_x: the vertical speed of the torpedo.
        :param ._speed_y: the horizontal speed of the torpedo.
        :param ._angle: the angle of the torpedo.
        :param ._special: boolean parameter which tells if the torpedo is
        special or not.
        :param ._life: how many iterations left for the torpedo to live.
        """
        GameObject.__init__(self)
        self._location_x = current_ship.get_location_x()
        self._location_y = current_ship.get_location_y()
        self._speed_x = self._get_torpedo_speed_x\
            (current_ship.get_speed_x(), current_ship.get_angle())
        self._speed_y = self._get_torpedo_speed_y\
            (current_ship.get_speed_y(), current_ship.get_angle())
        self._angle = current_ship.get_angle()
        self._special = special
        self._radius = TORPEDO_RADIUS

        if special:
            self._life = TORPEDO_SPECIAL_MAX_LIFE
        else:
            self._life = TORPEDO_MAX_LIFE
    def __init__(self, x, y, w, h, color, offset):
        GameObject.__init__(self, x, y, w, h)
        self.color = color

        self.offset = offset
        self.moving_left = False
        self.moving_right = False
Beispiel #3
0
    def __init__(self, x, y, w, h, text, on_click=lambda x: None, padding=0):
        GameObject.__init__(self, x, y, w, h)
        self.state = 'normal'
        self.on_click = on_click

        self.text = TextObject(x + padding, y + padding, lambda: text,
                               c.button_text_color, c.font_name, c.font_size)
Beispiel #4
0
 def __init__(self,
              game,
              x,
              y,
              delay=1,
              hp=1,
              damage=0.5,
              behavior=ai.approach_player_smart):
     GameObject.__init__(self, game, x, y, layer=4)
     idle = SpriteSheet("images/bug.png", (2, 1), 2)
     self.sprite.add_animation({"Idle": idle})
     self.sprite.start_animation("Idle")
     self.behavior = behavior
     self.game.movers += [self]
     self.hp = hp
     self.max_hp = hp
     self.damage = damage
     self.delay = delay
     self.map = game.map
     game.map.add_to_cell(self, (x, y))
     self.countdown = random.randint(0, delay)
     self.enemy = True
     self.hittable = True
     self.heart = pygame.image.load("images/heart_small.png")
     self.eheart = pygame.image.load("images/empty_heart_small.png")
     self.heart_width = self.heart.get_width()
     self.width = TILE_SIZE / 2
     self.hp_visible = True
 def __init__(self):
     GameObject.__init__(self, 0, 0)
     self.counter_continue = FrameCounter(20)
     self.counter_blank = FrameCounter(game_object.blank_time)
     self.renderer = None
     self.is_spawning = True
     self.counter_blank.expired = True
    def __init__(self, level_map, coord):

        GameObject.__init__(self, level_map, coord, False, True)

        self.obj_id = 'brazier'
        self.determine_initial_state()
        self.is_dead = False
 def __init__(self, type, pos, width, height, priority, speed):
     GameObject.__init__(self, type, pos, width, height, priority)
     self.rect = self.create_rect(pos, width, height)
     self.speed = speed
     self.direction = 'UP'
     self.movement_status = 'NORMAL'
     self.last_move = QPoint(0, 0)
Beispiel #8
0
 def __init__(self, x, y):
     GameObject.__init__(self, x, y)
     self.image = pygame.image.load("images/player-bullet.png")
     self.box_collider = BoxCollider(40, 40)
     self.velocity = (0, 0)
     self.returning = False
     self.counter = FrameCounter(60)
Beispiel #9
0
 def __init__(self):
     self.is_running = True
     self.clock = pygame.time.Clock()
     self.screen = pygame.display.set_mode(Constants.SIZE, Constants.FLAGS)
     self.player = GameObject()
     self.player.velocity.x = 0.001
     pygame.init()
Beispiel #10
0
class Game:
    """
    Gère la fenêtre ainsi que la boucle de jeu.
    La boucle de jeu comprends le traitement des événéments, le moteur physique et le moteur graphique.
    """
    def __init__(self):
        self.is_running = True
        self.clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode(Constants.SIZE, Constants.FLAGS)
        self.player = GameObject()
        self.player.velocity.x = 0.001
        pygame.init()

    def handle_events(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.is_running = False

    def update(self):
        self.player.update()

    def draw(self, interpolation):
        self.screen.fill(Constants.BG_COLOR)
        self.player.draw(self.screen, interpolation)
        pygame.display.flip()

    def run(self):
        lag = 0.0
        while self.is_running:
            lag += self.clock.tick()
            self.handle_events()
            while lag >= Constants.MS_PER_TICK:
                self.update()
                lag -= Constants.MS_PER_TICK
            self.draw(lag / Constants.MS_PER_TICK)
Beispiel #11
0
 def update(self):
     # skitter around randomly
     x, y = (random.random() * 2) - 1, (random.random() * 2) - 1
     x *= self.move_rate
     y *= self.move_rate
     self.move(x, y)
     GameObject.update(self)
Beispiel #12
0
 def update(self):
     # maybe create a star at the top, clear bottom line, then shift-wrap
     if random.random() < 0.25:
         self.create_star()
     self.art.clear_line(0, 0, self.art_height - 1)
     self.art.shift_all_frames(0, 1)
     GameObject.update(self)
Beispiel #13
0
 def update(self):
     GameObject.update(self)
     # grow only every few ticks, so you can watch the design grow
     if self.app.updates % self.ticks_per_grow != 0:
         return
     if not self.finished_growing:
         self.update_growth()
Beispiel #14
0
    def update(self, *args):
        GameObject.update(self, *args)

        self.rect.y += 3
        if self.rect.y > self.game.HEIGHT:
            self.kill()
            self.game.CreateStar()
 def __init__(self, x, y):
     GameObject.__init__(self, x, y)
     self.renderer = Animation(["images/warning_sign.png"], loop=True)
     self.box_collider = BoxCollider(64, 64)
     self.count = FrameCounter(50)
     pygame.mixer.Channel(3).play(
         pygame.mixer.Sound("music/warning (1).wav"))
Beispiel #16
0
    def update(self):
        GameObject.update(self)
        self.x += self.dx
        self.y += self.dy

        for game_object in game_objects:
            if type(game_object) == Wall:
                overlap = BoxCollider.overlap(self.box_collider,
                                              game_object.box_collider)
                if overlap:
                    pygame.mixer.Channel(6).play(
                        pygame.mixer.Sound("music/player/Boom.wav"))

                    self.deactivate()

        for game_object in game_objects:
            if type(game_object) == Enemy or type(game_object) == Enemy1:
                overlap = BoxCollider.overlap(self.box_collider,
                                              game_object.box_collider)
                if overlap:
                    pygame.mixer.Channel(6).play(
                        pygame.mixer.Sound("music/player/Boom.wav"))
                    game_object.hp += -self.dam
                    if game_object.hp <= 0:
                        gamelevel.append("*")
                        enemy_explosion = EnemyExplosion(
                            game_object.x, game_object.y, game_object.dx,
                            game_object.dy, game_object._type)
                        add(enemy_explosion)
                        game_object.deactivate()
                    self.deactivate()
Beispiel #17
0
 def __init__(self, x, y, input_manager):
     GameObject.__init__(self, x, y)
     self.image = pygame.image.load('image/player.png')
     self.input_manager = input_manager
     self.shoot_lock = False
     self.counter = FrameCounter(30)
     self.hp = 10
Beispiel #18
0
 def __init__(self, world, obj_data):
     GameObject.__init__(self, world, obj_data)
     i = 0
     for frame, layer, x, y in TileIter(self.art):
         self.art.set_color_at(frame, layer, x, y, TILE_COLORS[i], False)
         self.art.write_string(frame, layer, x, y, str(i + 1), 1)
         i += 1
Beispiel #19
0
 def __init__(self, x: int, y: int, size: int, speed, backgroundWidth: int,
              backgroundHeight: int):
     GameObject.__init__(self, x, y, size, size, speed)
     self.backgroundWidth = backgroundWidth
     self.backgroundHeight = backgroundHeight
     self.actualTop = self.top
     self.actualLeft = self.left
 def __init__(self, x, y):
     GameObject.__init__(self, x, y)
     self.input_manager = InputManager()
     self.left = pygame.image.load("images/left.png")
     self.right = pygame.image.load("images/right.png")
     self.all = pygame.image.load("images/all.png")
     self.image = self.all
Beispiel #21
0
 def __init__(self, image, x, y, speed):
     # https://younglinux.info/pygame/image
     self.image_surface = pygame.image.load(image)
     rect = self.image_surface.get_rect()
     GameObject.__init__(self, x + rect.left, y + rect.top, rect.width,
                         rect.height, speed)
     '''(random.randint(-5, -1), 0)'''
Beispiel #22
0
def scene2():
    scene = Scene()

    obj = GameObject('0')
    obj.load_mesh('../data/camero.obj')
    obj.load_texture('../data/camero.png', 256)
    obj.set_scale(20)
    obj.rotate_y(-45)
    scene.objects += [obj]

    scene.light = Light()
    scene.light.shadow_map_dim = 512
    scene.light.shadow_map_bias = 1
    scene.light.translate_z(1000)
    scene.light.translate_y(1500)
    scene.light.translate_x(2000)
    scene.light.rotate_y(100)
    scene.light.rotate_x(45)

    image_width = 640
    image_height = 480

    scene.camera = Camera(0.98, 0.735, image_width, image_height, 1, 10000, 20,
                          np.eye(4))
    scene.camera.translate_y(40)
    scene.camera.translate_z(60)
    scene.camera.rotate_x(35)

    return scene
 def __init__(self, x, y, hastighet_x, hastighet_y):
     GameObject.__init__(self,
                         x,
                         y,
                         hastighet_x,
                         hastighet_y,
                         image=bullet_image,
                         time_to_live=450)
Beispiel #24
0
 def __init__(self, x, y):
     GameObject.__init__(self,x ,y)
     self.overlap = False
     # 1 load image
     self.renderer = ImageRenderer("assets/images/sprite/gift/gift_close.png")
     self.width = 25
     self.height = 25
     self.box_collider = BoxCollider(self.width, self.height)
Beispiel #25
0
    def __init__(self, state, coord, player, obj_code):

        GameObject.__init__(self, state, coord, obj_code, player)

        self.owner_id = self.load_player_id(player)
        self.color = self.load_color(player)
        self.image = self.load_image(self.object_image_name())
        self.change_color(PlayerGameObject.START_COLOR, self.color)
 def __init__(self, x, y, hastighet_x=0, hastighet_y=0, target=None):
     GameObject.__init__(self,
                         x,
                         y,
                         hastighet_x,
                         hastighet_y,
                         image=enemy_image)
     self.target = target
Beispiel #27
0
 def __init__(self, x, y, input_manager):
     GameObject.__init__(self, x, y)
     self.input_manager = input_manager
     self.shoot_lock = False
     self.counter = FrameCounter(30)
     self.renderer = PlayerAnimator()
     self.dx = 0
     self.dy = 0
Beispiel #28
0
 def __init__(self, x, y, r, color, speed):
     GameObject.__init__(self, x - r, y - r, r * 2, r * 2, speed)
     
     self.radius = r
     
     self.diameter = r * 2
     
     self.color = color
    def update(self):
        GameObject.update(self)
        # self.x = 1000

        self.count.run()
        if self.count.expired:
            self.deactivate_if_needed()
            self.count.reset()
Beispiel #30
0
 def __init__(self):
     GameObject.__init__(self)
     self.load_anims("part", 11)
     # Load a random part and place it randomly on the conveyor belt.
     self.reset()
     self.rect.left = random.randint(0, 536)
     
     self.moved_once = False
Beispiel #31
0
    def __init__(self):
        GameObject.__init__(self)
        self.load_anims("part", 11)
        # Load a random part and place it randomly on the conveyor belt.
        self.reset()
        self.rect.left = random.randint(0, 536)

        self.moved_once = False
Beispiel #32
0
 def update(self):
     GameObject.update(self)
     self.spawn_counter.run()
     if self.spawn_counter.expired:
         self.x -= 20
         self.deactivate_if_needed()
         # self.spawn_counter.reset()
     else:
         self.x -= 0
Beispiel #33
0
    def __init__(self, position, angle, area, solids, objId=None):
        GameObject.__init__(self, position, angle, self.SIZE, self.TYPE, objId,
                area=area, solids=solids)

        self.health = self.HEALTH
        self.next_shot = 0
        self.respPos = position

        self.msgs = []
        self.currentMsg = None
        self.lastTimestamp = 0
Beispiel #34
0
    def update(self, speed = 1):
        GameObject.update(self, speed)

        self.rect.y += speed
        if len(self.game.bullets) % 2 == 0 and randint(0,100) % 9 == 0 and self.rect.y % 2 == 0:
            self.game.Fire(self)
        else:
            offset = randint(1,3)
            self.rect.x = (self.rect.x + offset) % self.game.WIDTH
        if self.rect.y > self.game.HEIGHT:
            self.kill()
Beispiel #35
0
 def update(self, speed = 5):
     GameObject.update(self, speed)
     
     if self.enemy == False:
         self.rect.y -= speed
         if self.rect.y < 0:
             self.kill()
     else:
         self.rect.y += speed
         if self.rect.y > self.game.HEIGHT:
             self.kill()
Beispiel #36
0
    def __init__(self):
        GameObject.__init__(self, 425.0, 500.0, 60, 60)    

        self.life = 5
        self.score = 0
        
        self.speed = 0.25
    
        self.projectile_list = list()
        self.fire_delay = 15
        
        self.move_right = self.move_left = self.fire_shot = False
Beispiel #37
0
 def __init__(self, projectile_list, x, y, max_side_move, max_down_move = 40):
     GameObject.__init__(self, x, y, 30, 30)
     self.speed = 0.05
     self.direction = self.MOVING_RIGHT
     
     self.projectile_list = projectile_list
     
     self.max_down_move = max_down_move
     self.max_side_move = max_side_move
     self._moved = max_side_move
     
     self.fire_delay = 0
    def __init__(self, world, position):
        GameObject.__init__(self)
        self.world = world

        self.alignment = 0
        self.neutralteam = NeutralTeam()
        self.team = self.neutralteam
        self.image = self.team.get_controlpoint_image()
        self.mask = pygame.mask.from_surface(self.image)
        
        self.rect = self.image.get_rect()
        self.rect.center = position
        
        self.layer = 1
Beispiel #39
0
    def __init__(self, world):
        GameObject.__init__(self)
        self.world = world
        self.image = pygame.image.load('graphics/ammo.png').convert_alpha()
        self.rect = self.image.get_rect()
        self.mask = pygame.mask.from_surface(self.image)

        #spawn at random location
        while True:
            self.rect.center = (
                utils.RANDOM.gauss(0.5,0.2)*self.world.level.WORLD_SIZE[0],
                utils.RANDOM.gauss(0.5,0.35)*self.world.level.WORLD_SIZE[1])
            if len(self.world.touching_objects(self)) == 0:
                break
Beispiel #40
0
 def __init__(self, name):
     GameObject.__init__(self, 425.0, 500.0, 60, 60)
     
     self.color = pygame.Color(255,255,255)
     
     self.life = 5
     self.score = 0
     
     self.speed = 0.25
 
     self.projectile_list = list()
     self.fire_delay = 15
     
     self.is_immune = True
     self.is_moving_right = self.is_moving_left = self.is_firing = False
     self.name = name
Beispiel #41
0
 def fromString(cls, data):
     msg = EntityMessage()
     msg.getHead(data)
     stateSize = GameObject.getStateSize(data[cls.HEADER:])
     msg.data = data[:cls.HEADER+stateSize]
     msg.state = data[cls.HEADER:cls.HEADER+stateSize]
     return msg
Beispiel #42
0
 def __init__(self, arena, number, damping, token_type=MARKER_TOKEN):
     self._body = arena._physics_world.create_body(position=(0, 0),
                                                   angle=0,
                                                   linear_damping=damping,
                                                   angular_damping=damping,
                                                   type=pypybox2d.body.Body.DYNAMIC)
     GameObject.__init__(self, arena)
     self.marker_info = create_marker_info_by_type(token_type, number)
     self.grabbed = False
     WIDTH=0.08
     self._body.create_polygon_fixture([(-WIDTH, -WIDTH),
                                        ( WIDTH, -WIDTH),
                                        ( WIDTH,  WIDTH),
                                        (-WIDTH,  WIDTH)],
                                       density=1,
                                       restitution=0.2,
                                       friction=0.3)
Beispiel #43
0
 def __init__(self, simulator):
     self._body = None
     self.zone = 0
     GameObject.__init__(self, simulator.arena)
     self.motors = [Motor(self)]
     make_body = simulator.arena._physics_world.create_body
     half_width = self.width * 0.5
     with self.arena.physics_lock:
         self._body = make_body(position=(0, 0),
                                angle=0,
                                linear_damping=0.0,
                                angular_damping=0.0,
                                type=pypybox2d.body.Body.DYNAMIC)
         self._body.create_polygon_fixture([(-half_width, -half_width),
                                            ( half_width, -half_width),
                                            ( half_width,  half_width),
                                            (-half_width,  half_width)],
                                           density=500*0.12) # MDF @ 12cm thickness
     simulator.arena.objects.append(self)
Beispiel #44
0
    def step(self, players, delta, timestamp):
        if len(players) == 0:
            return None

        if self.target is None:
            self.target = players.keys()[int(random.random() * len(players.keys()))]
        if self.target not in players or players[self.target].health <= 0:
            self.target = None
            return None

        self.rotate(vector=(players[self.target].x, players[self.target].y))
        GameObject.move(self, angle=self.angle, scale=self.SPEED*delta)

        if self.next_shot < timestamp:
            self.next_shot = timestamp + self.FIRE_PERIOD
            dist = self.size + self.FIRE_DIST + Bullet.SIZE
            bullet = Bullet((self.x + math.cos(self.angle) * dist,
                             self.y + math.sin(self.angle) * dist),
                            self.angle, owner=self)
            return bullet

        return None
Beispiel #45
0
    def __init__(self, projectiles, x, amountOfInvadersSpawned):
        maxInvaders = 5
        # check if there are destroyed invaders you can replace
        temp = amountOfInvadersSpawned / maxInvaders
        self.y = 50 * temp
        temp2 = temp * maxInvaders
        # amountOfInvadersOnThisLine
        aOIOTL = amountOfInvadersSpawned - temp2
        self.x = 50 * aOIOTL
        GameObject.__init__(self, self.x, self.y, 30, 30)

        self.projectile_list = projectiles
        self.max_down_move = 200
        self.max_side_move = 625
        self.howManyMoves = self.max_side_move
        self.direction = self.movingRight
        self.mvmtSpeed = 4

        self.shotDelay = random.randrange(1000, 3000)
        self.timeSinceLastShot = 0

        """
Beispiel #46
0
    def __init__(self, number, world, team):
        GameObject.__init__(self)
        self.collide = True
        self.dirty = 2 #always redraw
        
        self.number = number
        self.world = world
        self.team = team

        self.base_image = self.team.get_suit_image()
        self.rect = self.base_image.get_rect()
        self.mask = pygame.mask.from_surface(self.base_image)
        self.image = self.base_image
        self.font = pygame.font.SysFont("Arial", 9)
        
        self.observer = ObservationSprite(world, self, SIGHT)
        self.brain = self.team.get_brain()
        
        self.label = ''

        self.alive = False
        self.spawn()        
Beispiel #47
0
            bullet = Bullet((self.x + math.cos(self.angle) * dist,
                             self.y + math.sin(self.angle) * dist),
                            self.angle, owner=self)
            return bullet

        return None


    def hit(self, damage):
        self.health -= damage
        if self.health <= 0:
            self.alive = False
            return True
        return False

class GameObjectSprite(pygame.sprite.Sprite):

    def __init__(self, entity, image):
        pygame.sprite.Sprite.__init__(self)
        self.entity = entity
        self.entity.sprite = self
        self.src_image = image

    def update(self):
        self.image = pygame.transform.rotate(self.src_image, -self.entity.angle / math.pi * 180 - 90)
        self.rect = self.image.get_rect()
        self.rect.center = (self.entity.x, self.entity.y)

GameObject.registerType(Mob)
GameObject.registerType(Player)
GameObject.registerType(Bullet)
Beispiel #48
0
 def __init__(self, position, angle, owner=None, objId=None):
     GameObject.__init__(self, position, angle, self.SIZE, self.TYPE, objId, solid=False)
     if owner is not None:
         self.owner = owner.id
    def __init__(self, target_region=None, O_i_rect=None, action=None, showRender=False, checksolution=False, scenario_file='s5.json'):
       
        super(Scenario_Generator, self).__init__()
        self.showRender = showRender
        self.state = -1
        self.min_d = 9999999
        self.state_impulse = (0,0)
       
        # Tell the framework we're going to use contacts, so keep track of them
        # every Step.
        self.using_contacts=True
        self.beginContact = False
        self.contactAID = -1
        self.contactBID = -1
        #current simulation round        
        self.round = 0
        self.objID = 0
        world = self.world

        self.objects = []

        self.game_objects = []

        self.target_region = target_region

        width, height, immobile_objs, mobile_objs, manipulatable_objs, target_obj = sr.loadScenario(scenario_file)

        for obj in immobile_objs:
            ## create a simulator object
            gobj = GOBJ(obj['id'])            
            if obj['shape'] == "box":
                static_body = world.CreateStaticBody(position=obj['position'], shapes=polygonShape(box=obj['size']), angle=obj['angle'],userData=gobj)
                                                
            elif obj['shape'] == "polygon":
                static_body = world.CreateStaticBody(position=obj['position'], shapes=polygonShape(vertices=obj['vertices']), userData=gobj)

            # store coordinates info in the screen
            mass_center = static_body.fixtures[0].massData.center            
            vertices=[(static_body.transform*v) for v in static_body.fixtures[0].shape]
            #vertices=[(v[0], SCREEN_HEIGHT-v[1]) for v in vertices]
            gobj.setPosScr(vertices)
            gobj.setMassCenterSrc(static_body.transform * mass_center)
            
            self.game_objects.append(gobj)

        target_id = target_obj['id']

        for obj in mobile_objs:
            obj_id = obj['id']
         

            gobj = GOBJ(obj_id,role=GOBJ.MOVEABLE)
            if obj['shape'] == "box":
                dynamic_body = world.CreateDynamicBody(position=obj['position'], userData=gobj)
                dynamic_body.CreatePolygonFixture(box=obj['size'],density=obj['density'], friction=obj['friction'])
            
            mass_center = dynamic_body.fixtures[0].massData.center

            vertices=[(dynamic_body.transform*v)for v in dynamic_body.fixtures[0].shape]
            #vertices=[(v[0], SCREEN_HEIGHT-v[1]) for v in vertices]
            gobj.setPosScr(vertices)
            gobj.setMassCenterSrc(dynamic_body.transform * mass_center)
            self.game_objects.append(gobj)


        for obj in manipulatable_objs:
            gobj = GOBJ(obj['id'],role=GOBJ.MAN)
            if obj['shape'] == "box":
                dynamic_body = world.CreateDynamicBody(position=obj['position'], userData=gobj)
                dynamic_body.CreatePolygonFixture(box=obj['size'],density=obj['density'], friction=obj['friction'])
            
            mass_center = dynamic_body.fixtures[0].massData.center

            vertices=[(dynamic_body.transform*v)for v in dynamic_body.fixtures[0].shape]
            #vertices=[(v[0], SCREEN_HEIGHT-v[1]) for v in vertices]
            gobj.setPosScr(vertices)
            gobj.setMassCenterSrc(dynamic_body.transform * mass_center)
            self.game_objects.append(gobj)
                
        '''
    def __init__(self, width, height, immobile_objs, mobile_objs, manipulatable_obj, target_obj, showRender=True):
       
        super(Scenario_Generator, self).__init__()

        self.SCENARIO_WIDTH, self.SCENARIO_HEIGHT = width, height
        self.SCREEN_WIDTH, self.SCREEN_HEIGHT= self.SCENARIO_WIDTH * PPM, self.SCENARIO_HEIGHT * PPM

        self.showRender = showRender

        self.min_d = 9999999
        self.solved = False
        self.impulse = (0,0)
        self.p = (0,0)
        self.current_man_id = manipulatable_obj['id']
       
        # Tell the framework we're going to use contacts, so keep track of them
        # every Step.
        self.using_contacts=True
        self.beginContact = False
        self.current_contacts = set([])
        self.contactAID = -1
        self.contactBID = -1

        #current simulation round        
        self.round = 0
        

        world = self.world

        self.trajectory = []
        
        self.b2_objects = {}

        self.game_objects = []

        self.target_obj = target_obj
        self.goal = 0

        self.contacts_with_mobile_objs = []

        if self.target_obj == None:
            self.target_obj = target_obj
            if self.target_obj['goal'] == "RIGHT":
                self.goal = - pi/2
            elif self.target_obj['goal'] == "LEFT":
                self.goal = pi/2

        for obj in immobile_objs:
            ## create a simulator object
            gobj = GOBJ(obj['id'])            
            if obj['shape'] == "box":
                static_body = world.CreateStaticBody(position=obj['position'], shapes=polygonShape(box=obj['size']), angle=obj['angle'],userData=gobj)
                                                            
            elif obj['shape'] == "polygon":
                static_body = world.CreateStaticBody(position=obj['position'], shapes=polygonShape(vertices=obj['vertices']), userData=gobj)

            # store coordinates info in the screen
            mass_center = static_body.fixtures[0].massData.center            
            vertices=[(static_body.transform*v) for v in static_body.fixtures[0].shape]
            #vertices=[(v[0], SCREEN_HEIGHT-v[1]) for v in vertices]
            gobj.setPosScr(vertices)
            gobj.setMassCenterSrc(static_body.transform * mass_center)
            
            self.game_objects.append(gobj)

            self.b2_objects[obj['id']] = static_body

        self.mobile_objs_ids = []
        for obj in mobile_objs:
            obj_id = obj['id']
            if obj_id != self.target_obj['id']:         
                gobj = GOBJ(obj_id,role=GOBJ.MOVEABLE)
            else:
                gobj = GOBJ(obj_id,role=GOBJ.TARGET)

            if obj['shape'] == "box":
                dynamic_body = world.CreateDynamicBody(position=obj['position'], userData=gobj)
                dynamic_body.CreatePolygonFixture(box=obj['size'],density=obj['density'], friction=obj['friction'])
            
            mass_center = dynamic_body.fixtures[0].massData.center

            vertices=[(dynamic_body.transform*v)for v in dynamic_body.fixtures[0].shape]
            #vertices=[(v[0], SCREEN_HEIGHT-v[1]) for v in vertices]
            gobj.setPosScr(vertices)
            gobj.setMassCenterSrc(dynamic_body.transform * mass_center)

            self.game_objects.append(gobj)
            self.b2_objects[obj['id']] = dynamic_body
            self.mobile_objs_ids.append(obj_id)


        gobj = GOBJ(manipulatable_obj['id'],role=GOBJ.MAN)

        man_dynamic_body = world.CreateDynamicBody(position=manipulatable_obj['position'], userData=gobj)
        if manipulatable_obj['shape'] == "box":
            man_dynamic_body.CreatePolygonFixture(box=manipulatable_obj['size'],density=manipulatable_obj['density'], friction=manipulatable_obj['friction'])
            mass_center = man_dynamic_body.fixtures[0].massData.center
            vertices=[(man_dynamic_body.transform*v)for v in man_dynamic_body.fixtures[0].shape]
            gobj.setPosScr(vertices)
            gobj.setMassCenterSrc(man_dynamic_body.transform * mass_center)

        elif manipulatable_obj['shape'] == "circle":

            man_dynamic_body.CreateFixture(shape=b2CircleShape(radius=manipulatable_obj['radius']), density=manipulatable_obj['density'], friction=manipulatable_obj['friction'])
            man_dynamic_body.fixtures[0].restitution = manipulatable_obj['restitution']
            mass_center = man_dynamic_body.fixtures[0].massData.center
            position = man_dynamic_body.transform * man_dynamic_body.fixtures[0].shape.pos
            gobj.setPosScr([position])
            gobj.setMassCenterSrc(man_dynamic_body.transform * mass_center)
        
        self.game_objects.append(gobj)
        self.b2_objects[manipulatable_obj['id']] = man_dynamic_body
        
        self.mobile_objs_ids.append(manipulatable_obj['id'])
        #print dir(man_dynamic_body)
        #print man_dynamic_body.position

        '''
Beispiel #51
0
 def move(self, delta):
     GameObject.move(self, scale=delta*self.speed, angle=self.angle)
Beispiel #52
0
 def __init__(self, arena, number):
     GameObject.__init__(self, arena)
     self.marker_info = create_marker_info_by_type(MARKER_TOKEN, number)
     self.grabbed = False
Beispiel #53
0
 def __init__(self, arena, number, location=(0,0), heading=0):
     GameObject.__init__(self, arena)
     self.marker_info = create_marker_info_by_type(MARKER_ARENA, number)
     self.location = location
     self.heading = heading
Beispiel #54
0
 def __init__(self, xpos, ypos, speed):
     GameObject.__init__(self, xpos, ypos, 5, 30)
     #self.x = xpos
     #self.y = ypos
     self.speed = speed
     self.dt = 5
    return (command)

#  intro
print(bcolors.BOLD + bcolors.UNDERLINE + bcolors.BG_RED + "Welcome to Super Dungeon Slaughter!" + bcolors.ENDC)

#  set up battle
hero_name = input("\n\nWhat is your hero's name? ")
new_hero = Hero(hero_name)
new_hero.add_item_to_inventory(Potion_heal())
new_monster = bestiary.get_monster_from_bestiary_by_level(new_hero.level)

#  battle loop
print("Start the battle!")
print("Enter \"help\" or \"h\" for a list of commands.")

game_obj = GameObject(new_hero, new_monster)
fight = True

while (fight):
    command = getInput()

    if (command == "flee"):
        break
    else:
        command_obj.performCommand(command, game_obj)

    if (game_obj.HERO.hp <= 0):
        fight = False

    if (game_obj.MONSTER.hp <= 0):
        game_obj.HERO.total_kills += 1
Beispiel #56
0
 def update(self, *args):
     GameObject.update(self, *args)
     self.time -= 1
     if self.time <= 0:
         self.kill()
Beispiel #57
0
    def update(self, speed = 2):
        GameObject.update(self, speed)

        self.rect.y += speed
        if self.rect.y > self.game.HEIGHT:
            self.kill()
Beispiel #58
0
 def __init__(self, position, angle, area, solids, objId=None):
     GameObject.__init__(self, position, angle, self.SIZE, self.TYPE, objId,
                         area=area, solids=solids)
     self.health = self.HEALTH
     self.next_shot = 0
     self.target = None