From: <ch...@us...> - 2009-02-25 19:17:21
|
Revision: 281 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=281&view=rev Author: chozone Date: 2009-02-25 19:17:16 +0000 (Wed, 25 Feb 2009) Log Message: ----------- Avatars will now be shown directly, and they will be removed when user leaves ground/VP. You can now (temporarily) switch grounds with F9-F12. Changed the walking speed a bit, you walk slower now. Modified Paths: -------------- branches/VP-Grounds/modules/playground/avatar-static.py branches/VP-Grounds/modules/playground.py Modified: branches/VP-Grounds/modules/playground/avatar-static.py =================================================================== --- branches/VP-Grounds/modules/playground/avatar-static.py 2009-02-25 14:26:58 UTC (rev 280) +++ branches/VP-Grounds/modules/playground/avatar-static.py 2009-02-25 19:17:16 UTC (rev 281) @@ -4,20 +4,31 @@ def __init__(self, data, share): self.sh = share - + self.imageName=data['Avatar'][1] self.rect = Rect(data['Pos'][1], data['Pos'][2], 0, 0) self.zorder = self.rect.top + self.rect.height - self.sh['Downloader'].getImage(data['Avatar'][1], self.imageUpdate) + def show(self): + """ + Start the whole process of: + checking whether avatar is downloaded, [download it], return avatar, and finally: blit ourselves. + This has to be a seperate def. If you put this right into __init__, we will make playground blit + ourself, before the initialisation is ready. And so, if that's not ready, we're not in the objects + list of the playground, and we will not be blitted. + """ + self.sh['Downloader'].getImage(self.imageName, self.imageUpdate) def imageUpdate(self, image, *arg): + """ + The downloader will call this when he's finished. + Will load in the image, and make playground blit our rect. + """ self.image = image[0] self.rect.size = image[1].size self.zorder = self.rect.top + self.rect.height self.sh['Playground'].blit(self.rect) - def update(self, screen, rect): if self.rect.colliderect(rect): #Check if the rect collide with ours rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position Modified: branches/VP-Grounds/modules/playground.py =================================================================== --- branches/VP-Grounds/modules/playground.py 2009-02-25 14:26:58 UTC (rev 280) +++ branches/VP-Grounds/modules/playground.py 2009-02-25 19:17:16 UTC (rev 281) @@ -22,6 +22,8 @@ self.walkingDir = [False] * 4 #up, left, right, down self.timer = None + + self.walkingStep=10 #Size(px) of each step. #Loading all our objects-modules (kinda like interface.py) @@ -47,27 +49,38 @@ brains.setStatus('busy') elif ev.key == K_F4: brains.setStatus('idle') + + elif ev.key == K_F9: + self.sh['Connection'].send('POS', ['treehouse.0.0', 0, 0, 0]) + elif ev.key == K_F10: + self.sh['Connection'].send('POS', ['treehouse.0.0', 360, 360, 0]) + elif ev.key == K_F11: + self.sh['Connection'].send('POS', ['treehouse.0.1', 0, 0, 0]) + elif ev.key == K_F12: + self.sh['Connection'].send('POS', ['treehouse.0.1', 360, 360, 0]) + if self.dontUpdate == False: + #TODO: when you move diagonally, your speed should be a bit less, around 7 (this is sqrt(50)... for other walking speeds: walkingStep=sqrt(x^2+x^2) ) if ev.key == K_UP: - self.walking(0, +15, True) + self.walking(0, +self.walkingStep, True) elif ev.key == K_LEFT: - self.walking(1, +15, True) + self.walking(1, +self.walkingStep, True) elif ev.key == K_DOWN: - self.walking(2, +15, True) + self.walking(2, +self.walkingStep, True) elif ev.key == K_RIGHT: - self.walking(3, +15, True) + self.walking(3, +self.walkingStep, True) elif ev.type == KEYUP: if self.dontUpdate == False: if ev.key == K_UP: - self.walking(0, -15, False) + self.walking(0, -self.walkingStep, False) elif ev.key == K_LEFT: - self.walking(1, -15, False) + self.walking(1, -self.walkingStep, False) elif ev.key == K_DOWN: - self.walking(2, -15, False) + self.walking(2, -self.walkingStep, False) elif ev.key == K_RIGHT: - self.walking(3, -15, False) + self.walking(3, -self.walkingStep, False) @@ -90,15 +103,34 @@ self.loadGround(msg['data']) elif arg[0] == 'UserUpdate': - updateRects = [] + updateRects = [] #What's this?? user = arg[1] #Is this on our ground? Do we need to update it? if user.has_key('Pos') and user['Pos'] != None: + + #Has user gone offline, and should we delete the avatar object? + if user.has_key('Action') and user['Action']=='Offline': + tempRect=self.objects['av-%s'%user['Name']].rect + del self.objects['av-%s'%user['Name']] + self.blit(tempRect) + return + + #Now, create the avatar object, or just move him? if 'av-' + user['Name'] in self.objects.keys(): + #Just move the existing object self.objects['av-%s'%user['Name']].move(user['Pos']) else: + #Create new one! :D self.openObject('avatar-' + user['Avatar'][0], 'av-' + user['Name'], user) + self.objects['av-%s'%user['Name']].show() #Will start downloading, see modules/playground/avatar-static.py for full explanation + + else: + #Not in ground, but do we still have the avatar-object? + if 'av-' + user['Name'] in self.objects.keys(): + tempRect=self.objects['av-%s'%user['Name']].rect + del self.objects['av-%s'%user['Name']] + self.blit(tempRect) @@ -117,6 +149,9 @@ def blit(self, rect): + """ + Blit all (parts of) objects that are in `rect` in the playground. + """ if self.dontUpdate == False: self.lock.acquire() self.createRects() @@ -151,6 +186,9 @@ self.createRects() def openObject(self, objname, name, data): + """ + Create an new object, of type `objname`. + """ print '## Open Object', name, 'as', objname #DEBUG obj = self.modObjects[objname] obj = obj(data, self.sh) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |