From: <Blu...@us...> - 2010-08-31 18:13:22
|
Revision: 380 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=380&view=rev Author: BlueWolf_ Date: 2010-08-31 18:13:16 +0000 (Tue, 31 Aug 2010) Log Message: ----------- Added the background. This infinite grass likes to move! (use the keys) Modified Paths: -------------- trunk/client/playground.py Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-08-30 22:33:47 UTC (rev 379) +++ trunk/client/playground.py 2010-08-31 18:13:16 UTC (rev 380) @@ -26,6 +26,9 @@ self.status = None self.statuswhere = None + self.oldsurf = None + self.transit = None + # Login stuff self.loginbg = None self.loginbox = None @@ -34,7 +37,9 @@ # Playground stuff self.backgrounds = {} + self.viewport = None + def event(self, ev): if self.status == "login": @@ -49,7 +54,22 @@ if self.logingui != None: return self.logingui.event(ev) - + + + elif self.status == "playground": + if ev.type == KEYDOWN: + if ev.key == K_UP: + self.viewport.move_ip(0, -10) + self.playground_render() + if ev.key == K_DOWN: + self.viewport.move_ip(0, 10) + self.playground_render() + if ev.key == K_LEFT: + self.viewport.move_ip(-10, 0) + self.playground_render() + if ev.key == K_RIGHT: + self.viewport.move_ip(10, 0) + self.playground_render() def call(self, name, data): @@ -58,6 +78,8 @@ if data['status'] != self.status: # Unload data from the playground if self.status != None: + for name in self.backgrounds.keys(): + sh['downloader'].remove_usage(name) self.backgrounds = {} # Load the data for the login @@ -89,8 +111,10 @@ self.logingui = None # Load the data for the playground - self.surf.fill([0,0,0]) - sh['update']() + self.viewport = Rect(0, 0, 1000, 700) + self.oldsurf = self.surf.copy() + self.transit = 0 + self.playground_render(None, True) self.status = data['status'] self.statuswhere = data['where'] @@ -187,6 +211,42 @@ + def playground_render(self, rect = None, doupdate = True): + # Render the playground + if rect == None: + rect = Rect(0, 0, 1000, 700) + else: + rect = Rect(rect) + + # Blit the background + bg_offset = (self.viewport.left%250, self.viewport.top%250) + x_min = bg_offset[0]-250 + if x_min == -250: x_min = 0 + x_max = x_min + 250 * ((float(self.viewport.width) / 250)+1) + x_max = int(x_max) + y_min = bg_offset[1]-250 + if y_min == -250: y_min = 0 + y_max = y_min + 250 * ((float(self.viewport.height) / 250)+1) + y_max = int(y_max) + + for y in range(y_min, y_max, 250): + for x in range(x_min, x_max, 250): + bg_rect = Rect(x, y, 250, 250) + if bg_rect.colliderect(rect): + + background = self.backgrounds['bg-grass.png'] + bg_area = Rect( + rect.left - bg_rect.left, + rect.top - bg_rect.top, + rect.width, + rect.height) + + self.surf.blit(background, rect, bg_area) + + if doupdate: + sh['update'](rect) + + def download(self, filename, cache, name, *arg): if name == "background": self.backgrounds[filename] = cache This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |