Permalink
Browse files

mics updates, lots of new bugs :(

  • Loading branch information...
1 parent ffb76f3 commit 1c0fdd02c473e26b75c758ac750d428b060bc670 @bitcraft committed May 11, 2012
View
@@ -25,4 +25,8 @@ explosions\
http://opengameart.org/content/explosion-animations\
explosion animations\
jetrel\
-}
+\
+\
+tree.png\
+http://opengameart.org/content/gnarled-tree\
+geloescht}
View
@@ -1,165 +0,0 @@
-from lib2d.area import AbstractArea, Area
-from lib2d.buildarea import fromTMX
-from lib2d.avatar import Avatar, Animation, StaticAnimation
-from lib2d.objects import AvatarObject
-from lib.hero import Hero
-from lib.level import Level
-from lib.enemies import *
-from lib.misc import *
-from lib2d import res
-
-from collections import defaultdict
-import os
-
-
-
-# build the initial environment
-uni = Area()
-uni.name = 'MH'
-uni.setGUID(0)
-
-
-# build our avatars and heros
-avatar = Avatar()
-ani = Animation("hero-idle.png", "stand", 9, 1, 100)
-avatar.add(ani)
-ani = Animation("hero-walk.png", "walk", 10, 1, 100)
-avatar.add(ani)
-ani = Animation("hero-crouch.png", "crouch", 5, 1, 30)
-avatar.add(ani)
-ani = Animation("hero-uncrouch.png", "uncrouch", 5, 1, 30)
-avatar.add(ani)
-ani = Animation("hero-brake.png", "brake", 6, 1, 30)
-avatar.add(ani)
-ani = Animation("hero-run.png", "run", 16, 1, 30)
-avatar.add(ani)
-ani = Animation("hero-sprint.png", "sprint", 17, 1, 100)
-avatar.add(ani)
-ani = Animation("hero-wait.png", "wait", 6, 1, 100)
-avatar.add(ani)
-ani = Animation("hero-jump.png", "jump", 4, 1, 20)
-avatar.add(ani)
-ani = Animation("hero-die.png", "die", 3, 1, 85)
-avatar.add(ani)
-avatar.play("stand")
-npc = Hero()
-npc.setName("Doc")
-npc.setAvatar(avatar)
-npc.setGUID(1)
-npc.size = (4, 16, 32)
-npc.avatar.axis = (-7,0)
-uni.add(npc)
-
-
-# laser robot
-avatar = Avatar()
-ani = StaticAnimation("robot-stand.png", "stand")
-avatar.add(ani)
-ani = Animation("robot-shoot.png", "warn", 4, 1, 60)
-avatar.add(ani)
-ani = Animation("robot-shoot.png", "shoot", 4, 1, 30)
-avatar.add(ani)
-npc = LaserRobot()
-npc.setName("LaserRobot")
-npc.setAvatar(avatar)
-npc.setGUID(513)
-npc.size = (4, 14, 30)
-npc.avatar.axis = (-9,-2)
-uni.add(npc)
-
-
-# lifts
-avatar = Avatar()
-ani = StaticAnimation("lift-idle.png", "idle")
-avatar.add(ani)
-ani = Animation("lift-glow.png", "glow", 4, 1, 100)
-avatar.add(ani)
-npc = Lift()
-npc.setName("Lift")
-npc.setAvatar(avatar)
-npc.setGUID(769)
-npc.size = (4, 32, 16)
-npc.avatar.axis = (0,16)
-uni.add(npc)
-
-npc = npc.copy()
-npc.setGUID(770)
-uni.add(npc)
-
-npc = npc.copy()
-npc.setGUID(771)
-uni.add(npc)
-
-npc = npc.copy()
-npc.setGUID(772)
-uni.add(npc)
-
-npc = npc.copy()
-npc.setGUID(773)
-uni.add(npc)
-
-
-#lift buttons
-avatar = Avatar()
-ani = StaticAnimation("button2.png", "off")
-avatar.add(ani)
-ani = StaticAnimation("button1.png", "on")
-avatar.add(ani)
-npc = Callbutton()
-npc.setName("Callbutton")
-npc.setAvatar(avatar)
-npc.setGUID(257)
-npc.size = (4, 16, 32)
-uni.add(npc)
-
-npc = npc.copy()
-npc.setGUID(258)
-uni.add(npc)
-
-npc = npc.copy()
-npc.setGUID(259)
-uni.add(npc)
-
-npc = npc.copy()
-npc.setGUID(260)
-uni.add(npc)
-
-
-# load the avatar objects and set their world size based off the first frame
-# of their default animations
-#import pygame, time
-
-#pygame.init()
-#screen = pygame.display.set_mode((240, 480))
-#pygame.display.set_caption('Image Loading...')
-
-#for ao in [ i for i in uni.getChildren() if isinstance(i, AvatarObject) ]:
-# [ i.load() for i in ao.avatar.getChildren() ]
-# sx, sy = ao.avatar.default.getImage(0).get_size()
-# x, y, z, d, w, h = ao.parent.getBBox(ao)
-# ao.parent.setBBox(ao, (x, y, z, 4, sx, sy))
-# [ i.unload() for i in ao.avatar.getChildren() ]
-
-
-
-
-# always load the levels last since they may duplicate objects
-level = fromTMX(uni, "level1.tmx")
-level.setName("Level 1")
-level.setGUID(1001)
-
-
-#haccckk
-for lift in [ i for i in uni.getChildren() if isinstance(i, Lift) ]:
- body = lift.parent.getBody(lift)
- body.bbox = body.bbox.move(0,0,1)
-
-
-# move buttons back so they don't collide with stuff
-for button in [ i for i in uni.getChildren() if isinstance(i, Callbutton) ]:
- body = lift.parent.getBody(button)
- body.bbox = body.bbox.move(4,0,1)
-
-
-uni.save(os.path.join("resources", "worlds", "world"))
-#pygame.quit()
View
@@ -14,7 +14,6 @@ def update(self, time):
self.time += time
if self.time >= self.ttl:
self.destroy()
- pass
def draw(self, surface):
surface.fill((255,randint(0,255),255))
@@ -29,9 +28,12 @@ def __init__(self):
self.time = 0
self.warned = False
self.pushable = True
+ self.active = True
def update(self, time):
+ if not self.active: return
+
self.time += time
if self.time >= self.rate:
self.time -= self.rate
View
@@ -42,6 +42,11 @@ def play(self, filename, volume=1.0):
SoundMan = SoundManager()
+# GLOBAL LEET SKILLS
+heroBody = None
+
+
+
class LevelState(GameState):
"""
This state is where the player will move the hero around the map
@@ -63,13 +68,6 @@ class LevelState(GameState):
contains metadata that lib2d can use to layout and position objects
correctly.
- i would really like the game to be sandboxable...set traps,
- make contraptions, etc
-
- controls:
- picking up objects will affect what your buttons do
- equipted items always have a dedicated button
- should have hot-swap button and drop button
"""
def __init__(self, area, startPosition=None):
@@ -78,6 +76,8 @@ def __init__(self, area, startPosition=None):
def activate(self):
+ global hero_body
+
self.blank = True
self.background = (109, 109, 109)
self.foreground = (0, 0, 0)
@@ -88,11 +88,17 @@ def activate(self):
self.player_vector = (0,0,0)
self.old_player_vector = (0,0,0)
self.old_falling = None
- self.hero_jump = 35
+ self.hero_jump = 25
+
+ self.camera = None
# allow the area to get needed data
self.area.load()
+ # load the children
+ for child in self.area.getChildren():
+ child.load()
+
# get the root and the hero from it
root = self.area.getRoot()
self.hero = root.getChildByGUID(1)
@@ -102,16 +108,7 @@ def activate(self):
if not self.area.hasChild(self.hero):
self.area.add(self.hero)
- # attach a camera
- sw, sh = sd.get_size()
- mw = sw * .75
- mh = sh * .75
- self.camera = LevelCamera(self.area,((4,4), (mw, mh)),
- tmxdata=self.area.tmxdata)
-
- self.mapBorder = pygame.Rect((0,0,mw+6,mh+6))
- self.msgBorder = pygame.Rect((0,mh,sw,sh-mh))
- self.hudBorder = pygame.Rect((mw,0,sw-mw,mh+6))
+ hero_body = self.area.getBody(self.hero)
# make a list of elevators in the level
self.elevators = tmxloader.buildDistributionRects(self.area.tmxdata,
@@ -122,7 +119,10 @@ def activate(self):
res.playMusic(self.area.tmxdata.music)
except AttributeError:
res.fadeoutMusic()
-
+ self.music_playing = False
+ else:
+ self.music_playing = True
+
# load sounds from area
for filename in self.area.soundFiles:
SoundMan.loadSound(filename)
@@ -132,7 +132,7 @@ def deactivate(self):
pass
- def drawSidebar(self, surface, rect):
+ def drawInfobar(self, surface, rect):
# draw the static portions of the sidebar
sw, sh, sw, sh = rect
@@ -152,27 +152,34 @@ def drawSidebar(self, surface, rect):
def draw(self, surface):
- sw, sh = surface.get_size()
+ dirty = []
if self.blank:
self.blank = False
+ sw, sh = surface.get_size()
surface.fill(self.background)
- self.drawSidebar(surface, self.hudBorder)
+ mw = sw
+ mh = sh * .75
+ if not self.camera:
+ self.camera = LevelCamera(self.area,((4,4), (mw, mh)),
+ tmxdata=self.area.tmxdata)
+ self.mapBorder = pygame.Rect((0,0,mw,mh+6))
+ self.msgBorder = pygame.Rect((0,mh,sw,sh-mh))
self.border.draw(surface, self.msgBorder)
- self.camera.blank = True
dirty = [((0,0), (sw, sh))]
# the main map
self.camera.center(self.area.getPosition(self.hero))
- dirty = self.camera.draw(surface)
+ dirty.extend(self.camera.draw(surface))
+ # borders
+ self.border.draw(surface, self.mapBorder)
+
+ # hack
if self.area.drawables:
[ o.draw(surface) for o in self.area.drawables ]
self.blank = True
- # borders
- self.border.draw(surface, self.mapBorder)
-
#log = "\n".join(self.area.messages[-5:])
#rect = self.msgBorder.inflate(-16,-12)
#gui.drawText(surface, log, (0,0,0), rect, self.msgFont)
@@ -181,6 +188,8 @@ def draw(self, surface):
def update(self, time):
+ if self.blank: return
+
self.area.update(time)
self.camera.update(time)
@@ -300,7 +309,14 @@ def elevatorDown(self):
@receiver(emitSound)
def playSound(sender, **kwargs):
- SoundMan.play(kwargs['filename'])
+ x1, y1, z1 = kwargs['position']
+ x2, y2, z2 = hero_body.bbox.origin
+ d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2) + pow(z1-z2, 2))
+ try:
+ vol = 1/d * 20
+ except ZeroDivisionError:
+ vol = 1.0
+ SoundMan.play(kwargs['filename'], volume=vol)
@receiver(bodyAbsMove)
Oops, something went wrong.

0 comments on commit 1c0fdd0

Please sign in to comment.