예제 #1
0
 public static AnimalType <T> WithAsset <T>(this AnimalType <T> animal, AnimationDefintion anim, Vector2 size, Vector2?origin = null)
 {
     animal.Asset       = anim;
     animal.AssetOrigin = origin ?? animal.AssetOrigin;
     animal.Size        = size;
     return(animal);
 }
예제 #2
0
        public HUDAnimatedComponent(AnimationDefintion config, Vector2 size,
                                    Vector2 origin = default(Vector2), Rectangle?sourceRectangle = default(Rectangle?), float layerDepth = 0,
                                    Vector2 offset = default(Vector2)) : base(config.AssetName, size, origin, sourceRectangle, layerDepth, offset)
        {
            this.config = config;


            neutralFrames = config.Neutral;

            animByName       = config.Animations.ToDictionary(a => a.Name);
            CurrentAnimation = animByName.Values.First();

            if (!animByName.Values.All(a => neutralFrames.Intersect(a.FrameNumbers).Any()))
            {
                throw new NotSupportedException("All animations must have a netural frame in them!");
            }
        }
예제 #3
0
        public override void LoadContent()
        {
            base.LoadContent();

            Game.EngineComponents.Get <AudioManager>().PreloadSongs("Audio\\joinScreen", "Audio\\gamePlay");

            joinAnimationDefinition = Game.Content.LoadFromJson <AnimationDefintion>("Animations/join_anim");
            availablePlayerNames    = Game.Content.LoadFromJson <PlayerNamesDefinition>("Text/player_names_text").Names;

            // [FOREACH PERFORMANCE] Should not allocate garbage
            foreach (var p in Game.CurrentGameMode.PlayerInfos)
            {
                JoinPlayer(p.IsKeyboardPlayer, p.GamepadIndex, p);
            }

            // Player mode
            AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0.05f),
                                 new HUDComponent(Game.CurrentGameMode.PlayerMode == PlayerMode.Free4All ? "gameMode_freeForAll_" : "gameMode_2VS2_", new Vector2(0.5f, 0.32f), origin: new Vector2(0.5f, 0.5f)),
                                 new HUDTextComponent(MainFont, 0.04f, Game.CurrentGameMode.PlayerMode == PlayerMode.TwoVsTwo ? "Team 1" : "", origin: new Vector2(0.5f, 0.5f), offset: new Vector2(-0.25f, 0f)),
                                 new HUDTextComponent(MainFont, 0.04f, Game.CurrentGameMode.PlayerMode == PlayerMode.TwoVsTwo ? "Team 2" : "", origin: new Vector2(0.5f, 0.5f), offset: new Vector2(0.25f, 0f))
                                 ));



            AddEntity(new Entity(this, EntityType.UI, new Vector2(0.5f, 0.95f), pressStartToStart = new HUDTextComponent(MainFont, 0.08f, "PRESS START", origin: new Vector2(0.5f, 0.5f))
            {
                Opacity = 0
            }
                                 ));

            pressStartToStartAnimation = Dispatcher.AddAnimation(Animation.Get(0, 1, 1.5f, true, val => pressStartToStart.Opacity = val, EasingFunctions.ToLoop(EasingFunctions.QuadIn)).Set(a => a.IsRunning = false));

            // Keyboard Entity
            AddEntity(new Entity(this, EntityType.LayerIndependent, MakeInput(true, 0)));
            // Gamepads
            AddEntity(new Entity(this, EntityType.LayerIndependent, MakeInput(false, 0)));
            AddEntity(new Entity(this, EntityType.LayerIndependent, MakeInput(false, 1)));
            AddEntity(new Entity(this, EntityType.LayerIndependent, MakeInput(false, 2)));
            AddEntity(new Entity(this, EntityType.LayerIndependent, MakeInput(false, 3)));


            AddEntity(new Entity(this, EntityType.UI,
                                 joinComponent     = new HUDAnimatedComponent(joinAnimationDefinition, new Vector2(0.4f, 0.4f), origin: new Vector2(0.5f, 0.5f), offset: new Vector2(0.5f, 0.5f)),
                                 joinTextComponent = new HUDTextComponent(MainFont, 0.05f, "Press A to join", offset: new Vector2(0.5f, 0.575f), origin: new Vector2(0.5f, 0.5f), layerDepth: 0.1f)
                                 ));


            var backgroundSize = new Vector2(6f / 3.508f * 1.1f * GameConstants.ScreenHeight, 1.1f * GameConstants.ScreenHeight);

            AddEntity(new Entity(this, EntityType.Game, new SpriteComponent("background", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: -1.0f)));
            AddEntity(new Entity(this, EntityType.Game,
                                 new SpriteComponent("joinscreen_outerBorder", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: 0.9f),
                                 new PhysicsComponent(new PolygonShape(PolygonTools.CreateRectangle(GameConstants.ScreenWidth, 1, new Vector2(0, GameConstants.ScreenHeight / 2.0f), 0), 1)),
                                 new PhysicsComponent(new PolygonShape(PolygonTools.CreateRectangle(GameConstants.ScreenWidth, 1, new Vector2(0, -GameConstants.ScreenHeight / 2.0f), 0), 1)),
                                 new PhysicsComponent(new PolygonShape(PolygonTools.CreateRectangle(1, GameConstants.ScreenHeight, new Vector2(GameConstants.ScreenWidth / 2.0f, 0), 0), 1)),
                                 new PhysicsComponent(new PolygonShape(PolygonTools.CreateRectangle(1, GameConstants.ScreenHeight, new Vector2(-GameConstants.ScreenWidth / 2.0f, 0), 0), 1))
                                 ));
            AddEntity(new Entity(this, EntityType.Game,
                                 new SpriteComponent("joinscreen_trees_center", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: 0.9f),
                                 new PhysicsComponent(new CircleShape(GameConstants.ScreenHeight / 6.0f, 1f))
                                 ));
            AddEntity(new Entity(this, EntityType.Game,
                                 new SpriteComponent("joinscreen_trees_top", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: 0.9f),
                                 new PhysicsComponent(new PolygonShape(PolygonTools.CreateRectangle(1, GameConstants.ScreenHeight, new Vector2(0, -GameConstants.ScreenHeight / 4.0f), 0), 1))
                                 ));
            AddEntity(new Entity(this, EntityType.Game,
                                 new SpriteComponent("joinscreen_trees_bottom", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: 0.9f),
                                 new PhysicsComponent(new PolygonShape(PolygonTools.CreateRectangle(1, GameConstants.ScreenHeight, new Vector2(0, GameConstants.ScreenHeight / 4.0f), 0), 1))
                                 ));
            if (Game.CurrentGameMode.PlayerMode == PlayerMode.Free4All)
            {
                AddEntity(new Entity(this, EntityType.Game,
                                     new SpriteComponent("joinscreen_trees_left", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: 0.9f),
                                     new PhysicsComponent(new PolygonShape(PolygonTools.CreateRectangle(GameConstants.ScreenWidth, 1, new Vector2(-GameConstants.ScreenWidth / 4.0f, 0), 0), 1))
                                     ));
                AddEntity(new Entity(this, EntityType.Game,
                                     new SpriteComponent("joinscreen_trees_right", backgroundSize, new Vector2(0.5f, 0.5f), layerDepth: 0.9f),
                                     new PhysicsComponent(new PolygonShape(PolygonTools.CreateRectangle(GameConstants.ScreenWidth, 1, new Vector2(GameConstants.ScreenWidth / 4.0f, 0), 0), 1))
                                     ));
            }

            AddEntity(new Entity(this, EntityType.LayerIndependent, new CenterCameraComponent(Game.Camera)));


            this.TransitionIn();
        }