public override void FireThread() { Random rand = new Random(); Task.Run(() => { while (!IsDead() && ExistsInGameScreen) { int val = rand.Next(0, 2); Bullet.Bullet bullet, bullet2, bullet3, bullet4; if (val == 0) { bullet = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.LEFT)); bullet2 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.RIGHT)); bullet3 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.UP)); bullet4 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.DOWN)); } else { bullet = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.LEFT_UP)); bullet2 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.LEFT_DOWN)); bullet3 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.RIGHT_UP)); bullet4 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.RIGHT_DOWN)); } App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet2)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet3)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet4)); Thread.Sleep(RateOfFireInMilliSeconds); } }); }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { // TODO: Add your initialization code here _enemys = Game.Components.OfType <DrawScripts.DrawInOrder>().ToList()[0]._enemys; _player = Game.Components.OfType <DrawScripts.DrawInOrder>().ToList()[0]._player; _bullet = Game.Components.OfType <Bullet.Bullet>().ToList()[0]; _draw = Game.Components.OfType <DrawScripts.DrawInOrder>().ToList()[0]; base.Initialize(); }
public CharacterMovement(Game game) : base(game) { // TODO: Construct any child components here _player = Game.Components.OfType <DrawScripts.DrawInOrder>().ToList()[0]._player; _helthBar = Game.Components.OfType <DrawScripts.DrawInOrder>().ToList()[0]._UI[1]; _crossHair = Game.Components.OfType <DrawScripts.DrawInOrder>().ToList()[0]._UI[0]; _bullet = Game.Components.OfType <Bullet.Bullet>().ToList()[0]; _draw = Game.Components.OfType <DrawScripts.DrawInOrder>().ToList()[0]; _collider = Game.Components.OfType <Colliders.ColliderBulletscs>().ToList()[0]; }
public void shootOneBullet(Vector2 position, Vector2 direction, float kot) { Bullet.Bullet bulet = new Bullet.Bullet(Game); bulet.body = _bullet.body; bulet.position = position; bulet.direction = direction; bulet.rotation = kot; bulet.player = true; Game.Components.Add(bulet); _draw._bullets.Add(bulet); }
public override void FireThread() { Task.Run(() => { while (!IsDead() && ExistsInGameScreen) { Bullet.Bullet bullet = new Bullet.Bullet(Position, new RandomStraightPath()); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet)); Thread.Sleep(RateOfFireInMilliSeconds); } }); }
protected override void OnUpdate() { counter = (counter + 1) % 30; if (counter == 0) { var bullet = new Bullet.Bullet(Position); this.Layer.AddObject(bullet); bulletCompany.Add(bullet); } Position += new asd.Vector2DF(0, 1); base.OnUpdate(); }
public override void FireThread() { Random rand = new Random(); Task.Run(() => { while (!IsDead() && ExistsInGameScreen) { Bullet.Bullet bullet, bullet2, bullet3, bullet4, bullet5, bullet6, bullet7, bullet8; bullet = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.UP)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet)); Thread.Sleep(RateOfFireInMilliSeconds); bullet2 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.RIGHT_UP)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet2)); Thread.Sleep(RateOfFireInMilliSeconds); bullet3 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.RIGHT)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet3)); Thread.Sleep(RateOfFireInMilliSeconds); bullet4 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.RIGHT_DOWN)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet4)); Thread.Sleep(RateOfFireInMilliSeconds); bullet5 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.DOWN)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet5)); Thread.Sleep(RateOfFireInMilliSeconds); bullet6 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.LEFT_DOWN)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet6)); Thread.Sleep(RateOfFireInMilliSeconds); bullet7 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.LEFT)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet7)); Thread.Sleep(RateOfFireInMilliSeconds); bullet8 = new Bullet.Bullet(Position, new RandomStraightPath(RandomStraightPath.DIRECTION.LEFT_UP)); App.Current.Dispatcher.Invoke(() => AddThreatToCollection.Invoke(bullet8)); Thread.Sleep(RateOfFireInMilliSeconds); Thread.Sleep(RateOfFireInMilliSeconds); } }); }
private void Shoot(Enemy.enemy enemy) { Vector2 direction = _player.position - enemy.position; float distance = direction.Length(); direction /= distance; direction.Normalize(); double kot = Math.Atan2(_player.position.Y - enemy.position.Y, _player.position.X - enemy.position.X); Bullet.Bullet bulet = new Bullet.Bullet(Game); bulet.body = _bullet.body; bulet.position = enemy.position; bulet.direction = direction; bulet.rotation = (float)kot; bulet.player = false; Game.Components.Add(bulet); _draw._bullets.Add(bulet); }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. this.Game is where it can query for any required services and load this.Game.Content. /// </summary> public override void Initialize() { // TODO: Add your initialization code here //----------------------------------------------------------------------------Dodajanje ozadja DrawScripts.AnimSprite _spBackground = new DrawScripts.AnimSprite(this.Game); _spBackground.texture = this.Game.Content.Load <Texture2D>("Assets\\Background\\BackGround"); _spBackground.position = Vector2.Zero; _spBackground.animations = new List <Rectangle>(); _spBackground.animations.Add(new Rectangle(0, 0, _spBackground.texture.Width, _spBackground.texture.Height)); _spBackground.scale = new Vector2((float)this.Game.GraphicsDevice.Viewport.Width / _spBackground.texture.Width, (float)this.Game.GraphicsDevice.Viewport.Height / _spBackground.texture.Height); _spBackground.center = Vector2.Zero; _spBackground.currentAnim = 0; _spBackground.slika = true; this.Game.Components.Add(_spBackground); //------------------------------------------------------------------------dodajanje trupla glavnem igralcu DrawScripts.AnimSprite _aspCharacter = new DrawScripts.AnimSprite(this.Game); _aspCharacter.texture = this.Game.Content.Load <Texture2D>("Assets\\Character\\Character"); _aspCharacter.animations = new List <Rectangle>(); _aspCharacter.animations.Add(new Rectangle(0, 0, 31, 43)); //desno _aspCharacter.animations.Add(new Rectangle(32, 0, 31, 43)); //gor _aspCharacter.animations.Add(new Rectangle(56, 0, 31, 43)); //dol _aspCharacter.animations.Add(new Rectangle(88, 0, 31, 43)); //levo _aspCharacter.scale = new Vector2(2f, 2f); _aspCharacter.center = Vector2.Zero; this.Game.Components.Add(_aspCharacter); //---------------------------------------------------------------------------dodajanje nog glavnemu igralcu DrawScripts.AnimSprite _aspCharacterLegs = new DrawScripts.AnimSprite(this.Game); _aspCharacterLegs.texture = _aspCharacter.texture; _aspCharacterLegs.animations = new List <Rectangle>(); _aspCharacterLegs.animations.Add(new Rectangle(0, 57, 31, 28)); //desno _aspCharacterLegs.animations.Add(new Rectangle(32, 57, 31, 28)); //gor _aspCharacterLegs.animations.Add(new Rectangle(56, 57, 31, 28)); //dol _aspCharacterLegs.animations.Add(new Rectangle(88, 57, 31, 28)); //levo _aspCharacterLegs.animations.Add(new Rectangle(0, 86, 31, 28)); //stoji desno _aspCharacterLegs.animations.Add(new Rectangle(32, 86, 31, 28)); // stoji gor _aspCharacterLegs.scale = new Vector2(2f, 2f); _aspCharacterLegs.center = Vector2.Zero; this.Game.Components.Add(_aspCharacterLegs); Player.Player _player = new Player.Player(this.Game); _player.body = _aspCharacter; _player.legs = _aspCharacterLegs; _player.position = new Vector2((float)this.Game.GraphicsDevice.Viewport.Width / 2, (float)this.Game.GraphicsDevice.Viewport.Height / 2); _player.speed = 100; _player.shootSpeed = 1f; _player.multipleBoolets = false; _player.helth = 100; _player.shoot1 = this.Game.Content.Load <SoundEffect>("Assets\\Sounds\\GunSound1"); _player.shoot2 = this.Game.Content.Load <SoundEffect>("Assets\\Sounds\\GunSound2"); this.Game.Components.Add(_player); //-------------------------------------------------------------------dodajanje helth bara DrawScripts.AnimSprite _helthBar = new DrawScripts.AnimSprite(this.Game); _helthBar.font = this.Game.Content.Load <SpriteFont>("Assets\\Font\\Font");; _helthBar.slika = false; _helthBar.helthBar = true; this.Game.Components.Add(_helthBar); //---------------------------------------------------------------------dodajanje texta za stopnjo DrawScripts.AnimSprite _LevelText = new DrawScripts.AnimSprite(this.Game); _LevelText.font = _helthBar.font; _LevelText.slika = false; _LevelText.helthBar = false; _LevelText.text = "Trenutna stopnja: 1"; _LevelText.position = new Vector2(((int)this.Game.GraphicsDevice.Viewport.Width / 2) - 100, 0); this.Game.Components.Add(_LevelText); //----------------------------------------------------------------------------dodajanje croshaira DrawScripts.AnimSprite _spCrossHair = new DrawScripts.AnimSprite(this.Game); _spCrossHair.texture = this.Game.Content.Load <Texture2D>("Assets\\Character\\CrossHair"); _spCrossHair.position = Vector2.Zero; _spCrossHair.animations = new List <Rectangle>(); _spCrossHair.animations.Add(new Rectangle(0, 0, _spCrossHair.texture.Width, _spCrossHair.texture.Height)); _spCrossHair.scale = new Vector2(1, 1); _spCrossHair.center = new Vector2(_spCrossHair.texture.Width / 2, _spCrossHair.texture.Height / 2); _spCrossHair.currentAnim = 0; _spCrossHair.slika = true; this.Game.Components.Add(_spCrossHair); //----------------------------------------------------------------------------dodajanje metka DrawScripts.AnimSprite _spBullet = new DrawScripts.AnimSprite(this.Game); _spBullet.texture = this.Game.Content.Load <Texture2D>("Assets\\Character\\Bullet"); _spBullet.animations = new List <Rectangle>(); _spBullet.animations.Add(new Rectangle(0, 0, _spBullet.texture.Width, _spBullet.texture.Height)); _spBullet.scale = new Vector2(1, 1); _spBullet.center = new Vector2(_spBullet.texture.Width / 2, _spBullet.texture.Height / 2); _spBullet.currentAnim = 0; this.Game.Components.Add(_spBullet); Bullet.Bullet _bullet = new Bullet.Bullet(this.Game); _bullet.body = _spBullet; this.Game.Components.Add(_bullet); //-------------------------------------------------------------------dodajanje enemijev DrawScripts.AnimSprite _aspEnemy = new DrawScripts.AnimSprite(this.Game); _aspEnemy.texture = this.Game.Content.Load <Texture2D>("Assets\\Enemy\\Enemy"); _aspEnemy.animations = new List <Rectangle>(); _aspEnemy.animations.Add(new Rectangle(3, 7, 43, 19)); _aspEnemy.animations.Add(new Rectangle(56, 3, 43, 22)); _aspEnemy.scale = new Vector2(2f, 2f); _aspEnemy.currentAnim = 0; _aspEnemy.center = new Vector2(21, 11); this.Game.Components.Add(_aspEnemy); DrawScripts.AnimSprite _aspEnemy2 = new DrawScripts.AnimSprite(this.Game); _aspEnemy2.texture = _aspEnemy.texture; _aspEnemy2.animations = new List <Rectangle>(); _aspEnemy2.animations.Add(new Rectangle(1, 36, 43, 20)); _aspEnemy2.animations.Add(new Rectangle(56, 29, 43, 22)); _aspEnemy2.scale = new Vector2(2f, 2f); _aspEnemy2.currentAnim = 1; _aspEnemy2.center = new Vector2(21, 11); this.Game.Components.Add(_aspEnemy2); //------------------------------------------------------------------------------dodajanje powe upov DrawScripts.AnimSprite _powerUps = new DrawScripts.AnimSprite(this.Game); _powerUps.texture = this.Game.Content.Load <Texture2D>("Assets\\Character\\PowerUps"); this.Game.Components.Add(_powerUps); //------------------------------------------------------------------------------izrisevanje vseh objektov s skripto DrawInOrder List <DrawScripts.AnimSprite> _background = new List <DrawScripts.AnimSprite>(); _background.Add(_spBackground); List <Enemy.enemy> _enemys = new List <Enemy.enemy>(); List <DrawScripts.AnimSprite> _UI = new List <DrawScripts.AnimSprite>(); _UI.Add(_spCrossHair); _UI.Add(_helthBar); _UI.Add(_LevelText); DrawScripts.DrawInOrder _draw = new DrawScripts.DrawInOrder(this.Game, _background, _enemys, _player, _UI, new List <DrawScripts.AnimSprite>()); this.Game.Components.Add(_draw); //--------------------------------------------------------------------------------------------------- konec dodajanja elementov v izrisevanje //------------------------------------------------------------------------------------motor za metke Colliders.ColliderBulletscs collider = new Colliders.ColliderBulletscs(this.Game); this.Game.Components.Add(collider); //-------------------------------------------------------------------- motro za enemije Motors.EnemyMovement _enemyMove = new Motors.EnemyMovement(this.Game); this.Game.Components.Add(_enemyMove); //----------------------------------------------------------------------------------------------------------------------------------dodajanje motorja za igralca Motors.CharacterMovement _charMove = new Motors.CharacterMovement(this.Game); this.Game.Components.Add(_charMove); //----------------------------------------------------------------------------dodajanje collider za igralca Colliders.CharacterCollider _charCollider = new Colliders.CharacterCollider(this.Game); this.Game.Components.Add(_charCollider); //--------------------------------------------------------------add wave manager Manger.WaveManger _waveManager = new Manger.WaveManger(this.Game); this.Game.Components.Add(_waveManager); this.Game.IsMouseVisible = false; base.Initialize(); }
/// <summary> /// Fire a bullet in the associated level. /// </summary> /// <param name="b"></param> public void Fire(Bullet.Bullet b) { AssociatedLevel.EnemyBulletList.Add(b); }