Sections
Timeline
Sub-Sections
Download
Unified Diff
Zip Archive
Metanav
Preferences
About Trac
Links
Slowchop Studios
Gerald Kaszuba
Advertisement

Changeset 51

Show
Ignore:
Timestamp:
05/05/08 23:32:53 (8 months ago)
Author:
gak
Message:
 
Location:
muckaround/blobworld
Files:
2 added
3 modified

Legend:

Unmodified
Added
Removed
  • muckaround/blobworld/source/blobs.py

    r50 r51  
    22 
    33from pyglet.gl import * 
     4 
    45 
    56 
     
    1112        self.game = game 
    1213        self.owner = owner 
    13         self.position = pos 
     14        self.pos = pos 
    1415        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 
    1619        if self.game.renderable: 
    1720            Blob.init_render() 
     
    2023        return math.sqrt(self.girth / math.pi) 
    2124 
     25    radius = property(girth2radius) 
     26 
    2227    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 
    2436 
    2537    def render(self): 
    26         rad = self.girth2radius() 
    27         pos = self.position 
     38        glColor3f(*self.colour) 
    2839        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) 
    3142        glCallList(Blob.blob_list) 
    3243        glPopMatrix() 
     
    3950        glNewList(cls.blob_list, GL_COMPILE) 
    4051        glBegin(GL_LINE_LOOP) 
    41         steps = 25 
     52        steps = 20 
    4253        for a in xrange(steps): 
    4354            p = ( 
     
    5061 
    5162 
     63class 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 
     73class 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 
    5293class HomeBlob(Blob): 
    5394    pass 
    5495 
    5596class BuilderBlob(Blob): 
    56     pass 
    57  
    58 class FeederBlob(Blob): 
    5997    pass 
    6098 
     
    65103    pass 
    66104 
     105ALL_BUILDING_BLOBS = [HomeBlob, FeederBlob] 
    67106 
     107 
  • muckaround/blobworld/source/game.py

    r50 r51  
    44from level import Level 
    55from player import HumanPlayer, ComputerPlayer 
    6 from blobs import Blob 
     6from blobs import HomeBlob, BuilderBlob, FoodBlob, FeederBlob 
    77 
    88from pyglet.gl import * 
     
    3131 
    3232        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) 
    3435 
     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) 
    3540 
    3641    def init_video(self): 
     
    4752 
    4853    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) 
    5055 
    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) 
    5358        self.level.add_blob(blob) 
    54         owner.inform_blob_ownership(blob) 
     59        if owner: 
     60            owner.inform_blob_ownership(blob) 
    5561 
    5662    def render(self): 
  • muckaround/blobworld/test.py

    r50 r51  
    1414    game.level = LevelRenderable(game, 800, 600) 
    1515    game.spawn_players() 
     16    game.spawn_food() 
    1617 
    1718    last_think = time.time()