diff --git a/globals.py b/globals.py index 7744868d..06bc2d83 100644 --- a/globals.py +++ b/globals.py @@ -237,6 +237,10 @@ DEFAULT_FONT = 'ChunkFive Roman' CHAT_FONT = 'Silkscreen' +# Update mechanism settings +UPDATE_URL = 'https://github.com/boskee/Minecraft/archive/master.zip' +UPDATE_TEMPDIR = "pycraft_update" + class InvalidChoice(Exception): pass diff --git a/main.py b/main.py index 1c6c16b2..ce161e1b 100755 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ import time import gettext import sys +from random import choice # Third-party packages import pyglet @@ -25,6 +26,7 @@ from debug import log_info from mod import load_modules from savingsystem import save_world +from sounds import loop_choices, play_looping_sound class Window(pyglet.window.Window): @@ -132,6 +134,7 @@ def main(options): # window = Window(resizable=True, config=window_config) # except pyglet.window.NoSuchConfigException: window = Window(resizable=True, vsync=False) + play_looping_sound(random.choice(loop_choices)) pyglet.app.run() if G.CLIENT: @@ -144,8 +147,7 @@ def main(options): G.main_timer.stop() G.SERVER._stop.set() G.SERVER.shutdown() - -if __name__ == '__main__': +def start(): log_info('Starting pyCraft...') parser = argparse.ArgumentParser(description='Play a Python made Minecraft clone.') @@ -163,3 +165,7 @@ def main(options): options = parser.parse_args() main(options) + + +if __name__ == '__main__': + start() diff --git a/resources/sounds/background/1.wav b/resources/sounds/background/1.wav new file mode 100644 index 00000000..3452999e Binary files /dev/null and b/resources/sounds/background/1.wav differ diff --git a/resources/sounds/background/2.wav b/resources/sounds/background/2.wav new file mode 100644 index 00000000..f7eaad10 Binary files /dev/null and b/resources/sounds/background/2.wav differ diff --git a/sounds.py b/sounds.py index a1cf2e4a..b3fd0c28 100644 --- a/sounds.py +++ b/sounds.py @@ -14,6 +14,7 @@ __all__ = ( 'wood_break', 'water_break', 'leaves_break', 'glass_break', 'dirt_break', 'gravel_break', 'stone_break', 'melon_break', 'sand_break', 'play_sound', + 'loop_1', 'loop_2', 'loop_choices', 'play_looping_sound', ) pyglet.options['audio'] = ('openal', 'directsound', 'pulse', 'silent') @@ -31,6 +32,9 @@ stone_break = pyglet.resource.media("stone_break.wav", streaming=False) melon_break = pyglet.resource.media("melon_break.wav", streaming=False) sand_break = pyglet.resource.media("sand_break.wav", streaming=False) +loop_1 = pyglet.resource.media("background/1.wav", streaming=False) +loop_2 = pyglet.resource.media("background/2.wav", streaming=False) +loop_choices = (loop_1, loop_2) def play_sound(sound, player: custom_types.Player, position=None): if G.EFFECT_VOLUME <= 0: @@ -54,3 +58,14 @@ def play_sound(sound, player: custom_types.Player, position=None): return sound_player return sound_player + +def play_looping_sound(sound): + try: + driver = pyglet.media.drivers.silent.SilentAudioDriver + except: + looper = pyglet.media.SourceGroup(sound.audio_format, None) + looper.loop = True + looper.queue(sound) + p = pyglet.media.Player() + p.queue(looper) + p.play() diff --git a/update.py b/update.py new file mode 100644 index 00000000..d94a086d --- /dev/null +++ b/update.py @@ -0,0 +1,28 @@ +# Python packages +import shutil +import os +import zipfile +import urllib.request +from io import BytesIO + +# Third-party libraries +# Nothing for now... + +# Modules from this project +import globals as G + +def update(): + updatezip = urllib.request.urlopen(G.UPDATE_URL) + zipref = zipfile.ZipFile(BytesIO(updatezip.read())) + zipref.extractall(G.UPDATE_DIR) + zipref.close() + files=os.listdir(G.UPDATE_DIR) + for fle in files: + full_filename = os.path.join(G.UPDATE_DIR, fle) + if os.path.isfile(full_filename): + if file != "update.py": + current_dir=os.path.basename(os.getcwd()) + shutil.copy(full_filename, current_dir) + shutil.rmtree(G.UPDATE_DIR) + import main # Wonder what happens if you put this at the top? A TRACEBACK! + main.start()# Should work...