コード例 #1
0
ファイル: TimedDeath.py プロジェクト: wei0831/theLastRose
class TimedDeath:
    LifeTime = Property.Float(1.0)
    Active = Property.Bool(False)
    DestroyAtTheEnd = Property.Bool(False)

    def Initialize(self, initializer):
        self.Callback = None
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

    def Activate(self, callback=0):
        self.Active = True
        if callback != 0:
            self.SetCallBack(callback)

    def SetCallback(self, callback):
        self.Callback = callback

    def OnLogicUpdate(self, UpdateEvent):
        if not self.Active:
            pass
        else:
            self.LifeTime -= UpdateEvent.Dt
            if self.LifeTime <= 0:
                if self.Callback:
                    self.Callback(self)
                if self.DestroyAtTheEnd:
                    self.Owner.Destroy()
コード例 #2
0
class PlayerController:
    JumpStrength = Property.Float(2.0)
    MoveForce = Property.Float(3.0)
    JumpActive = Property.Bool(True)

    Active = Property.Bool(True)

    def Initialize(self, initializer):
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

    def OnLogicUpdate(self, UpdateEvent):
        if (not self.Active): return

        force = Vec3(0, 0, 0)
        impulse = Vec3(0, 0, 0)
        if Zero.Keyboard.KeyIsDown(Zero.Keys.D):
            force += Vec3(1, 0, 0)
        if Zero.Keyboard.KeyIsDown(Zero.Keys.A):
            force -= Vec3(1, 0, 0)
        if Zero.Keyboard.KeyIsDown(Zero.Keys.W):
            impulse += Vec3(0, 1, 0)
        if Zero.Keyboard.KeyIsDown(Zero.Keys.S):
            impulse += Vec3(0, -1, 0)

        self.Owner.RigidBody.ApplyLinearVelocity(force * self.MoveForce)
        self.Owner.RigidBody.ApplyLinearVelocity(impulse * self.JumpStrength)
コード例 #3
0
class CanBounce:
    Active = Property.Bool(True)
    ForcedVx = Property.Float(0)
    ForcedVy = Property.Float(0)
    UpdateBasedOnSprite = Property.Bool(False)

    def Initialize(self, initializer):
        self.InitialStrength = math.sqrt(self.ForcedVx**2 + self.ForcedVy**2)
        Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollision)

    def OnCollision(self, CollisionEvent):
        if self.Active:
            if self.UpdateBasedOnSprite:
                if (self.Owner.Sprite.FlipX == True and
                        self.ForcedVx > 0) or (self.Owner.Sprite.FlipX == False
                                               and self.ForcedVx < 0):
                    self.ForcedVx = -self.ForcedVx

            if CollisionEvent.OtherObject.Bounceable:
                impulseEvent = Zero.ScriptEvent()
                impulseEvent.ForcedVx = self.ForcedVx
                impulseEvent.ForcedVy = self.ForcedVy
                CollisionEvent.OtherObject.DispatchEvent(
                    "BounceEvent", impulseEvent)

    def ToDirection(self, normal):

        self.ForcedVx = self.InitialStrength * normal.x
        self.ForcedVy = self.InitialStrength * normal.y
コード例 #4
0
 def DefineProperties(self):
     self.ObjectX = Property.Float()
     self.FirstCameraSize = Property.Float()
     self.FirstScale = Property.Float()
     self.FirstPosition = Property.Float()
     self.Start = Property.Bool(True)
     self.Start2 = Property.Bool(True)
コード例 #5
0
class PlayerController:
    JumpStrength = Property.Float(2.0)
    MoveForce = Property.Float(3.0)
    JumpActive = Property.Bool(True)

    Active = Property.Bool(True)

    def Initialize(self, initializer):
        self.Space.SoundSpace.PlayCue("RainCue")
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

    def OnLogicUpdate(self, UpdateEvent):
        if (not self.Active): return
        self.Owner.Sprite.AnimationSpeed = abs(self.Owner.RigidBody.Velocity.x)

        force = Vec3(0, 0, 0)
        impulse = Vec3(0, 0, 0)
        if Zero.Keyboard.KeyIsDown(Zero.Keys.D):
            self.Owner.Sprite.FlipX = False
            force += Vec3(1, 0, 0)
        if Zero.Keyboard.KeyIsDown(Zero.Keys.A):
            self.Owner.Sprite.FlipX = True
            force -= Vec3(1, 0, 0)
        if Zero.Keyboard.KeyIsDown(Zero.Keys.W):
            impulse += Vec3(0, 1, 0)

        self.Owner.RigidBody.ApplyLinearVelocity(force * self.MoveForce)
        self.Owner.RigidBody.ApplyLinearVelocity(impulse * self.JumpStrength)
コード例 #6
0
class Hookable:
    Active = Property.Bool(False)
    NonActivatable = Property.Bool(False)
    def Initialize(self, initializer):
        if self.NonActivatable:
            self.Active = False
    
        
    def Hook(self, target):
        
        if self.Owner.TimedDeath:
            self.Owner.TimedDeath.Active = False
        if self.Active:
            if self.Owner.Teleportable:
                self.Owner.Teleportable.Active = False
            self.Owner.AttachToRelative(target)
            self.Owner.RigidBody.Static = True
            if not self.Owner.CanCollect:
                self.Owner.AddComponentByName("CanCollect")
        
    def UnHook(self):
        self.Owner.RigidBody.Static = False
        self.Owner.DetachRelative()
        if self.Owner.Teleportable:
            self.Owner.Teleportable.Active = True
        if self.Owner.TimedDeath:
            self.Owner.TimedDeath.Active = True
        if self.Owner.CanCollect:
            self.Owner.RemoveComponentByName("CanCollect")
コード例 #7
0
ファイル: CanTeleport.py プロジェクト: wei0831/theLastRose
class CanTeleport:
    Active = Property.Bool(True)
    SpriteDependentOffset = Property.Bool(False)
    Offset = Property.Float(3.5)
    
    def Initialize(self, initializer):
        pass
        
    def Teleport(self, target):
        if self.Active:
            canberooted = self.Owner.FindRoot().CanBeRooted
            if canberooted:
                if not self.SpriteDependentOffset:
                    target.Transform.Translation += canberooted.GetNormal() * self.Offset
                else:
                    for child in self.Owner.Parent.Hierarchy.Children:
                        if child.Name == "surfroot":
                            break
                    target.Transform.WorldTranslation = child.Transform.WorldTranslation + canberooted.GetNormal()*.1 + Vec3(0,0.2,0)
                if target.RigidBody:
                    target.RigidBody.ApplyLinearVelocity(canberooted.GetNormal()*10)
                    if not target.RigidBody.RotationLocked:
                        target.RigidBody.ApplyAngularVelocity(Vec3(0,0,10))
                    
            else:
                target.Transform.Translation += Vec3(0,self.Offset,0)
コード例 #8
0
ファイル: HealthStatus.py プロジェクト: wei0831/theLastRose
class HealthStatus:
    MaxHealth = Property.Float(100.0)
    RegenRate = Property.Float(0)
    Updatable = Property.Bool(True)
    UseVisualCue = Property.Bool(False)

    def Initialize(self, initializer):
        self.health = self.MaxHealth
        self.isdead = False
        self.init_regen = self.RegenRate
        if self.UseVisualCue:
            self.healthparticle = self.Space.CreateAtPosition(
                "HealthParticle", self.Owner.Transform.WorldTranslation)
            self.healthparticle.AttachToRelative(self.Owner)
            self.healthparticle.SphericalParticleEmitter.Active = False
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

    def AddHealth(self, health):

        if self.Updatable:
            if not self.isdead:
                self.health += health

                if health < 0 and self.UseVisualCue:
                    self.healthparticle.SphericalParticleEmitter.Active = True
                    self.healthparticle.SphericalParticleEmitter.ResetCount()

                if self.health > self.MaxHealth:
                    self.health = self.MaxHealth

                elif self.health < 0:
                    self.isdead = True
                    if self.Owner.CanFancyDie:
                        self.Owner.CanFancyDie.Die()
                    self.health = 0

    def GetHealth(self):
        return self.health

    def IsDead(self):
        return self.isdead

    def ResetRegen(self):
        self.RegenRate = self.init_regen

    def RegenHealth(self, regen_rate):
        self.RegenRate = regen_rate

    def ResetHealth(self):
        self.health = self.MaxHealth
        self.isdead = False

    def Reset(self):
        self.ResetHealth()
        self.ResetRegen()

    def OnLogicUpdate(self, UpdateEvent):
        if self.RegenRate != 0 and self.Updatable:
            self.AddHealth(UpdateEvent.Dt * self.RegenRate)
コード例 #9
0
    def DefineProperties(self):
        self.Start = Property.Bool(True)

        self.FireY = Property.Float(0)

        self.Speed = Property.Float(200)

        self.HasCollided = Property.Bool(False)
コード例 #10
0
    def DefineProperties(self):
        self.MaxHealth = Property.Float(50)
        self.CurrentHealth = Property.Float(50)
        self.Start = Property.Bool(True)
        self.CanExplode = Property.Bool(False)
        self.CanBlow = Property.Bool(True)

        self.CanPlaySound = Property.Bool(True)
コード例 #11
0
class AIMovementSentry:

    Speed = Property.Float(1.0)
    InitialDirection = Property.Vector3(Vec3(1, 0, 0))
    Active = Property.Bool(True)
    RandomStop = Property.Bool(True)
    RandomFlip = Property.Bool(True)

    def Initialize(self, initializer):
        self.Direction = self.InitialDirection
        self.resetcounter = 0
        self.SpeedMultiplier = 1
        self.target_multiplier = 1
        self.stopcounter = 0

        if not self.Owner.AIMovementInterface:
            self.Owner.AddComponentByName("AIMovementInterface")
            self.Owner.AIMovementInterface.Set(self)

        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)
        Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollision)

    def OnLogicUpdate(self, UpdateEvent):
        if self.Active:
            self.resetcounter -= 1
            if self.resetcounter == 0:
                self.SpeedMultiplier = 1

            self.stopcounter -= 1

            self.SpeedMultiplier = self.SpeedMultiplier * .99 + 1 * self.target_multiplier * 0.01

            self.Owner.Sprite.FlipX = self.Direction.x < 0
            self.Owner.Transform.Translation += self.Direction * self.Speed * self.SpeedMultiplier

            if self.RandomStop and self.stopcounter <= 0:
                self.stopcounter = random.random() * 200
                self.target_multiplier = random.random() * 2

            if self.RandomFlip and random.random() < 0.0001:
                self.Direction *= -1

    def OnCollision(self, CollisionEvent):
        if CollisionEvent.OtherObject.IsSentry:
            if abs(CollisionEvent.FirstPoint.WorldNormalTowardsOther.x) > 0.95:
                direction = CollisionEvent.OtherObject.IsSentry.SentryDirection

                if direction.x == 0 and direction.y == 0:
                    self.Direction = Vec3(
                        1, 0, 0
                    ) if CollisionEvent.FirstPoint.WorldNormalTowardsOther.x < 0 else Vec3(
                        -1, 0, 0)
                else:
                    self.Direction = direction

    def SlowDownBy(self, SlowDownRatio, TimeSteps):
        self.resetcounter = TimeSteps
        self.SpeedMultiplier = SlowDownRatio
コード例 #12
0
ファイル: FadeAnim.py プロジェクト: wei0831/theLastRose
class FadeAnim:
    FadingDuration = Property.Float(1)
    Active = Property.Bool(True)
    FadeDirection = Property.Int(-1)
    Repeat = Property.Bool(False)
        
    def Initialize(self, initializer):
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

        self.target = self.Owner.Sprite or self.Owner.SpriteText
        self.targetslist = tuple(item for item in (self.Owner.Sprite, self.Owner.SpriteText) if item)
                              
    def ApplyAlpha(self, target, alpha):        
        tc = target.Color
        target.Color = Vec4(tc.x, tc.y, tc.z, alpha)
        
            
    def CheckAlphaBound(self, alpha):
        # if alpha out of bounds
        if alpha < 0:
            alpha = 0
            if not self.Repeat:
                self.Active = False
            else:
                self.FadeDirection = 1
        elif alpha > 1:
            alpha = 1
            if not self.Repeat:
                self.Active = False
            else:
                self.FadeDirection = -1
        return alpha
        
    def OnLogicUpdate(self, UpdateEvent):
        if self.Active:    
            # calculate new alpha
            c = self.target.Color 
            alpha = c.a + self.FadeDirection * (1. / self.FadingDuration) * UpdateEvent.Dt             
            alpha = self.CheckAlphaBound(alpha)
                        
            for target in self.targetslist:
                self.ApplyAlpha(target, alpha)
            
            
    def Off(self):
        self.Active = False
        
    def On(self):
        self.Active = True
        
    def Toggle(self):
        self.Active = not self.Active
        
    def ResetAlpha(self, alpha=1):
        
        for target in self.targetslist:
            self.ApplyAlpha(target, 1)
コード例 #13
0
    def DefineProperties(self):
        self.Timer = Property.Float()
        self.Delay = Property.Float(3)
        self.CollisionGroupName = Property.String()
        self.CloudSpeed = Property.Float(10)

        self.Start = Property.Bool(True)
        self.Chance = Property.Int(0)
        self.IsLeft = Property.Bool(True)
コード例 #14
0
ファイル: MT.py プロジェクト: tung362/MtRainierHeroSquad
 def DefineProperties(self):
     self.Timer = Property.Float()
     self.Delay = Property.Float(1)
     self.CanMove = Property.Bool(True)
     self.X = Property.Float(0)
     self.Y = Property.Float(0)
     self.Z = Property.Float(0)
     self.Name = Property.String()
     
     self.CanPlaySound = Property.Bool(True)
コード例 #15
0
    def DefineProperties(self):
        self.MaxHealth = Property.Float(100)
        self.CurrentHealth = Property.Float(100)

        self.Start = Property.Bool(True)

        self.DeathSpawn = Property.Bool(False)

        self.CanTick = Property.Bool(True)
        self.LayDead = Property.Bool(False)
コード例 #16
0
    def DefineProperties(self):
        self.IsRight = Property.Bool(False)
        self.IsLeft = Property.Bool(False)
        self.LeftRight = Property.Bool(False)

        self.Start = Property.Bool(True)

        self.BodyX = Property.Float(0)
        self.BodyX = Property.Float(0)
        self.BodyZ = Property.Float(0)
コード例 #17
0
ファイル: Barrel.py プロジェクト: tung362/MtRainierHeroSquad
    def DefineProperties(self):
        self.MaxHealth = Property.Float(450)
        self.CurrentHealth = Property.Float(450)
        self.RandomTexture = Property.Int(0)
        self.Start = Property.Bool(True)
        self.TextureNumber = Property.Int(0)

        self.Switch1 = Property.Bool(True)
        self.Switch2 = Property.Bool(True)
        self.Switch3 = Property.Bool(True)
        self.Switch4 = Property.Bool(True)
コード例 #18
0
class MusicBox:

    CanNormal = Property.Bool(True)
    CanSedrickPlayOnce = Property.Bool(True)
    CanPlaySedrick1 = Property.Bool(True)
    CanPlaySedrick2 = Property.Bool(True)

    def DefineProperties(self):
        pass

    def Initialize(self, initializer):
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

    def OnLogicUpdate(self, UpdateEvent):
        Sedrick = self.Space.FindObjectByName("Sedrick")
        Sedrick1 = self.Space.FindObjectByName("Sedrick1")
        Sedrick2 = self.Space.FindObjectByName("Sedrick2")
        LevelSong = self.Space.FindObjectByName("LevelSong")

        if (Sedrick):
            if (Zero.Mouse.IsButtonDown(Zero.MouseButtons.Left)
                    and self.CanPlaySedrick1 is True):
                #print("Sedrick1")
                #Sedrick2.SoundEmitter.Stop()
                Sedrick2.SoundEmitter.Volume = 0
                LevelSong.SoundEmitter.Stop()
                Sedrick1.SoundEmitter.Play()
                self.CanPlaySedrick2 = True
                self.CanNormal = True
                self.CanPlaySedrick1 = False
            else:
                if (self.CanPlaySedrick2 is True and
                        not Zero.Mouse.IsButtonDown(Zero.MouseButtons.Left)):
                    #print("Sedrick2")
                    Sedrick1.SoundEmitter.Stop()
                    LevelSong.SoundEmitter.Stop()
                    Sedrick2.SoundEmitter.Volume = 0.2
                    if (self.CanSedrickPlayOnce is True):
                        Sedrick2.SoundEmitter.Play()
                        self.CanSedrickPlayOnce = False
                    self.CanPlaySedrick1 = True
                    self.CanNormal = True
                    self.CanPlaySedrick2 = False
        else:

            if (self.CanNormal is True):
                #print("Normal")
                Sedrick1.SoundEmitter.Stop()
                Sedrick2.SoundEmitter.Stop()
                LevelSong.SoundEmitter.Play()
                self.CanPlaySedrick1 = True
                self.CanPlaySedrick2 = True
                self.CanNormal = False
コード例 #19
0
    def DefineProperties(self):
        self.CanShoot = Property.Bool(False)

        self.RayCast1 = Property.Bool(False)
        self.RayCast2 = Property.Bool(False)
        self.RayCast3 = Property.Bool(False)
        self.RayCast4 = Property.Bool(False)
        self.RayCast5 = Property.Bool(False)
        self.RayCast6 = Property.Bool(False)
        self.RayCast7 = Property.Bool(False)
        self.RayCast8 = Property.Bool(False)
        self.RayCast9 = Property.Bool(False)
コード例 #20
0
    def DefineProperties(self):
        self.Start = Property.Bool(True)

        self.FireY = Property.Float(0)

        self.HasCollided = Property.Bool(False)

        self.Speed = Property.Float(20)

        self.CanExplode = Property.Bool(False)
        self.CanBlow = Property.Bool(True)

        self.CanPlaySound = Property.Bool(True)
コード例 #21
0
ファイル: RainGenerator.py プロジェクト: wei0831/theLastRose
class RainGenerator:
    CoolDown = Property.Float(0.25)
    Timer = 0
    Amount = Property.Int(10)
    SpeedVariation = Property.Float(-10)
    Activatable = Property.Bool(True)
    RainArchetype = Property.Archetype("Rain")
    RainShader = Property.Color(Color.LightBlue)
    ResourceSaver = Property.Bool(True)

    def Initialize(self, initializer):
        self.Active = True
        self.Player = self.Space.FindObjectByName("Player")
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

        self.LowerLeft = self.Owner.Transform.WorldTranslation + Vec3(
            -self.Owner.Transform.WorldScale.x / 2.0,
            -self.Owner.Transform.WorldScale.y / 2.0, 0)
        self.UpperRight = self.Owner.Transform.WorldTranslation + Vec3(
            self.Owner.Transform.WorldScale.x / 2.0,
            self.Owner.Transform.WorldScale.y / 2.0, 0)

    def OnLogicUpdate(self, UpdateEvent):
        if self.Activatable:
            if self.ResourceSaver:
                self.Active = abs(self.Owner.Transform.Translation.x -
                                  self.Player.Transform.Translation.x) < 10
            else:
                self.Active = True

            if self.Active:
                self.Timer += UpdateEvent.Dt

                if self.Timer > self.CoolDown:
                    self.Timer = 0
                    self.Rain()

    def Rain(self):
        tuple(self.GenerateRain() for _ in range(self.Amount))

    def GenerateRain(self):
        creatAt = Vec3(random.uniform(self.LowerLeft.x, self.UpperRight.x),
                       random.uniform(self.LowerLeft.y, self.UpperRight.y), 0)
        created = self.RainArchetype if self.RainArchetype else "Rain"
        obj = self.Space.CreateAtPosition(created, creatAt)
        obj.RigidBody.Velocity = Vec3(0,
                                      random.randint(self.SpeedVariation,
                                                     0), 0)
        for child in obj.Hierarchy.Children:
            child.Sprite.Color = self.RainShader
            child.Sprite.Color *= VectorMath.Vec4(1, 1, 1, 0.2)
コード例 #22
0
class ParticleFadeAnim:
    Active = Property.Bool(True)
    DecaySpeed = Property.Float(0.01)
    DestroyAtEnd = Property.Bool(True)

    def Initialize(self, initializer):
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

    def OnLogicUpdate(self, UpdateEvent):
        if self.Active:
            self.Owner.SpriteParticleSystem.Tint *= VectorMath.Vec4(
                1, 1, 1, 1 - self.DecaySpeed)
            if self.Owner.SpriteParticleSystem.Tint.a < 0.01:
                self.Owner.Destroy()
コード例 #23
0
ファイル: CanBounce.py プロジェクト: wei0831/theLastRose
class CanBounce:
    Active = Property.Bool(True)
    ForcedVx = Property.Float(0)
    ForcedVy = Property.Float(0)
    UpdateBasedOnSprite = Property.Bool(False)
    TopModify = Property.Bool(False)
    def Initialize(self, initializer):
        self.InitialStrength = math.sqrt(self.ForcedVx**2 + self.ForcedVy**2)
        Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollision)
        
    def OnCollision(self, CollisionEvent):
        if self.Active and CollisionEvent.OtherObject.Bounceable:
            modifier = -1 if self.UpdateBasedOnSprite and self.Owner.Sprite.FlipX else 1
            
            
            adder = 0
            if self.TopModify:
                boxloc = self.Owner.Transform.Translation + self.Owner.BoxCollider.Offset
                
                boxdims = self.Owner.BoxCollider.Size
                angle = self.Owner.Transform.EulerAngles.z
                normal = VectorMath.Vec3.RotateVector(VectorMath.Vec3(0,1,0), VectorMath.Vec3(0,0,1), angle)
                
                shifter = (boxloc + boxdims * .5 * normal) - CollisionEvent.FirstPoint.WorldPoint
                
                adder = shifter.y if shifter.y > 0 else 0
                if self.Owner.Name == "Mushroom":
                    print(adder)
                #rigid = CollisionEvent.OtherObject.RigidBody
                
                #def Modifying():
                #    rigid.Velocity += VectorMath.Vec3(0, shifter.y,0)
                    
                #seq = Action.Sequence(CollisionEvent.OtherObject.Actions)                
                #Action.Call(seq, Modifying)
                #Action.Delay(seq, 0.1)
                
            if CollisionEvent.OtherObject.Bounceable:
                impulseEvent = Zero.ScriptEvent()
                impulseEvent.ForcedVx = self.ForcedVx * modifier     
                impulseEvent.ForcedVy = self.ForcedVy + adder 
                CollisionEvent.OtherObject.DispatchEvent("BounceEvent", impulseEvent)
                
            
    def ToDirection(self, normal):
        
        self.ForcedVx = self.InitialStrength * normal.x
        self.ForcedVy = self.InitialStrength * normal.y
コード例 #24
0
class RainGenerator:
    Active = Property.Bool(True)
    
    CoolDown = Property.Float(0.25)
    AmountEachTime = Property.Int(10)
    Timer = 0

    Speed_DirX_Min = Property.Float(0)
    Speed_DirX_Max = Property.Float(2)
    Speed_DirY_Min = Property.Float(-2)
    Speed_DirY_Max = Property.Float(2)
    
    def Initialize(self, initializer):
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)
        
        self.LowerLeft = self.Owner.Transform.WorldTranslation + Vec3(-self.Owner.Transform.WorldScale.x/2.0, -self.Owner.Transform.WorldScale.y/2.0, 0)
        self.UpperRight = self.Owner.Transform.WorldTranslation + Vec3(self.Owner.Transform.WorldScale.x/2.0, self.Owner.Transform.WorldScale.y/2.0, 0)
        
    def OnLogicUpdate(self, UpdateEvent):
        if not self.Active: return
        self.Timer += UpdateEvent.Dt
        
        if self.Timer > self.CoolDown:
            self.Timer = 0
            self.Rain()

        
    def Rain(self):
        for i in range(self.AmountEachTime):
            self.GenerateRain()
                
    def GenerateRain(self):
        creatAt = Vec3(random.uniform(self.LowerLeft.x, self.UpperRight.x), random.uniform(self.LowerLeft.y, self.UpperRight.y), 0)
        obj = self.Space.CreateAtPosition("Rain", creatAt)
        obj.RigidBody.Velocity = Vec3(random.randint(self.Speed_DirX_Min, self.Speed_DirX_Max), random.randint(self.Speed_DirY_Min, self.Speed_DirY_Max), 0)
コード例 #25
0
class Bounceable:
    Decay = Property.Float(1)
    Active = Property.Bool(True)

    def Initialize(self, initializer):
        Zero.Connect(self.Owner, "BounceEvent", self.OnBounce)

    def OnBounce(self, BounceEvent):
        if self.Active:

            if self.Owner.PlayerController:
                self.Owner.PlayerController.TriggerBounced()
            Vx = BounceEvent.ForcedVx
            Vy = BounceEvent.ForcedVy

            self_v = self.Owner.RigidBody.Velocity
            self_v.x = self_v.x if Vx == 0 else Vx
            self_v.y = self_v.y if Vy == 0 else Vy
            self.Owner.RigidBody.Velocity = self_v * self.Decay

            if self.Owner.PlayerController and abs(Vx) > (Vy) * .9:
                self.Owner.PlayerController.LockHorizontal()

                seq = Action.Sequence(self.Owner.Actions)
                Action.Delay(seq, .35)
                Action.Call(seq, self.Owner.PlayerController.UnlockHorizontal)
            print("event received", self.Owner.Name, Vx, Vy,
                  self.Owner.RigidBody.Velocity)
コード例 #26
0
ファイル: BurnAnim.py プロジェクト: wei0831/theLastRose
class BurnAnim:

    Active = Property.Bool(True)
    Alpha = Property.Float(0.26)

    def Initialize(self, initializer):
        self.burnanim = None
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)

    def OnLogicUpdate(self, UpdateEvent):
        if not self.Active:
            if self.burnanim:
                self.burnanim.Destroy()
        else:
            if not self.burnanim:
                self.burnanim = self.Space.CreateAtPosition(
                    "FireParticle", self.Owner.Transform.Translation)
                t = self.burnanim.SpriteParticleSystem.Tint
                t.a = self.Alpha
                self.burnanim.SpriteParticleSystem.Tint = t

                self.burnanim.Transform.Scale = self.Owner.Transform.Scale

                self.burnanim.AttachToRelative(self.Owner)

    def Destroyed(self):
        if self.burnanim:
            self.burnanim.Destroy()
コード例 #27
0
ファイル: KeyHoleDoor.py プロジェクト: wei0831/theLastRose
class KeyHoleDoor:
    KeyHole = Property.String("")
    DoorTable = Property.ResourceTable()
    NextLevel = Property.Level()
    Teleport = Property.Cog()
    SimpleTeleport = Property.Bool(False)

    def Initialize(self, initializer):
        Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollision)
        self.TryKeyEvent = Zero.ScriptEvent()
        self.TryKeyEvent.Callback = lambda: self.OpenDoor()

        self.TryKeyEvent.KeyHole = self.KeyHole
        self.Opened = True if not self.KeyHole else False

        self.observer_list = []

    def OnCollision(self, CollisionEvent):
        CollisionEvent.OtherObject.DispatchEvent("TryKeyEvent",
                                                 self.TryKeyEvent)

    def TeleportThis(self, target):
        if self.NextLevel.Name != "DefaultLevel":
            self.Space.FindObjectByName("Camera").CameraFunction.SetCameraFade(
                Vec4(1, 1, 1, 0), Vec4(1, 1, 1, 1), .03, 0)
            sequence = Action.Sequence(self.Owner.Actions)

            ls = self.Space.FindObjectByName("LevelSettings").LevelStart
            if ls:
                hm = ls.HUDManager
                hm.CacheSkills()

            Action.Delay(sequence, 1.5)
            Action.Call(sequence, lambda: self.Space.LoadLevel(self.NextLevel))

        elif self.Teleport:
            camera = self.Space.FindObjectByName("Camera")

            dest = self.Teleport.Transform.Translation
            ct = camera.Transform.Translation
            pt = target.Transform.Translation

            #camera.CameraFunction.SetCameraFade(Vec4(0,0,0,1),Vec4(0,0,0,0),.03,0)
            #camera.Transform.Translation = VectorMath.Vec3(dest.x, dest.y,ct.z)
            target.Transform.Translation = VectorMath.Vec3(
                dest.x, dest.y, pt.z)

    def RegisterObserver(self, observer):
        self.observer_list.append(observer)

    def OpenDoor(self):
        self.Owner.Sprite.SpriteSource = self.DoorTable.FindResource("Black")
        self.Opened = True
        for callback in self.observer_list:
            callback()

        self.observer_list = []

    def IsOpened(self):
        return self.Opened
コード例 #28
0
class DestroyPlayAnim:
    InvalidateCollider = Property.Bool(True)
    def Initialize(self, initializer):
        self.Activated = False
        if not self.Owner.DestroyInterface:
            self.Owner.AddComponentByName("DestroyInterface")
    def Destroy(self):
        if not self.Activated:
            if self.InvalidateCollider:
                self.Owner.Collider.Offset += VectorMath.Vec3(0, 0, 999)
            
            self.Activated = True
            
            if not self.Owner.ActionList:
                self.Owner.AddComponentByName("ActionList")
            self.Owner.ActionList.EmptyAll()
            self.Owner.GrowthAnim.SetReverse(True)
            self.Owner.GrowthAnim.Active = True
                
            def waitmovieend():
                return not self.Owner.GrowthAnim.Active
            def destroy():
                self.Owner.Destroy()
            
            self.Owner.ActionList.AddCallback(callback=waitmovieend, 
                                              has_self=False, 
                                              blocking=True, 
                                              countdown=None)
                                              
            self.Owner.ActionList.AddCallback(callback=destroy, 
                                              has_self=False, 
                                              blocking=True, 
                                              countdown=0)
    def IsActivated(self):
        return self.Activated
コード例 #29
0
ファイル: CanBeRooted.py プロジェクト: wei0831/theLastRose
class CanBeRooted:
    ShouldRoot = Property.Bool(True)

    def Initialize(self, initializer):
        Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollision)
        self.normal = VectorMath.Vec3(0, 0, 0)

    def OnCollision(self, CollisionEvent):
        if CollisionEvent.OtherObject.GrowableGround or CollisionEvent.OtherObject.PlantAnnihilator:

            self.normal = -CollisionEvent.FirstPoint.WorldNormalTowardsOther
            self.normal.z = 0

            self.Owner.Transform.Translation += self.normal * CollisionEvent.FirstPoint.Penetration
            if self.ShouldRoot:
                #self.Owner.Transform.RotateByAngles(VectorMath.Vec3(0,0,self.normal.angleZ()-math.pi/2))
                #CollisionEvent.OtherObject.Transform.Rotation
                self.Owner.RigidBody.Kinematic = True

            #if self.Owner.CanBounce:
            #self.Owner.CanBounce.ToDirection(self.normal)

            Zero.Disconnect(self.Owner, Events.CollisionStarted, self)

    def GetNormal(self):
        return self.normal
コード例 #30
0
class AIMovementPacing:
    Duration = Property.Float(1.0)
    Speed = Property.Float(1.0)
    Direction = Property.Int(+1)
    Active = Property.Bool(+1)
    SpeedMultiplier = Property.Float(1.0)
    
    def Initialize(self, initializer):
        self.accum_dt = 0
        self.init_direction = self.Direction
        self.resetcounter = 0
        Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate)
        
    def OnLogicUpdate(self, UpdateEvent):
        if self.Active:
            if self.resetcounter > 0:
                self.resetcounter -= 1
            else:
                self.SpeedMultiplier = 1
                
            self.Owner.Sprite.FlipX = self.Direction > 0
            self.Owner.Transform.Translation += Vec3(self.Direction,0,0) * self.Speed * self.SpeedMultiplier

            self.accum_dt += UpdateEvent.Dt * self.Direction * self.init_direction
            if self.accum_dt > self.Duration:
                self.Direction = -1
            elif self.accum_dt < 0:
                self.Direction = +1
            
    def SlowDownBy(self, SlowDownRatio, TimeSteps):
        self.resetcounter = TimeSteps
        self.SpeedMultiplier = SlowDownRatio