Source Code Ludum Dare 39


class Barrel : ZilchComponent
{
    [Property]
    var BullitArchetype : Archetype = Archetype.Bad;
    
    [Property]
    var Shoot : Real = 2.0;
    function Initialize(init : CogInitializer)
    {
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        if (this.Shoot > 0)
        {
            this.Shoot = this.Shoot - event.Dt;
        }
        else if (this.Shoot <= 0)
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("shoot"));
            this.Space.CreateAtPosition(this.BullitArchetype, this.Owner.Transform.WorldTranslation);
            this.Shoot = 1.5;
        }
    }
}

class Bullit : ZilchComponent
{
    [Property]
    var Speed : Real = 7.0;    

    [Property]
    var ShootingDistance : Real = 5.0;
    
    var Player : Cog = null;
    
    function Initialize(init : CogInitializer)
    {
        this.Player = this.Space.FindObjectByName("Player");
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        if(this.Player != null)
        {
            var vec = Math.Normalize(this.Player.Transform.Translation - this.Owner.Transform.Translation);
             var dist = Math.Distance(this.Player.Transform.Translation, this.Owner.Transform.Translation);
             
             this.Owner.RigidBody.Velocity = this.Speed * vec;
        }
    }
    
    function OnCollisionStarted(event : CollisionEvent)
    {
        var otherObject = event.OtherObject;
        
        if (otherObject.Name == "Ground" || otherObject.Name == "Player")
        {
            this.Owner.Destroy();
        }
        
    }
}


class CameraLogic : ZilchComponent
{
    [Property]
    var TargetObjectCogPath : CogPath = null;

    var TargetObject : Cog = null;

    function Initialize(init : CogInitializer)
    {
        this.TargetObject = this.TargetObjectCogPath.Cog;
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        // create a new variable to hold the player's position
        var newCameraPos = this.TargetObject.Transform.Translation;
        // save the camera's z value
        newCameraPos.Z = this.Owner.Transform.Translation.Z;
        // set the camera's new position to newCameraPos
        this.Owner.Transform.LocalTranslation = newCameraPos - Real3(0,0,0);
    }
}


class EnemyMovement : ZilchComponent
{
    [Dependency]
    var Transform : Transform;
    
    //Player speed
    var Speed : Real = 0.1;
    
    //Player Jump
    var MaxJumpHeight : Real = 0.75;
    
    var LockX : Real;
    function Initialize(init : CogInitializer)
    {
        this.LockX = this.Owner.Transform.Translation.X;
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        if (this.Owner.Transform.Translation.X != this.LockX)
        {
            this.Owner.Transform.Translation.X = this.LockX;
            this.Owner.Transform.Translation = Real3(this.LockX, this.Owner.Transform.Translation.Y, this.Owner.Transform.Translation.Z);
            //Console.WriteLine(this.LockX);
        }
        //Jump
        if (this.MaxJumpHeight > 0)
        {
            this.Owner.Transform.Translation = this.Owner.Transform.Translation + Real3(0,this.Speed,0);
            this.MaxJumpHeight = this.MaxJumpHeight - event.Dt;
            if (this.MaxJumpHeight >= 0.25)
            this.Owner.Sprite.Color = Real4(this.MaxJumpHeight,this.MaxJumpHeight -0.25,this.MaxJumpHeight - 0.25,1);
        }
        else if (this.MaxJumpHeight <= 0)
        {
            //Console.WriteLine("BAM!");
            //this.MaxJumpHeight = this.MaxJumpHeight + 1.5;
        }
    }
    
    function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Ground")
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("Enemy"));
            this.MaxJumpHeight = 0.75;
            this.Owner.Sprite.Color = Real4(this.MaxJumpHeight - 0.25,this.MaxJumpHeight -0.25,this.MaxJumpHeight,1);
        }
        
        if (event.OtherObject.Name == "Player")
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("Enemy"));
            this.MaxJumpHeight = 0.75;
            this.Owner.Sprite.Color = Real4(this.MaxJumpHeight - 0.25,this.MaxJumpHeight -0.25,this.MaxJumpHeight,1);
        }
    }
}

class InfinityEffect : ZilchComponent
{
    
    var Test : Boolean = true;
    var Timer : Real = 0.5;
    function Initialize(init : CogInitializer)
    {
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        var loc = this.Owner.Transform.Translation;
        /*if (Zero.Keyboard.KeyIsPressed(Keys.Space))
        {
            Console.WriteLine(this.Timer);
        }*/
        
                if(this.Timer >= 0.0)
        {
            
            this.Timer -= event.Dt;

            //Rounds the timer to the second decimal place
            this.Timer = Math.Round(this.Timer, -2);

        }
        else
        {
            var moveSeq = Action.Sequence(this.Owner.Actions);
            if (this.Test == false && this.Timer <= 0)
            {
                this.Timer = this.Timer + 0.5;
                Action.Property(moveSeq, @this.Owner.Transform.Translation,
                Real3(loc.X, loc.Y - 0.2, loc.Z), 0.5, Ease.QuadInOut);
                this.Test = true;
                //Console.WriteLine("Hit!");
            }
            
            if (this.Test == true && this.Timer <= 0)
            {
                this.Test = false;
                this.Timer = this.Timer + 0.5;
                Action.Property(moveSeq, @this.Owner.Transform.Translation,
                Real3(loc.X, loc.Y + 0.2, loc.Z), 0.5, Ease.QuadInOut);
            }
            
        }
    }
}

class LevelVars : ZilchComponent
{
    [Property]
    var PlayerPosition : Real3 = Real3();
}

class LogoScript : ZilchComponent
{
    var StartScreen: Level = Level.Find("MenuLevel");
    var Rock : Boolean = false;
     
      [Property]
    var LogoCrackSprite : SpriteSource = null;
    
    [Property]
    var Timer : Real = 0.0;
    
    function Initialize(init : CogInitializer)
    {
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }
        
    function OnCollisionStarted(event : CollisionEvent)
    {
        var otherObject = event.OtherObject;
        
        if (otherObject.Name == "RockSprite")
        {
            this.Rock = true;
            this.Space.SoundSpace.PlayCue(SoundCue.Find("RockHit"));
            this.Owner.Sprite.SpriteSource = this.LogoCrackSprite;
        }
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        if (Zero.Keyboard.KeyIsPressed(Keys.Space))
        {
            this.Space.LoadLevel(this.StartScreen);
        }
        
        if(this.Timer > 0.0 && this.Rock == true)
        {
            //Subtracts Dt (passage of time each frame) from Timer so that it counts down to 0
            this.Timer -= event.Dt;

            //Rounds the timer to the second decimal place
            this.Timer = Math.Round(this.Timer, -2);
            
        }
        else if (this.Timer == 0.0 && this.Rock == true)
        {
            this.Space.LoadLevel(this.StartScreen);
            //var StartScreen: Level = Level.Find("StartMenu");
        }
        
    }
}

class MenuUI : ZilchComponent
{
    var StartScreen: Level = Level.Find("Level1");
    
    [Property]
    var CreditsPath : CogPath = null;
        var Det : Boolean = false;
        var Exit : Boolean = false;

    function Initialize(init : CogInitializer)
    {
          // Connections to the needed Mouse events (Enter, Exit, Up, Down)
          Zero.Connect(this.Owner, Events.MouseEnter, this.OnMouseEnter);
          Zero.Connect(this.Owner, Events.MouseExit, this.OnMouseExit);
          Zero.Connect(this.Owner, Events.MouseUp, this.OnMouseUp);
          Zero.Connect(this.Owner, Events.MouseDown, this.OnMouseDown);
          Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
    }
    
    function OnLogicUpdate(event : UpdateEvent)
    {
        if (this.Det == false)
        {
            if (this.CreditsPath.Cog != null)
            {
        var moveSeq = Action.Sequence(this.CreditsPath.Cog.Actions);
          Action.Property(moveSeq, @this.CreditsPath.Cog.Transform.Translation,
            Real3(75, -8.5, 0.15), 0.1, Ease.QuadInOut);
            }
            this.Owner.Sprite.Color = Real4(0.3,0.3,0.7,1);
            this.Owner.SpriteText.Color = Real4(0.7,0.7,0.7,1);
        }
        
    }
    
    function OnMouseEnter(event : ViewportMouseEvent)
    {
        this.Det = true;
      this.Owner.Sprite.Color = Real4(0.7,0.3,0.3,1);
      this.Owner.SpriteText.Color = Real4(1,1,1,1);
      this.Space.SoundSpace.PlayCue(SoundCue.Find("Hover"));
    }
    function OnMouseExit(event : ViewportMouseEvent)
    {
        this.Det = false;
      this.Owner.Sprite.Color = Real4(0.3,0.3,0.7,1);
      this.Owner.SpriteText.Color = Real4(0.7,0.7,0.7,1);
    }
     
        function OnMouseDown(event : ViewportMouseEvent)
    {
      
        if (this.Exit == false)
        {
            if (this.Owner.Name == "Play" )
            {
                this.Space.LoadLevel(this.StartScreen);
                this.Space.SoundSpace.PlayCue(SoundCue.Find("Click"));
            }
            
            if (this.Owner.Name == "Credits")
            {
                Console.WriteLine(this.Exit);
                var moveSeq = Action.Sequence(this.CreditsPath.Cog.Actions);
                Action.Property(moveSeq, @this.CreditsPath.Cog.Transform.Translation,
                Real3(8, -8.5, 0.15),1.5, Ease.QuadInOut);
                this.Space.SoundSpace.PlayCue(SoundCue.Find("Click"));
            }
            
        if (this.Owner.Name == "Exit")
        {
                this.GameSession.Quit();
        }
        
        }
    }

    // Responds to the mouse releasing a button
    function OnMouseUp(event : ViewportMouseEvent)
    {
    }
    
        function OnGameRequestQuit(event : GameEvent)
    {
        event.Handled = true;
        //Console.WriteLine("HIT1");
        if (this.Exit)
        {
            //Console.WriteLine("HIT2");
            //this.BlurScreenPath.Cog.Transform.Translation = Real3(-100.0,0.0,0.0);
            this.Exit = false;
        }
        else
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("GotHit"));
            this.Exit = true;
            //this.BlurScreenPath.Cog.Transform.Translation = Real3(0.0,0.0,0.0);
        }
    }

}

class Movement : ZilchComponent
{
    var DebugMode : Boolean = false;
    
    [Dependency]
    var Transform : Transform;
    
    //Player speed
    var Speed : Real = 0.1;
    
    //Player Jump
    var MaxJumpHeight : Real = 1.0;
    
    var HitTimer : Real = 1;
    var PE : Boolean = true;
    var Charge : Boolean = false;
    var Bad : Boolean = false;
    var Ground : Boolean = false;
    
    [Property]
    var DebugPath : CogPath = null;
    
    var Local : Real3;
    
    function Initialize(init : CogInitializer)
    {
        this.Local = this.Owner.Transform.Translation;
        this.Space.LevelSettings.LevelVars.PlayerPosition = this.Owner.Transform.Translation;
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
        Zero.Connect(this.Owner, Events.CollisionEnded, this.OnCollisionEnded);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        /*if (this.MaxJumpHeight >= 1)
        {
            this.Owner.Children.Current.SphericalParticleEmitter.Active = true;
        }
        else
        {
            this.Owner.Children.Current.SphericalParticleEmitter.Active = false;
        }*/
        
        if (Zero.Keyboard.KeyIsDown(Keys.Control) && Zero.Keyboard.KeyIsPressed(Keys.D))
        {
            if (this.DebugMode)
            {
                this.DebugMode = false;
            }
            else if (this.DebugMode == false)
            {
                this.DebugMode = true;
            }
            
            //this.DebugPath.Cog.SpriteText.Visible = this.DebugMode;
            Console.WriteLine(this.DebugMode);
        }
        
        //this.DebugPath.Cog.SpriteText.Text = "Power: `this.MaxJumpHeight`";
        
        if (Zero.Keyboard.KeyIsDown(Keys.D) && this.Bad == false)
        {
            this.Owner.Transform.Translation = this.Owner.Transform.Translation + Real3(this.Speed,0,0);
        }
        else if (Zero.Keyboard.KeyIsDown(Keys.D) && this.Bad)
        {
            this.Owner.Transform.Translation = this.Owner.Transform.Translation - Real3(this.Speed * 15,0,0);
            //Console.WriteLine("Hit");
        }
        
        if (Zero.Keyboard.KeyIsDown(Keys.A) && this.Bad == false)
        {
            this.Owner.Transform.Translation = this.Owner.Transform.Translation - Real3(this.Speed,0,0);
        }
        else if (Zero.Keyboard.KeyIsDown(Keys.A) && this.Bad)
        {
            this.Owner.Transform.Translation = this.Owner.Transform.Translation + Real3(this.Speed * 15,0,0);
            //Console.WriteLine("Hit");
        }
        
        
        if (this.MaxJumpHeight < 0.2466)
        {
            this.Owner.Transform.Translation = this.Local;
            this.MaxJumpHeight = 1;
            this.Owner.Sprite.Color = Real4(this.MaxJumpHeight - 0.25,this.MaxJumpHeight - 0.25,this.MaxJumpHeight,1);
        }
        
        if (this.MaxJumpHeight > 1)
        {
            this.MaxJumpHeight = 1;
        }
        
        if (Zero.Keyboard.KeyIsDown(Keys.Space) && this.Ground && this.MaxJumpHeight > 0.25)
        {
            this.Ground = false;
            this.Space.SoundSpace.PlayCue(SoundCue.Find("Jump"));
        }
        
        //Hit timer
        if (this.HitTimer > 0 && this.Bad)
        {
            this.HitTimer = this.HitTimer - event.Dt;
        }
        else if (this.HitTimer <= 0)
        {
            this.MaxJumpHeight = this.MaxJumpHeight - 0.15;
            this.HitTimer = 1;
            //Console.WriteLine("Hit");
            this.Owner.Sprite.Color = Real4(this.MaxJumpHeight - 0.25,this.MaxJumpHeight -0.25,this.MaxJumpHeight,1);
        }
        
        this.Owner.Children.Current.SpriteParticleSystem.Tint = this.Owner.Sprite.Color;
        
        //Charge up
        if (this.MaxJumpHeight < 1 && this.Charge)
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("Something"));  
            //this.Owner.Transform.Translation = this.Owner.Transform.Translation + Real3(0,this.Speed,0);
            this.MaxJumpHeight = this.MaxJumpHeight + event.Dt / 2.5;
            if (this.MaxJumpHeight < 1)
            this.Owner.Sprite.Color = Real4(this.MaxJumpHeight - 0.25,this.MaxJumpHeight - 0.25,this.MaxJumpHeight,1);
        }
        
        //Jump
        if (this.MaxJumpHeight > 0.25 && Zero.Keyboard.KeyIsDown(Keys.Space))
        {
            //this.Space.SoundSpace.PlayCue(SoundCue.Find("Something"));
            
            this.Owner.Transform.Translation = this.Owner.Transform.Translation + Real3(0,this.Speed * 1.3,0);
            this.MaxJumpHeight = this.MaxJumpHeight - event.Dt / 5;
            if (this.MaxJumpHeight >= 0.25)
            this.Owner.Sprite.Color = Real4(this.MaxJumpHeight - 0.25,this.MaxJumpHeight -0.25,this.MaxJumpHeight,1);
        }
        else if (this.MaxJumpHeight <= 0)
        {
            //Console.WriteLine("BAM!");
            //this.MaxJumpHeight = this.MaxJumpHeight + 1.5;
        }
    }
    
    function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Ground")
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("Something"));
            
            this.Ground = true;
            /*this.MaxJumpHeight = 0.75;
            if (this.MaxJumpHeight >= 0.22)
                this.Owner.Sprite.Color = Real4(this.MaxJumpHeight - 0.1,this.MaxJumpHeight -0.1,this.MaxJumpHeight,1);
        */
        }
        
        if (event.OtherObject.Name == "Bad" )
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("GotHit"));
            this.MaxJumpHeight = this.MaxJumpHeight - 0.15;
            this.Bad = true;
            //update player color
            //if (this.MaxJumpHeight >= 0.25)
            this.Owner.Sprite.Color = Real4(this.MaxJumpHeight - 0.25,this.MaxJumpHeight -0.25,this.MaxJumpHeight,1);
        }
        
        if (event.OtherObject.Name == "Charge" )
        {
            this.Charge = true;
            if (this.MaxJumpHeight < 1)
            {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("Charge"));
            }
        }
    }
    
    function OnCollisionEnded(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Charge" )
        {
            this.Charge = false;
        }
        
        if (event.OtherObject.Name == "Bad" )
        {
            this.Bad = false;
        }
        
        if (event.OtherObject.Name == "Ground" )
        {
            this.Ground = false;
        }
        
    }
}

class NextLevel1 : ZilchComponent
{
    var StartScreen: Level = Level.Find("Level2");
    
    function Initialize(init : CogInitializer)
    {
        //Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
    }
    
        function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Player")
        {
        this.Space.SoundSpace.PlayCue(SoundCue.Find("LevelEnd"));
        this.Space.LoadLevel(this.StartScreen);
        }
    }
}

class NextLevel2 : ZilchComponent
{
    var StartScreen: Level = Level.Find("Level3");
    
    function Initialize(init : CogInitializer)
    {
        //Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
    }
    
        function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Player")
        {
        this.Space.SoundSpace.PlayCue(SoundCue.Find("LevelEnd"));
        this.Space.LoadLevel(this.StartScreen);
        }
    }
}

class NextLevel3 : ZilchComponent
{
    var StartScreen: Level = Level.Find("Level4");
    
    function Initialize(init : CogInitializer)
    {
        //Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
    }
    
        function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Player")
        {
        this.Space.SoundSpace.PlayCue(SoundCue.Find("LevelEnd"));
        this.Space.LoadLevel(this.StartScreen);
        }
    }
}

class NextLevel4 : ZilchComponent
{
    var StartScreen: Level = Level.Find("Level5");
    
    function Initialize(init : CogInitializer)
    {
        //Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
    }
    
        function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Player")
        {
        this.Space.SoundSpace.PlayCue(SoundCue.Find("LevelEnd"));
        this.Space.LoadLevel(this.StartScreen);
        }
    }


class NextLevel6 : ZilchComponent
{
    var StartScreen: Level = Level.Find("Level7");
    
    function Initialize(init : CogInitializer)
    {
        //Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
    }
    
        function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Player")
        {
        this.Space.SoundSpace.PlayCue(SoundCue.Find("LevelEnd"));
        this.Space.LoadLevel(this.StartScreen);
        }
    }
}

class NextLevel7 : ZilchComponent
{
    var StartScreen: Level = Level.Find("Level8");
    
    function Initialize(init : CogInitializer)
    {
        //Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
    }
    
        function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Player")
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("LevelEnd"));
            this.Space.LoadLevel(this.StartScreen);
        }
    }
}

class NextLevel8 : ZilchComponent
{
    var StartScreen: Level = Level.Find("MenuLevel");
    
    function Initialize(init : CogInitializer)
    {
        //Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
        Zero.Connect(this.Owner, Events.CollisionStarted, this.OnCollisionStarted);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
    }
    
        function OnCollisionStarted(event : CollisionEvent)
    {
        if (event.OtherObject.Name == "Player")
        {
            this.Space.SoundSpace.PlayCue(SoundCue.Find("LevelEnd"));
            this.Space.LoadLevel(this.StartScreen);
        }
    }
}

class PersistentSound : ZilchComponent
{
    [Property]
    var BackgroundMenuMusic : SoundCue;
    [Property]
    var BackgroundGameMusic : SoundCue;

    [Property]
    var BackgroundMusicSpaceArch : Archetype;

    [Property]
    var MusicLevel : Level = null;

      var BackgroundMenuMusicSpace : Space;

    var BackgroundGameMusicSpace : Space;
    
    function Initialize(init : CogInitializer)
    {
        Zero.Connect(this.Space, Events.LevelStarted, this.OnLevelStarted);
    }
    
 
    function OnLevelStarted(event : GameEvent)
    {
        if(event.LevelName == "GameLevel")
        {
            if(this.BackgroundMenuMusicSpace != null)
            {
                this.BackgroundMenuMusicSpace.Destroy();
            }

            if(this.BackgroundGameMusicSpace != null)
            {
                Console.WriteLine("You almost created the same space twice!");
                this.BackgroundGameMusicSpace.Destroy();
            }

            this.BackgroundGameMusicSpace = this.GameSession.CreateSpace(this.BackgroundMusicSpaceArch);

            this.BackgroundGameMusicSpace.LoadLevel(this.MusicLevel);

            this.BackgroundGameMusicSpace.SoundSpace.PlayCue(this.BackgroundGameMusic);
        }
    else if(event.LevelName == "MenuLevel")
    {
      if(this.BackgroundGameMusicSpace != null)
      {
        this.BackgroundGameMusicSpace.Destroy();
      }

            if(this.BackgroundMenuMusicSpace == null)
            {

                this.BackgroundMenuMusicSpace = this.GameSession.CreateSpace(this.BackgroundMusicSpaceArch);

                this.BackgroundMenuMusicSpace.LoadLevel(this.MusicLevel);

                this.BackgroundMenuMusicSpace.SoundSpace.PlayCue(this.BackgroundMenuMusic);
            }
        }
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
    }
}

class RkeyReset : ZilchComponent
{
    function Initialize(init : CogInitializer)
    {
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        var player = this.Space.FindObjectByName("Player");
      // Reset the player when R is pressed
        if(Zero.Keyboard.KeyIsPressed(Keys.R) || player == null)
        {

            if(player != null)
            {
                player.Transform.Translation = this.Owner.LevelVars.PlayerPosition;
            }
        }
    }
}

class Shooter : ZilchComponent
{
    function Initialize(init : CogInitializer)
    {
        Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate);
    }

    function OnLogicUpdate(event : UpdateEvent)
    {
        var player = this.Space.FindObjectByName ("Player");
        this.Owner.Orientation.LookAtPoint (player.Transform.Translation);
    }
    
}

Files

MagneCube Ludum Dare 39 [Compo].exe 57 MB
Jul 30, 2017

Get MagneCube

Leave a comment

Log in with itch.io to leave a comment.