""" Apple Tree: Feed the hungry birds! """ import random from random import random as rnd import soya import soya.sphere #Apples are round :) import soya.sdlconst SC = soya.sdlconst from bird import FoodaffectedBird #Bird, BreedingBird, GrowingBird from appletree import AppleTree class TreeAndBirds(soya.World): def __init__(self): soya.World.__init__(self) self.tree = AppleTree(self) self.birds = [] for _ in range(3): b = FoodaffectedBird(self, (1 + rnd() * 2, 2 + rnd() * 2, 0.5 + rnd() * 3)) b.scale(0.3, 0.3, 0.3) self.birds.append(b) """bb = BreedingBird(self, (1, 1, 1)) bb.scale(0.3, 0.3, 0.3) self.birds.append(bb) gb = GrowingBird(self, (-1, -1, -1)) gb.scale(0.3, 0.3, 0.3) self.birds.append(gb)""" """scene basics""" light = soya.Light(self) light.set_xyz(1.0, 0.7, 1.0) light2 = soya.Light(self) light2.set_xyz(-1.0, 0.9, 0.7) light3 = soya.Light(self) light3.set_xyz(0.3, 0.8, -0.7) camera = soya.Camera(self) camera.set_xyz(0.0, 1.7, 4) #camera.look_at(soya.Vector(self, 0.0, 1, 0)) soya.set_root_widget(camera) self.camera = camera """game logic stuff""" #self.food = [] #does this mean this is a FoodWorld ? #now that is actually gotten from the tree self.has_added = 0 """controls""" self.keybindings = {SC.K_ESCAPE: self.quit, SC.K_LEFT: lambda: self.tree.turn_lateral(-10), SC.K_RIGHT: lambda: self.tree.turn_lateral(10), SC.K_UP: self.tree.grow, SC.K_DOWN: self.tree.revert } self.idler = soya.Idler(self) self.idler.idle() def get_food(self): return self.tree.apples food = property(get_food, None, None, "the food instances here now") def begin_round(self): for event in soya.process_event(): if event[0] == soya.sdlconst.KEYDOWN: try: self.keybindings[event[1]]() except KeyError: pass #if not self.food: # self.food.append(Apple(self, (rnd() * 3, rnd() * 3, rnd() * 3))) # self.has_added += 1 # print "Added food, now there is:", self.food, "total adds", self.has_added soya.World.begin_round(self) def give(self, food): """ the idea was that this would be in the tree. well now they are, so this is forwarded to there.. """ if food in self.food: self.food.remove(food) #is this double bookkeeping necessary? #self.remove(food) self.tree.remove(food) return food else: raise ValueError, "Does not have such food to give, " + str(food) def test(): pass def quit(self): self.idler.stop() def start(): soya.init(width = 700, height = 700) scene = TreeAndBirds() #PlantToy() #plant = Plant(scene) if __name__ == '__main__': #import profile #profile.run('start()', 'treebirdsprof') start()