private void AddGameObject() { GameObject gameObject = new GameObject(); Rigidbody rigidbody = new Rigidbody(); rigidbody.Mass = 0.5f + (float)random.NextDouble(); rigidbody.Acceleration = Vector3.Down * 9.81f; Vector3 direction = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); direction.Normalize(); rigidbody.Velocity = direction * ((float)random.NextDouble() * 5 + 5); rigidbody.AnimationSpeed = animationSpeed; gameObject.Add <Rigidbody>(rigidbody); SphereCollider sphereCollider = new SphereCollider(); sphereCollider.Radius = gameObject.Rigidbody.Transform.LocalScale.Y; sphereCollider.Transform = gameObject.Rigidbody.Transform; gameObject.Add <Collider>(sphereCollider); Texture2D texture = Content.Load <Texture2D>("Square"); Renderer renderer = new Renderer(model, gameObject.Rigidbody.Transform, camera, Content, GraphicsDevice, light, 1, "SimpleShading", 20f, texture); gameObject.Add <Renderer>(renderer); gameObjects.Add(gameObject); }
private void AddGameObject() { GameObject sphere = new GameObject(); Transform transform = sphere.Transform; SphereCollider sphereCollider = new SphereCollider(); Rigidbody rigidbody = new Rigidbody(); sphere.Transform.LocalPosition = Vector3.Zero; rigidbody.Transform = transform; Renderer renderer = new Renderer(model, sphere.Transform, camera, Content, GraphicsDevice, light, 2, "SimpleShading", 20f, texture); Vector3 direction = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); direction.Normalize(); rigidbody.Mass = 1; rigidbody.Velocity = direction * ((float)random.NextDouble() * 5 + 5); rigidbody.Mass = 1f + (float)random.NextDouble(); sphereCollider.Radius = 1 * transform.LocalScale.Y; sphereCollider.Transform = transform; sphere.Add <Rigidbody>(rigidbody); sphere.Add <Collider>(sphereCollider); sphere.Add <Renderer>(renderer); gameObjects.Add(sphere); count++; }
private static void AfterSceneLoad() { // Initialize basic game systems. var userInterfaceSystem = new UserInterfaceSystem(); var controlSystem = new ControlSystem(resourcesData.gameplaySettings); var keysSystem = new KeysSystem(resourcesData.stagePrefabs); var stageSystem = new StageSystem(resourcesData.stagePrefabs, keysSystem); var ballSystem = new BallSystem(resourcesData.ballPrefabs, stageSystem); var gameCurrencySystem = new GameCurrencySystem(userInterfaceSystem); var monetizationSystem = new MonetizationSystem(resourcesData.monetizationSettings, gameCurrencySystem); var shopSystem = new ShopSystem(resourcesData.shopModel, ballSystem, gameCurrencySystem, monetizationSystem); // Initialize gameplay systems. var gameInteractionsSystem = new GameInteractionsSystem(ballSystem, keysSystem, stageSystem); var gameInterfaceSystem = new GameInterfaceSystem(stageSystem, gameInteractionsSystem); // Register a proxy service for gameplay systems. var gameplaySystemsProxy = new GameplaySystemsProxy(); gameplaySystemsProxy.Add( gameInteractionsSystem, gameInterfaceSystem); // Initialize the state machine system with all dependencies. var gameStateMachine = new GameStateMachine( gameplaySystemsProxy, userInterfaceSystem, controlSystem, stageSystem, ballSystem, keysSystem, gameCurrencySystem, monetizationSystem); // Preserve links to game services. var storage = new GameObject("[Game Services]").AddComponent <GameServices>(); storage.Add( userInterfaceSystem, controlSystem, keysSystem, stageSystem, ballSystem, gameCurrencySystem, monetizationSystem, shopSystem); storage.Add( gameplaySystemsProxy, gameStateMachine); // Free the static reference to resources data - it's held by services from now. resourcesData = null; // Since there is only one scene in the project, we just link this very bootstrap script to the event of reloading scene. SceneManager.sceneLoaded += RebootOnNextSceneLoaded; }
public static GameObject CreatePlatform(Texture2D texture, Vector2 position) { var platform = new GameObject("Platform"); platform.Add(new TransformComponent(position)); platform.Add(new RenderComponent(texture)); platform.Add(new CollidableComponent()); return(platform); }
public static GameObject CreateBullet(Texture2D texture, Vector2 position) { var bullet = new GameObject("Bullet"); bullet.Add(new TransformComponent(position)); bullet.Add(new VelocityComponent(10)); bullet.Add(new RenderComponent(texture)); bullet.Add(new GravityComponent(new Vector2(0, 0.2f))); bullet.Add(new ChildComponent()); return(bullet); }
/// <summary> /// Constructor of BattlefieldScene class /// </summary> public BattlefieldScene() { for (int i = 0; i < SimultaneousSoldier; i++) { GameObject soldier = new GameObject(); soldier.Add(new HealthComponent()); soldier.Add(new ShieldComponent()); _gameObjectsPool.Push(soldier); } _mediator.RegisterListener(EventTypeConstant.DeathEvent, this); // Register a listener for a specific event _mediator.RegisterListener(EventTypeConstant.ShowMessageEvent, this); }
public void SetRelativepositionToMainParent(double parentX, double parentY, double parentAngle) { game.TestFunction = delegate { Vector delta = new Vector(10, 10); Vector parentPos = new Vector(parentX, parentY); parent.Position = parentPos; parent.Angle = Angle.FromDegrees(parentAngle); GameObject g1 = new GameObject(10, 10); parent.Add(g1); GameObject g2 = new GameObject(10, 10); g2.Position = new Vector(-100, 100); // Tällä ei tulisi olla mitään merkitystä g1.Add(g2); g2.RelativePositionToMainParent = delta; game.Add(parent); Assert.That(parent.Position, Is.EqualTo(parentPos).Using(new VectorComparer(0.001))); Assert.That(g2.Position, Is.EqualTo(parentPos + (new Vector(delta.X, delta.Y)).Transform(System.Numerics.Matrix4x4.CreateRotationZ((float)parent.Angle.Radians))).Using(new VectorComparer(0.001))); Assert.That(g2.RelativePositionToMainParent, Is.EqualTo(delta).Using(new VectorComparer(0.001))); Assert.Pass(); }; game.Run(); }
public static GameObject Construct(this GameObject instance, GameObject parent, params Tuple <Type, object>[] initializers) { GameObject go = null; bool a = instance.activeSelf; instance.SetActive(false); try { go = GameObject.Instantiate(instance) as GameObject; parent.Add(go); foreach (var i in initializers) { try { var c = go.GetComponent(i.Item1); if (c != null) { c.Setup(i.Item2); } } catch (Exception e) { Debug.LogException(e); } } go.SetActive(a); } catch (Exception e) { Debug.LogException(e); } instance.SetActive(a); return(go); }
public void GameObjectComponentAttachment() { GameObject gameObject = new GameObject(new Transform()); gameObject.Add(new CoroutineController()); Assert.AreEqual(2, gameObject.Count, "The count was not two, so the item was not added properly."); }
public void GameObjectComponentAttachmentValidators() { GameObject gameObject = new GameObject(new Transform()); gameObject.Add(new Transform()); Assert.AreEqual(1, gameObject.Count, "Count was not one, as it should've been as adding another transform shouldn't be possible."); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load <SpriteFont>("Fonts/Georgia"); model = Content.Load <Model>("Models/Sphere"); foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); } } cameraObject = new GameObject(); cameraObject.Transform.LocalPosition = Vector3.Backward * 20; camera = cameraObject.Add <Camera>(); boxCollider = new BoxCollider(); boxCollider.Size = 10; AddSphere(); haveThreadRunning = true; ThreadPool.QueueUserWorkItem( new WaitCallback(CollisionReset)); }
// Update is called once per frame void Update() { origin = transform.position; direction = transform.forward; /* * RaycastHit hit; * if (Physics.SphereCast(origin, sphereRadius, direction, out hit, maxDistance, layerMask, QueryTriggerInteraction.UseGlobal)) * { * currentHitObject = hit.transform.gameObject; * currentHitDistance = hit.distance; * } * else * { * currentHitDistance = maxDistance; * currentHitObject = null; * * }*/ currentHitDistance = maxDistance; currentHitObjects.Clear(); RaycastHit[] hits = new RaycastHit[10]; int numberOfHits = Physics.SphereCastNonAlloc(origin, sphereRadius, direction, hits, maxDistance, layerMask, QueryTriggerInteraction.UseGlobal); for (int i = 0; i < numberOfHits; i++) { currentHitObjects.Add(hits[i].transform.gameObject); currentHitDistance = hits[i].distance; } }
/// <summary> /// Creates a new GameObject with a CurvySplineGroup /// </summary> /// <param name="splines">the splines to add to the group</param> /// <returns>the new CurvySplineGroup component</returns> public static CurvySplineGroup Create(params CurvySpline[] splines) { CurvySplineGroup grp = new GameObject("Curvy Spline Group", typeof(CurvySplineGroup)).GetComponent <CurvySplineGroup>(); grp.Add(splines); return(grp); }
/// <summary> /// Creates this scene. /// </summary> public TestScene() { ActiveCamera.Zoom = 3; Background = new GameObject(); Background.AddModule <TextureModule>().TextureID = "bg"; Add(Background); Sprite = new GameObject(); Sprite.WorldPosition.X = -1; Sprite.WorldPosition.Y = -14; AnimatedTextureModule anim = Sprite.AddModule <AnimatedTextureModule>(); anim.Prefix = "down_walk"; anim.numFrames = 2; anim.Playing = true; anim.FPS = 6; Sprite.AddModule <GRIDController>(); Sprite.AddModule <TextureHitArea>(); Add(Sprite); GameObject sprite2 = new GameObject(); sprite2.AddModule <TextureModule>().TextureID = "down_stand"; sprite2.WorldPosition.X = 55; Sprite.Add(sprite2); }
private void RefreshTilePanel() { _tilePanel.ClearChildren(); _events.GetTileEvents(new TilePosition(_selectedTile.World)).ForEachIndex((e, i) => { _tilePanel.Add(Entity.Create(e.TypeName, new Transform2 { Size = new Size2(180, 60), Location = new Vector2(10 + _tilePanel.World.Location.X, 10 + _tilePanel.World.Location.Y + (70 * i)), ZIndex = ZIndex.Max - 12 }) .Add((o, r) => new Texture(r.CreateRectangle(Color.Red, o))) .Add(o => new MouseClickTarget { OnHit = () => { _events.Remove(e); RefreshTilePanel(); } }) .Add(new TextDisplay { Text = () => e.TypeName })); }); }
// -- JBehaviour -- public static T New <T>(string name = "New GameObject") where T : Component { var component = new GameObject().AddComponent <T>(); component.Add <ID>().Init(name); return(component); }
public void _0_Add_To_Balance() { var bankAccount = new GameObject("bankaccount").AddComponent <BankAccount>(); float amount = 10; bankAccount.Add(amount); Assert.AreEqual(bankAccount.Balance, amount); }
void InstantiateChildren(GameObject root, TransformCloneType cloneType, bool?setActive) { foreach (var child in children) { var childRoot = root.Add(child.original, cloneType, setActive); child.InstantiateChildren(childRoot, cloneType, setActive); } }
public void addGameObject() { GameObject gObj = new GameObject(); Model model = Content.Load <Model>("Sphere"); Rigidbody rigidbody = new Rigidbody(); Collider collider = new SphereCollider(); //Random Position float x = ((float)random.NextDouble() * 20) - 10; float y = ((float)random.NextDouble() * 20) - 10; float z = ((float)random.NextDouble() * 20) - 10; gObj.Transform.Position = new Vector3(x, y, z); rigidbody.Transform = gObj.Transform; mass = (float)random.NextDouble() + 1f; rigidbody.Mass = mass; Vector3 direction = new Vector3 ( (float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble() ); direction.Normalize(); Vector3 v = direction * ((float)random.NextDouble() * 20); rigidbody.Velocity = v; //Random Velocity Console.WriteLine(v.X + "\n" + v.Y + "\n" + v.Z + "\n"); SphereCollider sphereCollider = new SphereCollider(); sphereCollider.Radius = 1.0f * gObj.Transform.LocalScale.Y; sphereCollider.Transform = gObj.Transform; Renderer renderer = new Renderer(model, gObj.Transform, camera, Content, GraphicsDevice, light, 1, "SimpleShading.fx", 0.20f, texture); gObj.Add <Rigidbody>(rigidbody); gObj.Add <Collider>(sphereCollider); gObj.Add <Renderer>(renderer); gameObjects.Add(gObj); }
public void _2_Deduct_From_Balance() { var bankAccount = new GameObject("bankaccount").AddComponent <BankAccount>(); float amount = 10; bankAccount.Add(amount); bankAccount.Deduct(amount); Assert.AreEqual(bankAccount.Balance, 0); }
private void AddSphere() { GameObject gameObject = new GameObject(); Rigidbody rigidbody = gameObject.Add <Rigidbody>(); rigidbody.Mass = 1; //rigidbody.Acceleration = Vector3.Down * 9.81f; //rigidbody.Velocity = new Vector3((float)random.NextDouble() * 5, (float)random.NextDouble() * 5, (float)random.NextDouble() * 5); Vector3 direction = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); direction.Normalize(); rigidbody.Velocity = direction * ((float)random.NextDouble() * 5 + 5); SphereCollider sphereCollider = gameObject.Add <SphereCollider>(); sphereCollider.Radius = gameObject.Transform.LocalScale.Y; objects.Add(gameObject); colliders.Add(sphereCollider); rigidbodies.Add(rigidbody); }
private GameObject WithBoxColliders(TmxTilesetTile tile, GameObject entity) { //TODO: allow multiple boxes var box = tile.CollisionBoxes.First(); return(entity.Add(new Collision()) .Add(new BoxCollider( new Transform2( entity.World.Location + box.Location.ToVector2(), new Size2(box.Width, box.Height))))); }
public void _1_Add_To_Balance_Raise_Event() { var bankAccount = new GameObject("bankaccount").AddComponent <BankAccount>(); bool eventRaised = false; float amount = 10; bankAccount.OnBalanceChanged += (float amt, float balance) => { eventRaised = true; }; bankAccount.Add(amount); Assert.AreEqual(eventRaised, true); }
/// <summary> /// Starts this instance /// </summary> public override void Start() { if (GameObject.Contains <Sprite>()) { Sprite = (Sprite)GameObject.Get <Sprite>(); } else { Sprite = new Sprite(); GameObject.Add(Sprite); } }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); plane = Content.Load <Model>("Models/Plane"); sphere = Content.Load <Model>("Models/Sphere"); GameObject gameObject = new GameObject(); gameObject.Transform.LocalPosition = Vector3.One * 50; gameObject.Transform.Rotate(Vector3.Right, -MathHelper.PiOver2); camera = gameObject.Add <Camera>(); }
public static T GetOrAdd <T>(this GameObject gameObject) where T : Component { T value; if (gameObject.TryGet <T>(out value)) { return(value); } return(gameObject.Add <T>()); }
private void AddSphere() { GameObject gameObject = new GameObject(); Transform transform = new Transform(); transform.LocalScale *= random.Next(1, 10) * 0.25f; transform.Position = Vector3.Zero; Rigidbody rigidbody = new Rigidbody(); rigidbody.Transform = transform; rigidbody.Mass = 0.5f + (float)random.NextDouble(); // Lab 7: random mass rigidbody.Acceleration = Vector3.Down * 9.81f; // rigidbody.Velocity = new Vector3((float)random.NextDouble() * 5, (float)random.NextDouble() * 5, (float)random.NextDouble() * 5); Vector3 direction = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); direction.Normalize(); rigidbody.Velocity = direction * ((float)random.NextDouble() * 5 + 5); SphereCollider sphereCollider = new SphereCollider(); sphereCollider.Radius = gameObject.Transform.LocalScale.Y; sphereCollider.Transform = transform; Texture2D texture = Content.Load <Texture2D>("Square"); light.Transform = new Transform(); light.Transform.LocalPosition = Vector3.Backward * 10 + Vector3.Right * 5; renderer = new Renderer(model, gameObject.Transform, camera, Content, GraphicsDevice, light, 1, "SimpleShading", 20f, texture); gameObject.Add(rigidbody); gameObject.Add <Collider>(sphereCollider); gameObject.Add(renderer); // gameObject.Add(transform); gameObject.Add(camera); gameObjects.Add(gameObject); }
public GameObject SpawnFuel(float positionX, float positionY) { int type = (int)PyroGameObjectTypes.Fuel; GameObject result = mGameObjectPool.Allocate(); result.SetPosition(positionX, positionY); result.ActivationRadius = mActivationRadiusTight; result.width = 32; result.height = 32; result.PositionLocked = true; result.DestroyOnDeactivation = false; result.life = 1; result.team = GameObject.Team.NONE; FixedSizeArray <BaseObject> staticData = GetStaticData(type); if (staticData == null) { ContentManager content = sSystemRegistry.Game.Content; GraphicsDevice device = sSystemRegistry.Game.GraphicsDevice; int staticObjectCount = 1; staticData = new FixedSizeArray <BaseObject>(staticObjectCount); const int fileImageSize = 64; Rectangle crop = new Rectangle(0, 0, fileImageSize, fileImageSize); Texture2D texture = content.Load <Texture2D>(@"pics\fuel"); DrawableTexture2D textureDrawable = new DrawableTexture2D(texture, (int)result.width, (int)result.height); textureDrawable.SetCrop(crop); RenderComponent render = (RenderComponent)AllocateComponent(typeof(RenderComponent)); render.Priority = PyroSortConstants.FUEL; render.setDrawable(textureDrawable); staticData.Add(render); SetStaticData(type, staticData); } LifetimeComponent lifetime = AllocateComponent <LifetimeComponent>(); lifetime.SetDeathSound(fuelSound); result.Add(lifetime); AddStaticData(type, result, null); return(result); }
public void MoveTo() { game.TestFunction = delegate { Vector delta = new Vector(10, 10); Vector posToMove = new Vector(20, 20); GameObject g = new GameObject(10, 10); g.Position = delta; parent.Add(g); game.Add(parent); parent.MoveTo(posToMove, 20, () => { Assert.That(parent.Position, Is.EqualTo(posToMove).Using(new VectorComparer(0.1))); Assert.That(g.Position, Is.EqualTo(posToMove + delta).Using(new VectorComparer(0.1))); Assert.Pass(); }); }; game.Run(); }
private GameObject CreateButton(string buttonString, string Text, Vector2 Position, Vector2 Scale, List <Animation> animations, Action <Button> onClick = null, Action <Button> onEnter = null, Action <Button> onLeave = null, Action <Button> onHover = null) { GameObject container = new GameObject("BtnContainer"); GameObject obj = new GameObject("Button"); GameObject tObj = new GameObject("Text"); Texture btnIdle = TextureLoader.FileToTexture(buttonString + ".png"); Texture btnHover = TextureLoader.FileToTexture(buttonString + "H.png"); Texture btnClick = TextureLoader.FileToTexture(buttonString + "C.png"); Button btn = new Button(btnIdle, DefaultFilepaths.DefaultUiImageShader, 1, btnClick, btnHover, onClick, onEnter, onHover, onLeave); UiTextRendererComponent tr = new UiTextRendererComponent("Arial", false, 1, DefaultFilepaths.DefaultUiTextShader); obj.AddComponent(btn); tObj.AddComponent(tr); container.Add(obj); container.Add(tObj); Add(container); btn.Position = Position; btn.Scale = Scale; Vector2 textpos = Position; tr.Scale = Vector2.One * 2; tr.Center = true; tr.Position = textpos; tr.Text = Text; Animator anim = new Animator(animations, btn, tr); obj.AddComponent(anim); return(obj); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); // Let's load our model model = Content.Load <Model>("Models/Torus"); parentObject = new GameObject(); childObject = new GameObject(); childObject.Transform.Parent = parentObject.Transform; childObject.Transform.LocalPosition = Vector3.Right * 10; cameraObject = new GameObject(); cameraObject.Transform.LocalPosition = Vector3.Backward * 50; camera = cameraObject.Add <Camera>(); texture = Content.Load <Texture2D>("Textures/Square"); effect = Content.Load <Effect>("Effects/SimpleShading"); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); model = Content.Load<Model>("Models/Sphere"); foreach (ModelMesh mesh in model.Meshes) foreach (BasicEffect effect in mesh.Effects) effect.EnableDefaultLighting(); cameraObject = new GameObject(); cameraObject.Transform.LocalPosition = Vector3.Backward * 20; camera = cameraObject.Add<Camera>(); boxCollider = new BoxCollider(); boxCollider.Size = 10; AddSphere(); }
void luoperustorni() { // TODO: (JR) nimeäminen Vector testivektori = new Vector(100, 0); perusase = new AssaultRifle(35, 10); // TODO: (JR) nimeäminen! GameObject tykki1 = new GameObject(40, 40); tykki1.Position = testivektori; tykki1.Image = turretlvl1; Add(tykki1); tykki1.Add(perusase); ajasta(testivektori, perusase); }
public PistonSet spawnIfFull(bool[] isFull) { var pistonSet = new GameObject().AddComponent <PistonSet>(); pistonSet.Init(this); for (int i = 0; i < isFull.Length; ++i) { if (isFull[i] && !nthPistonExists[i]) { var pair = SpawnNthPair(i); pistonSet.Add(pair); } } return(pistonSet); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("Fonts/Georgia"); model = Content.Load<Model>("Models/Sphere"); foreach (ModelMesh mesh in model.Meshes) foreach (BasicEffect effect in mesh.Effects) effect.EnableDefaultLighting(); cameraObject = new GameObject(); cameraObject.Transform.LocalPosition = Vector3.Backward * 20; camera = cameraObject.Add<Camera>(); boxCollider = new BoxCollider(); boxCollider.Size = 10; AddSphere(); haveThreadRunning = true; ThreadPool.QueueUserWorkItem( new WaitCallback(CollisionReset)); }
void CreateBody(Device device, Texture texture) { _sizeContainer = Add(new GameObject()); // Container vai ser rotacionado no plano xz para olhar na direção do movimento var container = _sizeContainer.Add(new GameObject { (_collider = new Components.AxisAlignedBoxCollider { Object = this }) //new Behaviors.LookForward() }); // Body container poderá rotacionar no seu eixo X, sem que a direção seja impactada var bodyContainer = container.Add(new GameObject()); //.add(Behaviors.RotateWhileJumping, { speed: 6 }); bodyContainer.Translate(0, 0.1f, 0); _body = bodyContainer.Add(new GameObject()); _body.Translate(0, -0.5f - bodyContainer.Transform.TranslationVector.Y, 0); var xAxis = new Vector3(1, 0, 0); AddHead(device, texture); AddCap(device, texture); AddChest(device, texture); AddArm(device, texture, new Vector3(-0.35f, 0.05f, 0f)) .Add(new SwingWhileMoving(xAxis) { Inverse = true }); AddArm(device, texture, new Vector3(0.35f, 0.05f, 0f)) .Add(new SwingWhileMoving(xAxis)); AddLeg(device, texture, new Vector3(-0.125f, -0.35f, 0f)) .Add(new SwingWhileMoving(xAxis)); AddLeg(device, texture, new Vector3(0.125f, -0.35f, 0f)) .Add(new SwingWhileMoving(xAxis) { Inverse = true }); }
void ReloadScene(Device device) { bool gameRunning = false; if (_map != null) { gameRunning = true; _map.Dispose(); } string[] mapContent = File.ReadAllLines(_mapFile); _mapModifyDate = File.GetLastWriteTime(_mapFile); _map = Add(new GameObject()); var y = mapContent.Length; for (var l = 0; l < mapContent.Length; l++) { var line = mapContent[l]; for (int x = 0; x < line.Length; x++) { var c = line[x]; string blockTexture = null; switch (c) { case 'm': case 'M': if (_player == null || _oldStartPos != new Vector3(x, y, 0)) { if (_player == null) { _player = (Mario)Add(new Mario(device)); var deathController = _player.SearchComponent<MainPlayerDeath>(); GameObject dummyCameraTarget = null; deathController.OnDeathStarted += delegate { dummyCameraTarget = Add(new GameObject()); dummyCameraTarget.Translate(_player.GlobalTransform.TranslationVector); _camera.SearchComponent<LookAtObject>().Target = dummyCameraTarget; }; deathController.OnDeathFinalized += delegate { if (dummyCameraTarget != null) { dummyCameraTarget.Dispose(); dummyCameraTarget = null; } _camera.SearchComponent<LookAtObject>().Target = _player; deathController.Reset(); ReloadScene(device); _player.Enabled = true; _player.Transform = Matrix.Translation(_oldStartPos.X, _oldStartPos.Y + 0.5f, 0); _player.SearchComponent<RigidBody>().Momentum = Vector3.Zero; _player.SearchComponent<Blink>().IsActive = true; _camera.Transform = _player.Transform * Matrix.Translation(0, 0, -15); }; } _player.Transform = Matrix.Translation(x, y + 0.5f, 0); _oldStartPos = new Vector3(x, y, 0); } _player.IsSmall = c == 'm'; break; case 'G': _map.Add(new Goomba(device)).Translate(x, y, 0); break; case '?': _map.Add(new ItemBlock(device)).Translate(x, y, 0); break; case 'B': _map.Add(new BrickBlock(device)).Translate(x, y, 0); break; case 'P': { if (l > 0 && mapContent[l - 1].Length > x && mapContent[l - 1][x] == c) break; var height = 1; while (l + height < mapContent.Length && mapContent[l + height][x] == c) height++; _map.Add(new Pipe(device, height)).Translate(x, y - (float)(height - 1) / 2, 0); break; } case '|': { if (l > 0 && mapContent[l - 1].Length > x && mapContent[l - 1][x] == c) break; var height = 1; while (l + height < mapContent.Length && mapContent[l + height][x] == c) height++; _map.Add(new Poll(device, height)).Translate(x, y - (float)(height - 1) / 2, 0); break; } case 'D': { int width = 1; while (x + 1 < line.Length && line[x + 1] == 'D') { width++; x++; } _map.Add(new Trigger(o => o.Object.SendMessage("OnDeath", true), width, 1, 2, new Vector3(x - (float)(width - 1) / 2, y, 0))); break; } case '^': { int width = 1; while (x + 1 < line.Length && line[x + 1] == '^' && width < 3) { width++; x++; } var size = width == 1 ? 2 : 4; var sprite = _map.Add(new Objects.Sprite(device, "grass_" + width, size)); sprite.Transform = Matrix.Translation(x - 0.5f, y + size / 2 - 0.5f, -0.75f); break; } case 'H': case 'h': { var size = c == 'H' ? 8 : 4; var sprite = _map.Add(new Objects.Sprite(device, "hill_" + size, size)); sprite.Transform = Matrix.Translation(x, y + size / 2 - 0.5f, 1); break; } case '#': { var size = 8; var sprite = _map.Add(new Objects.Sprite(device, "castle", size)); sprite.Transform = Matrix.Translation(x, y + size / 2 - 0.5f, 1); break; } case 'C': { int width = 1; while (x + 1 < line.Length && line[x + 1] == 'C' && width < 3) { width++; x++; } var cloud = _map.Add(new Cloud(device, width)); cloud.Transform = Matrix.Scaling(2) * Matrix.Translation(x - (float)(width - 0.5f), y, 5f); break; } case 'W': { int width = 1; while (x + 1 < line.Length && line[x + 1] == 'W') { width++; x++; } var water = _map.Add(new Water(device, 10 * width, 20)); water.Transform *= Matrix.Scaling(0.1f) * Matrix.Translation(x - (float)(width - 1) / 2, y, 0); break; } case 'S': blockTexture = "solid"; break; case 'F': blockTexture = "floor"; break; } if (blockTexture != null) { int width = 1; while (x + 1 < line.Length && line[x + 1] == c) { width++; x++; } var obj = _map.Add(new Block(device, width, 1, 2, blockTexture)); obj.Translate(x - (float)(width - 1) / 2, y, 0); } } y--; } if (gameRunning) _map.Init(); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); plane = Content.Load<Model>("Models/Plane"); sphere = Content.Load<Model>("Models/Sphere"); GameObject gameObject = new GameObject(); gameObject.Transform.LocalPosition = Vector3.One * 50; gameObject.Transform.Rotate(Vector3.Right, -MathHelper.PiOver2); camera = gameObject.Add<Camera>(); }
/// <summary> /// Creates a new GameObject with a CurvySplineGroup /// </summary> /// <param name="splines">the splines to add to the group</param> /// <returns>the new CurvySplineGroup component</returns> public static CurvySplineGroup Create(params CurvySpline[] splines) { CurvySplineGroup grp = new GameObject("Curvy Spline Group", typeof(CurvySplineGroup)).GetComponent<CurvySplineGroup>(); grp.Add(splines); return grp; }
void LisaaAliNelio(GameObject palikka, double sivulle, double alas) { var nelio = new GameObject(PalikanKoko-2, PalikanKoko-2); nelio.Color = palikka.Color; nelio.Position = new Vector(sivulle * PalikanKoko, alas * PalikanKoko); palikka.Add(nelio); }
private void AddSphere() { GameObject gameObject = new GameObject(); Rigidbody rigidbody = gameObject.Add<Rigidbody>(); rigidbody.Mass = 1; //rigidbody.Acceleration = Vector3.Down * 9.81f; //rigidbody.Velocity = new Vector3((float)random.NextDouble() * 5, (float)random.NextDouble() * 5, (float)random.NextDouble() * 5); Vector3 direction = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); direction.Normalize(); rigidbody.Velocity = direction * ((float)random.NextDouble() * 5 + 5); SphereCollider sphereCollider = gameObject.Add<SphereCollider>(); sphereCollider.Radius = gameObject.Transform.LocalScale.Y; objects.Add(gameObject); colliders.Add(sphereCollider); rigidbodies.Add(rigidbody); }