Exemplo n.º 1
0
 /// <summary>
 /// Stops the animation of the provided sprite component.
 /// </summary>
 /// <param name="spriteComponent">the sprite component to stop</param>
 public void Stop(SpriteComponent spriteComponent)
 {
     spriteComponent.ElapsedTime       = 0;
     spriteComponent.CurrentIndexIndex = 0;
     spriteComponent.ClearAnimations();
     playingSprites.Remove(spriteComponent);
 }
Exemplo n.º 2
0
        public override void Start()
        {
            enemyNormalSprite = Asset.Load<SpriteSheet>("enemy_active");
            enemyExplosionSprite = Asset.Load<SpriteSheet>("enemy_blowup");

            // Register ourself to the logic to detect collision
            Logic.WatchEnemy(Entity);

            enemySpriteComponent = Entity.Get<SpriteComponent>();

            Reset();
        }
Exemplo n.º 3
0
        public override void Start()
        {
            playerController = Entity.Get<PhysicsComponent>().Elements[0].Character;

            //Please remember that in the GameStudio element the parameter Step Height is extremely important, it not set properly it will cause the entity to snap fast to the ground
            playerController.JumpSpeed = 5.0f;
            playerController.Gravity = -10.0f;
            playerController.FallSpeed = 10.0f;

            playerController.FirstContactStart += playerController_OnFirstContactBegin;

            idleGroup = Asset.Load<SpriteSheet>("player_idle");
            runGroup = Asset.Load<SpriteSheet>("player_run");
            playerSprite = Entity.Get<SpriteComponent>();
            PlayIdle();
        }
Exemplo n.º 4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            font = Asset.Load<SpriteFont>("Font");
            teapot = Asset.Load<Model>("Teapot");
            batch = new SpriteBatch(GraphicsDevice);

            BuildUI();

            spriteComponent = new SpriteComponent { SpriteProvider = new SpriteFromSheet { Sheet = Asset.Load<SpriteSheet>("SpriteSheet") } };
            modelComponent = new ModelComponent { Model = teapot };
            modelComponent2 = new ModelComponent { Model = teapot };
            modelComponent3 = new ModelComponent { Model = teapot };
            entity = new Entity { spriteComponent, modelComponent };
            entity2 = new Entity { modelComponent2 };
            entity3 = new Entity { modelComponent3 };
            SceneSystem.SceneInstance.Scene.Entities.Add(entity);
            SceneSystem.SceneInstance.Scene.Entities.Add(entity2);
            SceneSystem.SceneInstance.Scene.Entities.Add(entity3);

            if (Input.Accelerometer.IsSupported)
                Input.Accelerometer.IsEnabled = true;

            if (Input.Compass.IsSupported)
                Input.Compass.IsEnabled = true;

            if (Input.Gyroscope.IsSupported)
                Input.Gyroscope.IsEnabled = true;

            if (Input.UserAcceleration.IsSupported)
                Input.UserAcceleration.IsEnabled = true;

            if (Input.Gravity.IsSupported)
                Input.Gravity.IsEnabled = true;

            if (Input.Orientation.IsSupported)
                Input.Orientation.IsEnabled = true;

            ChangeScene(0);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Queue the sprite animation defined by the provided sequence of indices at the end of the animation queue.
        /// </summary>
        /// <param name="spriteComponent">The sprite component containing the animation</param>
        /// <param name="indices">The sequence of indices defining the sprite animation</param>
        /// <param name="repeatMode">The value indicating how to loop the animation</param>
        /// <param name="framesPerSeconds">The animation speed in frames per second. 0 to use the sprite animation system default speed.</param>
        public void Queue(SpriteComponent spriteComponent, int[] indices, AnimationRepeatMode repeatMode, float framesPerSeconds = 0)
        {
            if (spriteComponent == null)
            {
                return;
            }

            var animationInfo = new SpriteComponent.AnimationInfo
            {
                ShouldLoop      = repeatMode == AnimationRepeatMode.LoopInfinite,
                FramePerSeconds = framesPerSeconds > 0 ? framesPerSeconds : DefaultFramesPerSecond,
                SpriteIndices   = SpriteComponent.GetNewSpriteIndicesList()
            };

            foreach (var i in indices)
            {
                animationInfo.SpriteIndices.Add(i);
            }

            spriteComponent.Animations.Enqueue(animationInfo);

            playingSprites.Add(spriteComponent);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Play the sprite animation defined by the provided sequence of indices.
        /// </summary>
        /// <param name="spriteComponent">The sprite component containing the animation</param>
        /// <param name="indices">The sequence of indices defining the sprite animation</param>
        /// <param name="repeatMode">The value indicating how to loop the animation</param>
        /// <param name="framesPerSeconds">The animation speed in frames per second. 0 to use the sprite animation system default speed.</param>
        /// <param name="clearQueuedAnimations">Indicate if queued animation should be cleared</param>
        public void Play(SpriteComponent spriteComponent, int[] indices, AnimationRepeatMode repeatMode, float framesPerSeconds = 0, bool clearQueuedAnimations = true)
        {
            if (spriteComponent == null)
            {
                return;
            }

            var animationInfo = new SpriteComponent.AnimationInfo
            {
                ShouldLoop      = repeatMode == AnimationRepeatMode.LoopInfinite,
                SpriteIndices   = SpriteComponent.GetNewSpriteIndicesList(),
                FramePerSeconds = framesPerSeconds > 0 ? framesPerSeconds : DefaultFramesPerSecond,
            };

            foreach (var i in indices)
            {
                animationInfo.SpriteIndices.Add(i);
            }

            spriteComponent.RecycleFirstAnimation();
            spriteComponent.Animations.Enqueue(animationInfo);
            var queuedAnimationsCount = spriteComponent.Animations.Count - 1;

            for (int i = 0; i < queuedAnimationsCount; i++)
            {
                var queuedAnimation = spriteComponent.Animations.Dequeue();
                if (!clearQueuedAnimations)
                {
                    spriteComponent.Animations.Enqueue(queuedAnimation);
                }
            }

            playingSprites.Add(spriteComponent);
            spriteComponent.ElapsedTime       = 0;
            spriteComponent.CurrentIndexIndex = 0;
            spriteComponent.IsPaused          = false;
        }
 void MakeUnit()
 {
     units++;
     SpriteController spriteController;
     string name;
     switch (producedUnit)
     {
         case 0:
             pickaxes++;
             name = side + "Pickaxe";
             spriteController = new PickaxeController
             {
                 mode = 4,
                 side = unitSide,
                 maxDistance = unitDistance,
                 castle = Entity
             };
             break;
         case 1:
             swords++;
             name = side + "Sword";
             spriteController = new SwordController
             {
                 mode = 4,
                 side = unitSide,
                 maxDistance = unitDistance,
                 castle = (from entities in SceneSystem.SceneInstance where entities.Name == enemy select entities).FirstOrDefault()
             };
             break;
         case 2:
             bowArrows++;
             name = side + "BowArrow";
             spriteController = new BowArrowController
             {
                 mode = 4,
                 side = unitSide,
                 maxDistance = unitDistance
             };
             break;
         case 3:
             wands++;
             name = side + "Wand";
             spriteController = new WandController
             {
                 mode = 4,
                 side = unitSide,
                 maxDistance = unitDistance
             };
             break;
         default:
             name = side + "Unit";
             spriteController = new SpriteController
             {
                 mode = 0,
                 side = unitSide,
                 maxDistance = unitDistance
             };
             break;
     }
     //make entity with specific name and add proper sprite sheet and script to it
     Entity entity;
     if (Entity.Name.Contains("Enemy"))
     {
         entity = new Entity(new Vector3(37, unitPosition, 0), name);
     }
     else
     {
         entity = new Entity(new Vector3(3, unitPosition, 0), name);
     }
     SpriteComponent spriteComponent = new SpriteComponent();
     SpriteSheet spriteSheet = Asset.Get<SpriteSheet>(name.Replace("Enemy", ""));
     spriteComponent.SpriteProvider = new SpriteFromSheet
     {
         Sheet = spriteSheet
     };
     spriteComponent.CurrentFrame = 4 + unitSide;
     ScriptComponent scriptComponent = new ScriptComponent();
     scriptComponent.Scripts.Add(spriteController);
     entity.Add<SpriteComponent>(SpriteComponent.Key, spriteComponent);
     entity.Add<ScriptComponent>(ScriptComponent.Key, scriptComponent);
     SceneSystem.SceneInstance.Scene.AddChild(entity);
 }
Exemplo n.º 8
0
        public override async Task Execute()
        {
            agentIdle = Asset.Load<SpriteSheet>("character_idle");
            agentRun = Asset.Load<SpriteSheet>("character_run");
            agentShoot = Asset.Load<SpriteSheet>("character_shoot");
            agentSpriteRegion = agentIdle.Sprites.First().Region;
            var bulletSpriteSheet = Asset.Load<SpriteSheet>("bullet");

            agentSpriteComponent = Entity.Get<SpriteComponent>();

            // Calculate offset of the bullet from the Agent if he is facing left and right side
            // TODO fix this
            var bulletOffset = new Vector3(1f, 0.2f, 0f); //new Vector3(agentSpriteRegion.Width * 0.5f, -14f, 0);

            // Initialize game entities
            CurrentAgentAnimation = AgentAnimation.Idle;

            var isAgentFacingRight = true;
            var shootDelayCounter = 0f;

            while (Game.IsRunning)
            {
                await Script.NextFrame();

                var inputState = GetKeyboardInputState();

                if (inputState == InputState.None)
                    inputState = GetPointerInputState();

                // Reset the shoot delay, if state changes
                if (inputState != InputState.Shoot && CurrentAgentAnimation == AgentAnimation.Shoot)
                    shootDelayCounter = 0;

                if (inputState == InputState.RunLeft || inputState == InputState.RunRight)
                {
                    // Update Agent's position
                    var dt = (float)Game.UpdateTime.Elapsed.TotalSeconds;

                    Entity.Transform.Position.X += ((inputState == InputState.RunRight) ? AgentMoveDistance : -AgentMoveDistance) * dt;

                    if (Entity.Transform.Position.X < -gameWidthHalfX)
                        Entity.Transform.Position.X = -gameWidthHalfX;

                    if (Entity.Transform.Position.X > gameWidthHalfX)
                        Entity.Transform.Position.X = gameWidthHalfX;

                    isAgentFacingRight = inputState == InputState.RunRight;

                    // If agent face left, flip the sprite
                    Entity.Transform.Scale.X = isAgentFacingRight ? 1f : -1f;

                    // Update the sprite animation and state
                    agentSpriteComponent.SpriteProvider = new SpriteFromSheet { Sheet = agentRun };
                    CurrentAgentAnimation = AgentAnimation.Run;
                }
                else if (inputState == InputState.Shoot)
                {
                    // Update shootDelayCounter, and check whether it is time to create a new bullet
                    shootDelayCounter -= (float)Game.UpdateTime.Elapsed.TotalSeconds;

                    if (shootDelayCounter > 0)
                        continue;


                    // Reset shoot delay
                    shootDelayCounter = AgentShootDelay;

                    // Spawns a new bullet
                    var bullet = new Entity
                    {
                        new SpriteComponent { SpriteProvider = new SpriteFromSheet { Sheet = bulletSpriteSheet } },

                        // Will make the beam move along a direction at each frame
                        new ScriptComponent { Scripts = { new BeamScript { DirectionX = isAgentFacingRight? 1f : -1f } } }
                    };

                    bullet.Transform.Position = (isAgentFacingRight)
                        ? Entity.Transform.Position + bulletOffset
                        : Entity.Transform.Position + (bulletOffset * new Vector3(-1, 1, 1));

                    SceneSystem.SceneInstance.Scene.AddChild(bullet);
                    Logic.WatchBullet(bullet);

                    // Start animation for shooting
                    agentSpriteComponent.SpriteProvider = new SpriteFromSheet { Sheet = agentShoot };
                    CurrentAgentAnimation = AgentAnimation.Shoot;
                }
                else
                {
                    agentSpriteComponent.SpriteProvider = new SpriteFromSheet { Sheet = agentIdle };
                    CurrentAgentAnimation = AgentAnimation.Idle;
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Resumes a previously paused animation.
 /// </summary>
 /// <param name="spriteComponent">the sprite component to resume</param>
 public void Resume(SpriteComponent spriteComponent)
 {
     spriteComponent.IsPaused = false;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Pauses the animation of the provided sprite component.
 /// </summary>
 /// <param name="spriteComponent">the sprite component to pause</param>
 public void Pause(SpriteComponent spriteComponent)
 {
     spriteComponent.IsPaused = true;
 }