Bug fixes for Chips Challenge
This commit is contained in:
parent
608253e0c8
commit
a5dbc3958d
5 changed files with 44 additions and 38 deletions
|
|
@ -2,16 +2,16 @@
|
|||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
import audiocore
|
||||
import audiobusio
|
||||
from definitions import PLAY_SOUNDS
|
||||
|
||||
class Audio:
|
||||
def __init__(self, *, bit_clock, word_select, data):
|
||||
self._audio = audiobusio.I2SOut(bit_clock, word_select, data)
|
||||
def __init__(self, audio_bus, sounds):
|
||||
self._audio = audio_bus
|
||||
self._wav_files = {}
|
||||
|
||||
def add_sound(self, sound_name, file):
|
||||
self._wav_files[sound_name] = file
|
||||
for sound_name, file in sounds.items():
|
||||
self._add_sound(sound_name, file)
|
||||
# Play the first sound in the list to initialize the audio system
|
||||
self.play(tuple(self._wav_files.keys())[0], wait=True)
|
||||
|
||||
def play(self, sound_name, wait=False):
|
||||
if not PLAY_SOUNDS:
|
||||
|
|
@ -23,3 +23,6 @@ class Audio:
|
|||
if wait:
|
||||
while self._audio.playing:
|
||||
pass
|
||||
|
||||
def _add_sound(self, sound_name, file):
|
||||
self._wav_files[sound_name] = file
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ import board
|
|||
import picodvi
|
||||
import framebufferio
|
||||
import displayio
|
||||
import adafruit_tlv320
|
||||
import audiobusio
|
||||
from audio import Audio
|
||||
from game import Game
|
||||
from definitions import SECOND_LENGTH, TICKS_PER_SECOND
|
||||
|
||||
|
|
@ -17,13 +20,33 @@ from definitions import SECOND_LENGTH, TICKS_PER_SECOND
|
|||
# Change this to use a different data file
|
||||
DATA_FILE = "CHIPS.DAT"
|
||||
|
||||
SOUND_EFFECTS = {
|
||||
"BUTTON_PUSHED": "/sounds/pop2.wav",
|
||||
"DOOR_OPENED": "/sounds/door.wav",
|
||||
"ITEM_COLLECTED": "/sounds/blip2.wav",
|
||||
"BOOTS_STOLEN": "/sounds/strike.wav",
|
||||
"WATER_SPLASH": "/sounds/water2.wav",
|
||||
"TELEPORT": "/sounds/teleport.wav",
|
||||
"CANT_MOVE": "/sounds/oof3.wav",
|
||||
"CHIP_LOSES": "/sounds/bummer.wav",
|
||||
"LEVEL_COMPLETE": "/sounds/ditty1.wav",
|
||||
"IC_COLLECTED": "/sounds/click3.wav",
|
||||
"BOMB_EXPLOSION": "/sounds/hit3.wav",
|
||||
"SOCKET_SOUND": "/sounds/chimes.wav",
|
||||
"TIME_LOW_TICK": "/sounds/click1.wav",
|
||||
"TIME_UP": "/sounds/bell.wav"
|
||||
}
|
||||
|
||||
displayio.release_displays()
|
||||
|
||||
audio_settings = {
|
||||
'bit_clock': board.D9,
|
||||
'word_select': board.D10,
|
||||
'data': board.D11
|
||||
}
|
||||
i2c = board.I2C()
|
||||
dac = adafruit_tlv320.TLV320DAC3100(i2c)
|
||||
dac.configure_clocks(sample_rate=44100, bit_depth=16)
|
||||
dac.headphone_output = True
|
||||
dac.headphone_volume = -15 # dB
|
||||
|
||||
audio_bus = audiobusio.I2SOut(board.D9, board.D10, board.D11)
|
||||
audio = Audio(audio_bus, SOUND_EFFECTS)
|
||||
|
||||
fb = picodvi.Framebuffer(320, 240, clk_dp=board.CKP, clk_dn=board.CKN,
|
||||
red_dp=board.D0P, red_dn=board.D0N,
|
||||
|
|
@ -32,7 +55,7 @@ fb = picodvi.Framebuffer(320, 240, clk_dp=board.CKP, clk_dn=board.CKN,
|
|||
color_depth=8)
|
||||
display = framebufferio.FramebufferDisplay(fb)
|
||||
|
||||
game = Game(display, DATA_FILE, **audio_settings)
|
||||
game = Game(display, DATA_FILE, audio)
|
||||
tick_length = SECOND_LENGTH / 1000 / TICKS_PER_SECOND
|
||||
while True:
|
||||
start = time.monotonic()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
from micropython import const
|
||||
|
||||
# Settings
|
||||
PLAY_SOUNDS = False
|
||||
PLAY_SOUNDS = True
|
||||
|
||||
# Timing Constants
|
||||
TICKS_PER_SECOND = const(20)
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ def get_victory_message(deaths):
|
|||
return None
|
||||
|
||||
class Game:
|
||||
def __init__(self, display, data_file, **kwargs):
|
||||
def __init__(self, display, data_file, audio):
|
||||
self._display = display
|
||||
self._images = {}
|
||||
self._buffers = {}
|
||||
|
|
@ -78,7 +78,7 @@ class Game:
|
|||
self._loading_group = displayio.Group()
|
||||
self._tile_size = 24 # Default tile size (length and width)
|
||||
self._digit_dims = (0, 0)
|
||||
self._gamelogic = GameLogic(data_file, **kwargs)
|
||||
self._gamelogic = GameLogic(data_file, audio)
|
||||
self._databuffer = DataBuffer()
|
||||
self._color_index = {}
|
||||
self._init_display()
|
||||
|
|
@ -850,5 +850,5 @@ Total Score: {score[3]}"""
|
|||
y_pos * self._tile_size + VIEWPORT_OFFSET[1], top_tile, bottom_tile
|
||||
)
|
||||
|
||||
self._draw_hint()
|
||||
self._draw_title_dialog()
|
||||
self._draw_hint()
|
||||
|
|
|
|||
|
|
@ -13,24 +13,6 @@ from element import Element
|
|||
from level import Level, Tile
|
||||
from point import Point
|
||||
from slip import Slip
|
||||
from audio import Audio
|
||||
|
||||
SOUND_EFFECTS = {
|
||||
"BUTTON_PUSHED": "/sounds/pop2.wav",
|
||||
"DOOR_OPENED": "/sounds/door.wav",
|
||||
"ITEM_COLLECTED": "/sounds/blip2.wav",
|
||||
"BOOTS_STOLEN": "/sounds/strike.wav",
|
||||
"WATER_SPLASH": "/sounds/water2.wav",
|
||||
"TELEPORT": "/sounds/teleport.wav",
|
||||
"CANT_MOVE": "/sounds/oof3.wav",
|
||||
"CHIP_LOSES": "/sounds/bummer.wav",
|
||||
"LEVEL_COMPLETE": "/sounds/ditty1.wav",
|
||||
"IC_COLLECTED": "/sounds/click3.wav",
|
||||
"BOMB_EXPLOSION": "/sounds/hit3.wav",
|
||||
"SOCKET_SOUND": "/sounds/chimes.wav",
|
||||
"TIME_LOW_TICK": "/sounds/click1.wav",
|
||||
"TIME_UP": "/sounds/bell.wav"
|
||||
}
|
||||
|
||||
def is_ice(tile):
|
||||
return tile == TYPE_ICE or TYPE_ICEWALL_SOUTHEAST <= tile <= TYPE_ICEWALL_NORTHEAST
|
||||
|
|
@ -73,7 +55,8 @@ class GameLogic:
|
|||
A class to represent the state of the game as well as
|
||||
control all the game movements and actions.
|
||||
"""
|
||||
def __init__(self, data_file, **kwargs):
|
||||
def __init__(self, data_file, audio):
|
||||
self._audio = audio
|
||||
self._tileset = [Element() for _ in range(0x70)]
|
||||
self._chip = Creature()
|
||||
self._create_tileset()
|
||||
|
|
@ -96,10 +79,7 @@ class GameLogic:
|
|||
self._current_time = 0
|
||||
self._last_slip_dir = NONE
|
||||
self._controller_dir = NONE
|
||||
self._audio = Audio(**kwargs)
|
||||
self._time_limit = 0
|
||||
for sound_name, file in SOUND_EFFECTS.items():
|
||||
self._audio.add_sound(sound_name, file)
|
||||
|
||||
def dec_level(self):
|
||||
if self.current_level_number > 1:
|
||||
|
|
|
|||
Loading…
Reference in a new issue