예제 #1
0
        public static GameObject[] CreateEnemy(Vector3 position)
        {
            if (!init)
            {
                init      = true;
                headTex   = TextureLoader.FileToTexture("assets/textures/enemyHead.jpg");
                bulletTex = TextureLoader.ColorToTexture(Color.Red);
            }

            Mesh enemyHeadModel = enemyhead_prefab.Copy();
            Mesh enemyModel     = enemy_prefab.Copy();
            Mesh bullet         = bullet_prefab.Copy();


            GameObject enemyHead = new GameObject(new Vector3(0, 0.5f, 0), "Nozzle");
            GameObject enemy     = new GameObject(position, "Enemy");
            Collider   collider  = new Collider(new Sphere(Vector3.Zero, 1, 1), "physics");

            collider.PhysicsCollider.Material      = new Material(10, 10, 0);
            collider.PhysicsCollider.LinearDamping = 0.99f;
            enemy.AddComponent(collider);


            //Movement for Player Head
            OffsetConstraint connection = new OffsetConstraint()
            {
                Damping   = 0,  //Directly over the moving collider, no inertia
                MoveSpeed = 20, //Even less inertia by moving faster in general
            };

            connection.Attach(enemy, Vector3.UnitY * 1);

            enemyHead.AddComponent(connection);
            enemyHead.Scale = new Vector3(0.6f);


            enemyHead.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, enemyHeadModel,
                                                                headTex, 1));
            enemy.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, enemyModel,
                                                            TextureGenerator.GetPlayerTexture(), 1));

            enemy.AddComponent(new EnemyComponent(enemyHead, bullet, DefaultFilepaths.DefaultLitShader, 50, false));


            return(new[] { enemy, enemyHead });
        }
예제 #2
0
        public static GameObject[] CreatePlayer(Vector3 position, BasicCamera cam)
        {
            Mesh mouseTargetModel = MeshLoader.FileToMesh("assets/models/sphere_smooth.obj");


            GameObject mouseTarget = new GameObject(Vector3.UnitY * -3, "BG");

            mouseTarget.Scale = new Vector3(1, 1, 1);
            mouseTarget.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, mouseTargetModel,
                                                                  Prefabs.White, 1));

            Mesh playerModel = MeshLoader.FileToMesh("assets/models/sphere_smooth.obj");
            Mesh headModel   = MeshLoader.FileToMesh("assets/models/cube_flat.obj");
            Mesh bullet      = MeshLoader.FileToMesh("assets/models/cube_flat.obj");


            GameObject player  = new GameObject(new Vector3(0, 10, 0), "Player");
            GameObject playerH = new GameObject(new Vector3(0, 10, 0), "PlayerHead");
            GameObject lightS  = new GameObject(Vector3.UnitY * 2f, "Light");

            playerH.Add(lightS);
            lightS.AddComponent(new LightComponent()
            {
                AmbientContribution = 0f
            });
            lightS.LocalPosition = Vector3.UnitY * 14f;



            //Movement for camera
            OffsetConstraint cameraController = new OffsetConstraint {
                Damping = 0, MoveSpeed = 2
            };

            cameraController.Attach(player, new Vector3(0, 15, 5));
            cam.AddComponent(cameraController);

            //Rotation for Player Head depending on mouse position
            cam.AddComponent(new CameraRaycaster(mouseTarget, playerH));

            //Movement for Player Head
            OffsetConstraint connection = new OffsetConstraint()
            {
                Damping   = 0,  //Directly over the moving collider, no inertia
                MoveSpeed = 20, //Even less inertia by moving faster in general
            };

            connection.Attach(player, Vector3.UnitY * 1);
            playerH.AddComponent(connection);
            playerH.Scale = new Vector3(0.6f);
            playerH.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, headModel,
                                                              TextureLoader.FileToTexture("assets/textures/playerHead.png"), 1));


            //Player Setup
            Collider collider = new Collider(new Sphere(Vector3.Zero, 1, 10), LayerManager.NameToLayer("physics"));

            collider.PhysicsCollider.PositionUpdateMode = PositionUpdateMode.Continuous;
            collider.PhysicsCollider.Material           = new Material(1.5f, 1.5f, 0);
            collider.PhysicsCollider.LinearDamping      = 0.99f;

            player.AddComponent(collider);


            player.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, playerModel,
                                                             TextureGenerator.GetPlayerTexture(), 1));

            AudioSourceComponent source = new AudioSourceComponent();

            AudioLoader.TryLoad("assets/audio/ShootSound.wav", out ShootSound);
            AudioLoader.TryLoad("assets/audio/ShootSound2.wav", out ShootSound2);
            AudioLoader.TryLoad("assets/audio/SpawnSound.wav", out SpawnSound);
            AudioLoader.TryLoad("assets/audio/JumpSound.wav", out JumpSound);
            source.Clip = SpawnSound;
            source.Play();
            source.UpdatePosition = false;
            source.Gain           = 0.5f;
            player.AddComponent(source);

            player.AddComponent(new PlayerController(playerH, bullet,
                                                     TextureLoader.ColorToTexture(Color.Red), DefaultFilepaths.DefaultLitShader, 650, false, source));
            player.LocalPosition = position;


            GameObject playerUI = new GameObject("PlayerHUD");

            playerUI.AddComponent(new PlayerHUD());


            return(new[] { player, playerH, playerUI });
        }