예제 #1
0
파일: samus.py 프로젝트: Hatchet2k4/mannux
    def MorphState(self):
        self.Animate( ('blank',), loop=False)

        self.morph_trail = []

        X = math.pi*2 #I know this value is way too big, but it seems to fit for some reason...
        self.boosting = False
        self.boostticks = 0
        #self.CheckBallObstructions()
        #self.CheckObstructions()

        self.checkslopes = True

        while True:
            self.ticks += 1
            #self.morph_base.Update()
            #self.morph_overlay.Update()

            if self.boosting:
                max_morph_vx = 8.0 #boost speed!
                max_morph_vy = 8.0
                morph_friction = self.morph_friction
                morph_accel = 0.0
                air_accel = 0.0
                morph_airfriction = self.morph_airfriction * 6
                if abs(self.vx) <= 2.0: #need to f*****g find a better way around this for falling vertically... vector perhaps?
                    self.boosting = False
                #self.boostticks -= 1
                #if self.boostticks == 0:
                #    self.boosting = False
            else:
                max_morph_vx = self.max_morph_vx #standard max speed
                max_morph_vy = self.max_morph_vy
                morph_friction = self.morph_friction
                morph_accel = self.morph_accel
                air_accel = self.air_accel
                morph_airfriction = self.morph_airfriction



            #just bomb jumped, and falling again, so check for slopes again.
            if self.bombjumping == True and self.vy >=0:
                self.checkslopes = True
                self.bombjumping = False

            if self.ticks % 2 == 0: #cheap hack to make the trail longer without so many samples
                self.morph_trail.append( (self.x+9, self.y+25) ) #center of morphball
                if len(self.morph_trail) > self.max_trail_len:
                    self.morph_trail = self.morph_trail[1:] #keep list at most len items long

            if "up" in self.pressed and not self.ceiling and not self.boosting:
                #gonna need to edit this mad style, to check for a cieling within 16 pixels.
                #also check for floor and set to fall state if appropriate
                self.state = self.CrouchState
                self.morph_trail = []
                #self.y-=16

            if self.floor:
                self.vy = 0
                if "left" in self.pos and not self.left_wall:
                    if abs(self.vx) < max_morph_vx:
                        self.vx-=morph_accel
                        if self.vx < -max_morph_vx:
                            self.vx = -max_morph_vx
                    self.direction = Dir.LEFT
                    if self.vx > 0 or abs(self.vx) > self.max_morph_vx:
                        self.vx = vecmath.decrease_magnitude(self.vx, morph_friction)
                elif "right" in self.pos and not self.right_wall:
                    if abs(self.vx) < max_morph_vx:
                        self.vx+=morph_accel
                        if self.vx > max_morph_vx:
                            self.vx = max_morph_vx
                    self.direction = Dir.RIGHT
                    if self.vx < 0 or abs(self.vx) > self.max_morph_vx:
                        self.vx = vecmath.decrease_magnitude(self.vx, morph_friction)
                else:
                    self.vx = vecmath.decrease_magnitude(self.vx, morph_friction)
            else:
                self.vy += self.gravity
                if self.vy > max_morph_vy:
                    self.vy = max_morph_vy

                if "left" in self.pos and not self.left_wall:
                    self.vx -= air_accel
                    if self.vx < -max_morph_vx:
                        self.vx = -max_morph_vx
                    self.direction = Dir.LEFT
                elif "right" in self.pos and not self.right_wall:
                    self.vx += air_accel
                    if self.vx > max_morph_vx:
                        self.vx = max_morph_vx
                    self.direction = Dir.RIGHT
                else:
                    self.vx = vecmath.decrease_magnitude(self.vx, morph_airfriction)

            if "boost" in self.pos:
                if self.morph_boost < 100:
                    self.morph_boost += 2
            elif self.morph_boost > 32:
                #boost! terribly hacky
                self.boosting = True

                self.vx = self.vx * (2.5*self.morph_boost/100.0)
                self.vy = self.vy * (1.5*self.morph_boost/100.0)
                self.morph_boost = 0
                #self.boostticks = 20
                max_morph_vx = max_morph_vy = 8.0


            self.vx = vecmath.clamp(self.vx, -max_morph_vx, max_morph_vx)
            self.vy = vecmath.clamp(self.vy, -max_morph_vy, max_morph_vy)
            self.morph_angle = (self.morph_angle + self.vx * X)

            yield None
예제 #2
0
파일: samus.py 프로젝트: Hatchet2k4/mannux
    def Input(self, position, pressed): #essentially Update() now.
        self.pos = position
        self.pressed = pressed

        if self.fire_delay > 0:
            self.fire_delay -= 1


        #Missile HOLD button.
        if "missile_hold" in position:
            self.missile_held = True
            if self.sec_armed == False:
                if self.cur_state in self.morph_states and self.equipment["Power Bombs"].cur > 0:
                    self.sec_armed = True
                elif self.cur_state not in self.morph_states and self.equipment[("Missiles", "Super Missiles")[self.cur_missile]].cur > 0:
                    self.sec_armed = True
        elif self.sec_armed and self.missile_held:
            self.sec_armed = False
            self.missile_held = False


        #Item stuff depending on missile_style.
        if controls.missile_style == 0:
            #Dual style.
            if "beam_select" in pressed:
                self.ChangeBeam()

            elif "weapon_select" in pressed:
                self.ChangeMissile()

            if "fire" in pressed:
                print "Fire main weapon"
                self.FireMain()

            elif "fire_missile" in pressed:
                self.sec_armed = True
                self.FireSecondary()

        else:
            #Swap style.
            if "beam_select" in pressed:
                if self.cur_type == 0:
                    #Change beam.
                    self.ChangeBeam()
                else:
                    self.ChangeMissile()

            elif "weapon_select" in pressed:
                #Change between beam and missile.
                self.cur_type = (self.cur_type + 1) % 2

            if "fire" in pressed:
                if self.cur_type == 0:
                    self.FireMain()
                else:
                    self.sec_armed = True
                    self.FireSecondary()

            elif "fire_missile" in pressed:
                if self.cur_type == 0:
                    self.sec_armed = True
                    self.FireSecondary()
                else:
                    self.FireMain()

        if self.checkslopes:
            if not self.CheckSlopes():
                self.CheckObstructions()
        else:
            self.CheckObstructions()



        if self.cur_state not in self.morph_states:
            self.vx = vecmath.clamp(self.vx, -self.max_vx, self.max_vx)
            self.vy = vecmath.clamp(self.vy, -100, self.max_vy) #-100 so WIP can sleep.

        #HACK for getting into morph ball tunnels. surprisingly, it works!
        #optimisation:
        #should only check for whether it'll pass through a tile position...
        tunnelled = False
        temp = -1
        if self.cur_state in self.morph_states:
            if self.right_wall and "right" in position:
                temp = self.y
                self.y = int(self.y)
                for y in range(3):
                    self.y += 1
                    if not self.CheckWall(Dir.RIGHT):
                        self.y+=1
                        if self.CheckWall(Dir.RIGHT): #ensure the passage is *just* big enough
                            self.x+=2
                            tunnelled = True
                        self.y -= 1
                        break
            elif self.left_wall and "left" in position:
                temp = self.y
                self.y = int(self.y)
                for i in range(3):
                    self.y += 1
                    if not self.CheckWall(Dir.LEFT):
                        self.y+=1
                        if self.CheckWall(Dir.LEFT): #ensure the passage is *just* big enough
                            self.x-=2
                            tunnelled = True
                        self.y-=1
                        break




        if not tunnelled:
            if temp != -1:
                self.y = temp
            self.x += self.vx
            self.y += self.vy

        if self.platform is not None:
            if self.platform in self.detect_collision():
                self.x += self.platform.vx
                self.y += self.platform.vy
            else:
                self.platform = None


        self.sprite.x = int(self.x)
        self.sprite.y = int(self.y)
        self.state__()
        self.animation()