From: <ch...@us...> - 2009-02-24 20:14:42
|
Revision: 279 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=279&view=rev Author: chozone Date: 2009-02-24 20:14:37 +0000 (Tue, 24 Feb 2009) Log Message: ----------- Avatars are now moved correctly(blit+update is now good). There are still some bugs, like when user enters, you don't see his avatar, and when other people walk, it's waaay too slow. 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-22 10:59:48 UTC (rev 278) +++ branches/VP-Grounds/modules/playground/avatar-static.py 2009-02-24 20:14:37 UTC (rev 279) @@ -23,3 +23,19 @@ rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect screen.blit(self.image, myPos, rect) #Blit + + + def move(self, pos): + """ + Call this def to move this avatar to pos x=pos[1], y=pos[2]. + Will update rect, and make playground module update our old+new area + """ + oldRect=self.rect.__copy__() + + self.rect.x=pos[1] + self.rect.y=pos[2] + self.zorder = self.rect.top + self.rect.height + + updateRect=oldRect.union(self.rect) + + self.sh['Playground'].blit(updateRect) Modified: branches/VP-Grounds/modules/playground.py =================================================================== --- branches/VP-Grounds/modules/playground.py 2009-02-22 10:59:48 UTC (rev 278) +++ branches/VP-Grounds/modules/playground.py 2009-02-24 20:14:37 UTC (rev 279) @@ -95,7 +95,10 @@ user = arg[1] #Is this on our ground? Do we need to update it? if user.has_key('Pos') and user['Pos'] != None: - self.openObject('avatar-' + user['Avatar'][0], 'av-' + user['Name'], user) + if 'av-' + user['Name'] in self.objects.keys(): + self.objects['av-%s'%user['Name']].move(user['Pos']) + else: + self.openObject('avatar-' + user['Avatar'][0], 'av-' + user['Name'], user) @@ -148,6 +151,7 @@ self.createRects() def openObject(self, objname, name, data): + print '## Open Object', name, 'as', objname #DEBUG obj = self.modObjects[objname] obj = obj(data, self.sh) self.objects[name] = obj This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <ch...@us...> - 2009-03-03 19:53:08
|
Revision: 284 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=284&view=rev Author: chozone Date: 2009-03-03 19:53:06 +0000 (Tue, 03 Mar 2009) Log Message: ----------- Added new avatar type: avatar_multipart. Also really small bugfix in playground. Modified Paths: -------------- branches/VP-Grounds/modules/playground.py Added Paths: ----------- branches/VP-Grounds/modules/playground/avatar-multipart.py Added: branches/VP-Grounds/modules/playground/avatar-multipart.py =================================================================== --- branches/VP-Grounds/modules/playground/avatar-multipart.py (rev 0) +++ branches/VP-Grounds/modules/playground/avatar-multipart.py 2009-03-03 19:53:06 UTC (rev 284) @@ -0,0 +1,88 @@ +from functions import * + +class Object(): + def __init__(self, data, share): + self.sh = share + + self.imageList=data['Avatar'][1:] + self.imageNameList=data['Avatar'][1:] + self.rect = Rect(data['Pos'][1], data['Pos'][2], 0, 0) + self.zorder = self.rect.top + self.rect.height + + 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. + """ + + #We have multiple images, so loop through them, to download them all + for image in self.imageList: + self.sh['Downloader'].getImage(image, self.imageUpdate, image) + + 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. + """ + imageName=arg[0] + image=image + + self.imageList[self.imageNameList.index(imageName)]=image + + #Does our list still contain strings? + #(wich indicates we are still awaiting some downloads) + for img in self.imageList: + if type(img)!=tuple: return + + self.buildAvatar() + + 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 + myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect + screen.blit(self.image, myPos, rect) #Blit + + + def move(self, pos): + """ + Call this def to move this avatar to pos x=pos[1], y=pos[2]. + Will update rect, and make playground module update our old+new area + """ + oldRect=self.rect.__copy__() + + self.rect.x=pos[1] + self.rect.y=pos[2] + self.zorder = self.rect.top + self.rect.height + + updateRect=oldRect.union(self.rect) + + self.sh['Playground'].blit(updateRect) + + + def buildAvatar(self): + oldRect=self.rect.__copy__() #So we can combine it later with our new rect, so we can also update te old area + + #Update Width(w) and height(h) + self.rect.w=max([rect.w for img,rect in self.imageList]) + self.rect.h=0 + for img, rect in self.imageList: self.rect.h+=rect.h + + #And the zorder('cause we have new height) + self.zorder=self.rect.top+self.rect.height + + #Create clean surface for our avatar + self.image=pygame.Surface(self.rect.size, SRCALPHA, 32) + + #Blit all parts on this fresh surface + y=0 + for img,rect in self.imageList: + x=self.rect.w/2-rect.w/2 + self.image.blit(img, (x,y)) + y+=rect.h + + #Combine rects, and update area. It's time to show ourselves! :D + updateRect=self.rect.union(oldRect) + self.sh['Playground'].blit(updateRect) Modified: branches/VP-Grounds/modules/playground.py =================================================================== --- branches/VP-Grounds/modules/playground.py 2009-02-26 21:42:09 UTC (rev 283) +++ branches/VP-Grounds/modules/playground.py 2009-03-03 19:53:06 UTC (rev 284) @@ -110,7 +110,7 @@ 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': + if user.has_key('Action') and user['Action']=='Offline' and '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) @@ -191,9 +191,12 @@ Create an new object, of type `objname`. """ - if not objname in self.modObjects.keys(): return - print '## Open Object', name, 'as', objname #DEBUG + if not objname in self.modObjects.keys(): + print 'ERROR @Playground: Object type', objname,'not found, cannot open', name + return + #print '## Open Object', name, 'as', objname #DEBUG + obj = self.modObjects[objname] obj = obj(data, self.sh) self.objects[name] = obj This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2009-03-23 14:09:30
|
Revision: 287 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=287&view=rev Author: chozone Date: 2009-03-23 14:08:58 +0000 (Mon, 23 Mar 2009) Log Message: ----------- Z position added in all avatars (i think). You can now also run (hold ctrl) Modified Paths: -------------- branches/VP-Grounds/modules/playground/avatar-multidir.py branches/VP-Grounds/modules/playground/avatar-multidir_parts.py branches/VP-Grounds/modules/playground/avatar-multipart.py branches/VP-Grounds/modules/playground/avatar-static.py branches/VP-Grounds/modules/playground.py Modified: branches/VP-Grounds/modules/playground/avatar-multidir.py =================================================================== --- branches/VP-Grounds/modules/playground/avatar-multidir.py 2009-03-08 11:15:18 UTC (rev 286) +++ branches/VP-Grounds/modules/playground/avatar-multidir.py 2009-03-23 14:08:58 UTC (rev 287) @@ -10,7 +10,7 @@ self.image=None self.fullImage=None - self.rect = Rect(data['Pos'][1], data['Pos'][2], 0, 0) + self.rect = Rect(data['Pos'][1], data['Pos'][2]-data['Pos'][3], 0, 0) self.zorder = self.rect.top + self.rect.height self.blitRect = Rect(0,0,0,0) #Internal rect, inside fullImage @@ -66,7 +66,7 @@ elif self.rect.y > pos[2]: self.setDir('u') self.rect.x=pos[1] - self.rect.y=pos[2] + self.rect.y=pos[2]-pos[3] self.zorder = self.rect.top + self.rect.height updateRect=oldRect.union(self.rect) Modified: branches/VP-Grounds/modules/playground/avatar-multidir_parts.py =================================================================== --- branches/VP-Grounds/modules/playground/avatar-multidir_parts.py 2009-03-08 11:15:18 UTC (rev 286) +++ branches/VP-Grounds/modules/playground/avatar-multidir_parts.py 2009-03-23 14:08:58 UTC (rev 287) @@ -8,7 +8,7 @@ self.imageList=data['Avatar'][1:] self.imageNameList=data['Avatar'][1:] - self.rect = Rect(data['Pos'][1], data['Pos'][2], 0, 0) + self.rect = Rect(data['Pos'][1], data['Pos'][2]-data['Pos'][3], 0, 0) self.zorder = self.rect.top + self.rect.height def show(self): @@ -63,7 +63,7 @@ elif self.rect.y > pos[2]: self.setDir('u') self.rect.x=pos[1] - self.rect.y=pos[2] + self.rect.y=pos[2]-pos[3] self.zorder = self.rect.top + self.rect.height updateRect=oldRect.union(self.rect) Modified: branches/VP-Grounds/modules/playground/avatar-multipart.py =================================================================== --- branches/VP-Grounds/modules/playground/avatar-multipart.py 2009-03-08 11:15:18 UTC (rev 286) +++ branches/VP-Grounds/modules/playground/avatar-multipart.py 2009-03-23 14:08:58 UTC (rev 287) @@ -6,7 +6,7 @@ self.imageList=data['Avatar'][1:] self.imageNameList=data['Avatar'][1:] - self.rect = Rect(data['Pos'][1], data['Pos'][2], 0, 0) + self.rect = Rect(data['Pos'][1], data['Pos'][2]-data['Pos'][3], 0, 0) self.zorder = self.rect.top + self.rect.height def show(self): @@ -54,7 +54,7 @@ oldRect=self.rect.__copy__() self.rect.x=pos[1] - self.rect.y=pos[2] + self.rect.y=pos[2]-pos[3] self.zorder = self.rect.top + self.rect.height updateRect=oldRect.union(self.rect) Modified: branches/VP-Grounds/modules/playground/avatar-static.py =================================================================== --- branches/VP-Grounds/modules/playground/avatar-static.py 2009-03-08 11:15:18 UTC (rev 286) +++ branches/VP-Grounds/modules/playground/avatar-static.py 2009-03-23 14:08:58 UTC (rev 287) @@ -5,7 +5,7 @@ self.sh = share self.imageName=data['Avatar'][1] - self.rect = Rect(data['Pos'][1], data['Pos'][2], 0, 0) + self.rect = Rect(data['Pos'][1], data['Pos'][2]-data['Pos'][3], 0, 0) self.zorder = self.rect.top + self.rect.height def show(self): @@ -44,7 +44,7 @@ oldRect=self.rect.__copy__() self.rect.x=pos[1] - self.rect.y=pos[2] + self.rect.y=pos[2]-pos[3] self.zorder = self.rect.top + self.rect.height updateRect=oldRect.union(self.rect) Modified: branches/VP-Grounds/modules/playground.py =================================================================== --- branches/VP-Grounds/modules/playground.py 2009-03-08 11:15:18 UTC (rev 286) +++ branches/VP-Grounds/modules/playground.py 2009-03-23 14:08:58 UTC (rev 287) @@ -24,6 +24,7 @@ self.timer = None self.walkingStep=10 #Size(px) of each step. + self.runningStep=20 #Size(px) of each step while running. #Loading all our objects-modules (kinda like interface.py) @@ -62,26 +63,42 @@ 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) ) + dir=-1 + tempStep=self.runningStep if ev.mod & KMOD_CTRL else self.walkingStep if ev.key == K_UP: - self.walking(0, +self.walkingStep, True) + dir=0 elif ev.key == K_LEFT: - self.walking(1, +self.walkingStep, True) + dir=1 elif ev.key == K_DOWN: - self.walking(2, +self.walkingStep, True) + dir=2 elif ev.key == K_RIGHT: - self.walking(3, +self.walkingStep, True) + dir=3 + elif ev.key == K_RCTRL or ev.key == K_LCTRL: + for d, s in enumerate(self.walkingDir): + if s: self.walking(d, self.runningStep-s, True, True) + + + if dir != -1: + self.walking(dir, tempStep, True) elif ev.type == KEYUP: if self.dontUpdate == False: + dir=-1 if ev.key == K_UP: - self.walking(0, -self.walkingStep, False) + dir=0 elif ev.key == K_LEFT: - self.walking(1, -self.walkingStep, False) + dir=1 elif ev.key == K_DOWN: - self.walking(2, -self.walkingStep, False) + dir=2 elif ev.key == K_RIGHT: - self.walking(3, -self.walkingStep, False) + dir=3 + elif ev.key == K_RCTRL or ev.key == K_LCTRL: + for d, s in enumerate(self.walkingDir): + if s: self.walking(d, -self.runningStep+self.walkingStep, False, True) + if dir != -1: + self.walking(dir, -self.walkingDir[dir], False) + def call(self, *arg): @@ -217,16 +234,16 @@ return [item[1] for item in sortList] - def walking(self, direction, speed, keyDown): + def walking(self, direction, speed, keyDown, ctrl=False): #Repeating key prevention. #Check if keyDown was already send to this direction if keyDown == True: - if self.walkingDir[direction] == False: - self.walkingDir[direction] = True + if not self.walkingDir[direction] or ctrl: + self.walkingDir[direction] += speed self.sh['Brains'].walking(direction, speed) else: - if self.walkingDir[direction] == True: - self.walkingDir[direction] = False + if self.walkingDir[direction] or ctrl: + self.walkingDir[direction] += speed self.sh['Brains'].walking(direction, speed) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |