Ejemplo n.º 1
0
    def display(self):
        global MUSIC, IS_MODE_TERMINATE

        if MUSIC != 0:
            pyxel.stop()
            MUSIC = 0
            # pyxel.playm(MUSIC, loop=True)
            pyxel.play(0,6, loop=True)
            pyxel.play(1,8, loop=True)

        pyxel.cls(10)
        if pyxel.btn(pyxel.KEY_SPACE):
            IS_MODE_TERMINATE =1
Ejemplo n.º 2
0
    def update(self):
        if pyxel.btn(pyxel.KEY_Q):
            pyxel.quit()

        player.update()
        for enemy in enemies:
            if abs(player.x - enemy.x) < 6 and abs(player.y - enemy.y) < 6:
                game_over()
                return
            enemy.update()
            if enemy.x < scroll_x - 8 or enemy.x > scroll_x + 160 or enemy.y > 160:
                enemy.is_alive = False
        cleanup_list(enemies)
Ejemplo n.º 3
0
def draw():
    global memoryX
    global memoryY
    pyxel.cls(7)
    if pyxel.btn(pyxel.KEY_SPACE):
        memoryX = -1
        memoryY = -1
        pyxel.line(0, 0, pyxel.mouse_x, pyxel.mouse_y, 0)
    if pyxel.btnr(pyxel.KEY_SPACE):
        memoryX = pyxel.mouse_x
        memoryY = pyxel.mouse_y
    if memoryX >= 0 and memoryY >= 0:
        pyxel.line(0, 0, memoryX, memoryY, 0)
Ejemplo n.º 4
0
    def update_player(self):
        if pyxel.btn(pyxel.KEY_LEFT):
            self.player_x = max(self.player_x - 2, pyxel.width - 30)
            self.player_y = max(self.player_y - 2, pyxel.width - 2)

        if pyxel.btn(pyxel.KEY_RIGHT):
            self.player_x = min(self.player_x + 2, pyxel.width - 30)

        self.player_y += self.player_vy
        self.player_vy = min(self.player_vy + 1, 8)

        if self.player_y > pyxel.height:
            if self.player_is_alive:
                self.player_is_alive = False
                pyxel.play(3, 5)

            if self.player_y > 600:
                self.score = 0
                self.player_x = 72
                self.player_y = -16
                self.player_vy = 0
                self.player_is_alive = True
Ejemplo n.º 5
0
    def update(self):
        pow_vec = Vector(
            pyxel.btn(pyxel.KEY_RIGHT) - pyxel.btn(pyxel.KEY_LEFT),
            pyxel.btn(pyxel.KEY_DOWN) - pyxel.btn(pyxel.KEY_UP))
        s_len = pow_vec.squared_length()
        if s_len != 0:
            pow_vec *= 1 / math.sqrt(s_len)
        self.speed += pow_vec * 2

        if pyxel.btnp(pyxel.KEY_SPACE, 0, 5):

            if self.lr == 1:
                Beam(self.characters, self.beams, self.position + Vector(8, 5))
                self.lr = 0
            else:
                Beam(self.characters, self.beams,
                     self.position + Vector(8, -5))
                self.lr = 1

        super().update()
        if self.position.x < self.image_rect.size.x / 2:
            self.position.x = self.image_rect.size.x / 2
        if self.position.y < self.image_rect.size.y / 2:
            self.position.y = self.image_rect.size.y / 2
        if self.position.x > pyxel.width - self.image_rect.size.x / 2:
            self.position.x = pyxel.width - self.image_rect.size.x
        if self.position.y > pyxel.height - self.image_rect.size.y / 2:
            self.position.y = pyxel.height - self.image_rect.size.y

        pos = self.position
        radius = max(self.image_rect.size.x, self.image_rect.size.y) / 2
        for enemy in self.enemies:
            enemy_pos = enemy.position
            enemy_radius = max(enemy.image_rect.size.x,
                               enemy.image_rect.size.y) / 2
            if (enemy_pos - pos).length() < radius + enemy_radius:
                self.__del__()
                app.running = False
                break
Ejemplo n.º 6
0
def update():
    global pX, pY, pVY, p_alive, score
    if btnp(KEY_Q): quit()
    if btn(KEY_LEFT) or btn(GAMEPAD_1_LEFT): pX = max(pX - 2, 0)
    if btn(KEY_RIGHT) or btn(GAMEPAD_1_RIGHT):
        pX = min(pX + 2, pyxel.width - 16)
    for i, (x, y, a) in enumerate(floor):  # update_floor
        if a and x - 16 <= pX <= x + 40 and y - 16 <= pY <= y + 8 and 0 < pVY:
            a, score, pVY, _ = 0, score + 10, -12, play(3, 3)
        floor[i] = (x - 4 + 240, RDI(8, 104),
                    1) if x - 4 < -40 else (x - 4, y + (a == 0) * 6, a)
    for i, (x, y, k, a) in enumerate(fruit):
        if a and abs(x - pX) < 12 and abs(y - pY) < 12:
            a, score, pVY, _ = 0, score + (k + 1) * 100, min(pVY,
                                                             -8), play(3, 4)
        fruit[i] = (x - 2 + 240, RDI(0, 104), RDI(0, 2),
                    1) if x - 2 < -40 else (x - 2, y, k, a)
    pY, pVY = pY + pVY, min(pVY + 1, 8)
    if pY > pyxel.height:
        if p_alive:
            (p_alive, _) = (0, play(3, 5))  # play sound could be merged !
        if pY > 600: score, pX, pY, pVY, p_alive = 0, 72, -16, 0, 1
Ejemplo n.º 7
0
    def read_input(self):
        if pyxel.btn(pyxel.KEY_RIGHT):
            self.v_hor += VELOCITY_MOVE_STEP
            self.v_hor = min(self.v_hor, VELOCITY_MOVE_MAX)
            self.dir = DIR_RIGHT
            self.env.eventloop.send(EVENT_WALK_START)

        if pyxel.btn(pyxel.KEY_LEFT):
            self.v_hor -= VELOCITY_MOVE_STEP
            self.v_hor = max(self.v_hor, -VELOCITY_MOVE_MAX)
            self.dir = DIR_LEFT
            self.env.eventloop.send(EVENT_WALK_START)

        if self.jump_limit > 0 and pyxel.btnp(pyxel.KEY_UP):
            self.jump_limit -= 1
            self.v_vert = VELOCITY_JUMP

        if pyxel.btnr(pyxel.KEY_UP) and self.vmove_up():
            self.v_vert = -DISTANCE_ZERO_THRESHOLD

        if pyxel.btnr(pyxel.KEY_LEFT) or pyxel.btnr(pyxel.KEY_RIGHT):
            self.env.eventloop.send(EVENT_WALK_STOP)
Ejemplo n.º 8
0
    def strum(self):
        is_strumming = pyxel.btn(pyxel.KEY_SPACE) or self.joystick.is_strumming
        strum = not self.store.state['strum'] and is_strumming

        if is_strumming != self.store.state['strum']:
            self.store.dispatch(actions.SET_STRUM, strum=strum)

        note = next(self.upcoming_notes, None)
        if strum:
            if note and not note['hit'] and self.note_hit(note):
                self.store.dispatch(actions.NOTE_HIT, note=note)
            else:
                self.store.dispatch(actions.NOTE_MISS)
Ejemplo n.º 9
0
    def update(self):

        if (self.active):
            self.state = self.isColliding()

            if (self.state and pyxel.btn(pyxel.MOUSE_LEFT_BUTTON)):
                self.setCol = self.col[2]
            elif (self.state):
                self.setCol = self.col[1]
            else:
                self.setCol = self.col[0]
        else:
            self.state = False
Ejemplo n.º 10
0
    def keyDownScan(self):
        if (pyxel.btn(pyxel.KEY_W)):
            self.velocity[1] -= VELOCITY
        if (pyxel.btn(pyxel.KEY_A)):
            self.velocity[0] -= VELOCITY
        if (pyxel.btn(pyxel.KEY_S)):
            self.velocity[1] += VELOCITY
        if (pyxel.btn(pyxel.KEY_D)):
            self.velocity[0] += VELOCITY
        if (pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON)):
            self.shoot(1)
        if (pyxel.btnp(pyxel.MOUSE_RIGHT_BUTTON)):
            self.shoot(2)
        if (pyxel.btnp(pyxel.KEY_SPACE)):
            self.shoot(3)
        if (pyxel.btnp(pyxel.KEY_Q)):
            print(self.shoots)

        self.pos[1] += self.velocity[1]
        self.pos[0] += self.velocity[0]

        if (self.velocity[0] > 0):
            self.velocity[0] -= REDUCE_VELOCITY
        if (self.velocity[0] < 0):
            self.velocity[0] += REDUCE_VELOCITY

        if (self.velocity[1] > 0):
            self.velocity[1] -= REDUCE_VELOCITY
        if (self.velocity[1] < 0):
            self.velocity[1] += REDUCE_VELOCITY

        if (self.velocity[0] < (MAX_VELOCITY * -1)):
            self.velocity[0] = MAX_VELOCITY * -1
        if (self.velocity[0] > MAX_VELOCITY): self.velocity[0] = MAX_VELOCITY

        if (self.velocity[1] < (MAX_VELOCITY * -1)):
            self.velocity[1] = MAX_VELOCITY * -1
        if (self.velocity[1] > MAX_VELOCITY): self.velocity[1] = MAX_VELOCITY
Ejemplo n.º 11
0
 def check_input(self):
     if self.current_game_state == GameState.GAME_OVER:
         if pyxel.btn(pyxel.KEY_ENTER):
             self.start_new_game()
     if pyxel.btnp(pyxel.KEY_M):
         self.toggle_music()
     if pyxel.btn(pyxel.KEY_RIGHT):
         if len(self.input_queue) == 0:
             if self.snake_direction != Direction.LEFT and self.snake_direction != Direction.RIGHT:
                 self.input_queue.append(Direction.RIGHT)
         else:
             if self.input_queue[-1] != Direction.LEFT and self.input_queue[
                     -1] != Direction.RIGHT:
                 self.input_queue.append(Direction.RIGHT)
     elif pyxel.btn(pyxel.KEY_LEFT):
         if len(self.input_queue) == 0:
             if self.snake_direction != Direction.RIGHT and self.snake_direction != Direction.LEFT:
                 self.input_queue.append(Direction.LEFT)
         else:
             if self.input_queue[-1] != Direction.RIGHT and self.input_queue[
                     -1] != Direction.LEFT:
                 self.input_queue.append(Direction.LEFT)
     elif pyxel.btn(pyxel.KEY_DOWN):
         if len(self.input_queue) == 0:
             if self.snake_direction != Direction.UP and self.snake_direction != Direction.DOWN:
                 self.input_queue.append(Direction.DOWN)
         else:
             if self.input_queue[-1] != Direction.UP and self.input_queue[
                     -1] != Direction.DOWN:
                 self.input_queue.append(Direction.DOWN)
     elif pyxel.btn(pyxel.KEY_UP):
         if len(self.input_queue) == 0:
             if self.snake_direction != Direction.DOWN and self.snake_direction != Direction.UP:
                 self.input_queue.append(Direction.UP)
         else:
             if self.input_queue[-1] != Direction.DOWN and self.input_queue[
                     -1] != Direction.UP:
                 self.input_queue.append(Direction.UP)
Ejemplo n.º 12
0
    def move(self):
        is_slanting = False
        slanting_speed = 0.71
        is_slow = False

        if pyxel.btn(pyxel.KEY_LEFT_SHIFT):
            is_slow = True

        # 上または下と左または右が押されたとき移動量を0.71倍する
        if (pyxel.btn(pyxel.KEY_RIGHT) or pyxel.btn(pyxel.KEY_LEFT)) and \
            (pyxel.btn(pyxel.KEY_UP) or pyxel.btn(pyxel.KEY_DOWN)):
            is_slanting = True

        if pyxel.btn(pyxel.KEY_RIGHT):
            Player.x += self.speed * (slanting_speed if is_slanting else
                                      1) * (self.slow_speed if is_slow else 1)
        elif pyxel.btn(pyxel.KEY_LEFT):
            Player.x -= self.speed * (slanting_speed if is_slanting else
                                      1) * (self.slow_speed if is_slow else 1)

        if pyxel.btn(pyxel.KEY_UP):
            Player.y -= self.speed * (slanting_speed if is_slanting else
                                      1) * (self.slow_speed if is_slow else 1)
        elif pyxel.btn(pyxel.KEY_DOWN):
            Player.y += self.speed * (slanting_speed if is_slanting else
                                      1) * (self.slow_speed if is_slow else 1)

        self.view_start_x = Player.x - self.width / 2
        self.view_start_y = Player.y - self.height / 2

        # 画面外に行かないように移動制限
        if self.view_start_x < 0:
            Player.x = self.width / 2
        elif self.view_start_x + self.width >= pyxel.width:
            Player.x = pyxel.width - self.width / 2 - 1

        if self.view_start_y < 0:
            Player.y = self.height / 2
        elif self.view_start_y + self.height >= pyxel.height:
            Player.y = pyxel.height - self.height / 2 - 1

        self.view_start_x = Player.x - self.width / 2
        self.view_start_y = Player.y - self.height / 2
Ejemplo n.º 13
0
    def update(self):
        if self.game_state == GameState.PLAYING:
            for obj in self.game_objects.objects:
                obj.reset()

            monster = self.game_objects[0]
            corpse = self.game_objects[1]
            if monster.collision(corpse.box):
                self.game_objects[1] = Corpse(self.game_objects,
                                              random.randint(16, 240),
                                              random.randint(32, 240))
                self.game_objects.score += 1
                self.game_objects.add(
                    Enemy(self.game_objects, random.randint(16, 256 - 16),
                          256 - 32))

            if pyxel.btn(pyxel.KEY_H):
                enemy = Enemy(self.game_objects, random.randint(16, 256 - 16),
                              256 - 32)
                for e in self.events:
                    e.subscribe(enemy)
                self.game_objects.add(enemy)

            for event in self.events:
                event.trigger()

            for obj in self.game_objects.objects:
                obj.update()

            if len(
                [e for e in self.game_objects.objects if isinstance(e, Enemy)
                 ]) <= 0:
                self.game_state = GameState.GAME_OVER
            if self.game_objects.score >= 10:
                self.game_state = GameState.WON
        else:
            if pyxel.btn(pyxel.KEY_N):
                self.new_game()
Ejemplo n.º 14
0
    def update(self):
        if self.fuel < 0:
            self.fuel = 0

        if pyxel.btn(pyxel.KEY_UP) and self.fuel > 0:
            self.ac = (10 / 12000 * abs(210 - self.vel))
            self.fuel -= abs(0.1 * self.waste_each_100 / 100 /
                             (self.vel / 10 if self.vel >= 10 else 1))
        elif pyxel.btn(pyxel.KEY_DOWN):
            if int(self.vel) > 0:
                self.ac = -30 / 60
            elif self.fuel > 0:
                self.ac = -30 / 60
                self.fuel -= abs(0.1 * self.waste_each_100 / 100)
            else:
                self.ac = 0
        elif self.vel != 0:
            self.ac = 4 / 60 * (-1 if self.vel > 0 else 1)

        if not int(self.vel) == 0:
            if pyxel.btn(pyxel.KEY_RIGHT):
                self.angle -= 0.5 / self.vel if self.vel > 15 else 0.08
            elif pyxel.btn(pyxel.KEY_LEFT):
                self.angle += 0.5 / self.vel if self.vel > 15 else 0.08

        self.angle %= 2 * math.pi

        self.vel += self.ac

        #print('VEL:', int( self.vel ), 'FUEL:', self.fuel)

        if abs(self.vel) < 0.01:
            self.vel = 0
        elif self.vel < -15:
            self.vel = -15

        self.x += 0.1 * self.vel * math.cos(self.angle)
        self.y -= 0.1 * self.vel * math.sin(self.angle)
Ejemplo n.º 15
0
    def update(self):
        if self.game_state == 'start':
            if pyxel.btnp(pyxel.KEY_SPACE):
                self.game_state = 'playing'
        elif self.game_state == 'playing':
            if pyxel.btnp(pyxel.KEY_SPACE):
                self.jump = True
                pyxel.play(ch=0, snd=0)
            if self.jump:
                self.dinasour_pos[1] -= self.jump_distance
                self.jump_distance -= 0.6
                if self.dinasour_pos[1] > 56:
                    self.dinasour_pos[1] = 56
                    self.jump = False
                    self.jump_distance = 8
            if pyxel.btn(pyxel.KEY_LEFT):
                self.dinasour_pos[0] -= 2
            elif pyxel.btn(pyxel.KEY_RIGHT):
                self.dinasour_pos[0] += 2
            self.cactus_pos[0] -= self.move_speed
            self.cactus_pos[2] -= self.move_speed
            self.bird_pos[0] -= self.move_speed + 1
            if self.cactus_pos[0] < -10:
                self.score += 1
                self.cactus_pos[0] = randint(max(220, self.cactus_pos[2] + 80),
                                             300)
            if self.cactus_pos[2] < -10:
                self.score += 1
                self.cactus_pos[2] = randint(max(220, self.cactus_pos[0] + 80),
                                             300)
            if self.bird_pos[0] < -10:
                self.score += 1
                self.bird_pos[0] = randint(400, 800)
                self.bird_pos[1] = randint(20, 60)

            self.collision_detect(self.cactus_pos, 0, 16, 16)
            self.collision_detect(self.cactus_pos, 2, 16, 16)
            self.collision_detect(self.bird_pos, 0, 16, 16)
Ejemplo n.º 16
0
    def update(self):
        # Update the crosshair position
        self.crosshair.update(pyxel.mouse_x, pyxel.mouse_y)

        # Create a copy of our splat list but remove any small splats.
        self.splats = [splat for splat in self.splats if splat.radius >= 1]

        # If the user left-clicked, create a splat at the mouse cursor position.
        if pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON):
            self.splats.append(Splat(pyxel.mouse_x, pyxel.mouse_y, 8))

        # If the user right-clicked, create a bunch of splats at the mouse cursor position.
        if pyxel.btn(pyxel.MOUSE_RIGHT_BUTTON):
            self.splats.append(Splat(pyxel.mouse_x, pyxel.mouse_y, 6))
Ejemplo n.º 17
0
    def update(self):
        """Update logic of game. Updates the snake and checks for scoring/win condition."""

        if not self.death:
            self.update_direction()
            self.update_snake()
            self.check_death()
            self.check_apple()

        if pyxel.btn(pyxel.KEY_Q):
            pyxel.quit()

        if pyxel.btnp(pyxel.KEY_R):
            self.reset()
    def update(self):
        if (self.game_state != 'playing'):
            if (pyxel.frame_count % 5):
                self.rotating_font_color = self.random_color()
            if (len(self.stals)):
                self.stals = []

            # check to see if the player wants to move on
            if (pyxel.btnr(pyxel.KEY_SPACE)):
                if (self.game_state == 'title'):
                    self.game_state = 'playing'
                    self.initialize()
                if (self.game_state == 'gameover'):
                    self.game_state = 'title'
        else:
            if (pyxel.btn(pyxel.KEY_UP)):
                self.hero_height = np.minimum(self.hero_height + 1, pyxel.height)
            elif (pyxel.btn(pyxel.KEY_DOWN)):
                self.hero_height = np.maximum(self.hero_height - 1, 4)

            self.update_stal()
            self.update_hero()
            self.check_collision()
Ejemplo n.º 19
0
    def __on_update(self):
        if pyxel.btn(pyxel.KEY_LEFT_ALT) or pyxel.btn(pyxel.KEY_RIGHT_ALT):
            editor = self._editor_button.value
            editor_count = len(self._editor_list)

            if pyxel.btnp(pyxel.KEY_LEFT):
                self.set_editor((editor - 1) % editor_count)
            elif pyxel.btnp(pyxel.KEY_RIGHT):
                self.set_editor((editor + 1) % editor_count)

        editor = self._editor_list[self._editor_button.value]
        self._undo_button.is_enabled = editor.can_undo
        self._redo_button.is_enabled = editor.can_redo

        if pyxel.btn(pyxel.KEY_CONTROL):
            if pyxel.btnp(pyxel.KEY_S):
                self._save_button.press()

            if editor.can_undo and pyxel.btnp(pyxel.KEY_Z):
                self._undo_button.press()

            if editor.can_redo and pyxel.btnp(pyxel.KEY_Y):
                self._redo_button.press()
Ejemplo n.º 20
0
    def __update(self) -> None:
        self.__update_key_status()
        if self.__status == Status.START and pyxel.btn(pyxel.KEY_S):
            self.__entity_manager.init()
            self.__status = Status.GAMING
        elif pyxel.btn(pyxel.KEY_R):
            self.__level = 0
            self.__score = 0
            self.__status = Status.START
        elif self.__timer.time_pass_ns > self.__config.get_tick_time(
                self.__level) and self.__status == Status.GAMING:
            try:
                lines = self.__entity_manager.process_tick(self.__key_status)
            except DeathException:
                self.__status = Status.DEATH
            else:
                self.__score += lines * self.__config.score_per_line
                self.__best_score = max(self.__score, self.__best_score)
                self.__level = self.__score // self.__config.score_per_level

            self.__key_status = KeyStatus.get_status()

            self.__timer.start()
Ejemplo n.º 21
0
    def __on_update(self):
        if (self.parent.cursor_y > 0 or self.parent.play_pos > -1
                or pyxel.btn(pyxel.KEY_CONTROL)):
            return

        if pyxel.btnp(pyxel.KEY_1):
            self._tone = (self._tone + 1) % 4

        self.note = None
        for i, key in enumerate(self._key_table):
            if pyxel.btn(key):
                self.note = self.parent.octave * 12 + i
                break

        if pyxel.btn(pyxel.KEY_A):
            self.note = -1

        if self.note is not None:
            self._sound.note[0] = self.note
            self._sound.tone[0] = self._tone
            pyxel.play(1, 64)
        else:
            pyxel.stop(1)
Ejemplo n.º 22
0
    def update_player(self):
        if pyxel.btn(pyxel.KEY_LEFT) or pyxel.btn(pyxel.GAMEPAD_1_LEFT):
            self.player_x = max(self.player_x - 2, 0)
            self.direction = LEFT

        if pyxel.btn(pyxel.KEY_RIGHT) or pyxel.btn(pyxel.GAMEPAD_1_RIGHT):
            self.player_x = min(self.player_x + 2, pyxel.width - 16)
            self.direction = RIGHT

        if pyxel.btn(pyxel.KEY_UP) or pyxel.btn(pyxel.GAMEPAD_1_UP):
            self.player_y = max(self.player_y - 2, 0)
            self.direction = UP

        if pyxel.btn(pyxel.KEY_DOWN) or pyxel.btn(pyxel.GAMEPAD_1_DOWN):
            self.player_y = min(self.player_y + 2, pyxel.height - 16)
            self.direction = DOWN
Ejemplo n.º 23
0
    def act(self):
        # self.character.position['x'] = (self.character.position['x'] + 1) % pyxel.width

        # GAMEPAD_1_LEFT throwing error.
        # if (pyxel.btn(pyxel.KEY_S) or pyxel.btn(pyxel.GAMEPAD_1_LEFT)) and (pyxel.btn(pyxel.KEY_F) or pyxel.btn(pyxel.GAMEPAD_1_RIGHT)):
        #     self.character.momentum_horizontal = 0
        # elif pyxel.btn(pyxel.KEY_S) or pyxel.btn(pyxel.GAMEPAD_1_LEFT):
        #     self.character.momentum_horizontal = 1
        # elif pyxel.btn(pyxel.KEY_F) or pyxel.btn(pyxel.GAMEPAD_1_RIGHT):
        #     self.character.momentum_horizontal = -1
        # else:
        #     self.character.momentum_horizontal = 0

        if pyxel.btn(pyxel.KEY_S) and pyxel.btn(pyxel.KEY_F):
            self.character.momentum_horizontal = 0
        elif pyxel.btn(pyxel.KEY_S):
            self.character.momentum_horizontal = -1
        elif pyxel.btn(pyxel.KEY_F):
            self.character.momentum_horizontal = 1
        else:
            self.character.momentum_horizontal = 0

        self.character.act()
Ejemplo n.º 24
0
    def process_input(self):
        if (pyxel.btn(pyxel.KEY_SHIFT) or pyxel.btn(pyxel.KEY_CONTROL)
                or pyxel.btn(pyxel.KEY_ALT)):
            return

        if pyxel.btnp(pyxel.KEY_LEFT, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME):
            self.move_left()

        if pyxel.btnp(pyxel.KEY_RIGHT, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME):
            self.move_right()

        if pyxel.btnp(pyxel.KEY_UP, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME):
            self.move_up()

        if pyxel.btnp(pyxel.KEY_DOWN, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME):
            self.move_down()

        if pyxel.btnp(pyxel.KEY_BACKSPACE, WIDGET_HOLD_TIME,
                      WIDGET_REPEAT_TIME):
            self.backspace()

        if pyxel.btnp(pyxel.KEY_DELETE, WIDGET_HOLD_TIME, WIDGET_REPEAT_TIME):
            self.delete()
Ejemplo n.º 25
0
    def update(self):
        if pyxel.btnp(pyxel.KEY_Q):
            pyxel.quit()

        if pyxel.btnp(pyxel.KEY_R):
            self.loadData()

        if pyxel.btn(pyxel.KEY_RIGHT) or pyxel.btn(pyxel.GAMEPAD_1_RIGHT):
            self.map_x += 1
        elif pyxel.btn(pyxel.KEY_LEFT) or pyxel.btn(pyxel.GAMEPAD_1_LEFT):
            self.map_x -= 1

        if pyxel.btn(pyxel.KEY_UP) or pyxel.btn(pyxel.GAMEPAD_1_UP):
            self.map_y -= 1
        elif pyxel.btn(pyxel.KEY_DOWN) or pyxel.btn(pyxel.GAMEPAD_1_DOWN):
            self.map_y += 1
Ejemplo n.º 26
0
    def draw(self):
        pyxel.cls(COL_BACKGROUND)
        for i in range(SCREEN_HEIGHT // TILE_SIZE):
            for j in range(SCREEN_WIDTH // TILE_SIZE):
                pyxel.rectb(j * TILE_SIZE, i * TILE_SIZE,
                            (j + 1) * TILE_SIZE - 1, (i + 1) * TILE_SIZE - 1,
                            5)

        for obj in self.objectHandler.objects:
            obj.draw()

        if pyxel.btn(pyxel.KEY_T):
            for i in range(128):
                draw_tile(i % 10 + 1, i // 10 + 1, i, 1 + i % 14)
Ejemplo n.º 27
0
    def update(self):
        if pyxel.btn(pyxel.KEY_LEFT_ALT) or pyxel.btn(pyxel.KEY_RIGHT_ALT):
            screen = self._screen_button.value
            screen_count = len(self._screen_list)

            if pyxel.btnp(pyxel.KEY_LEFT):
                self.set_screen((screen - 1) % screen_count)
            elif pyxel.btnp(pyxel.KEY_RIGHT):
                self.set_screen((screen + 1) % screen_count)

        screen = self._screen_list[self._screen_button.value]
        self._undo_button.is_enabled = screen.can_undo
        self._redo_button.is_enabled = screen.can_redo

        if pyxel.btn(pyxel.KEY_CONTROL):
            if screen.can_undo and pyxel.btnp(pyxel.KEY_S):
                self._save_button.press()
            elif screen.can_undo and pyxel.btnp(pyxel.KEY_Z):
                self._undo_button.press()
            elif screen.can_redo and pyxel.btnp(pyxel.KEY_Y):
                self._redo_button.press()

        Widget.update(self._root_widget)
Ejemplo n.º 28
0
    def update(self):
        self.events()

        # move the moving apples
        for b in self.badapplelist:
            b.x += b.xspeed
            b.y += b.yspeed

        for b in self.goldenapplelist:
            b.x += b.xspeed
            b.y += b.yspeed

        if pyxel.btn(pyxel.KEY_ESCAPE):
            pyxel.quit()
Ejemplo n.º 29
0
    def update(self):
        if pyxel.btn(pyxel.KEY_LEFT):
            self.x -= PLAYER_SPEED

        if pyxel.btn(pyxel.KEY_RIGHT):
            self.x += PLAYER_SPEED

        if pyxel.btn(pyxel.KEY_UP):
            self.y -= PLAYER_SPEED

        if pyxel.btn(pyxel.KEY_DOWN):
            self.y += PLAYER_SPEED

        self.x = max(self.x, 0)
        self.x = min(self.x, pyxel.width - self.w)
        self.y = max(self.y, 0)
        self.y = min(self.y, pyxel.height - self.h)

        if pyxel.btnp(pyxel.KEY_SPACE):
            Bullet(self.x + (PLAYER_WIDTH - BULLET_WIDTH) / 2,
                   self.y - BULLET_HEIGHT / 2)

            pyxel.play(0, 0)
Ejemplo n.º 30
0
 def update(self):
     """
     Update the ship location. Most of the player input happens here.
     """
     if pyxel.btn(pyxel.KEY_D) or pyxel.btn(pyxel.KEY_RIGHT):
         if self.coords[0] < pyxel.width - 15:
             self.coords[0] += 1
     if pyxel.btn(pyxel.KEY_A) or pyxel.btn(pyxel.KEY_LEFT):
         if self.coords[0] > 10:
             self.coords[0] -= 1
     if pyxel.btn(pyxel.KEY_W) or pyxel.btn(pyxel.KEY_UP):
         if self.coords[1] > pyxel.height - self.HEIGHT * 5:
             self.coords[1] -= 1
     if pyxel.btn(pyxel.KEY_S) or pyxel.btn(pyxel.KEY_DOWN):
         if self.coords[1] < pyxel.height - self.HEIGHT - 5:
             self.coords[1] += 1