/// <summary> /// Initialize to implement per main type. /// </summary> override public void Initialize() { // create the scene GameScene scene = new GameScene(); // create camera object camera = new GameObject(); Camera cameraComponent = new Camera(); cameraComponent.CameraType = CameraType.Orthographic; Point screenSize = Managers.GraphicsManager.ViewportSize; float ratio = (float)screenSize.X / (float)screenSize.Y; cameraComponent.ForceScreenSize = new Point((int)(50f * ratio), (int)(25f * ratio)); camera.AddComponent(cameraComponent); camera.SceneNode.Position = new Vector3(50, 100, 150); camera.SceneNode.RotationX = -(float)System.Math.PI * 0.25f; camera.Parent = scene.Root; // create a tilemap fsor the floor TileMap tilemap = scene.Root.AddComponent(new TileMap(Vector2.One * 10f, 10)) as TileMap; // create floor material BasicMaterial tilesMaterial = new BasicMaterial(); tilesMaterial.Texture = Resources.GetTexture("game/floor"); tilesMaterial.TextureEnabled = true; tilesMaterial.SpecularColor = Color.Black; // create some floor tiles for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { GameObject tile = tilemap.GetTile(new Point(i, j)); ShapeRenderer tileModel = tile.AddComponent(new ShapeRenderer(ShapeMeshes.Plane)) as ShapeRenderer; tileModel.SetMaterial(tilesMaterial); tile.SceneNode.Scale = Vector3.One * 5f; tile.SceneNode.RotationX = (float)System.Math.PI * -0.5f; } } // create random grass sprites System.Random rand = new System.Random(); for (int i = 0; i < 100; ++i) { GameObject grassObj = new GameObject("grass"); grassObj.SceneNode.Scale = Vector3.One * 5; grassObj.SceneNode.Position = new Vector3((float)rand.NextDouble() * 90f, 2.5f, (float)rand.NextDouble() * 90f); grassObj.AddComponent(new BillboardRenderer("game/grass", faceCamera: false)); grassObj.Parent = scene.Root; } // create a tree GameObject treeObj = new GameObject("tree"); treeObj.SceneNode.Scale = Vector3.One * 30; treeObj.SceneNode.Position = new Vector3(50, 15f, 25); treeObj.AddComponent(new BillboardRenderer("game/tree", faceCamera: false)); treeObj.Parent = scene.Root; // create a spritesheet with animations (8 steps on X axis, 4 directions on Y axis) SpriteSheet sp = new SpriteSheet(new Point(8, 4)); // add character sprite GameObject spriteObj = new GameObject("player"); spriteObj.SceneNode.Scale = Vector3.One * 10; spriteObj.SceneNode.Position = new Vector3(50, 5, 50); spriteObj.AddComponent(new SpriteRenderer(sp, "game/rpg_sprite_walk", faceCamera: false)); spriteObj.Parent = scene.Root; // define walking animation and play on character SpriteAnimationClip animationClip = new SpriteAnimationClip(startStep: 0, endStep: 7, speed: 10f, loop: true); spriteObj.GetComponent <SpriteRenderer>().PlayAnimation(animationClip); // set scene GeonBitMain.Instance.Application.LoadScene(scene); }
/// <summary> /// Initialize to implement per main type. /// </summary> override public void Initialize() { // create the scene GameScene scene = new GameScene(); // create skybox Managers.GraphicsManager.CreateSkybox(null, scene.Root); Managers.Diagnostic.DebugRenderPhysics = false; // create camera object GameObject camera = new GameObject(); Camera cameraComponent = new Camera(); camera.AddComponent(cameraComponent); cameraComponent.LookAt = new Vector3(100, 2, 100); camera.SceneNode.Position = new Vector3(0, 5, 0); camera.AddComponent(new CameraEditorController()); camera.Parent = scene.Root; // create a tilemap for the floor TileMap tilemap = scene.Root.AddComponent(new TileMap(Vector2.One * 10f, 10)) as TileMap; // create floor material LitMaterial tilesMaterial = new LitMaterial(); tilesMaterial.Texture = Resources.GetTexture("game/floor"); tilesMaterial.TextureEnabled = true; tilesMaterial.SpecularColor = Color.Black; // set ambient light scene.Lights.AmbientLight = new Color(20, 20, 20, 255); // add robot model GameObject robot = new GameObject(); var robotRenderer = robot.AddComponent(new ModelRenderer("Game/robot")) as ModelRenderer; var robotMat = new LitMaterial(); robotMat.Texture = Resources.GetTexture("Game/robottexture_0"); robotMat.TextureEnabled = true; robotMat.DiffuseColor = Color.White; robotRenderer.SetMaterial(robotMat); robot.SceneNode.Scale = Vector3.One * tileSize * 0.75f; robot.SceneNode.Position = new Vector3(tilemapSize * tileSize * 0.5f, 10f, tilemapSize * tileSize * 0.5f); robot.Parent = scene.Root; // attach light to camera { var lightComponent = camera.AddComponent(new Light()) as Light; lightComponent.Intensity = 2f; lightComponent.Range = tileSize * 15f; lightComponent.Color = Color.Green; } // add directional light { var lightComponent = scene.Root.AddComponent(new Light()) as Light; lightComponent.Intensity = 0.25f; lightComponent.Range = 0f; lightComponent.Direction = Vector3.Normalize(new Vector3(0.2f, 1f, 0.1f)); lightComponent.Color = Color.White; } // attach lights lightsCenter = new GameObject(); lightsCenter.Name = "LightsCenter"; lightsCenter.SceneNode.Position = robot.SceneNode.Position; for (int i = -1; i <= 1; i += 2) { GameObject lightGo = new GameObject(); lightGo.Name = "Light" + i.ToString(); lightGo.SceneNode.PositionX = i * tileSize * 3f; var lightComponent = lightGo.AddComponent(new Light()) as Light; lightComponent.Intensity = 3; lightComponent.Range = tileSize * 15.5f; lightComponent.Color = i == -1 ? Color.Red : Color.Blue; lightGo.Parent = lightsCenter; } lightsCenter.Parent = scene.Root; // create some floor tiles for (int i = 0; i < tilemapSize; ++i) { for (int j = 0; j < tilemapSize; ++j) { GameObject tile = tilemap.GetTile(new Point(i, j)); ShapeRenderer tileModel = tile.AddComponent(new ShapeRenderer(ShapeMeshes.Plane)) as ShapeRenderer; tileModel.SetMaterial(tilesMaterial); tile.SceneNode.Scale = Vector3.One * tileSize * 0.5f; tile.SceneNode.RotationX = (float)System.Math.PI * -0.5f; } } // add floor physical body GameObject floorPhysics = new GameObject(); float wholePlaneSize = tilemapSize * tileSize; StaticBody floorBody = floorPhysics.AddComponent(new StaticBody(new CollisionBox(wholePlaneSize, 5f, wholePlaneSize))) as StaticBody; floorBody.Restitution = 0.75f; floorPhysics.SceneNode.Position = new Vector3((wholePlaneSize - tileSize) * 0.5f, -2.5f, (wholePlaneSize - tileSize) * 0.5f); floorPhysics.Parent = scene.Root; // add diagnostic data paragraph to scene var diagnosticData = new GeonBit.UI.Entities.Paragraph("", GeonBit.UI.Entities.Anchor.BottomLeft, offset: Vector2.One * 10f, scale: 0.7f); diagnosticData.BeforeDraw = (GeonBit.UI.Entities.Entity entity) => { diagnosticData.Text = Managers.Diagnostic.GetReportString(); }; scene.UserInterface.AddEntity(diagnosticData); // set scene GeonBitMain.Instance.Application.LoadScene(scene); }
/// <summary> /// Initialize to implement per main type. /// </summary> override public void Initialize() { // set scene size int sceneSize = 10000; // create the scene GameScene scene = new GameScene(); GameObject.OctreeSceneBoundaries = new BoundingBox(Vector3.One * -sceneSize, Vector3.One * sceneSize); GameObject.OctreeMaxDivisions = 7; GameObject octree = new GameObject("octree", SceneNodeType.OctreeCulling); octree.Parent = scene.Root; // create skybox Managers.GraphicsManager.CreateSkybox(null, scene.Root); // default no culling node types GameObject.DefaultSceneNodeType = SceneNodeType.Simple; // create camera GameObject camera = new GameObject(); Camera cameraComponent = new Camera(); camera.AddComponent(cameraComponent); cameraComponent.LookAt = new Vector3(100, 2, 100); camera.SceneNode.Position = new Vector3(0, 100, 0); camera.AddComponent(new CameraEditorController()); cameraComponent.FarPlane = 5000; camera.Parent = scene.Root; // create floor material GeonBit.Core.Graphics.Materials.BasicMaterial tilesMaterial = new GeonBit.Core.Graphics.Materials.BasicMaterial(); tilesMaterial.Texture = Resources.GetTexture("test/floor"); tilesMaterial.TextureEnabled = true; tilesMaterial.SpecularColor = Color.Black; // for random positions System.Random rand = new System.Random(); // create some starting tiles for (int i = 0; i < 80; ++i) { for (int j = 0; j < 80; ++j) { GameObject obj = new GameObject(); ShapeRenderer tileModel = obj.AddComponent(new ShapeRenderer(ShapeMeshes.Cube)) as ShapeRenderer; tileModel.SetMaterial(tilesMaterial); obj.SceneNode.Scale = Vector3.One * 10; obj.SceneNode.Position = new Vector3( rand.Next(-sceneSize, sceneSize), rand.Next(-sceneSize, sceneSize), rand.Next(-sceneSize, sceneSize)); obj.Parent = octree; } } // add diagnostic data paragraph to scene var diagnosticData = new GeonBit.UI.Entities.Paragraph("", GeonBit.UI.Entities.Anchor.BottomLeft, offset: Vector2.One * 10f, scale: 0.7f); diagnosticData.BeforeDraw = (GeonBit.UI.Entities.Entity entity) => { diagnosticData.Text = Managers.Diagnostic.GetReportString(); }; scene.UserInterface.AddEntity(diagnosticData); // set scene scene.Load(); }
/// <summary> /// Initialize to implement per main type. /// </summary> override public void Initialize() { // create the scene GameScene scene = new GameScene(); // create skybox Managers.GraphicsManager.CreateSkybox(null, scene.Root); Managers.Diagnostic.DebugRenderPhysics = false; // create camera object GameObject camera = new GameObject(); Camera cameraComponent = new Camera(); camera.AddComponent(cameraComponent); cameraComponent.LookAt = new Vector3(100, 2, 100); camera.SceneNode.Position = new Vector3(0, 5, 0); camera.AddComponent(new CameraEditorController()); camera.Parent = scene.Root; // create a tilemap for the floor TileMap tilemap = scene.Root.AddComponent(new TileMap(Vector2.One * 10f, 10)) as TileMap; // create floor material BasicMaterial tilesMaterial = new BasicMaterial(); tilesMaterial.Texture = Resources.GetTexture("game/floor"); tilesMaterial.TextureEnabled = true; tilesMaterial.SpecularColor = Color.Black; // create some floor tiles for (int i = 0; i < tilemapSize; ++i) { for (int j = 0; j < tilemapSize; ++j) { GameObject tile = tilemap.GetTile(new Point(i, j)); ShapeRenderer tileModel = tile.AddComponent(new ShapeRenderer(ShapeMeshes.Plane)) as ShapeRenderer; tileModel.SetMaterial(tilesMaterial); tile.SceneNode.Scale = Vector3.One * tileSize * 0.5f; tile.SceneNode.RotationX = (float)System.Math.PI * -0.5f; } } // add floor physical body GameObject floorPhysics = new GameObject(); float wholePlaneSize = tilemapSize * tileSize; StaticBody floorBody = floorPhysics.AddComponent(new StaticBody(new CollisionBox(wholePlaneSize, 5f, wholePlaneSize))) as StaticBody; floorBody.Restitution = 0.75f; floorPhysics.SceneNode.Position = new Vector3((wholePlaneSize - tileSize) * 0.5f, -2.5f, (wholePlaneSize - tileSize) * 0.5f); floorPhysics.Parent = scene.Root; // create some random physical objects for (int i = 0; i < 100; ++i) { GameObject obj = CreateRandomShape(); obj.Parent = scene.Root; } // add diagnostic data paragraph to scene var diagnosticData = new GeonBit.UI.Entities.Paragraph("", GeonBit.UI.Entities.Anchor.BottomLeft, offset: Vector2.One * 10f, scale: 0.7f); diagnosticData.BeforeDraw = (GeonBit.UI.Entities.Entity entity) => { diagnosticData.Text = Managers.Diagnostic.GetReportString(); }; scene.UserInterface.AddEntity(diagnosticData); // set scene GeonBitMain.Instance.Application.LoadScene(scene); }