From: <ch...@us...> - 2009-03-31 20:47:03
|
Revision: 294 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=294&view=rev Author: chozone Date: 2009-03-31 20:46:57 +0000 (Tue, 31 Mar 2009) Log Message: ----------- NOTE: NOT finished, some (visual) debugging still active! After a lot of debugging, the first parts of walls are here! Still need to work on walls+Z/height, and walls of other users. For debugging: the grey transparant blocks in objects are their walls, the red line under the user is the rect of the user. (note that you can't see the Z/height in these debug-walls) Modified Paths: -------------- branches/VP-Grounds/brains.py branches/VP-Grounds/modules/playground/object.py branches/VP-Grounds/modules/playground.py Modified: branches/VP-Grounds/brains.py =================================================================== --- branches/VP-Grounds/brains.py 2009-03-29 21:11:28 UTC (rev 293) +++ branches/VP-Grounds/brains.py 2009-03-31 20:46:57 UTC (rev 294) @@ -1,6 +1,7 @@ from language import * import notify from connection import Connection +from pygame import Rect class Brains(): """ @@ -102,28 +103,48 @@ def doWalk(self): """ - This will be started from walkTimer + This will be started from walkTimer. + This will update our position wit each step, so we can blit it. + But it will NOT send our position to the server, that would cause + waaay to much traffic. For this we have the walkUpdateTimer. """ - #Update our position + ##Update our position #Get our name first name = self.sh['conf']['account']['user'] users = self.sh['users'] if name in users: - users[name]['Pos'][2] -= self.walkingDir[0] - users[name]['Pos'][1] -= self.walkingDir[1] - users[name]['Pos'][2] += self.walkingDir[2] - users[name]['Pos'][1] += self.walkingDir[3] + tPos=users[name]['Pos'][:] - self.sh['Interface'].call('playground', 'UserUpdate', users[name]) + tPos[1] -= self.walkingDir[1] + tPos[1] += self.walkingDir[3] - #print users[name]['Pos'] + #Are there any walls in the way? + if not self.checkWall(tPos): + updated=True + users[name]['Pos'][:]=tPos + else: + updated=False + tPos=users[name]['Pos'][:] + + tPos[2] -= self.walkingDir[0] + tPos[2] += self.walkingDir[2] + + #Are there any walls in the way, for y now? + if self.checkWall(tPos): tPos=users[name]['Pos'][:] + + if users[name]['Pos']!=tPos or updated: + users[name]['Pos']=tPos + + self.sh['Interface'].call('playground', 'UserUpdate', users[name]) def doWalkUpdate(self): """ - This will be started each 0.5 seconds from walkTimerUpdate + This will be started from walkTimerUpdate. + It sends our current position to the server. + Has to be on a slower interval than walkTimer. """ #Update our position to the server! @@ -135,3 +156,37 @@ if self.walkTimer.isRunning == False: #Stop ourself since nothing has to be updated return False + + def checkWall(self, pos): + """ + CheckWall(pos) ==> True if there is a wall on pos. + """ + + walls = self.sh['Ground-walls'] #[0]=lists, [1]=pygame rects + + #Is our rect-wallist already build? + if walls[1]==[]: + if walls[0]==[]: return #No walls at all: user can move :) + + for wall in walls[0]: + rect=Rect(wall[0], wall[2], wall[1]-wall[0], wall[3]-wall[2]) + walls[1].append(rect) + + #Do we have a rect for ourselves? + #TODO: later loop through all users(in our ground), and check/create + #rects for them all, and see if another user is in the way + #Creating rects for other users in getData, or somewhere where their pos update is processed + ownName=self.sh['conf']['account']['user'] + ownSh=self.sh['users'][ownName] + ownSh['collRect'].x=pos[1] + ownSh['collRect'].y=pos[2]+ownSh['size'][2]-1 + + collides = ownSh['collRect'].collidelistall(walls[1]) + + #No collides with walls, user can move :) + if collides == []: return + + #Well, we're on a wall, but are we IN it, or is + #it floating above us/are we floating above it? + #TODO: making this... (Z positions) + return True Modified: branches/VP-Grounds/modules/playground/object.py =================================================================== --- branches/VP-Grounds/modules/playground/object.py 2009-03-29 21:11:28 UTC (rev 293) +++ branches/VP-Grounds/modules/playground/object.py 2009-03-31 20:46:57 UTC (rev 294) @@ -10,6 +10,24 @@ self.size = [int(i) for i in obj['size']] self.objZorder = int(obj['zorder']) + self.walls = data['objecttype']['walls'] + #Convert a dict of walls (in format 'name':['X1','X2','Y1','Y2','Z1','Z2']) + #to a simple list with all int values + self.walls = [[int(i) for i in w] for w in self.walls.values()] + + #Create a copy of our walls, and move these walls, so they + #are real position, instead of internal position + self.realWalls=[] + for wall in self.walls: + wall = wall[:] #Make a copy of this var, so we don't change it in our origional list + wall[0]+=self.pos[0] + wall[1]+=self.pos[0] + wall[2]+=self.pos[1] + wall[3]+=self.pos[1] + self.realWalls.append(wall) + + + self.imageD = obj['imageD'] self.imageN = obj['imageN'] self.imageStyle = 'D' @@ -35,11 +53,18 @@ if list(image[1].size) != self.size: self.image[0] = pygame.transform.smoothscale(self.image[0], self.size) + n=0 + for wall in self.walls: + rect=Rect(wall[0], wall[2], wall[1]-wall[0], wall[3]-wall[2]) + col=(50+20*n,50+20*n,50+20*n,200) + self.image[0].fill(col,rect) + + n+=1 + self.sh['Playground'].blit(self.rect) def update(self, screen, rect): - #print rect, self.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 Modified: branches/VP-Grounds/modules/playground.py =================================================================== --- branches/VP-Grounds/modules/playground.py 2009-03-29 21:11:28 UTC (rev 293) +++ branches/VP-Grounds/modules/playground.py 2009-03-31 20:46:57 UTC (rev 294) @@ -20,8 +20,8 @@ self.timer = None - self.walkingStep=10 #Size(px) of each step. - self.runningStep=20 #Size(px) of each step while running. + self.walkingStep=5 #Size(px) of each step. + self.runningStep=15 #Size(px) of each step while running. #Loading all our objects-modules (kinda like interface.py) @@ -106,6 +106,7 @@ #Wait with updating until all data has arrived self.dontUpdate = True self.objects = {} + self.sh['Ground-walls']=[[],[]] #Purge all walls, while all objects are gone, and with them, all walls elif msg['state'] == 'free': #We're free to update! @@ -137,6 +138,14 @@ self.openObject('avatar-' + user['Avatar'][0], 'av-' + user['Name'], user) if not 'avatar-' + user['Avatar'][0] in self.modObjects.keys(): return self.objects['av-%s'%user['Name']].show() #Will start downloading, see modules/playground/avatar-static.py for full explanation + + #Create a 'coll(ide)Rect, the rect that will be used when checking for walls + rRect=self.objects['av-%s'%user['Name']].rect + shUsr=self.sh['users'][user['Name']] + shUsr['collRect']=Rect((rRect.x, rRect.y+rRect.h-1), (rRect.w, 1)) + shUsr['size']=(rRect.w, 1, rRect.h) + + else: #Not in ground, but do we still have the avatar-object? @@ -156,6 +165,12 @@ rect = rect.move(-myRect[0], -myRect[1]) #Move rect to our position myPos = (myRect[0] + rect[0], myRect[1] + rect[1]) #Calculate our position from the rect screen.blit(self.surf, myPos, rect) #Blit + + + ownName=self.sh['conf']['account']['user'] + if ownName in self.sh['users'].keys(): + ownRect=self.sh['users'][ownName]['collRect'] + screen.fill((220,20,20), ownRect) def close(self): del self.sh['Playground'] @@ -201,6 +216,9 @@ #What is this? if info['object'] == 'object': self.openObject('object', name, info) + + #Add walls to our wall-list thingy + for wall in self.objects[name].realWalls: self.sh['Ground-walls'][0].append(wall) def openObject(self, objname, name, data): """ @@ -211,7 +229,7 @@ print 'ERROR @Playground: Object type', objname,'not found, cannot open', name return - #print '## Open Object', name, 'as', objname #DEBUG + print '## Open object', name, 'as', objname#, '==', data #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. |