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

Feature #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.venv
/__pycache__
/.vscode
49 changes: 30 additions & 19 deletions bambam.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import argparse
import fnmatch
from pygame.locals import Color, RLEACCEL, QUIT, KEYDOWN, MOUSEMOTION, MOUSEBUTTONDOWN, MOUSEBUTTONUP

import os

class BambamException(Exception):
"""Represents a bambam-specific exception."""
Expand Down Expand Up @@ -79,7 +79,8 @@ def get_color(cls):
@classmethod
def load_image(cls, fullname, colorkey=None):
"""
Load image/, handling setting of the transparency color key.
Load image/, handling setting of the transparency colo
r key.
"""
try:
image = pygame.image.load(fullname)
Expand Down Expand Up @@ -122,14 +123,14 @@ def load_items(cls, lst, blacklist, load_function, items_type):
"""
Runs load_function on elements of lst unless they are blacklisted.
"""
result = []
result = {}
errors_encountered = False
for name in lst:
if any(fnmatch.fnmatch(name, p) for p in blacklist):
print("Skipping blacklisted item:", name)
else:
try:
result.append(load_function(name))
result[os.path.splitext(os.path.basename(name))[0]]= load_function(name)
except ResourceLoadException as e:
print(e)
errors_encountered = True
Expand Down Expand Up @@ -189,20 +190,25 @@ def input(self, events, quit_pos):
self.screen.blit(self.background, (0, 0))
pygame.display.flip()

# play random sound
if not self.sound_muted:
if event.type == KEYDOWN and self.args.deterministic_sounds:
self.sounds[event.key % len(self.sounds)].play()
if event.type == pygame.KEYDOWN:
# show self.images
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this comment, it makes even less sense now.

if (event.unicode.isalpha() or event.unicode.isdigit()):
self.print_letter(event.unicode)
if not self.sound_muted: # play random sound
self.sounds[random.choice(list(self.sounds))].play()
else:
self.sounds[random.randint(
0, len(self.sounds) - 1)].play()

# show self.images
if event.type == pygame.KEYDOWN and (event.unicode.isalpha() or event.unicode.isdigit()):
self.print_letter(event.unicode)
else:
self.print_image()
pygame.display.flip()
if self.args.deterministic_sounds:
# get sound count
name = random.choice(list(self.sounds))
self.print_image(name)
if not self.sound_muted:
self.sounds[name].play()
else:
self.print_image(random.choice(list(self.sounds)))
if not self.sound_muted:
self.sounds[random.choice(list(self.sounds))].play()

pygame.display.flip()

# mouse motion
elif event.type == MOUSEMOTION:
Expand All @@ -222,11 +228,16 @@ def input(self, events, quit_pos):

return quit_pos

def print_image(self):
def print_image(self,name=''):
"""
Prints an image at a random location.
"""
img = self.images[random.randint(0, len(self.images) - 1)]
if not self.args.deterministic_sounds and (not name or name not in self.images):
img = self.images[random.choice(list(self.images))]
elif self.args.deterministic_sounds and name in self.images:
img = self.images[name]
else:
return
w = random.randint(0, self.swidth - img.get_width())
h = random.randint(0, self.sheight - img.get_height())
self.screen.blit(img, (w, h))
Expand Down
4 changes: 4 additions & 0 deletions data/.directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Dolphin]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file for? I don't think bambam uses it? In that case please add it to .gitignore and remove from PR.

Timestamp=2019,6,13,23,32,32
Version=4
ViewMode=1
Binary file removed data/alien1.gif
Binary file not shown.
Binary file added data/bear.wav
Binary file not shown.
Binary file removed data/boilingwater1a.wav
Binary file not shown.
Binary file removed data/boom.wav
Binary file not shown.
Binary file added data/chimp.wav
Binary file not shown.
Binary file removed data/churchbell1.wav
Binary file not shown.
Binary file added data/cow.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/cow.ogg
Binary file not shown.
Binary file added data/dog.wav
Binary file not shown.
Binary file added data/eagle.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/eagle.wav
Binary file not shown.
Binary file added data/elephant.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/elephant.wav
Binary file not shown.
Binary file added data/frog.wav
Binary file not shown.
Binary file added data/hen2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/horse1a.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/house_lo.wav
Binary file not shown.
Binary file removed data/iguana.gif
Binary file not shown.
Binary file removed data/jet2.wav
Binary file not shown.
Binary file removed data/kangaroo.gif
Binary file not shown.
Binary file added data/lamb.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/punch.wav
Binary file not shown.
Binary file removed data/register.wav
Binary file not shown.
Binary file removed data/secosmic_lo.wav
Binary file not shown.
Binary file removed data/splat2a.wav
Binary file not shown.
Binary file removed data/splat3a.wav
Binary file not shown.
Binary file removed data/whiff.wav
Binary file not shown.
Binary file removed data/wolves.wav
Binary file not shown.
Binary file removed data/zipperdn1.wav
Binary file not shown.