Ejemplo n.º 1
0
        public override void Initialize()
        {
            playerEntity       = (PlayerEntity)Entity;
            animationComponent = playerEntity.GetComponentByName <AnimatedSpriteComponent>("playerAnim");

            base.Initialize();
        }
Ejemplo n.º 2
0
        public AnimalEntity(Scene scene, Vector2 location, AnimalType <T> animal, float rotation = 0) : base(scene, EntityType.Game, location, bodyType: BodyType.Dynamic)
        {
            AnimalType             = animal;
            AddComponent(animation = new AnimatedSpriteComponent(animal.Asset, animal.Size, animal.AssetOrigin));
            AddComponent(new PhysicsComponent(animal.CollisionShape));
            AddComponent(viewSensor = new SensorComponent("view",
                                                          new PolygonShape(PolygonTools.CreateCapsule(animal.ViewDistance, animal.ViewSize / 2, 4, animal.ViewSize, 8), 1),
                                                          e => e is PlayerEntity && ((PlayerEntity)e).State == PlayerState.Luring));

            AddComponent(hearingSensor = new SensorComponent("hearing",
                                                             new CircleShape(animal.HearingDistance, 1),
                                                             e => e is PlayerEntity && ((PlayerEntity)e).State == PlayerState.Shouting));

            AddComponent(new MovementBasicsComponent());
            AddComponent(new RaycastSensorComponent(animal.ViewDistance));
            AddComponent(new AudioSourceComponent());

            aiComponent = new StateBasedAIComponent <T>(animal.InitalState);

            AddComponent(aiComponent);
            aiComponent.StateChanged += AiComponent_StateChanged1;

            // [FOREACH PERFORMANCE] Should not allocate garbage
            foreach (var b in animal.Behaviors)
            {
                AddComponent(b());
            }

            Body.Rotation = rotation;
        }
Ejemplo n.º 3
0
        public static void Main(string[] _)
        {
            game = new GameBuilder()
                   .SetTitle("Engine demo")
                   .SetFont("Lucidas Console", 10, 10)
                   .SetWindowSize(90, 35)
                   .SetPosition(5, 5)
                   .SetCursorVisible(false)
                   .LimitFPS(200)
                   .SetRenderer <SimpleColorOnlySurfaceRenderer, DoubleBufferedOutputHandler>()
                   .Build();

            game.OpenDevMenu = false;

            EntityManager.EnableRegistry(false);

            // Create camera
            EntityManager.AddEntity().AddComponent <CameraComponent>();

            AnimatedSpriteComponent animatedCharacter = EntityManager.AddEntity().AddComponent <AnimatedSpriteComponent>();

            animatedCharacter.ImportSheet("assets/landscape", new Vector2Int(90, 35));
            animatedCharacter.animationDelay     = 0;
            animatedCharacter.Transform.position = new Vector2(0, 0);

            // ProcessRendererComponent processRenderer = EntityManager.AddEntity().AddComponent<ProcessRendererComponent>();
            // processRenderer.AttachProcess(Process.GetProcessById(6936).Handle);

            int iterations     = 0;
            int maxInterations = 20;

            while (game.IsRunning)
            {
                game.StartFrame();

                game.HandleEvents();
                game.Update();
                game.Render();

                game.WaitFrame();

                game.EndFrame();

                if (iterations++ >= maxInterations)
                {
                    WinApi.SetConsoleTitle("FPS : " + Math.Ceiling(1000 / game.FrameDuration.TotalMilliseconds));
                    iterations = 0;
                }
            }

            game.Clean();

            Console.ReadLine();
        }
Ejemplo n.º 4
0
        public PlayerEntity(Scene scene, Vector2 position, PlayerInfo player) : base(scene, EntityType.Game, position, bodyType: FarseerPhysics.Dynamics.BodyType.Dynamic)
        {
            var playerAnimationDefinition  = Scene.Game.Content.LoadFromJson <AnimationDefintion>("Animations/player_anim");
            var scareAnimDefinition        = Scene.Game.Content.LoadFromJson <AnimationDefintion>("Animations/scare_anim");
            var attractAnimationDefinition = Scene.Game.Content.LoadFromJson <AnimationDefintion>("Animations/attract_anim");

            this.PlayerInfo = player;
            switch (player.Color)
            {
            case PlayerColors.Green:
                playerAnimationDefinition.AssetName = "player_green_anim";
                break;

            case PlayerColors.Pink:
                playerAnimationDefinition.AssetName = "player_pink_anim";
                break;

            case PlayerColors.Purple:
                playerAnimationDefinition.AssetName = "player_purple_anim";
                break;

            case PlayerColors.Yellow:
                playerAnimationDefinition.AssetName = "player_yellow_anim";
                break;

            default:
                playerAnimationDefinition.AssetName = "player_yellow_anim";
                break;
            }



            AddComponent(playerAnim  = new AnimatedSpriteComponent(playerAnimationDefinition, new Vector2(1.0f, 1.0f), new Vector2(0.5f, 0.5f), name: "playerAnim"));
            AddComponent(attractAnim = new AnimatedSpriteComponent(attractAnimationDefinition, new Vector2(3.0f, 3.0f), new Vector2(0.5f, 0.5f), name: "attractAnim"));
            AddComponent(scareAnim   = new AnimatedSpriteComponent(scareAnimDefinition, new Vector2(5.0f, 5.0f), new Vector2(0.5f, 0.5f), name: "scareAnim"));

            AddComponent(scoreComponent = new ScoreComponent(player.Color.GetColor(), name: "score"));

            AddComponent(new PhysicsComponent(new CircleShape(0.25f, 1)));
            AddComponent(new PlayerControllerComponent(player));
            AddComponent(new AudioSourceComponent(new [] { "Audio/Hit1", "Audio/Hit2", "Audio/Hit3" }, new string[] {}));
        }