def loadModels(self): self.environment = loader.loadModel("models/gamedev/grassy") self.environment.reparentTo(render) self.environment.setScale(3.4) self.environment.setPos(0,12,-0.45) self.environment.setH(78) self.background = OnscreenImage(image = 'models/gamedev/lvl2background.jpg', pos = (0,40,0),scale=42.5, hpr = (0,-1,0)) self.background.reparentTo(render) bounds = self.environment.getChild(0).getBounds() radius = bounds.getRadius()*1.5 center = bounds.getCenter()+Vec3(0,12,0) #print center self.ball = [] for i in range(self.ballNum+1): balls.define(self.ball,i,render,center,radius) # ** Load male character that will represent first player** # self.playerModel = Actor("models/gamedev/redguy-model",{"walk":"models/gamedev/redguy-run"}) self.playerModel.reparentTo(render) self.playerModel.setScale(.1) self.playerModel.setH(90) # ** Position player at center of the field with it lying directly above the field. ** # self.playerModel.setPos(-10,0,0.76) # ** Load female character that will represent second player** # self.playerModel2 = Actor("models/gamedev/bluegirl-model",{"walk2":"models/gamedev/bluegirl-run"}) self.playerModel2.reparentTo(render) self.playerModel2.setScale(.1) self.playerModel2.setH(0) # ** Position player at center of the field with it lying directly above the field. ** # self.playerModel2.setPos(10,0,1.0)
def eat(self,cEntry): if str(cEntry.getIntoNodePath().getParent()) == "render/blueball": #Blue ball picked up, update score self.player2Score+=1 elif str(cEntry.getIntoNodePath().getParent()) == "render/redball": #Red ball picked up, update score self.player1Score+=1 elif str(cEntry.getIntoNodePath().getParent()) == "render/crystalball": #Freezes the field (Ice) self.environment.setColor(0,.9,1) taskMgr.doMethodLater(10, self.switch, 'changeStage') self.speed1 = 14 self.speed2 = 14 self.turnSpeed1 = 110 self.turnSpeed2 = 110 taskMgr.doMethodLater(10, self.returnSpeeds, 'returnSpeedsToNormal') elif str(cEntry.getIntoNodePath().getParent()) == "render/red_blue": #Switch Sphere Colors for i in self.ball: if i.getName() == "blueball": i.removeNode() children = i.getGeomNode().getChildren() children.detach() i.loadModel("models/gamedev/redball") i.setName("redball") i.reparentTo(render) elif i.getName() == "redball": i.removeNode() children = i.getGeomNode().getChildren() children.detach() i.loadModel("models/gamedev/blueball") i.setName("blueball") i.reparentTo(render) elif str(cEntry.getIntoNodePath().getParent()) == "render/fireball": #Stop your opponent for a few seconds if (str(cEntry.getFromNodePath().getParent()) == "render/redgirl") or (str(cEntry.getFromNodePath().getParent()) == "render/redguy"): self.speed2 = 0 self.turnSpeed2 = 0 self.ignore("o") taskMgr.doMethodLater(3, self.returnSpeeds2, 'returnSpeedsToNormal') else: self.speed1 = 0 self.turnSpeed1 = 0 self.ignore("w") taskMgr.doMethodLater(3, self.returnSpeeds2, 'returnSpeedsToNormal') elif str(cEntry.getIntoNodePath().getParent()) == "render/black_white": self.ignoreColl = 1 x = Vec3(self.playerModel.getPos()) y = Vec3(self.playerModel2.getPos()) self.playerModel.setPos(y) self.playerModel2.setPos(x) self.ignoreColl = 0 elif str(cEntry.getIntoNodePath().getParent()) == "render/golden": if (str(cEntry.getFromNodePath().getParent()) == "render/redgirl") or (str(cEntry.getFromNodePath().getParent()) == "render/redguy"): self.speed1 = 14 self.turnSpeed1 = 110 taskMgr.doMethodLater(8, self.returnSpeeds3, 'returnSpeedsToNormal') else: self.speed2 = 14 self.turnSpeed2 = 110 taskMgr.doMethodLater(8, self.returnSpeeds3, 'returnSpeedsToNormal') elif str(cEntry.getIntoNodePath().getParent()) == "render/greenball": if (str(cEntry.getFromNodePath().getParent()) == "render/redgirl") or (str(cEntry.getFromNodePath().getParent()) == "render/redguy"): self.player1Score += 5 else: self.player2Score += 5 elif str(cEntry.getIntoNodePath().getParent()) == "render/blackball": camera.setPosHpr(Vec3(0,-55,110), Vec3(0,-20,0)) taskMgr.doMethodLater(5,self.restoreCamera,'restoreCamera') elif str(cEntry.getIntoNodePath().getParent()) == "render/translucent": for i in self.ball: i.hide() taskMgr.doMethodLater(6,self.showBalls,'returnBallsToNormal') cEntry.getIntoNodePath().getParent().removeNode() #Drop a New Ball bounds = self.environment.getChild(0).getBounds() radius = bounds.getRadius()*1.8 center = bounds.getCenter()+Point3(0,10,0) self.ballNum+=1 balls.define(self.ball,self.ballNum,render,center,radius) boundsB = self.ball[self.ballNum].getChild(0).getBounds() centerB = boundsB.getCenter() radiusB = boundsB.getRadius()*.8 cSphereB = CollisionSphere(centerB,radiusB) cNodeB = CollisionNode("ball") cNodeB.addSolid(cSphereB) cNodePathB = self.ball[self.ballNum].attachNewNode(cNodeB) self.dropSingle()