def __init__(self, property: IO_Property, name="arrow", axis=-1): super().__init__(property, name) self.texture = IO_TextureManager.getInstance().textureMap["Rock2"] self.force = IO_Vector(x=5, y=0) self.rigidBody.gravity = IO_Vector() self.force *= axis self.axis = axis
def update(self, dt, game): self.rigidBody.applyForceX(self.force.x) self.rigidBody.update(dt) self.transform.translateX(self.rigidBody.position.x) self.rigidBody.unSetForce() for actor in game.level.characters.values(): if IO_CollisonHandler.getInstance().CheckCollision( actor.collider.box, self.collider.box): if (actor != game.level.pink and actor.isFrozen == False): actor.isDead = True actor.rigidBody.applyForceX(self.force.x) actor.rigidBody.gravity = IO_Vector(y=0) elif (actor != game.level.pink and actor.isFrozen): actor.rigidBody.applyForceX(self.axis * 4) game.level.pink.projectiles.remove(self) if self.transform.x < 0 or self.transform.x > 608: if self in game.level.pink.projectiles: game.level.pink.projectiles.remove(self)
def update(self, dt, game): self.rigidBody.applyForceX(self.force.x) self.rigidBody.update(dt) self.transform.translateX(self.rigidBody.position.x) self.rigidBody.unSetForce() for actor in game.level.characters.values(): if IO_CollisonHandler.getInstance().CheckCollision( actor.collider.box, self.collider.box): if (actor != game.level.dude): self.force.x = 0 actor.rigidBody.gravity = IO_Vector(y=2) if actor.isDead and actor.isFrozen == False: actor.transform.y = actor.transform.y - 20 if abs(actor.transform.x - game.level.dude.transform.x ) < 28 and actor.isDead == False: actor.rigidBody.applyForceX(10 * self.axis) actor.isFrozen = actor.isDead = True game.level.dude.projectiles.remove(self) elif (actor != game.level.dude and actor.isFrozen): game.level.dude.projectiles.remove(self) if self.transform.x < 0 or self.transform.x > 608: if self in game.level.dude.projectiles: game.level.dude.projectiles.remove(self)
def __init__(self): """ Virtually private constructor. """ if IO_Camera.__instance != None: raise Exception("This class is a IO_Camera!") else: IO_Camera.__instance = self super().__init__() self.target = None self.position = IO_Vector() self.viewBox = pygame.Rect(0, 0, 0, 0) self.screenSize = IO_SCREEN_SIZE
def __init__(self,x : int, y : int,w : int,h : int, num:int, force:IO_Vector = IO_Vector(y=-3)): super().__init__( IO_Property(texture=IO_TextureManager.getInstance().textureMap["obstacle"],x = x, y = y ,w = w, h = h), name="Barrier"+str(num)) self.buttons : list[Button] = [] self.force : IO_Vector = force self.startingpos = IO_Point(self.transform.x,self.transform.y) self.opentime = 40
def init(self, screenSize=IO_SCREEN_SIZE): self.target = IO_Point() self.position = IO_Vector() self.viewBox = pygame.Rect(0, 0, screenSize[0], screenSize[1]) self.screenSize = screenSize
def parse(self, source): xmlRoot = IO_XmlHandler.getRoot(source) xmllevels = IO_XmlHandler.getChild(xmlRoot, "level") for xmllevel in xmllevels: level = Level() name = IO_XmlHandler.getAttribute(xmllevel, "name") map = IO_XmlHandler.getAttribute(xmllevel, "map") self.levelMap[name] = level level.name = name level.map = IO_MapManager.getInstance().maps[map] level.wall = IO_MapManager.getInstance().maps[map].layers["wall"] xmlcharacters = IO_XmlHandler.getChild(xmllevel, "character")[0] for xmlcharacter in xmlcharacters: #print(xmlcharacter.tag) #xmlActor = IO_XmlHandler.getChild(xmlcharacter,xmlcharacter.tag)[0] x = float(IO_XmlHandler.getAttribute(xmlcharacter, "x")) y = float(IO_XmlHandler.getAttribute(xmlcharacter, "y")) w = float(IO_XmlHandler.getAttribute(xmlcharacter, "w")) h = float(IO_XmlHandler.getAttribute(xmlcharacter, "h")) actor = None if xmlcharacter.tag == "Dude": actor = level.dude = Dude( IO_Property(animation=IO_AnimationHandler.getInstance( ).animationMap[xmlcharacter.tag + "_Monster_Idle_4"], x=x, y=y, w=w, h=h)) if xmlcharacter.tag == "Owlet": actor = level.owlet = Owlet( IO_Property(animation=IO_AnimationHandler.getInstance( ).animationMap[xmlcharacter.tag + "_Monster_Idle_4"], x=x, y=y, w=w, h=h)) if xmlcharacter.tag == "Pink": actor = level.pink = Pink( IO_Property(animation=IO_AnimationHandler.getInstance( ).animationMap[xmlcharacter.tag + "_Monster_Idle_4"], x=x, y=y, w=w, h=h)) level.characters[xmlcharacter.tag] = actor xmlBarriers = IO_XmlHandler.getChild(xmllevel, "barrier") num = 0 for xmlBarrier in xmlBarriers: x = float(IO_XmlHandler.getAttribute(xmlBarrier, "x")) y = float(IO_XmlHandler.getAttribute(xmlBarrier, "y")) w = float(IO_XmlHandler.getAttribute(xmlBarrier, "w")) h = float(IO_XmlHandler.getAttribute(xmlBarrier, "h")) forceX = float(IO_XmlHandler.getAttribute( xmlBarrier, "forceX")) forceY = float(IO_XmlHandler.getAttribute( xmlBarrier, "forceY")) barrier = Barrier(x=x, y=y, w=w, h=h, num=num, force=IO_Vector(x=forceX, y=forceY)) num += 1 xmlbuttons = IO_XmlHandler.getChild(xmlBarrier, "button") numb = 0 for xmlbutton in xmlbuttons: x = float(IO_XmlHandler.getAttribute(xmlbutton, "x")) y = float(IO_XmlHandler.getAttribute(xmlbutton, "y")) buttons = Button(x=x, y=y, name=str(numb)) barrier.buttons.append(buttons) numb += 1 level.barriers.append(barrier) xmlSpikes = IO_XmlHandler.getChild(xmllevel, "spike") num = 0 for xmlSpike in xmlSpikes: x = float(IO_XmlHandler.getAttribute(xmlSpike, "x")) y = float(IO_XmlHandler.getAttribute(xmlSpike, "y")) w = float(IO_XmlHandler.getAttribute(xmlSpike, "w")) h = float(IO_XmlHandler.getAttribute(xmlSpike, "h")) spike = Spike(x=x, y=y, w=w, h=h, num=str(num)) level.spikes.append(spike) num += 1 xmlGoal = IO_XmlHandler.getChild(xmllevel, "goal")[0] x = float(IO_XmlHandler.getAttribute(xmlGoal, "x")) y = float(IO_XmlHandler.getAttribute(xmlGoal, "y")) level.goal = Goal(x=x, y=y)