projects
/
koperkapel.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cd05c8c
)
Use projectile images.
author
Simon Cross
<hodgestar@gmail.com>
Sat, 5 Mar 2016 22:05:46 +0000
(
00:05
+0200)
committer
Simon Cross
<hodgestar@gmail.com>
Sat, 5 Mar 2016 22:05:46 +0000
(
00:05
+0200)
koperkapel/weapons.py
patch
|
blob
|
history
diff --git
a/koperkapel/weapons.py
b/koperkapel/weapons.py
index 7dcb41ed154250bcc009f0f5ce8fdf80261e2a56..80d1e93c5353b9a51c926d0bfad244f675fc8092 100644
(file)
--- a/
koperkapel/weapons.py
+++ b/
koperkapel/weapons.py
@@
-3,19
+3,20
@@
from pygame.surface import Surface
from pygame.draw import circle
from pgzero.loaders import images, sounds
from pygame.surface import Surface
from pygame.draw import circle
from pgzero.loaders import images, sounds
-from .actors.anim
surf
import AnimatedSurfActor
+from .actors.anim import AnimatedSurfActor
from .util import safepath
class Weapon:
def __init__(self, name, damage, image_name=None, bullet_range=0,
from .util import safepath
class Weapon:
def __init__(self, name, damage, image_name=None, bullet_range=0,
- can_tape=True, frames=("_1",), sound=None):
+ can_tape=True, frames=("_1",),
projectile=None,
sound=None):
self.name = name
self.image_name = image_name or name
self.frames = frames
self.damage = damage
self.bullet_range = bullet_range
self.can_tape = can_tape
self.name = name
self.image_name = image_name or name
self.frames = frames
self.damage = damage
self.bullet_range = bullet_range
self.can_tape = can_tape
+ self.projectile = projectile
self.sound = None
if sound:
self.sound = sounds.load(sound)
self.sound = None
if sound:
self.sound = sounds.load(sound)
@@
-30,10
+31,12
@@
class Weapon:
WEAPONS = [
Weapon("spit", damage=1, bullet_range=2, can_tape=False,
WEAPONS = [
Weapon("spit", damage=1, bullet_range=2, can_tape=False,
- image_name="blank", frames=("",), sound="fire_spit"),
+ image_name="blank", frames=("",), sound="fire_spit",
+ projectile="spit"),
Weapon("butter_knife", damage=2),
Weapon("crowbar", damage=4),
Weapon("butter_knife", damage=2),
Weapon("crowbar", damage=4),
- Weapon("gun", damage=4, bullet_range=4, sound='gun_fire'),
+ Weapon("gun", damage=4, bullet_range=4, sound='gun_fire',
+ projectile="bullet"),
]
WEAPON_LOOKUP = {w.name: w for w in WEAPONS}
]
WEAPON_LOOKUP = {w.name: w for w in WEAPONS}
@@
-51,14
+54,25
@@
class WeaponActor(AnimatedSurfActor):
class BulletActor(AnimatedSurfActor):
def __init__(self, weapon, **kw):
class BulletActor(AnimatedSurfActor):
def __init__(self, weapon, **kw):
+ frames = self._shiny_frames(weapon)
+ if frames is None:
+ frames = self._ugly_circle_frames(weapon)
+ super().__init__(frames=frames, **kw)
+ self.weapon = weapon
+
+ def _shiny_frames(self, weapon):
+ if weapon.projectile is None:
+ return None
+ surf = images.load(safepath("projectiles/%s" % (weapon.projectile,)))
+ return [surf]
+
+ def _ugly_circle_frames(self, weapon):
radius = min(weapon.damage * 5, 32)
surf = Surface((radius * 2, radius * 2))
surf.convert_alpha()
surf.fill((255, 255, 255, 0))
circle(surf, (255, 0, 255, 32), (radius, radius), radius)
radius = min(weapon.damage * 5, 32)
surf = Surface((radius * 2, radius * 2))
surf.convert_alpha()
surf.fill((255, 255, 255, 0))
circle(surf, (255, 0, 255, 32), (radius, radius), radius)
- frames = [surf]
- super().__init__(frames=frames, **kw)
- self.weapon = weapon
+ return [surf]
class WeaponFactory:
class WeaponFactory: