public override void Update(float delta) { if (_isCreating) { _lastCreatingTime += delta; if (_lastCreatingTime >= _cooldown) { _isCreating = false; } return; } var position = new Vector3(GameObject.Position.X, GameObject.Position.Y - 0.27f, GameObject.Position.Z); var direction = _target.Position - position; direction.Normalize(); Game3DObject copyBullet = _bullet.GetCopy(); copyBullet.MoveTo(position); //copyBullet.MoveTo(GameObject.Position); if ((GameObject.Position - _target.Position).Length() <= 1.5f) { copyBullet.AddScript(new BulletScript(direction)); GameObject.Scene.AddGameObject(copyBullet); OnEggShoot?.Invoke(); } _lastCreatingTime = 0; _isCreating = true; }
public override void Update(float delta) { if (_isReloading) { _reloadingTime += delta; if (_reloadingTime >= _cooldown) { _isReloading = false; } return; } if (_inputController.MouseUpdate && _inputController.MouseButtons[0]) { Vector3 rotation = GameObject.Rotation; rotation.Y = GameObject.Children[1].Rotation.Y; Matrix rotationMatrix = Matrix.RotationYawPitchRoll(rotation.Z, rotation.Y, rotation.X); Vector3 direction = (Vector3)Vector3.Transform(Vector3.UnitZ, rotationMatrix); Game3DObject bullet = _bulletPrototype.GetCopy(); bullet.MoveTo(GameObject.Position + direction); bullet.AddScript(new BulletScript(direction, 1, 1)); GameObject.Scene.AddGameObject(bullet); OnCakeShoot?.Invoke(); _reloadingTime = 0; _isReloading = true; } }
private void CreatePlatforms(Loader loader, int index, Vector3 position) { var file = @"Resources\Models\platform" + index.ToString() + ".fbx"; var obstacle = loader.LoadGameObjectFromFile(file, position, Vector3.Zero); obstacle.Tag = "obstacle"; obstacle.Collision = new BoxCollision(2.2f, 0.8f * index); obstacle.AddComponent(new ColliderComponent()); obstacle.AddScript(new ColliderScript()); var platform = new Game3DObject(new Vector3(0.0f, 1.5f * index, 0.0f), Vector3.Zero); platform.Tag = "ground"; platform.Collision = new BoxCollision(1.8f, 0.8f); platform.AddComponent(new ColliderComponent()); platform.AddScript(new ColliderScript()); obstacle.AddChild(platform); AddGameObject(obstacle); }
protected override void InitializeObjects(Loader loader, SharpAudioDevice audioDevice) { string file = @"Models\T_Rex.fbx"; _go = loader.LoadGameObjectFromFile(file, Vector3.Zero, new Vector3(0, MathUtil.PiOverTwo, 0)); Game3DObject g1 = loader.LoadGameObjectFromFile(file, new Vector3(1, 1, 0), Vector3.Zero); Game3DObject g2 = loader.LoadGameObjectFromFile(file, new Vector3(-1, 1, 0), Vector3.Zero); Game3DObject g3 = loader.LoadGameObjectFromFile(file, Vector3.UnitZ * 2, Vector3.Zero); _go.AddChild(g1); _go.AddChild(g2); _go.AddChild(g3); _go.AddScript(new DinoMovementScript()); AddGameObject(_go); AddGameObject(loader.LoadGameObjectFromFile(@"Models\dsa.fbx", Vector3.UnitX * 5, Vector3.Zero)); _voice = new SharpAudioVoice(audioDevice, @"Sounds\again.wav"); _voice2 = new SharpAudioVoice(audioDevice, @"Sounds\again.wav"); }
private void CreatePlayerLoader(Loader loader) { // создание игрока _player = new Game3DObject(new Vector3(0.0f, 10.0f, -5.0f), Vector3.Zero); float deltaAngle = Camera.FOVY / Game.RenderForm.ClientSize.Height; _player.Tag = "player"; _player.Collision = new BoxCollision(1.0f, 1.7f); _player.AddComponent(new PhysicsComponent()); _player.AddScript(new PhysicsScript()); _player.AddComponent(new ColliderComponent()); _player.AddScript(new ColliderScript()); var playerComponent = new PlayerComponent(); playerComponent.OnArrowsCountChanged += UpdateArrowsCountUI; playerComponent.OnHealthChanged += (count) => _healthProgressBar.Value = count; playerComponent.AddArrows(ArrowType.Standart, 5); playerComponent.AddArrows(ArrowType.Poison, 2); _player.AddComponent(playerComponent); _player.AddScript(new PlayerMovement(deltaAngle, 4f, 0.5f, 2.0f)); _player.AddChild(Camera); // доабвление игроку лука string file = @"Resources\Models\bow.fbx"; var bow = loader.LoadGameObjectFromFile(file, new Vector3(-0.017f, 0.94f, 0.08f), Vector3.Zero); _player.AddChild(bow); //добавление точки появления стрел игроку var arrowParrent = new Game3DObject(new Vector3(-0.052f, 0.95f, 0.0f), Vector3.Zero); arrowParrent.AddComponent(new VisibleComponent()); arrowParrent.AddScript(new VisibleScript()); // скрипт стрельбы var bowShootScript = new BowShoot(2.0f, 1.0f); //создание копируемых стрел для игрока //обычная стрела file = @"Resources\Models\arrow.fbx"; var arrow = loader.LoadGameObjectFromFile(file, Vector3.Zero, Vector3.Zero); arrow.Collision = new BoxCollision(0.3f, 0.2f, 0.3f); var arrowComponents = new List <Func <ObjectComponent> > { () => new ArrowComponent(), () => new PhysicsComponent(0.05f), () => new ColliderComponent() }; var arrowScripts = new List <Func <Script> > { () => new Arrow(arrowParrent, 20.0f, 5.0f), () => new PhysicsScript(), () => new ColliderScript() }; var arrowTemplate = new CopyableGameObject(arrow, arrowScripts, arrowComponents); bowShootScript.AddArrowTemplate(ArrowType.Standart, arrowTemplate); //стрела с ядом file = @"Resources\Models\arrowPoison.fbx"; arrow = loader.LoadGameObjectFromFile(file, Vector3.Zero, Vector3.Zero); arrow.Collision = new BoxCollision(0.3f, 0.2f, 0.3f); arrowComponents = new List <Func <ObjectComponent> > { () => new ArrowComponent(), () => new PhysicsComponent(0.05f), () => new ColliderComponent() }; arrowScripts = new List <Func <Script> > { () => new PoisonArrow(arrowParrent, 20.0f, 5.0f, 5.0f), () => new PhysicsScript(), () => new ColliderScript() }; arrowTemplate = new CopyableGameObject(arrow, arrowScripts, arrowComponents); bowShootScript.AddArrowTemplate(ArrowType.Poison, arrowTemplate); arrowParrent.AddScript(bowShootScript); //добавление стрел к точке появления file = @"Resources\Models\arrow.fbx"; arrow = loader.LoadGameObjectFromFile(file, Vector3.Zero, Vector3.Zero); arrowParrent.AddChild(arrow); file = @"Resources\Models\arrowPoison.fbx"; arrow = loader.LoadGameObjectFromFile(file, Vector3.Zero, Vector3.Zero); arrow.IsHidden = true; arrowParrent.AddChild(arrow); _player.AddChild(arrowParrent); AddGameObject(_player); }