def build_parts(self,**kw): self.light = lighting.claim_light() stylesheet.load(monsters.MonsterStyles) stylesheet.load(graphics.BallStyles) start_btn = panel.LabelPanel( "Start", text=" Start ", geom=dict(pos=(512,200,0)), style_classes=['button']) quit_btn = panel.LabelPanel( "Quit", text=" Quit ", geom=dict(pos=(512,100,0)), style_classes=['button']) ov = OrthoView( "ortho", [start_btn, quit_btn], geom=dict(left=0,right=1024,top=768,bottom=0,far=1000), style={"ClearColor":(0,0,0,0)}) if main.options.time: ov.append(ClockPart(geom=dict(pos=(50,50,0)))) with ov.compile_style(): glDisable(GL_LIGHTING) self.append(ov) sv = SceneView("scene") self.level = level = levelfile.load_level("title.lev") hf = graphics.HexagonField("hexfield",level) sv.append(hf) for coords, classname in level.monsters.items(): pos = collision.h_centre(*coords) M = getattr(monsters,classname,monsters.Monster) m = M(classname, geom=dict(pos=pos,angle=0)) sv.append(m) for coords, classname in level.powerups.items(): pos = collision.h_centre(*coords) M = getattr(graphics,classname,graphics.Ball) m = M(classname, geom=dict(pos=pos,angle=0)) m.duration = float('inf') sv.append(m) sv.camera.look_at(pos,10) sv.camera.look_from_spherical(45,270,70) sv.camera.step(1) self.camera = sv.camera with sv.compile_style(): glEnable(GL_LIGHTING) lighting.light_position(self.light,(10,10,10,0)) lighting.light_colour(self.light,(1,1,1,1)) lighting.light_switch(self.light,True) self.append(sv)
def add_thing_to_view(self,coords,module,classname): M = getattr(module,classname) mname = repr(coords) m = M(mname) m.pos = collision.h_centre(*coords) m.restyle(True) m.duration = float('inf') # for balls self.parts["view"].append(m)
def build_powerups(self,level): ps = [] for coords, classname in level.powerups.items(): pos = collision.h_centre(*coords) P = getattr(graphics,classname,graphics.Ball) p = P(repr(coords), geom=dict(pos=pos,angle=0)) p.duration = float('inf') ps.append(p) return ps
def step(self,ms): self.step_contents(ms) lighting.step(ms) self.camera.step(ms) if self.camera.animator.finished(): hexlist = [self.level.start, self.level.exit] hexlist.extend(self.level.monsters.keys()) poslist = [tuple(collision.h_centre(*coords)) for coords in hexlist] poslist.append(poslist[0]) steplist = [10000 for coords in hexlist] steplist.append(1000) self.camera.animator.sequence("looking_at",poslist,steplist)
def build_monsters(self,level): ms = [] count = 0 for coords, classname in level.monsters.items(): pos = collision.h_centre(*coords) M = getattr(monsters,classname,monsters.Monster) if classname == "Hunter" or coords == level.exit: vel = Vec(0,0) else: # random direction and speed vel = (random.choice(collision.H_NORMAL) * random.gauss(M.speed,0.02) * 0.01) m = M("{0}{1}".format(classname,count), velocity=vel, geom=dict(pos=pos,angle=0)) if classname == "Balrog": # The Balrog knows where you are. m.player = self.player count += 1 ms.append(m) return ms
def on_collision(self,what,where,direction): if isinstance(what,graphics.Ball): self.hunt(what,where,1.1) self.harm_type = "provoked a" sounds.play("roar") self.enrage() elif isinstance(what,graphics.Player): self.eat(what,direction) sounds.play("munch") else: self.turn_to(direction) self.pos = where self.rage -= 1 if self.rage <= 0: self.hiding = True x,y,_ = where hc,hr = collision.nearest_neighbours(x,y,0).next() self.pos = collision.h_centre(hc,hr) self.velocity = Vec(0,0,0) self.prepare()
def hex_to_world_coords(col,row): x,y,_ = collision.h_centre(col,row) return x,y