Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (controller.currentSpeed == 0)
     {
         sprite.SetAnimation(0, 0);
     }
     else
     {
         sprite.SetAnimation(4, 19, 20, true);
     }
 }
Example #2
0
 public void Open()
 {
     Entry.SetAnimation(AnimationState.Play);
     IsOpening      = true;
     IsClosing      = false;
     Entry.OnFinish = () =>
     {
         Entry.SetAnimation(AnimationState.Pause);
         IsOpening = false;
         IsOpen    = true;
     };
 }
Example #3
0
	// Update is called once per frame
	void Update () {
		if (Time.timeScale > 0) {
			if (!jumping) {
				if (!physics.grounded) {// && controller.amountToMove.y < -controller.gravity * Time.deltaTime) {
					sprite.SetAnimation (35,35);
					sprite.looping = true;
				} else if (controller.currentSpeed == 0) {
					sprite.SetAnimation (0,0);
					sprite.looping = true;
				} else {
					sprite.SetAnimation (4,19, 20, true);
					sprite.looping = true;
				}
			}
		}
	}
Example #4
0
        public override void Start()
        {
            Sprite s = (new Sprite("../../../../data/images/coin_spritesheet.png", vec2.Zero, Scale));

            s.SetAnimation(4, 0.5f);
            AddChildShape(s);
            SetCircleCollider(Scale.x);
            rigidbody = new Rigidbody(this, 0, true, true, "coin");
        }
Example #5
0
 public virtual void Die()
 {
     if (IsExploding)
     {
         return;
     }
     IsExploding = true;
     DieTexture.ToStart();
     Game.Sounds.BallBounce.Play();
     PlayArena.Vaus.AddScore(Scoring.Alien);
     DieTexture.SetAnimation(AnimationState.Play);
     DieTexture.OnFinish = () =>
     {
         DieTexture.SetAnimation(AnimationState.Stop);
         Location    = new Vector2(Location.X, Game.Height);
         IsExploding = false;
         Life        = 0;
     };
 }
Example #6
0
        public override void Start()
        {
            base.Start();

            m_audioCmpBallLaunch = new AudioComponent("Audio/Sounds.lua::BallShot");
            Owner.Attach(m_audioCmpBallLaunch);

            Sprite sprite1 = Sprite.Create("Graphics/LauncherCentralShield.lua::Sprite");

            sprite1.SetAnimation("Normal");
            sprite1.Alpha             = 0;
            m_spriteCmp1              = new SpriteComponent(sprite1, "ArenaOverlay5");
            m_spriteCmp1.Visible      = false;
            sprite1.Playing           = true;
            m_spriteCmp1.Sprite.Scale = new Vector2(m_scale, m_scale);

            Owner.Attach(m_spriteCmp1);

            Sprite sprite2 = Sprite.Create("Graphics/LauncherCentralShield.lua::Sprite2");

            sprite2.SetAnimation("Normal");
            sprite2.Alpha        = 0;
            m_spriteCmp2         = new SpriteComponent(sprite2, "ArenaOverlay5");
            m_spriteCmp2.Visible = false;
            sprite2.Playing      = true;

            Owner.Attach(m_spriteCmp2);

            var basicEffect = new BasicEffect(Engine.Renderer.Device);

            basicEffect.LightingEnabled    = false;
            basicEffect.VertexColorEnabled = true;
            basicEffect.FogEnabled         = false;
            m_effect = new EffectWrapper(basicEffect);

            int capacity = 512 * 512 * 4;

            m_lineMesh     = new DynamicMesh <VertexPositionColor>(Engine.Renderer.Device, VertexPositionColor.VertexDeclaration, PrimitiveType.LineList, capacity);
            m_triangleMesh = new DynamicMesh <VertexPositionColor>(Engine.Renderer.Device, VertexPositionColor.VertexDeclaration, PrimitiveType.TriangleList, capacity);

            Engine.Renderer.RenderLayers["ArenaOverlay7"].Renderables.Add(this);

            m_chargeTimerMS         = new Timer(Engine.GameTime.Source, 2000);
            m_chargeTimerMS.OnTime += m_chargeTimerMS_OnTime;

            m_maxChargeTimerMS         = new Timer(Engine.GameTime.Source, 300);
            m_maxChargeTimerMS.OnTime += m_maxChargeTimerMS_OnTime;

            m_chargedMax = false;

            m_launcherTeam = new List <Player>();

            m_shield = new LauncherShield(this);
            Owner.Attach(m_shield);
        }
Example #7
0
        public override void Update(Sprite sprite)
        {
            var keyboard = Keyboard.GetState();

            var direction = Vector2.Zero;
            var anim      = sprite.AnimationInfo.CurrentAnimationName;
            var speed     = 0f;

            if (keyboard.IsKeyDown(Keys.D))
            {
                direction.X = 1;
                sprite.DrawInfo.FlipFlags = SpriteEffects.None;
                speed = 3f;
            }

            if (keyboard.IsKeyDown(Keys.A))
            {
                direction.X = -1;
                sprite.DrawInfo.FlipFlags = SpriteEffects.FlipHorizontally;
                speed = 3f;
            }

            if (keyboard.IsKeyDown(Keys.W))
            {
                anim        = "walk_up";
                direction.Y = -1;
                speed       = 3f;
            }

            if (keyboard.IsKeyDown(Keys.S))
            {
                anim        = "walk_down";
                direction.Y = 1;
                speed       = 3f;
            }

            if (direction.X != 0f)
            {
                anim = "walk_right";
            }

            if (direction.LengthSquared() > 1f)
            {
                direction.Normalize();
            }

            sprite.SetAnimation(anim);
            sprite.AnimationInfo.Animations[sprite.AnimationInfo.CurrentAnimationName].Speed = speed;

            if (sprite.MoveAndCollide(direction, out var overlap))
            {
            }

            Layout.Current.MoveAndClamp(sprite.BodyInfo.Position - new Vector2((View.ResolutionWidth / 2) - sprite.BodyInfo.Width / 2, View.ResolutionHeight / 2 - sprite.BodyInfo.Height / 2));
        }
Example #8
0
        public void AddController(MenuController ctrl)
        {
            if (m_ctrlInfos.ContainsKey(ctrl))
            {
                return;
            }

            ControllerInfo info = new ControllerInfo();

            info.State           = ControllerState.None;
            info.Controller      = ctrl;
            info.ControllerIndex = m_ctrlInfos.Keys.Count;
            info.PlayerIndex     = -1;

            Sprite edgeSprite = Sprite.Create("Graphics/controlSprite.lua::Sprite");

            info.SpriteCmp = new SpriteComponent(edgeSprite, "Menu");
            if (ctrl.Type == InputType.Gamepad)
            {
                edgeSprite.SetAnimation("Gamepad");
            }
            else
            {
                edgeSprite.SetAnimation("Keyboard");
            }
            info.SpriteCmp.Visible      = false;
            info.SpriteCmp.Sprite.Scale = iconSpriteScale * Vector2.One;
            Menu.Owner.Attach(info.SpriteCmp);

            info.TextCmp            = new TextComponent("Menu");
            info.TextCmp.Style      = m_style;
            info.TextCmp.Alignement = TextAlignementHorizontal.Center;
            info.TextCmp.Text       = GetControllerText(ctrl);
            info.TextCmp.Visible    = false;
            Menu.Owner.Attach(info.TextCmp);

            m_ctrlInfos.Add(ctrl, info);
        }
Example #9
0
        public void SetDirection(Direction direction)
        {
            if (CurrentDirection == direction)
            {
                return;
            }
            CurrentDirection = direction;
            Animator frame;

            if (AnimationsDirections.TryGetValue(direction, out frame))//.Single(animation => animation.DirectionToMove == direction);
            {
                Sprite.SetAnimation(frame.FirstFrame, frame.LastFrame);
            }
        }
Example #10
0
    // Add an explosion into the list (will remove self once complete)
    public void AddExplosion(Vector2 Position)
    {
        // Allocate and register the new sprite, starting with the explosion
        // Note: slight randomization to add effect
        Sprite Explosion = new Sprite("Textures/ExplosionSprite" + UnityEngine.Random.Range(0, 2)); // [0, 1]
        Explosion.SetPosition(Position);
        Explosion.SetAnimation(Vector2.zero, new Vector2(20, 20), 7, 0.06f + UnityEngine.Random.Range(-0.01f, 0.05f));
        Explosion.SetGeometrySize(Explosion.GetSpriteSize() * (0.6f + UnityEngine.Random.Range(-0.2f, 0.2f)));
        Explosion.SetRotationCenter(Explosion.GetGeometrySize() / UnityEngine.Random.Range (1.0f, 2.0f));
        Explosion.SetRotation(UnityEngine.Random.Range(0.0f, 2.0f * Mathf.PI));
        Explosion.SetDepth(Globals.ExplosionDepth);

        // Register to renderer and list
        Globals.WorldView.SManager.AddSprite(Explosion);
        Explosions.Add(Explosion);

        // Add explosion audio
        int Index = UnityEngine.Random.Range(1, 4); // [1, 4)
        Globals.WorldView.AManager.PlayAudio(Position, "Explosion" + Index);
    }
Example #11
0
    /*** Public ***/
    // Standard constructor: needs to have a paried config file name
    // which should implement all of the groups and key-value pairs
    // found in the ship demo config file
    public BaseShip(String ConfigFileName)
    {
        // Load the ship's properties
        this.ConfigFileName = ConfigFileName;
        ConfigFile Info = new ConfigFile(ConfigFileName);

        /*** General Init. ***/

        // Save the health components
        ShieldHealth = ShieldMaxHealth = Info.GetKey_Int("General", "Shield");
        HullHealth = HullMaxHealth = Info.GetKey_Int("General", "Hull");

        // Save velicity limit and default pos to center
        MaxVelocity = Info.GetKey_Vector2("General", "MaxVelocity");
        ShipAcceleration = new Vector2();
        ShipVelocity = new Vector2();
        ShipPosition = new Vector3();

        // Get all group names to load up specialty geometry
        String TextureName = Info.GetKey_String("General", "Texture");
        String[] GroupNames = Info.GetGroupNames();

        /*** Frame, Shield & Hull ***/

        // For each group, look just for "Frame" and "Shield"
        foreach(String GroupName in GroupNames)
        {
            // If shield
            if(GroupName.ToLower().StartsWith("shield") == true)
            {
                // Get animation / frame info
                ShieldAnimation = LoadHullType(Info, GroupName);

                // Register the sprite with the sprite manager
                ShieldSprite = new Sprite("Textures/" + TextureName);
                ShieldSprite.SetAnimation(ShieldAnimation.Pos, ShieldAnimation.Size, ShieldAnimation.FrameCount, ShieldAnimation.FrameTime);
                ShieldSprite.SetGeometrySize(ShieldSprite.GetSpriteSize());
                ShieldSprite.SetRotationCenter(ShieldSprite.GetGeometrySize() / 2.0f);
                ShieldSprite.SetDepth(Globals.ShieldDepth);
                Globals.WorldView.SManager.AddSprite(ShieldSprite);
            }
            // Elif base frame
            else if(GroupName.ToLower().StartsWith("frame") == true)
            {
                // Get animation / frame info
                FrameAnimation = LoadHullType(Info, GroupName);

                // Register the sprite with the sprite manager
                FrameSprite = new Sprite("Textures/" + TextureName);
                FrameSprite.SetAnimation(FrameAnimation.Pos, FrameAnimation.Size, FrameAnimation.FrameCount, FrameAnimation.FrameTime);
                FrameSprite.SetGeometrySize(FrameSprite.GetSpriteSize());
                FrameSprite.SetRotationCenter(FrameSprite.GetGeometrySize() / 2.0f);
                FrameSprite.SetDepth(Globals.FrameDepth);
                Globals.WorldView.SManager.AddSprite(FrameSprite);
            }
        }

        // Load all the hulls
        HullList = new List<BaseShip_Hull>();
        foreach(String GroupName in GroupNames)
        {
            if(GroupName.ToLower().StartsWith("hull") == true)
            {
                BaseShip_Hull Hull = LoadHullType(Info, GroupName);
                HullList.Add(Hull);
            }
        }

        // Default to initial hull
        HullSprite = new Sprite("Textures/" + TextureName);
        HullSkinIndex = 0; // Index grows while health goes down
        BaseShip_Hull HullAnimation = HullList[HullSkinIndex];

        HullSprite.SetAnimation(HullAnimation.Pos, HullAnimation.Size, HullAnimation.FrameCount, HullAnimation.FrameTime);
        HullSprite.SetGeometrySize(HullSprite.GetSpriteSize());
        HullSprite.SetRotationCenter(HullSprite.GetGeometrySize() / 2.0f);
        HullSprite.SetDepth(Globals.HullDepth);
        Globals.WorldView.SManager.AddSprite(HullSprite);

        /*** Contrails ***/

        // Load all contrails
        ContrailList = new List<BaseShip_Contrail>();
        foreach(String GroupName in GroupNames)
        {
            BaseShip_Contrail NewContrail = LoadContrail(Info, GroupName);
            if(NewContrail != null)
                ContrailList.Add(NewContrail);
        }

        /*** Weapons ***/

        // Load all weapons
        WeaponsList = new List<BaseShip_Weapon>();
        foreach(String GroupName in GroupNames)
        {
            BaseShip_Weapon NewWeapon = LoadWeapon(Info, GroupName);
            if(NewWeapon != null)
                WeaponsList.Add(NewWeapon);
        }

        /*** Animation Entities ***/

        // Load all animations
        DetailsList = new List<BaseShip_Detail>();
        foreach(String GroupName in GroupNames)
        {
            BaseShip_Detail Detail = LoadDetail(Info, GroupName);
            if(Detail != null)
                DetailsList.Add(Detail);
        }

        /*** Misc. ***/

        // Chunk count
        foreach(String GroupName in GroupNames)
        {
            if(GroupName.ToLower().StartsWith("chunk"))
                ChunkCount++;
        }

        // Generate unique ship name
        NameGenerator NameGen = new NameGenerator();
        ShipName = NameGen.generateName();
    }
Example #12
0
        public void Init()
        {
            m_effects = new List <PlayerEffect>();

            var allPlayerSpriteInfos = Engine.AssetManager.Get <PlayerSpriteInfo[]>("Game/PlayerSprites.lua::PlayerSprites");
            var playerSpriteInfo     = allPlayerSpriteInfos[(int)m_playerIndex];

            Sprite playerSprite = Sprite.CreateFromTexture(playerSpriteInfo.Material);

            playerSprite.Scale = new Vector2(0.48f, 0.48f);
            m_spritePlayerCmp  = new ColorMaskedSprite(playerSprite, "ArenaOverlay9");
            var texAsset = playerSpriteInfo.Mask;

            m_spritePlayerCmp.Mask = texAsset;
            ResetColors();
            Owner.Attach(m_spritePlayerCmp);

            m_shadowCmp = new SpriteComponent(
                Sprite.CreateFromTexture("Graphics/playerShadow.png"),
                "ArenaOverlay8");
            m_shadowCmp.Sprite.Scale = playerSprite.Scale;
            Owner.Attach(m_shadowCmp);

            Sprite sparksSprite = Sprite.Create("Graphics/playerSprite.lua::Sprite");

            sparksSprite.SetAnimation("Sparks");
            sparksSprite.Playing = true;
            m_sparksCmp          = new SpriteComponent(sparksSprite, "ArenaOverlay10");
            m_sparksCmp.Visible  = false;
            Owner.Attach(m_sparksCmp);

            Sprite goldFxSprite = Sprite.Create("Graphics/playerSprite.lua::Sprite");

            goldFxSprite.SetAnimation("GoldFx");
            goldFxSprite.Playing      = false;
            m_goldFxSpriteCmp         = new SpriteComponent(goldFxSprite, "ArenaOverlay10");
            m_goldFxSpriteCmp.Visible = false;
            Owner.Attach(m_goldFxSpriteCmp);

            Sprite shieldUpFxSprite = Sprite.Create("Graphics/playerSprite.lua::Sprite");

            shieldUpFxSprite.SetAnimation("ShieldUp");
            shieldUpFxSprite.Playing      = false;
            m_shieldUpFxSpriteCmp         = new SpriteComponent(shieldUpFxSprite, "ArenaOverlay10");
            m_shieldUpFxSpriteCmp.Visible = false;
            Owner.Attach(m_shieldUpFxSpriteCmp);

            // Physic
            m_bodyCmp = new RigidBodyComponent();
            CircleShape bodyShape = new CircleShape(ConvertUnits.ToSimUnits(Parameters.Radius), 1.0f);
            Fixture     fix       = new Fixture(m_bodyCmp.Body, bodyShape);

            Owner.Attach(m_bodyCmp);

            m_bodyCmp.Body.FixedRotation = true;

            m_bodyCmp.Body.LinearDamping       = Parameters.Physic.LinearDamping;
            m_bodyCmp.Body.AngularDamping      = Parameters.Physic.AngularDamping;
            m_bodyCmp.Body.Restitution         = Parameters.Physic.Restitution;
            m_bodyCmp.Body.Mass                = Parameters.Physic.Mass;
            m_bodyCmp.Body.CollisionCategories = (Category)CollisionType.Player;
            m_bodyCmp.Body.SleepingAllowed     = false;
            m_bodyCmp.Body.IsBullet            = true;

            // Blink
            m_blink = new PlayerBlink(this);
            Owner.Attach(m_blink);

            if (m_playerIndex == PlayerIndex.One)
            {
                m_bodyCmp.Body.CollisionCategories = (Category)CollisionType.Gameplay | (Category)CollisionType.Player | (Category)CollisionType.TeamA;
            }
            if (m_playerIndex == PlayerIndex.Two)
            {
                m_bodyCmp.Body.CollisionCategories = (Category)CollisionType.Gameplay | (Category)CollisionType.Player | (Category)CollisionType.TeamA;
            }
            if (m_playerIndex == PlayerIndex.Three)
            {
                m_bodyCmp.Body.CollisionCategories = (Category)CollisionType.Gameplay | (Category)CollisionType.Player | (Category)CollisionType.TeamB;
            }
            if (m_playerIndex == PlayerIndex.Four)
            {
                m_bodyCmp.Body.CollisionCategories = (Category)CollisionType.Gameplay | (Category)CollisionType.Player | (Category)CollisionType.TeamB;
            }

            // Audio
            m_audioCmpBallShot = new AudioComponent("Audio/Sounds.lua::BallShot");
            Owner.Attach(m_audioCmpBallShot);
            m_audioCmpStun = new AudioComponent("Audio/Sounds.lua::Stun");
            Owner.Attach(m_audioCmpStun);
            m_audioCmpCharge = new AudioComponent("Audio/Sounds.lua::Charge");
            Owner.Attach(m_audioCmpCharge);

            //
            m_ballTrigger = new TriggerComponent();
            var triggerFixture = FixtureFactory.AttachCircle(
                ConvertUnits.ToSimUnits(Parameters.Radius + Parameters.BallSnapRadius),
                0,
                m_ballTrigger.Body);

            triggerFixture.IsSensor         = true;
            m_ballTrigger.Body.CollidesWith = (Category)CollisionType.Ball;
            Owner.Attach(m_ballTrigger);

            m_magnetSensor = new TriggerComponent();
            triggerFixture = FixtureFactory.AttachCircle(
                ConvertUnits.ToSimUnits(Parameters.MagnetRadiusMax),
                0,
                m_magnetSensor.Body);
            triggerFixture.IsSensor          = true;
            m_magnetSensor.Body.CollidesWith = (Category)CollisionType.Ball;
            Owner.Attach(m_magnetSensor);

            Engine.World.EventManager.AddListener((int)EventId.MatchBegin, OnMatchBegin);
            Engine.World.EventManager.AddListener((int)EventId.FirstPeriod, OnFirstPeriod);
            Engine.World.EventManager.AddListener((int)EventId.HalfTime, OnHalfTime);
            Engine.World.EventManager.AddListener((int)EventId.HalfTimeTransition, OnHalfTimeTransition);
            Engine.World.EventManager.AddListener((int)EventId.SecondPeriod, OnSecondPeriod);
            Engine.World.EventManager.AddListener((int)EventId.MatchEnd, OnMatchEnd);
            Engine.World.EventManager.AddListener((int)EventId.Victory, OnMatchVictory);
            Engine.World.EventManager.AddListener((int)EventId.KickOff, OnKickOff);

            m_ballAngle = 0;

            //Initialise ChargetShots Timer
            float chargeTimeMS = Parameters.ChargedShot.ChargeTimeMS;

            chargeTimeMS      *= ComputeSkillCoef("ChargedShotTime", Parameters.Skills.ChargedShotTimeBase, Parameters.Skills.ChargedShotTimeCoef);
            m_chargedShotTimer = new Timer(Engine.GameTime.Source, chargeTimeMS, TimerBehaviour.Stop);

            float delay = Engine.Debug.EditSingle("ChargedShotDelay", 250);

            m_chargedShotDelayTimer = new Timer(Engine.GameTime.Source, delay);

            ShakeComponent shakeCmp = new ShakeComponent(m_spritePlayerCmp);

            shakeCmp.ShakeAmount = 4.0f;
            Owner.Attach(shakeCmp);

            PlayerOffScreenMarker offScreenMarker = new PlayerOffScreenMarker();

            Owner.Attach(offScreenMarker);

            if (m_playerInfo.InputType == InputType.AI && m_teamMate.PlayerInfo.InputType == InputType.AI)
            {
                offScreenMarker.Hide = true;
            }

            m_moveDirection = Vector2.Zero;

            m_bodyCmp.OnCollision += new CollisionEvent(OnCollision);

            m_bodyCmp.UserData.Add("Tag", "Player");

            //Antenna
            var playerAntenna = new PlayerAntenna();

            Owner.Attach(playerAntenna);
        }
Example #13
0
 public void Flash()
 {
     FlashTexture.ToStart();
     FlashTexture.SetAnimation(AnimationState.Play);
     FlashTexture.OnFinish = () => FlashTexture.SetAnimation(AnimationState.Stop);
 }
Example #14
0
    // Add glow ontop of what is being fired
    public void AddGlow(Vector2 Position)
    {
        // Sprite info
        Vector2 GlowPos = ProjectileInfo.GetKey_Vector2("Glow", "Pos");
        Vector2 GlowSize = ProjectileInfo.GetKey_Vector2("Glow", "Size");

        // Allocate and register the new sprite
        // Note: slight randomization to add effect
        Sprite Explosion = new Sprite("Textures/Projectiles");
        Explosion.SetAnimation(GlowPos, GlowSize, 1, 1.0f);

        // Set in-world properties
        Explosion.SetPosition(Position);
        Explosion.SetGeometrySize(Explosion.GetSpriteSize() * (0.6f + UnityEngine.Random.Range(-0.2f, 0.2f)));
        Explosion.SetRotationCenter(Explosion.GetGeometrySize() / 2.0f);
        Explosion.SetRotation(UnityEngine.Random.Range(0.0f, 2.0f * Mathf.PI));
        Explosion.SetDepth(Globals.ExplosionDepth);

        // Register to renderer and list
        Globals.WorldView.SManager.AddSprite(Explosion);
        Glow.Add(Explosion);
    }
Example #15
0
 internal void SetAnimation(string p_animationname)
 {
     Sprite.SetAnimation(p_animationname);
 }