Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background music #102

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import time
import gettext
import sys
from random import choice

# Third-party packages
import pyglet
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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.')
Expand All @@ -163,3 +165,7 @@ def main(options):

options = parser.parse_args()
main(options)


if __name__ == '__main__':
start()
Binary file added resources/sounds/background/1.wav
Binary file not shown.
Binary file added resources/sounds/background/2.wav
Binary file not shown.
15 changes: 15 additions & 0 deletions sounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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:
Expand All @@ -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()
28 changes: 28 additions & 0 deletions update.py
Original file line number Diff line number Diff line change
@@ -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...