Changeset 51
- Timestamp:
- 05/05/08 23:32:53 (8 months ago)
- Location:
- muckaround/blobworld
- Files:
-
- 2 added
- 3 modified
-
source/blobs.py (modified) (6 diffs)
-
source/game.py (modified) (3 diffs)
-
source/level-slow.py (added)
-
source/setup.py (added)
-
test.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
muckaround/blobworld/source/blobs.py
r50 r51 2 2 3 3 from pyglet.gl import * 4 4 5 5 6 … … 11 12 self.game = game 12 13 self.owner = owner 13 self.pos ition= pos14 self.pos = pos 14 15 self.girth = girth 15 self.radius = self.girth2radius() 16 self.colour = (1, 1, 1) 17 self.no_growth = False 18 self.collides_with = ALL_BUILDING_BLOBS 16 19 if self.game.renderable: 17 20 Blob.init_render() … … 20 23 return math.sqrt(self.girth / math.pi) 21 24 25 radius = property(girth2radius) 26 22 27 def think(self, dt): 23 self.girth += dt * 100 28 if not self.no_growth: 29 self.girth += dt * 10 30 self.no_growth = False 31 32 def collision(self, other): 33 if isinstance(other, FoodBlob): 34 return 35 self.no_growth = True 24 36 25 37 def render(self): 26 rad = self.girth2radius() 27 pos = self.position 38 glColor3f(*self.colour) 28 39 glPushMatrix() 29 glTranslatef( pos[0],pos[1], 0)30 glScalef( rad, rad, 1)40 glTranslatef(self.pos[0], self.pos[1], 0) 41 glScalef(self.radius, self.radius, 1) 31 42 glCallList(Blob.blob_list) 32 43 glPopMatrix() … … 39 50 glNewList(cls.blob_list, GL_COMPILE) 40 51 glBegin(GL_LINE_LOOP) 41 steps = 2 552 steps = 20 42 53 for a in xrange(steps): 43 54 p = ( … … 50 61 51 62 63 class FoodBlob(Blob): 64 65 def __init__(self, *args, **kwargs): 66 Blob.__init__(self, *args, **kwargs) 67 self.colour = (0.2, 0.9, 0.2) 68 self.collides_with = [] 69 70 def think(self, dt): 71 pass 72 73 class FeederBlob(Blob): 74 75 def __init__(self, *args, **kwargs): 76 Blob.__init__(self, *args, **kwargs) 77 self.colour = (0.7, 1.0, 0.2) 78 self.is_feeding = False 79 self.collides_with = [FoodBlob] + ALL_BUILDING_BLOBS 80 81 def think(self, dt): 82 if self.is_feeding and not self.no_growth: 83 self.girth += dt * 20 84 self.is_feeding = False 85 self.no_growth = False 86 87 def collision(self, other): 88 if isinstance(other, FoodBlob): 89 self.is_feeding = True 90 else: 91 self.no_growth = True 92 52 93 class HomeBlob(Blob): 53 94 pass 54 95 55 96 class BuilderBlob(Blob): 56 pass57 58 class FeederBlob(Blob):59 97 pass 60 98 … … 65 103 pass 66 104 105 ALL_BUILDING_BLOBS = [HomeBlob, FeederBlob] 67 106 107 -
muckaround/blobworld/source/game.py
r50 r51 4 4 from level import Level 5 5 from player import HumanPlayer, ComputerPlayer 6 from blobs import Blob6 from blobs import HomeBlob, BuilderBlob, FoodBlob, FeederBlob 7 7 8 8 from pyglet.gl import * … … 31 31 32 32 for p in self.players: 33 self.add_blob(p, rand_pos(self.level.width, self.level.height), 5) 33 self.add_blob(HomeBlob, p, 34 rand_pos(self.level.width, self.level.height), 50) 34 35 36 def spawn_food(self): 37 for a in xrange(100): 38 self.add_blob(FoodBlob, None, 39 rand_pos(self.level.width, self.level.height), 20) 35 40 36 41 def init_video(self): … … 47 52 48 53 def on_mouse_press(self, x, y, button, modifiers): 49 self.add_blob( self.human, (x, y), 10)54 self.add_blob(FeederBlob, self.human, (x, y), 50) 50 55 51 def add_blob(self, owner, pos, radius):52 blob = Blob(self, owner, pos, radius)56 def add_blob(self, typ, owner, pos, radius): 57 blob = typ(self, owner, pos, radius) 53 58 self.level.add_blob(blob) 54 owner.inform_blob_ownership(blob) 59 if owner: 60 owner.inform_blob_ownership(blob) 55 61 56 62 def render(self): -
muckaround/blobworld/test.py
r50 r51 14 14 game.level = LevelRenderable(game, 800, 600) 15 15 game.spawn_players() 16 game.spawn_food() 16 17 17 18 last_think = time.time()