def update(self): self.last.x=self.x self.last.y=self.y #print "last",self,self.last.x,self.last.y FlxCore.update(self); if(not self.active): return; #animation if((self._curAnim != None) and (self._curAnim.delay > 0) and (self._curAnim.looped or not self.finished)): self._frameTimer += FlxG.elapsed; #print self._frameTimer,self._curAnim.delay,FlxG.elapsed #raw_input() if(self._frameTimer > self._curAnim.delay): self._frameTimer -= self._curAnim.delay; if(self._curFrame == len(self._curAnim.frames)-1): if(self._curAnim.looped): self._curFrame = 0; self.finished = true; else: self._curFrame+=1; self.calcFrame(); #print "curframe",self._curFrame #motion + physics self.angularVelocity = FlxG.computeVelocity(self.angularVelocity,self.angularAacceleration,self.angularDrag,self.maxAngular) self.angle += (self.angularVelocity)*FlxG.elapsed; self.thrustComponents=FlxPoint(); if(self.thrust != 0): self.thrustComponents = FlxG.rotatePoint(-self.thrust,0,0,0,self.angle); maxComponents = FlxG.rotatePoint(-maxself.thrust,0,0,0,self.angle); maxself.velocity.x = Math.abs(maxComponents.x); maxself.velocity.y = Math.abs(maxComponents.y); else: self.thrustComponents = self._pZero; self.velocity.x = FlxG.computeVelocity(self.velocity.x,self.acceleration.x+self.thrustComponents.x,self.drag.x,self.maxVelocity.x) self.x += (self.velocity.x)*FlxG.elapsed; self.velocity.y = FlxG.computeVelocity(self.velocity.y,self.acceleration.y+self.thrustComponents.y,self.drag.y,self.maxVelocity.y) self.y += (self.velocity.y)*FlxG.elapsed;
def old_collide(self,Spr): #x y not chongdie #print "=",self.x,self.y,self.width,self.height,"collide",Spr.x,Spr.y,Spr.width,Spr.height if((Math.abs(Spr.x + (Spr.width>>1) - self.x - (self.width>>1)) > (self.width>>1) + (Spr.width>>1)) and (Math.abs(Spr.y + (Spr.height>>1) - self.y - (self.height>>1)) > (self.height>>1) + (Spr.height>>1))): return; #print FlxG.elapsed,":",self.x,self.y,self.width,self.height,"collide",Spr.x,Spr.y,Spr.width,Spr.height yFirst= true; if((Math.abs(Spr.velocity.x) > Math.abs(Spr.velocity.y))): yFirst = false; #print "yfirst=false",Spr.y else: #print "yfirst=true",Spr.y pass checkForMoreX = false; checkForMoreY = false; if(yFirst): if(Spr.velocity.y > 0): #print "velocity.y>0" if(self.overlapsPoint(Spr.x + (Spr.width>>1),Spr.y + Spr.height)): if(Spr.hitFloor()): Spr.y = self.y - Spr.height; else: checkForMoreY = true; elif(Spr.velocity.y < 0): #print "velocity.y<0" if(self.overlapsPoint(Spr.x + (Spr.width>>1),Spr.y)): if(Spr.hitCeiling()): Spr.y = self.y + self.height; else: checkForMoreY = true; if(Spr.velocity.x < 0): #print "velocity.x<0",self.x,self.y,self.width,self.height,Spr.x,Spr.y,Spr.width,Spr.height if(self.overlapsPoint(Spr.x,Spr.y + (Spr.height>>1))): if(Spr.hitWall()): #print "hitwall" Spr.x = self.x + self.width; else: #print "check more x" checkForMoreX = true; elif(Spr.velocity.x > 0): #print "velocity.x>0" if(self.overlapsPoint(Spr.x + Spr.width,Spr.y + (Spr.height>>1))): if(Spr.hitWall()): Spr.x = self.x - Spr.width; else: checkForMoreX = true; else: if(Spr.velocity.x < 0): if(self.overlapsPoint(Spr.x,Spr.y + (Spr.height>>1))): if(Spr.hitWall()): Spr.x = self.x + self.width; else: checkForMoreX = true; elif(Spr.velocity.x > 0): if(self.overlapsPoint(Spr.x + Spr.width,Spr.y + (Spr.height>>1))): if(Spr.hitWall()): Spr.x = self.x - Spr.width; else: checkForMoreX = true; if(Spr.velocity.y > 0): if(self.overlapsPoint(Spr.x + (Spr.width>>1),Spr.y + Spr.height)): if(Spr.hitFloor()): Spr.y = self.y - Spr.height; else: checkForMoreY = true; elif(Spr.velocity.y < 0): if(self.overlapsPoint(Spr.x + (Spr.width>>1),Spr.y)): if(Spr.hitCeiling()): Spr.y = self.y + self.height; else: checkForMoreY = true; if( not checkForMoreY and not checkForMoreX): return; bias = Spr.width>>3; if(bias < 1): bias = 1; if(checkForMoreY and checkForMoreX): #print "check more y and x",Spr.y if(yFirst): if(checkForMoreY): if((Spr.x + Spr.width - bias > self.x) and (Spr.x + bias < self.x + self.width)): if((Spr.velocity.y > 0) and (Spr.y + Spr.height > self.y) and (Spr.y + Spr.height < self.y + self.height) and Spr.hitFloor()): Spr.y = self.y - Spr.height; elif((Spr.velocity.y < 0) and (Spr.y > self.y) and (Spr.y < self.y + self.height) and Spr.hitCeiling()): Spr.y = self.y + self.height; if(checkForMoreX): if((Spr.y + Spr.height - bias > self.y) and (Spr.y + bias < self.y + self.height)): if((Spr.velocity.x > 0) and (Spr.x + Spr.width > self.x) and (Spr.x + Spr.width < self.x + self.width) and Spr.hitWall()): Spr.x = self.x - Spr.width; elif((Spr.velocity.x < 0) and (Spr.x > self.x) and (Spr.x < self.x + self.width) and Spr.hitWall()): Spr.x = self.x + self.width; else: if(checkForMoreX): if((Spr.y + Spr.height - bias > self.y) and (Spr.y + bias < self.y + self.height)): if((Spr.velocity.x > 0) and (Spr.x + Spr.width > self.x) and (Spr.x + Spr.width < self.x + self.width) and Spr.hitWall()): Spr.x = self.x - Spr.width; elif((Spr.velocity.x < 0) and (Spr.x > self.x) and (Spr.x < self.x + self.width) and Spr.hitWall()): Spr.x = self.x + self.width; if(checkForMoreY): if((Spr.x + Spr.width - bias > self.x) and (Spr.x + bias < self.x + self.width)): if((Spr.velocity.y > 0) and (Spr.y + Spr.height > self.y) and (Spr.y + Spr.height < self.y + self.height) and Spr.hitFloor()): Spr.y = self.y - Spr.height; elif((Spr.velocity.y < 0) and (Spr.y > self.y) and (Spr.y < self.y + self.height) and Spr.hitCeiling()): Spr.y = self.y + self.height; elif(checkForMoreY): #print "check more y",Spr.y if((Spr.x + Spr.width - bias > self.x) and (Spr.x + bias < self.x + self.width)): if((Spr.velocity.y > 0) and (Spr.y + Spr.height > self.y) and (Spr.y + Spr.height < self.y + self.height) and Spr.hitFloor()): Spr.y = self.y - Spr.height; elif((Spr.velocity.y < 0) and (Spr.y > self.y) and (Spr.y < self.y + self.height) and Spr.hitCeiling()): Spr.y = self.y + self.height; elif(checkForMoreX): if((Spr.y + Spr.height - bias > self.y) and (Spr.y + bias < self.y + self.height)): if((Spr.velocity.x > 0) and (Spr.x + Spr.width > self.x) and (Spr.x + Spr.width < self.x + self.width) and Spr.hitWall()): Spr.x = self.x - Spr.width; elif((Spr.velocity.x < 0) and (Spr.x > self.x) and (Spr.x < self.x + self.width) and Spr.hitWall()): Spr.x = self.x + self.width;