示例#1
0
 def __init__(self, app, scene, filename=None, **kwargs):
     super().__init__(app, scene, filename, **kwargs)
     self.solid = True
     self.hp = 1
     self.stats = None
     self.alive = True  # prevent mutliple kill()
     self.friendly = False
     self.stats = Stats()
示例#2
0
    def __init__(self, app, state=None):

        super().__init__(app, state)

        self.scene = Scene(self.app, self)
        self.gui = Scene(self.app, self)
        self.slots = SlotList()
        self.paused = False

        # self.scene.add(ButtaBomber(app, self.scene, vec3(0, 0, -3000)))
        # self.scene.add(Powerup(app, self.scene, 'star', position=vec3(0, 0, -3000)))

        # create terminal first since player init() writes to it
        self.terminal = self.gui.add(Terminal(self.app, self.scene))

        self.app.inputs = self.build_inputs()
        self.camera = self.scene.add(Camera(app, self.scene, self.app.size))
        stats = self.stats = self.app.data["stats"] = self.app.data.get(
            "stats", Stats()
        )
        self.level = stats.level
        self.player = self.scene.add(Player(app, self.scene, level=self.level))

        # self.scripts += self.score_screen

        # self.camera.slots.append(
        #     self.player.on_move.connect(lambda: self.camera.update_pos(self.player))
        # )

        self.debug = False
        self.slots += [
            app.inputs["debug"].on_press(lambda _: self.debug_mode(True)),
            app.inputs["debug"].on_release(lambda _: self.debug_mode(False)),
        ]
        self.slots += [
            app.inputs["pause"].on_press(self.toggle_pause),
        ]

        self.time = 0

        # score backdrop
        backdrop_h = int(24 * 1.8)

        # draw a score backdrop
        rows = 8
        for i in range(rows):
            h = int(backdrop_h) // rows
            y = h * i
            backdrop = pygame.Surface((self.app.size.x, h))
            interp = i / rows
            interp_inv = 1 - i / rows
            backdrop.set_alpha(255 * interp * 0.4)
            # backdrop.fill((0))
            backdrop.fill(pg_color(ncolor("white") * interp_inv))
            self.scene.on_render += lambda _, y=y, backdrop=backdrop: self.app.screen.blit(
                backdrop, (0, y)
            )
    def __init__(self, app, state=None):

        super().__init__(app, state, self)

        self.stats = self.app.data["stats"] = self.app.data.get(
            "stats", Stats())

        self.scene = Scene(self.app, self)

        self.terminal = self.scene.add(Terminal(self.app, self.scene))
        self.camera = self.scene.add(Camera(app, self.scene, self.app.size))
        self.ground = self.scene.add(Ground(app, self.scene, GROUND_HEIGHT))
        self.terminal.position.z -= 10

        self.time = 0
示例#4
0
    def __init__(self, app, scene, speed=PLAYER_SPEED, level=0):
        super().__init__(app, scene, filename=SHIP_IMAGE_PATH)
        self.game_state = self.scene.state

        # persistant stats for score screen
        self.stats = self.app.data["stats"] = self.app.data.get(
            "stats", Stats())

        self.scene.player = self

        self.max_hp = self.hp = 3
        self.friendly = True  # determines what Beings you can damage
        self.crosshair_surf: SurfaceType = app.load_img(
            CROSSHAIR_IMAGE_PATH, 3)
        self.crosshair_surf_green = app.load_img(CROSSHAIR_GREEN_IMAGE_PATH, 3)
        self.crosshair_scale = 1

        self.slots += [
            self.app.inputs["hmove"].always_call(self.set_vel_x),
            self.app.inputs["vmove"].always_call(self.set_vel_y),
            self.app.inputs["fire"].always_call(self.fire),
            self.app.inputs["switch-gun"].on_press_repeated(
                self.next_gun, 0.5),
            # self.app.inputs["test"].on_press(self.explode),
        ]

        self.position = vec3(0, 0, 0)
        self.collision_size = vec3(50, 50, 500)
        self.speed = vec3(speed)
        self.velocity = vec3(self.speed)

        self.alive = True
        self.solid = True
        self.blinking = False
        self.targeting = False
        self.hide_stats = 0
        self.score_flash = 0.0
        self.weapon_flash = 0.0
        self.health_flash = 0.0

        self.level = level
        self.weapons: List[Weapon] = self.get_guns()
        self.current_weapon = 0

        self.scripts += [self.blink, self.smoke]
示例#5
0
    def process_state_change(self):
        """
        Process pending state changes
        """
        lvl = None

        try:
            lvl = int(self.next_state)
            pass
        except ValueError:
            pass

        if lvl:
            stats = self.data["stats"] = self.data.get("stats", Stats())
            stats.level = lvl
            self.next_state = "game"

        if self.next_state:
            self._state = self.STATES[self.next_state.lower()](self)

        self.next_state = None