Esempio n. 1
0
 def __init__(self, camera, player, space):
     Stage.__init__(self, player, space)
     self.load("data/stage0.txt", space)
     self.camera = camera
     info0 = gameobject.InfoBlock(util.vec2(-64, 16), "data/info_bubble0_0.png", space, "data/info_bubble0_")
     info1 = gameobject.InfoBlock(util.vec2(32, 16), "data/info_bubble1_0.png", space, "data/info_bubble1_")
     info2 = gameobject.InfoBlock(
         util.vec2(304, 16),
         "data/info_bubble2_0.png",
         space,
         "data/info_bubble2_",
         6,
         [0, 1, 2, 3, 5, 5, 6, 6, 5, 5, 6, 6],
     )
     info3 = gameobject.InfoBlock(
         util.vec2(512, 16),
         "data/info_bubble3_0.png",
         space,
         "data/info_bubble3_",
         7,
         [0, 1, 2, 3, 4, 5, 6, 7, 6, 7, 6, 7],
         2,
     )
     self.info_blocks.append(info1)
     self.info_blocks.append(info0)
     self.info_blocks.append(info2)
     self.info_blocks.append(info3)
Esempio n. 2
0
    def update(self):
        delta = util.vec2(self.lookat_pos.x - self.real_pos.x, self.lookat_pos.y - self.real_pos.y)
        if (delta.x > self.center.x * self.delta_threshold):
            movedelta = delta.x - self.center.x * (1.0 - self.delta_threshold)
            self.real_pos = util.vec2(self.real_pos.x + movedelta / 10.0, self.real_pos.y)
        elif (-delta.x > self.center.x * self.delta_threshold):
            movedelta = -delta.x - self.center.x * (1.0 - self.delta_threshold)
            self.real_pos = util.vec2(self.real_pos.x - movedelta / 10.0, self.real_pos.y)

        if (delta.y > self.center.y * self.delta_threshold):
            self.real_pos = util.vec2(self.real_pos.x, self.real_pos.y + 2)
        elif (-delta.y > self.center.y * self.delta_threshold):
            self.real_pos = util.vec2(self.real_pos.x, self.real_pos.y - 2)

        """delta = util.vec2(self.lookat_pos.x - self.real_pos.x, self.lookat_pos.y - self.real_pos.y)
Esempio n. 3
0
 def __init__(self,name,pos,speed,repeat = False,animated = False,blend = False):
     self.image = util.load_image(name)
     self.rect = self.image.get_rect()
     self.width = self.rect.width
     self.height = self.rect.height
     self.is_animated = animated
     self.pos = pos
     self.draw_pos = util.vec2(0,0)
     self.speed = speed
     self.inv_speed = speed/100.
     self.repeat = repeat
     self.offset = 320
     self.last_frame_pos = 0
     self.blend = blend
Esempio n. 4
0
    def start_new_level(self, stage_id):
        self.current_stage_id = stage_id

        self.restart_level_counter = -1
        self.init_physics()
        self.remove_player = False

        self.player = player.Player(util.vec2(100,20), self.space)
        self.active_color = self.player.toggle_color(CRED)

        self.gui_key.reset()

        stages = {
            stage.STAGE_INTRO: stage.StageIntro,
            stage.STAGE_0: stage.Stage0,
            stage.STAGE_1: stage.Stage1,
            stage.STAGE_2: stage.Stage2,
            stage.STAGE_4: stage.Stage4,
            stage.STAGE_3: stage.Stage3,
            stage.STAGE_5: stage.Stage5,
            stage.STAGE_6: stage.Stage6,
            stage.STAGE_7: stage.Stage7,
            stage.STAGE_8: stage.Stage8,
            stage.STAGE_9: stage.Stage9,
            stage.STAGE_10: stage.Stage10,
            stage.STAGE_11: stage.Stage11
        }

        if not self.current_stage_id == stage.STAGE_INTRO:
            self.map_timer.reset()
            self.map_timer.show()
        else:
            self.map_timer.hide()

        if stage_id > len(stages)-1:
            stage_id = 0
            self.current_stage_id = 0

        self.set_level(stages[stage_id](self.camera, self.player, self.space))
Esempio n. 5
0
    def load(self, filepath, space):
        import sys

        # goal
        doorblock = util.load_image("data/entity_door0.png")

        # standard blocks
        rblock = util.load_image("data/red_block16.png")
        gblock = util.load_image("data/green_block16.png")
        bblock = util.load_image("data/blue_block16.png")
        wblock = util.load_image("data/bw_block16.png")
        # keys
        rkblock = util.load_image("data/red_key0.png")
        gkblock = util.load_image("data/green_key0.png")
        bkblock = util.load_image("data/blue_key0.png")
        # movable
        r_movableblock = util.load_image("data/red_movable_block0.png")
        g_movableblock = util.load_image("data/green_movable_block0.png")
        b_movableblock = util.load_image("data/blue_movable_block0.png")

        with open(filepath) as f:
            data = f.readlines()

        xoffset = 7
        yoffset = 3

        for rnum, row in enumerate(data):
            for cnum, col in enumerate(row):
                movable = False
                if col == "1":
                    block = r_movableblock
                    movable = True
                    type = gameobject.OBJECT_TYPE_RED
                elif col == "2":
                    block = g_movableblock
                    movable = True
                    type = gameobject.OBJECT_TYPE_GREEN
                elif col == "3":
                    block = b_movableblock
                    movable = True
                    type = gameobject.OBJECT_TYPE_BLUE
                elif col == "R":
                    block = rblock
                    type = gameobject.OBJECT_TYPE_RED
                elif col == "G":
                    block = gblock
                    type = gameobject.OBJECT_TYPE_GREEN
                elif col == "B":
                    block = bblock
                    type = gameobject.OBJECT_TYPE_BLUE
                elif col == "W":
                    block = wblock
                    type = gameobject.OBJECT_TYPE_BW
                elif col == "X":
                    block = rkblock
                    type = gameobject.OBJECT_TYPE_KEY_RED
                elif col == "Y":
                    block = gkblock
                    type = gameobject.OBJECT_TYPE_KEY_GREEN
                elif col == "Z":
                    block = bkblock
                    type = gameobject.OBJECT_TYPE_KEY_BLUE
                elif col == "D":
                    block = doorblock
                    type = gameobject.OBJECT_TYPE_GOAL
                    self.doorpos = (cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
                elif col == "P":
                    self.player.body.position = (cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
                    continue
                else:
                    continue
                pos = util.vec2(cnum * 16 - xoffset * 16, rnum * 16 - yoffset * 16)
                if movable:
                    go = gameobject.MovableBlock(pos, util.to_sprite(block), space, type)
                    self.game_objects.append(go)
                else:
                    go = gameobject.StaticBlock(pos, util.to_sprite(block), space, type)
                    self.tiles.append(go)
Esempio n. 6
0
 def update(self, camera_pos):
     self.body.angle = 0
     self.draw_pos = util.vec2(
         self.body.position.x - camera_pos.x, self.body.position.y - camera_pos.y
     )  # util.vec2(self.sprite.rect.left - camera_pos.x, self.sprite.rect.top - camera_pos.y)
Esempio n. 7
0
    def __init__(self, pos, sprite, space, obj_type, mass=5.0):
        self.draw_pos = util.vec2(0, 0)
        self.sprite = sprite
        # self.move(pos.x, pos.y)

        self.object_type = obj_type
Esempio n. 8
0
    def __init__(self, size, scale):
        pygame.init()
        self.scale = scale
        self.size = size
        if scale:
            self.window = pygame.display.set_mode((size[0]*2, size[1]*2))
        else:
            self.window = pygame.display.set_mode(size)

        self.screen = pygame.Surface(size)
        self.screen.set_colorkey((0,0,0))
        self.actual_screen = pygame.display.get_surface()
        self.camera = camera.Camera(util.vec2(30,25),size)

        pygame.mouse.set_visible(0)
        self.clock = pygame.time.Clock()
        self.is_running = True

        self.restart_level_counter = -1
        self.current_stage_id = stage.STAGE_INTRO
        self.remove_player = False

        # physics
        #init_physics()


        # music:
        self.bg_music = util.load_sound("data/channel_panic!-theme.ogg")
        #self.bg_music.play(-1)
        #self.bg_music_playing = True
        self.bg_music_playing = False
        # billboards
        self.billboards = []
        self.billboards.append(billboard.Billboard("data/background_stars.png",util.vec2(0,0),10,True))
        self.billboards.append(billboard.Billboard("data/background_city.png",util.vec2(0,210),40,True,False,False))
        self.billboards.append(billboard.Billboard("data/background_city2.png",util.vec2(0,190),30,True,False,True))

        #timer
        self.map_timer = billboard.GuiTimerBar(util.vec2(240,0),15)

        # misc
        names = util.name_sequence("data/entity_door","png",4)
        # lol hack
        frames = util.get_sequence(names,[0,1,2,3,4,4,4,4,4,4,4,4,4,4])
        self.door_anim = animation.Animation(frames,8)
        self.animate_door = False

        self.fade_in_out = False
        self.fade_in_out_time = 0

        self.playing_intro = True

        # key gui thingy
        self.gui_key = billboard.GuiKeys(util.vec2(0,0),16)

        # game settings
        #self.player = player.Player(util.vec2(100,20), self.space)
        #print(self.player.object_type)
        #self.camera = camera.Camera(util.vec2(30,25),size)
        #self.current_stage = None
        # set color key to black
        #self.screen.set_colorkey(pygame.Color(0,0,0))
        pygame.key.set_repeat(1, 20)
Esempio n. 9
0
    def run(self):

        pxf_logo = animation.new_animation("data/pxf_logo0", "png", 12, 5, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12][:-1])
        pxf_logo.play()
        intro_end_time = 5000
        while self.playing_intro:
            self.dt_last_frame = self.clock.tick(60)
            intro_end_time -= self.dt_last_frame
            if intro_end_time <= 0:
                self.playing_intro = False

            self.screen.fill([0,0,0])

            for event in pygame.event.get():
                if event.type == QUIT:
                    self.playing_intro = False
                    self.is_running = False
                if event.type == pygame.KEYUP:
                    if (event.key == K_ESCAPE):
                        self.playing_intro = False



            pxf_logo.update(self.dt_last_frame)
            pxf_logo.draw(self.screen, (self.size[0] / 2 - 64, self.size[1] / 2 - 64), True)

            if self.scale:
                pygame.transform.scale2x(self.screen, self.actual_screen)
            else:
                self.actual_screen.blit(self.screen, (0, 0))

            pygame.display.flip()



        #self.set_level(stage.Stage1(self.camera, self.player, self.space))
        self.start_new_level(self.current_stage_id)

        while self.is_running:
            # update time
            self.dt_last_frame = self.clock.tick(60)

            if (self.restart_level_counter > 0):
                self.player.body.position = (-111111, -111111)
                self.restart_level_counter -= self.dt_last_frame / 1000.0
                if (self.restart_level_counter <= 0):
                    self.start_new_level(self.current_stage_id)

            # event handling
            if (self.restart_level_counter < 0):
                for event in pygame.event.get():
                    if event.type == QUIT:
                        self.is_running = False
                    elif event.type in (KEYDOWN, KEYUP):
                        self.handle_input(event)

                # handle game input
                self.game_input()

            self.screen.fill([0,0,0])

            # update animation
            #self.anim_test.update(self.dt_last_frame)
            #self.anim_test.draw(self.screen)

            # update player
            self.player.update(self.camera.get_pos(),self.dt_last_frame)

            # update physics
            self.space.step(1/60.0)
            if (self.remove_player):
                self.space.add_collisionpair_func(gameobject.OBJECT_TYPE_PLAYER, gameobject.OBJECT_TYPE_RED, None)
                self.space.add_collisionpair_func(gameobject.OBJECT_TYPE_PLAYER, gameobject.OBJECT_TYPE_GREEN, None)
                self.space.add_collisionpair_func(gameobject.OBJECT_TYPE_PLAYER, gameobject.OBJECT_TYPE_BLUE, None)
                self.space.add_collisionpair_func(gameobject.OBJECT_TYPE_PLAYER, gameobject.OBJECT_TYPE_BW, None)
                self.remove_player = False

            # update game objects
            for object in self.current_stage.tiles:
                #object.update(self.camera.pos)
                object.update(self.camera.get_pos())

            for splosion in self.current_stage.splosion_objects:
                splosion.update(self.camera.get_pos())

            for obj in self.current_stage.game_objects:
                obj.update(self.camera.get_pos())

            for inf in self.current_stage.info_blocks:
                inf.update(self.camera.get_pos(),self.dt_last_frame)

            # update camera
            if (self.restart_level_counter < 0):
                self.camera.set_lookat(util.vec2(self.player.body.position.x, self.player.body.position.y))
            self.camera.update()

            # draw billboards
            for billboard in self.billboards:
                billboard.update(self.camera.get_pos(),self.dt_last_frame)
                billboard.draw(self.screen)

            # update game
            self.current_stage.draw(self.screen)

            if self.animate_door:
                self.door_anim.update(self.dt_last_frame)
                p = self.current_stage.doorpos
                p = (p[0] - self.camera.get_pos().x, p[1] - self.camera.get_pos().y)
                self.door_anim.draw(self.screen, p, True)
                if self.door_anim.current == len(self.door_anim.frames)-1:
                    self.start_new_level(self.current_stage_id + 1)
                    self.door_anim.current = 0
                    self.animate_door = False
                    self.door_anim.stop()
                elif self.door_anim.current == 3:
                    self.fade_in_out = True
                    self.fade_in_out_time = 3


            self.player.draw(self.screen)

            # draw key gui
            self.gui_key.draw(self.screen)

            self.map_timer.update(self.dt_last_frame)
            self.map_timer.draw(self.screen)

            self.check_timer()

            if self.fade_in_out:
                self.fade_in_out_time -= self.dt_last_frame / 1000.0
                surf = pygame.Surface(self.size)
                surf.fill((0, 0, 0))
                if self.fade_in_out_time > 2.0:
                    a = 255 - int(255 * ((self.fade_in_out_time-2.0)/2.0))
                else:
                    a = int(255 * ((self.fade_in_out_time)/1.0))
                surf.set_alpha(a)
                self.screen.blit(surf, (0, 0))
                if self.fade_in_out_time <= 0.0:
                    self.fade_in_out = False

            # fps limit
            #3self.clock.tick(25)
            self.update_title()

            if self.scale:
                pygame.transform.scale2x(self.screen, self.actual_screen)
            else:
                self.actual_screen.blit(self.screen, (0, 0))

            # swap buffers
            pygame.display.flip()
Esempio n. 10
0
 def create_splosions(self, spltype):
     for i in range(30):
         splobj = gameobject.SplosionBlock(util.vec2(self.player.body.position.x, self.player.body.position.y), self.space, spltype)
         self.current_stage.splosion_objects.append(splobj)
Esempio n. 11
0
 def __init__(self,pos,size):
     self.real_pos = util.vec2(pos.x, pos.y)
     self.lookat_pos = util.vec2(pos.x, pos.y)
     self.center = util.vec2(size[0] / 2.0, size[1] / 2.0)
     self.rect = Rect((0,0),size)
     self.delta_threshold = 0.5
Esempio n. 12
0
 def get_pos(self):
     return util.vec2(self.real_pos.x - self.center.x, self.real_pos.y - self.center.y)
Esempio n. 13
0
 def set_lookat(self, pos):
     self.lookat_pos = util.vec2(pos.x, pos.y)