コード例 #1
0
        public void AnonymousEntitiesDoNotHaveEqualNames()
        {
            Scene scene = new Scene("Test Scene");
            scene.AddEntity(new Entity());
            scene.AddEntity(new Entity());

            Assert.AreEqual(2, scene.Entities.Count);
        }
コード例 #2
0
ファイル: SceneTests.cs プロジェクト: kinectitude/kinectitude
        public void AddEntity()
        {
            bool collectionChanged = false;

            Scene scene = new Scene("Test Scene");
            scene.Entities.CollectionChanged += (o, e) => collectionChanged = true;

            Entity entity = new Entity();
            scene.AddEntity(entity);

            Assert.IsTrue(collectionChanged);
            Assert.AreEqual(1, scene.Entities.Count());
        }
コード例 #3
0
ファイル: SceneTests.cs プロジェクト: kinectitude/kinectitude
        public void RemoveEntity()
        {
            int eventsFired = 0;

            Scene scene = new Scene("Test Scene");
            scene.Entities.CollectionChanged += (o, e) => eventsFired++;

            Entity entity = new Entity();
            scene.AddEntity(entity);
            scene.RemoveEntity(entity);

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(0, scene.Entities.Count());
        }
コード例 #4
0
 public static void PlayOneShot(string spriteName, string animName, int x, int y, Scene scene, int layer)
 {
     Entity entity = new Entity();
     entity.posX = x;
     entity.posY = y;
     entity.scene = scene;
     scene.AddEntity(entity);
     entity.layer = layer;
     entity.SetSprite(spriteName);
     entity.sprite.PlayAnimation(animName);
     entity.sprite.SetAnimCompleteCallback(delegate {
         scene.RemoveEntity(entity);
     });
 }
コード例 #5
0
    public static void PlayOneShot(string spriteName, string animName, int x, int y, Scene scene, int layer)
    {
        Entity entity = new Entity();

        entity.posX  = x;
        entity.posY  = y;
        entity.scene = scene;
        scene.AddEntity(entity);
        entity.layer = layer;
        entity.SetSprite(spriteName);
        entity.sprite.PlayAnimation(animName);
        entity.sprite.SetAnimCompleteCallback(delegate {
            scene.RemoveEntity(entity);
        });
    }
コード例 #6
0
ファイル: Doctor.cs プロジェクト: Fungeey/IceCreamJam
        public override void OnDeath()
        {
            // Spawn death animation
            var deathAnimation = Scene.AddEntity(new AnimatedEntity());

            deathAnimation.Position = Position;

            var texture = Scene.Content.LoadTexture(ContentPaths.Doctor + "DocDeath.png");
            var sprites = Sprite.SpritesFromAtlas(texture, 48, 32);

            deathAnimation.animator.AddAnimation("Death", 20, sprites.ToArray());
            deathAnimation.animator.Play("Death", SpriteAnimator.LoopMode.ClampForever);

            Pool <Doctor> .Free(this);
        }
コード例 #7
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            Scene = Scene.CreateWithDefaultRenderer(Color.CornflowerBlue);

            Scene.SetDesignResolution(DesignWidth, DesignHeight, Scene.SceneResolutionPolicy.ShowAllPixelPerfect);

            Screen.SetSize(DesignWidth * 3, DesignHeight * 3);

            //Scene.AddEntity(new Level("Level1"));
            //Scene.AddEntity(new Camera)

            Scene.AddEntity(new HUD());
        }
コード例 #8
0
        public override void OnAddedToScene()
        {
            base.OnAddedToScene();
            var coneTexture = Scene.Content.LoadTexture(ContentPaths.Scoop_Cone);

            coneDecal = Scene.AddEntity(new SpriteEntity(coneTexture, Constants.RenderLayer_Truck, 0.5f));
            coneDecal.ToggleVisible(defaultVisible);
            coneSpring = coneDecal.AddComponent(new EntitySpringComponent(this, weaponMountOffset, 5));

            shootFX = Scene.AddEntity(new AnimatedEntity());
            AddFXAnimation();
            shootFX.ToggleVisible(defaultVisible);

            playerMove = weaponComponent.GetComponent <PlayerMovementComponent>();
        }
コード例 #9
0
ファイル: SpawnerComponent.cs プロジェクト: Octanum/Corvus
        public Entity Spawn()
        {
            int    index  = RandomNumber(SpawnRangeMin, SpawnRangeMax + 1);//EntitiesToSpawn.Count());
            Entity entity = CorvEngine.Components.Blueprints.EntityBlueprint.GetBlueprint(EntitiesToSpawn[index]).CreateEntity();

            entity.Position = this.Parent.Position;
            entity.Size     = EntitySize;
            Scene.AddEntity(entity);

            if (OnEnemySpawn != null)
            {
                OnEnemySpawn(this, new EnemySpawnedEvent(entity));
            }
            return(entity);
        }
コード例 #10
0
        public Scene GameplayScene(Gameplay gameplay)
        {
            var scene = new Scene();

            scene.AddAsset(new Asset <Texture2D>("tile"));
            scene.AddAsset(new Asset <Texture2D>("player"));
            scene.AddAsset(new Asset <Texture2D>("tile_placer"));
            scene.AddAsset(new Asset <Texture2D>("lettertiles"));
            scene.AddAsset(new Asset <Texture2D>("crystals"));
            scene.AddAsset(new Asset <Texture2D>("stairs"));
            scene.AddAsset(new Asset <Texture2D>("rocks"));
            scene.AddAsset(new Asset <Texture2D>("btoy"));
            scene.AddAsset(new Asset <SpriteFont>("Font"));

            SpriteLayers.Setup(scene);

            scene.AddEntity(new GameplayControllerEntity(gameplay));
            scene.AddEntity(new DungeonLevelDisplay(gameplay));
            scene.AddEntity(new PlayerEntity(gameplay));
            scene.AddEntity(new TilePlacerEntity(gameplay));
            scene.AddEntity(new Hud(gameplay));

            return(scene);
        }
コード例 #11
0
        private void Shoot()
        {
            if (Scene == null)       // Don't continue shooting if doctor is dead
            {
                return;
            }

            var knife = Pool <DoctorKnife> .Obtain();

            knife.Initialize(shootDirection, Position);

            if (knife.IsNewProjectile)
            {
                Scene.AddEntity(knife);
            }
        }
コード例 #12
0
ファイル: Grid.cs プロジェクト: barrage125/MyFirstNez
        //Populates Grid with Tile entities. Public for testing purposes
        public void BuildGrid()
        {
            currentWidth  = Nez.Random.NextInt(Width.Maximum - Width.Minimum) + Width.Minimum;
            currentHeight = Nez.Random.NextInt(Height.Maximum - Height.Minimum) + Height.Minimum;

            for (int x = 0; x < currentWidth; x++)
            {
                for (int y = 0; y < currentHeight; y++)
                {
                    Scene.AddEntity(new Tile(x, y, this));
                }
            }

            Transform.SetPosition((Screen.Width - ((currentWidth) * tileSize)) / 2, (Screen.Height - ((currentHeight) * tileSize)) / 2);
            Debug.DrawHollowRect(new Rectangle((int)Position.X, (int)Position.Y, currentWidth * tileSize, currentHeight * tileSize), Color.Green, 100000);
        }
コード例 #13
0
            private void CreateRotatingText()
            {
                var text = new Entity();

                text.AddComponent(Transform2DComponent.CreateDefault());
                text.AddComponent(new TextRendererComponent {
                    Text = "I am Text!", Color = Color.FromArgb(255, 0, 255, 0), FontSize = FontSize.FromPoints(16)
                });
                text.AddComponent(new FollowEllipseComponent {
                    Velocity = 1, Width = 300, Height = 300
                });
                text.AddComponent(new RotateComponent());
                text.AddComponent(new DoMagicWithTextComponent());

                Scene.AddEntity(text);
            }
コード例 #14
0
ファイル: Example2.cs プロジェクト: MeLikeyCode/Tergie
        public static void Start()
        {
            Scene scene = new Scene(80, 30);

            Entity entity = new Entity(Utils.GetTestGraphics());

            scene.AddEntity(entity);

            // make the entity move in its Update() method
            entity.Updated += (sender, dt) =>
            {
                entity.Pos.X += 1 * dt;
            };

            Game.Start(scene, 80, 30);
        }
コード例 #15
0
            private void CreateKeyText()
            {
                var text = new Entity();

                text.AddComponent(Transform2DComponent.CreateDefault());
                text.AddComponent(new TextRendererComponent
                {
                    Color            = Color.FromArgb(255, 255, 0, 255),
                    FontSize         = FontSize.FromDips(25),
                    SortingLayerName = "UI"
                });
                text.AddComponent(new InputComponent());
                text.AddComponent(new SetTextForCurrentKeyComponent());

                Scene.AddEntity(text);
            }
コード例 #16
0
 /// <summary>
 /// Add entity to scene
 /// </summary>
 /// <param name="pEntity">Entity to add</param>
 /// <param name="pName">Name of the scene to add to, if blank will add entity to the current scene</param>
 public void AddToScene(Entity pEntity, string pName = null)
 {
     if (pName == null)
     {
         _current.AddEntity(pEntity);
         _entityManager.AddEntity(pEntity);
     }
     else
     {
         _scenes[pName].AddEntity(pEntity);
         if (_scenes[pName] == _current)
         {
             _entityManager.AddEntity(pEntity);
         }
     }
 }
コード例 #17
0
        public override void OnAddedToScene()
        {
            base.OnAddedToScene();

            var popsicleTexture = Scene.Content.LoadTexture(ContentPaths.Popsicle + "Popsicle_Basic.png");

            this.loadedPopsicle = Scene.AddEntity(new SpriteEntity(popsicleTexture, Constants.Layer_WeaponOver, 0.5f));
            this.loadedPopsicle.ToggleVisible(this.defaultVisible);

            this.shatterFX = Scene.AddEntity(new AnimatedEntity());
            AddFXAnimation();
            shatterFX.ToggleVisible(false);
            shatterFX.animator.RenderLayer = Constants.Layer_WeaponOver;
            shatterFX.animator.LayerDepth  = 0.4f;
            shatterFX.animator.OnAnimationCompletedEvent += (s) => ReloadPopsicle();
        }
コード例 #18
0
        internal static Scene Create(Gameplay gp)
        {
            var scene = new Scene();

            scene.AddAsset(new Asset <SpriteFont>("ProtoFont"));


            scene.AddSpriteLayer(new SpriteLayer(SpriteLayers.Default));

            var l = new Entity();

            l.AddComponent(new TextSprite("ProtoFont", "Main Menu", SpriteLayers.Default));
            scene.AddEntity(l);


            return(scene);
        }
コード例 #19
0
            private void CreateCamera()
            {
                var camera = new Entity();

                camera.AddComponent(new Transform2DComponent
                {
                    Translation = new Vector2(0, 0),
                    Rotation    = 0,
                    Scale       = Vector2.One
                });
                camera.AddComponent(new CameraComponent {
                    ViewRectangle = new Vector2(1600, 900), AspectRatioBehavior = AspectRatioBehavior.Underscan
                });
                camera.AddComponent(new TopDownCameraForBoxComponent());

                Scene.AddEntity(camera);
            }
コード例 #20
0
            public Entity CreateSprite(Scene scene, AssetId spriteAssetId, Vector2?translation = null, double rotation = 0, Vector2?scale = null)
            {
                var entity = new Entity();

                entity.AddComponent(new Transform2DComponent
                {
                    Translation = translation ?? Vector2.Zero,
                    Rotation    = rotation,
                    Scale       = scale ?? Vector2.One
                });
                entity.AddComponent(new SpriteRendererComponent
                {
                    Sprite = _assetStore.GetAsset <Sprite>(spriteAssetId)
                });
                scene.AddEntity(entity);

                return(entity);
            }
コード例 #21
0
            public Entity CreateCamera(Scene scene)
            {
                var entity = new Entity();

                entity.AddComponent(new Transform2DComponent
                {
                    Translation = Vector2.Zero,
                    Rotation    = 0,
                    Scale       = Vector2.One
                });
                entity.AddComponent(new CameraComponent
                {
                    ViewRectangle = new Vector2(200, 200)
                });
                scene.AddEntity(entity);

                return(entity);
            }
コード例 #22
0
        public static Scene Create(object param)
        {
            var scene = new Scene();

            var fader = Entity.Empty
                        .ScaleTo(1920, 1080)
                        .AddSpriteRenderer("Textures/empty", color: Color.Black, origin: Vector2.Zero)
                        .AddComponent(new FadeInSprite())
                        .AddAudioSource("Songs/DarkTimes", autoPlay: true, loop: true)
                        .AddComponent(new FadeInAudio());

            scene
            .AddEntity(new Background("Textures/title"))
            .AddEntity(new MainMenu(fader))
            .AddEntity(fader);

            return(scene);
        }
コード例 #23
0
 /// <summary>
 /// Adds colliders to each non-walkable tile of the scene.
 /// </summary>
 /// <param name="scene"></param>
 /// <param name="context"></param>
 public static void AddTileColliders(Scene scene, Context context)
 {
     for (int i = 0; i < scene.Tiles.Width; i++)
     {
         for (int j = 0; j < scene.Tiles.Height; j++)
         {
             if (!scene.Tiles[i, j].Walkable)
             {
                 Entity dummy = new Entity(context)
                 {
                     Position = new Vector3(i + 0.5f, j + 0.5f, 0)
                 };
                 dummy.Collider = new RectangleCollider(dummy, false, 1, 1);
                 scene.AddEntity(dummy);
             }
         }
     }
 }
コード例 #24
0
            public Entity AddCamera(Transform2DComponent?transformComponent = null)
            {
                var entity = new Entity();

                entity.AddComponent(transformComponent ?? Transform2DComponent.CreateDefault());
                entity.AddComponent(new CameraComponent
                {
                    ViewRectangle = new Vector2(ScreenWidth, ScreenHeight)
                });
                _scene.AddEntity(entity);

                return(entity);
            }
コード例 #25
0
        /// <summary>Updates the particle system state.</summary>
        /// <param name="t">The total game time, in seconds.</param>
        /// <param name="dt">The time, in seconds, since the last call to this method.</param>
        public override void Draw(float t, float dt)
        {
            // We're doing this in the draw method because we don't care about physical accuracy here,
            // we just want to render nice effects.
            base.Draw(t, dt);

            foreach (var cb in mPartsToSpawn)
            {
                var eid = Scene.AddEntity();

                var components = cb();
                foreach (var component in cb())
                {
                    Scene.AddComponent(eid, component, component.GetType());
                }
            }

            mPartsToSpawn.Clear();
            mPartsToRemove.Clear();

            foreach (var e in Scene.GetComponents <CParticle>())
            {
                var part = (CParticle)e.Value;

                part.Life -= dt;
                if (part.Life <= 0.0f)
                {
                    mPartsToRemove.Add(e.Key);
                    continue;
                }

                // Symplectic Euler is definitely ok for particles.
                part.Velocity += dt * part.F();
                part.Position += dt * part.Velocity;

                // Not sure what else to do. Need to update transform to match physical part position.
                ((CTransform)Scene.GetComponentFromEntity <CTransform>(e.Key)).Position = part.Position;
            }

            foreach (var eid in mPartsToRemove)
            {
                Scene.RemoveEntity(eid);
            }
        }
コード例 #26
0
        public Scene GameStartScene(Gameplay gameplay)
        {
            var scene = new Scene();

            scene.AddAsset(new Asset <SpriteFont>("Font"));
            SpriteLayers.Setup(scene);

            var text =
                @"Wordgeon Descent - The Search for the Blank Tile of Yendor

You are Kenney Letter, a Wizard of Letters and Words. You have
mastered converting crystals in to letter tiles which allow
you to traverse the lava dungeons of Wordgeon, that is, so long as
you arrange the the letter tiles into proper connected words.

Legend tells of a blank tile deep in the Wordgeon dungeon. This
so called Blank Tile o Yendor has the power to free letter tile
wizardry from having to arrage tiles in to proper words.

It is your quest to descend the lava dungeon of Wordgeon and find the
blank tile. Be careful to collect crystals as you go so that you don't
run out of letter tiles that would leave you stuck in the depths of
the dungeon.

Good luck!

Press [Enter] to start...
";

            var e = new Entity();

            e.Position = new Microsoft.Xna.Framework.Vector2(100, 300);
            e.AddComponent(new TextSprite("Font", text, SpriteLayers.Default));
            scene.AddEntity(e);
            e.AddComponent(new RelayBehavior(() =>
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                {
                    scene.Load(nameof(GameplayScene), gameplay);
                }
            }));

            return(scene);
        }
コード例 #27
0
        public override void OnAddedToScene()
        {
            base.OnAddedToScene();

            tileMap = Core.Content.LoadTiledMap(System.IO.Path.Combine(
                                                    Core.Content.RootDirectory,
                                                    "Levels/TileMap1.tmx"));

            tileMapRenderer = AddComponent(new TiledMapRenderer(tileMap));

            tileMapRenderer.SetLayersToRender(new string[] { "Foreground", "Background" });

            tileMapRenderer.PhysicsLayer = (int)Physics.PhysicsLayer.Collidable;

            tileMapRenderer.CollisionLayer = tileMap.GetLayer <TmxLayer>("Collision");

            tileMapRenderer.AddColliders();

            tileMapRenderer.LayerDepth = 1;

            TmxObjectGroup objectsLayer = tileMap.GetObjectGroup("Objects");

            objectsLayer.Visible = false;

            foreach (TmxObject obj in objectsLayer.Objects)
            {
                switch (obj.Type)
                {
                case AvatarObjectType:
                    Avatar avatar = Scene.AddEntity(new Avatar(obj.Position() + TiledObjectOffset));
                    Scene.Camera.AddComponent(new FollowCamera(avatar, FollowCamera.CameraStyle.LockOn));
                    break;

                case SlimeObjectType:
                    Slime slime = Scene.AddEntity(
                        new Slime(
                            obj.Position() + TiledObjectOffset,
                            obj.FullName()));

                    break;
                }
            }
        }
コード例 #28
0
            private void CreateRectangle(double x, double y, double w, double h, bool fillInterior = true)
            {
                var rectangle = new Entity();

                rectangle.AddComponent(new Transform2DComponent
                {
                    Translation = new Vector2(x, y),
                    Rotation    = 0,
                    Scale       = Vector2.One
                });
                rectangle.AddComponent(new RectangleRendererComponent
                {
                    Dimension    = new Vector2(w, h),
                    Color        = Color.FromArgb(255, 0, 0, 255),
                    FillInterior = fillInterior
                });

                Scene.AddEntity(rectangle);
            }
コード例 #29
0
 public void Update(PartyMember partyMember, Delta delta)
 {
     particleTimer += delta.Time;
     if (particleTimer >= particleTime)
     {
         particleTimer = 0.0f;
         Rectangle boundingBox = partyMember.BattleEntity.GetBoundingBox();
         float     x           = boundingBox.X + (boundingBox.Width / 2) + Game1.Random.Next(boundingBox.Width / 2) - (boundingBox.Width / 4);
         float     y           = boundingBox.Y + (boundingBox.Height / 2) + (Game1.Random.Next(boundingBox.Height / 4) - (boundingBox.Height / 8));
         if (textureData != null)
         {
             Scene.AddEntity(new FloatingParticle(new Vector2(x, y), new Vector2(0.0f, -200.0f), new Vector2(0.3f), 1.4f, textureData));
         }
         else if (text != null)
         {
             Scene.AddEntity(new FloatingText(text, textColor, new Vector2(x, y), 3.0f, true));
         }
     }
 }
コード例 #30
0
        public Entity CreateStaticSprite(Scene scene, double x, double y)
        {
            var entity = new Entity();

            scene.AddEntity(entity);

            entity.AddComponent(new Transform2DComponent
            {
                Translation = new Vector2(x, y),
                Rotation    = 0,
                Scale       = Vector2.One
            });
            entity.AddComponent(new SpriteRendererComponent
            {
                Sprite = _assetStore.GetAsset <Sprite>(AssetsIds.PaintColorPalette)
            });

            return(entity);
        }
コード例 #31
0
        public void TryToSpawnCar()
        {
            if (cars.Count >= targetCarNumber)
            {
                spawnRoutine.Stop();
                return;
            }

            foreach (Vector2 spawnPoint in spawnPoints.Shuffle())
            {
                if (Physics.OverlapCircle(spawnPoint, 100) == null)
                {
                    Scene.AddEntity(new CivilianCar(this)
                    {
                        Position = spawnPoint
                    });
                    return;
                }
            }
        }
コード例 #32
0
        public override void Update()
        {
            TotalTime += Time.DeltaTime;
            double diff = Math.Round(StartTime - TotalTime, 2);

            if (diff <= 0)
            {
                if (this != null)
                {
                    Scene.AddEntity(new AbilityAnimationEntity(ability, target, source));
                    channelBarWindow.RemoveElements();
                    Scene.RemoveSceneComponent <ChannelBarComponent>();
                }
            }
            else
            {
                channelBarWindow.UpdateBar((TotalTime / StartTime), (float)Math.Round((StartTime - TotalTime), 3));
            }
            base.Update();
        }
コード例 #33
0
            private void CreateEllipse(double x, double y, double radiusX, double radiusY, bool fillInterior = true)
            {
                var rectangle = new Entity();

                rectangle.AddComponent(new Transform2DComponent
                {
                    Translation = new Vector2(x, y),
                    Rotation    = 0,
                    Scale       = Vector2.One
                });
                rectangle.AddComponent(new EllipseRendererComponent
                {
                    RadiusX      = radiusX,
                    RadiusY      = radiusY,
                    Color        = Color.FromArgb(255, 0, 0, 255),
                    FillInterior = fillInterior
                });

                Scene.AddEntity(rectangle);
            }
コード例 #34
0
        public void Load(string filePath)
        {
            TmxMap map   = Scene.Content.LoadTiledMap(filePath);
            var    layer = map.GetLayer <TmxLayer>(Constants.TiledLayerBuildings);

            Scene.AddEntity(new TiledMap(map));

            //foreach(TmxLayerTile t in layer.Tiles) {
            //    if(t == null)
            //        continue;
            //
            //    t.TilesetTile.Properties.TryGetValue(Constants.TiledPropertyID, out var value);
            //
            //    Building b;
            //    if(value == "Building") {
            //        b = Scene.AddEntity(new Building());
            //        b.Position = map.TileToWorldPosition(t.Position);
            //    }
            //}
        }
コード例 #35
0
        public SceneViewModel(Scene scene)
        {
            this.scene = scene;

            Entities = new ComputedObservableCollection<Entity, EntityViewModel>(scene.Entities, (entity) => new EntityViewModel(entity));

            scene.PropertyChanged += Scene_PropertyChanged;

            AddAttributeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    scene.CreateAttribute();
                }
            );

            RemoveAttributeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Attribute attribute = parameter as Attribute;
                    scene.RemoveAttribute(attribute);
                }
            );

            AddEntityCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity entity = new Entity();
                    scene.AddEntity(entity);
                }
            );

            RemoveEntityCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity entity = parameter as Entity;
                    scene.RemoveEntity(entity);
                }
            );
        }
コード例 #36
0
        private Scene CreateScene(ParseTreeNode node)
        {
            Scene scene = new Scene(grammar.GetName(node));

            foreach (Tuple<string, object> attribute in GetProperties(node))
            {
                ParseTreeNode attributeNode = (ParseTreeNode)attribute.Item2;
                scene.AddAttribute(new Attribute(attribute.Item1) { Value = new Value(getStrVal(attributeNode)) });
            }

            foreach (ParseTreeNode managerNode in grammar.GetOfType(node, grammar.Manager))
            {
                Manager manager = CreateManager(managerNode);
                scene.AddManager(manager);
            }

            foreach (ParseTreeNode entityNode in grammar.GetOfType(node, grammar.Entity))
            {
                Entity entity = CreateEntity(entityNode, scene, false);
                scene.AddEntity(entity);
            }

            return scene;
        }
コード例 #37
0
        public void CannotRenameToDuplicateNameInSameScope()
        {
            Game game = new Game("Test Game");
            game.AddPrototype(new Entity() { Name = "TestEntity" });

            Scene scene = new Scene("Test Scene");

            Entity entity = new Entity() { Name = "TestEntity2" };
            scene.AddEntity(entity);

            game.AddScene(scene);

            entity.Name = "TestEntity";

            Assert.AreEqual(1, scene.Entities.Count);
            Assert.AreEqual("TestEntity2", entity.Name);
        }
コード例 #38
0
        public void CanAddDuplicateNameInDifferentScope()
        {
            Game game = new Game("Test Game");

            Scene scene1 = new Scene("Test Scene");

            Entity entity1 = new Entity() { Name = "TestEntity" };
            scene1.AddEntity(entity1);

            game.AddScene(scene1);

            Scene scene2 = new Scene("Test Scene 2");

            Entity entity2 = new Entity() { Name = "TestEntity" };
            scene2.AddEntity(entity2);

            game.AddScene(scene2);

            Assert.AreEqual(1, scene1.Entities.Count);
            Assert.AreEqual(1, scene2.Entities.Count);
        }
コード例 #39
0
ファイル: Game1.cs プロジェクト: konlil/pipe
        protected override void Initialize()
        {
            base.Initialize();

            main_ui = new MainUI(this);
            main_ui.Initialize();

            scene = new Scene(this, 0, "test");
            Scm.AddScene(scene);
            Scm.SetActiveScene(scene);

            /*
            Vector3 camera_position = new Vector3(0, 10, 51);
            Vector3 camera_target = camera_position + Vector3.Forward;
            Camera cam = new Camera();
            cam.Initialize();
            cam.Fov = MathHelper.PiOver4;
            scene.ActiveCamera = cam;
             */
            camera = new Camera(this);
            scene.ActiveCamera = camera;

            //camera_ctrl = new FpsCameraController(this);
            //cam.AttachController(camera_ctrl);
            //camera_ctrl.Enabled = true;

            //////////////////////////////////////////////////////////////////////////
            Axis axis = new Axis(this);
            axis.Initialize();
            scene.AddEntity(axis);

            axis.Pose.SetScale(10, 10, 10);

            ////////////////////////////////��������ķָ���//////////////////////////////////////////
            Terrain terrain = new Terrain(this, "Textures\\flat_map", null);
            terrain.Initialize();
            scene.AddEntity(terrain);

            camera.Target = new Vector3(terrain.WidthInPixel / 2.0f, 0, -terrain.HeightInPixel / 2.0f);
            //camera.Target = new Vector3(0, 0, 0);

            //////////////////////////////////////////////////////////////////////////
            //Quad s1 = new Quad(this);
            //s1.Initialize();
            //scene.AddEntity(s1);

            //s1.Pose.SetPosition(0, 0, 0);
            //s1.Pose.SetScale(4, 4, 1);

            //////////////////////////////////////////////////////////////////////////
            //Avatar a1 = new Avatar(this, "Models\\p1_wedge");
            //a1.Initialize();
            //scene.AddEntity(a1);

            //a1.pose.SetPosition(10, 20, -10);
            //a1.pose.SetScale(0.01f, 0.01f, 0.01f);

            //////////////////////////////////////////////////////////////////////////
            Light l1 = new Light(this, new Vector3(0.0f, 1.0f, 0.0f), new Vector3(1.0f, -1.0f, -1.0f));
            scene.AddLight(l1);

            //////////////////////////////////////////////////////////////////////////
            Box b1 = new Box(this);
            b1.Initialize();
            b1.SetScale(10.0f, 10.0f, 10.0f);
            b1.SetPosition(100, 10, -100);
            scene.AddEntity(b1);

            Box b2 = new Box(this);
            b2.Initialize();
            b2.SetScale(10, 10, 10);
            b2.SetPosition(150, 10, -150);
            scene.AddEntity(b2);

            //////////////////////////////////////////////////////////////////////////
            float bx = 200;
            float by = 20;
            float bz = -200;

               // Sphere s1 = new Sphere(this);
               // s1.Initialize();
               // s1.SetScale(10, 10, 10);
               // s1.SetPosition(bx + 0.0442591f, by + 0.017970f, bz + 0.045182f);
               // s1.ModelFile = "Models\\SphereLowPoly";
               // scene.AddEntity(s1);

            Axis a1 = new Axis(this);
            a1.Initialize();
            a1.SetScale(10, 10, 10);
            Matrix rot = new Matrix();
            rot.M11 = 9.9994452992e-001f; rot.M12 = 2.8077475493e-003f; rot.M13 = 1.0151533926e-002f;
            rot.M21 = -2.8522679263e-003f; rot.M22 = 9.9998636727e-001f; rot.M23 = 4.3737664750e-003f;
            rot.M31 = -1.0139115101e-002f; rot.M32 = -4.4024787564e-003f; rot.M33 = 9.9993890640e-001f;
            a1.SetRotation(rot);
            a1.SetPosition(bx + 0.0442591f, by + 0.017970f, bz + 0.045182f);
            scene.AddEntity(a1);

            //Sphere s2 = new Sphere(this);
            //s2.Initialize();
            //s2.SetScale(10, 10, 10);
            //s2.SetPosition(bx -0.028148f, by -0.875799f, bz-0.436862f);
            //s2.ModelFile = "Models\\SphereLowPoly";
            //scene.AddEntity(s2);

            Axis a2 = new Axis(this);
            a2.Initialize();
            a2.SetScale(10, 10, 10);
            Matrix rot2 = new Matrix();
            rot2.M11 = 9.9927846095e-001f; rot2.M12 = -2.9406460387e-002f; rot2.M13 = -2.4037836360e-002f;
            rot2.M21 = 2.3013993637e-002f; rot2.M22 = 9.7227461380e-001f; rot2.M23 = -2.3270674991e-001f;
            rot2.M31 = 3.0214459887e-002f; rot2.M32 = 2.3198563629e-001f; rot2.M33 = 9.7224983979e-001f;
            a1.SetRotation(rot2);
            a2.SetPosition(bx-0.028148f, by-0.875799f, bz-0.436862f);
            scene.AddEntity(a2);

            //////////////////////////////////////////////////////////////////////////

            GenericMaterial mat_b2 = new GenericMaterial(this, "Effects\\generic");
            mat_b2.CurrentTechniqueName = "TGeneric";
            mat_b2.DiffuseTextureName = "Textures\\wood";
            mat_b2.EmissiveColor = new Vector3(0.1f, 0.1f, 0.1f);
            mat_b2.SpecularColor = new Vector3(0.0f, 1.0f, 0.0f);
            mat_b2.SpecularPower = 60.0f;
            mat_b2.FogEnabled = true;

            b2.Context.Material = mat_b2;
        }
コード例 #40
0
        // Multiple inheritance tests
        private static Game CreateTestGame()
        {
            var game = new Game("Test Game");

            var prototypeA0 = new Entity() { Name = "prototypeA0" };
            game.AddPrototype(prototypeA0);
            var prototypeB0 = new Entity() { Name = "prototypeB0" };
            game.AddPrototype(prototypeB0);
            var prototypeC0 = new Entity() { Name = "prototypeC0" };
            game.AddPrototype(prototypeC0);

            var prototypeA1 = new Entity() { Name = "prototypeA1" };
            prototypeA1.AddPrototype(prototypeA0);
            game.AddPrototype(prototypeA1);

            var prototypeB1 = new Entity() { Name = "prototypeB1" };
            prototypeB1.AddPrototype(prototypeB0);
            prototypeB1.AddPrototype(prototypeC0);
            game.AddPrototype(prototypeB1);

            var scene = new Scene("Test Scene");
            game.FirstScene = scene;
            var testEntity = new Entity() { Name = "testEntity" };
            scene.AddEntity(testEntity);
            testEntity.AddPrototype(prototypeA1);
            testEntity.AddPrototype(prototypeB1);

            return game;
        }
コード例 #41
0
        public void Scene_RemoveEntity()
        {
            var scene = new Scene("Test Scene");
            var entity = new Entity();
            scene.AddEntity(entity);

            CommandHelper.TestUndoableCommand(
                () => Assert.AreEqual(1, scene.Entities.Count),
                () => scene.RemoveEntityCommand.Execute(entity),
                () => Assert.AreEqual(0, scene.Entities.Count)
            );
        }
コード例 #42
0
        public void Scene_Delete()
        {
            var scene = new Scene("Test Scene");
            var entity = new Entity();
            scene.AddEntity(entity);

            CommandHelper.TestUndoableCommand(
                () => Assert.AreEqual(1, scene.EntityPresenters.Count),
                () => scene.DeleteCommand.Execute(Enumerable.Repeat(scene.EntityPresenters.First(), 1)),
                () => Assert.AreEqual(0, scene.EntityPresenters.Count)
            );
        }