public override void Update(Vector2 playerPosition) { if ((CurCharge >= chargeTime) && BulletList.Count < 4 && _fired == false) { BulletList.Add(new Bullet(new Vector2(shipLocation.X + Width, shipLocation.Y + Height / 2), Globals.GameWindowY / BulletScale, (Globals.GameWindowY / BulletScale) * (bulletTexture.Bounds.Height / bulletTexture.Bounds.Width), 0, BulYVel)); BulYVel = BulYVel * -1; CurCharge = 0; } else if (BulletList.Count >= 4 && _fired == false) { _fired = true; FireBullet(playerPosition); } else if (_fired && BulletList.Count == 0) { _fired = false; } CurCharge++; if (BulletList.Count != 0) { for (int i = BulletList.Count - 1; i >= 0; i--) { if (BulletList[i].BulletLocation.X > 0 && BulletList[i].BulletLocation.X < Globals.GameWindowX && BulletList[i].BulletLocation.Y > 0 && BulletList[i].BulletLocation.Y < Globals.GameWindowY) { BulletList[i].Update(); } else { BulletList.RemoveAt(i); } } } }
void CustomActivity(bool firstTimeCalled) { if (InputManager.Keyboard.KeyDown(Keys.Left)) { var radians = PlayerInstance.RotationDegreesPerSecond * (Math.PI / 180) * TimeManager.SecondDifference; PlayerInstance.RotationZ += (float)radians; } if (InputManager.Keyboard.KeyDown(Keys.Right)) { var radians = PlayerInstance.RotationDegreesPerSecond * (Math.PI / 180) * TimeManager.SecondDifference; PlayerInstance.RotationZ -= (float)radians; } if (InputManager.Keyboard.KeyReleased(Keys.Space)) { var bullet = new Bullet(); bullet.Velocity.X = (float)(bullet.Speed * Math.Cos(PlayerInstance.RotationZ)); bullet.Velocity.Y = (float)(bullet.Speed * Math.Sin(PlayerInstance.RotationZ)); bullet.RotationZ = PlayerInstance.RotationZ; BulletList.Add(bullet); } if (InputManager.Keyboard.KeyReleased(Keys.Escape)) { if (IsPaused) { UnpauseThisScreen(); } else { PauseThisScreen(); } } if (InputManager.Keyboard.KeyReleased(Keys.F12)) { RestartScreen(true); } }
public override void Shoot() { if (DateTime.Now > nextAttackTime && ammunition >= 1) { ammunition--; nextAttackTime = DateTime.Now.AddMilliseconds(attackSpeed); float yValue = position.Y + ObjectSize.Height / 2 - standartBulletSize.Height / 2; Vector2 leftBulletPosition = new Vector2(position.X, yValue); Vector2 midleBulletPosition = new Vector2(position.X + ObjectSize.Width / 2 - standartBulletSize.Width / 2, yValue); Vector2 rightBulletPosition = new Vector2(position.X + ObjectSize.Width - standartBulletSize.Width, yValue); newBullet = new Bullet(BulletSkin, leftBulletPosition, standartBulletSize, 1, this); BulletList.Add(newBullet); newBullet = new Bullet(BulletSkin, midleBulletPosition, standartBulletSize, 0, this); BulletList.Add(newBullet); newBullet = new Bullet(BulletSkin, rightBulletPosition, standartBulletSize, 2, this); BulletList.Add(newBullet); } }
public void ShootBullet() { float x = EmitPoint.X; float y = EmitPoint.Y; PointF originalPosition; float num1; if (x == -99999.0) { originalPosition = MyPlane.OriginalPosition; num1 = originalPosition.X; } else if (x == -99998.0) { originalPosition = this.OriginalPosition; num1 = originalPosition.X; } else { num1 = (float)(x - 320.0 + 192.0); } float num2; if (y == -99999.0) { originalPosition = MyPlane.OriginalPosition; num2 = originalPosition.Y; } else if (y == -99998.0) { originalPosition = this.OriginalPosition; num2 = originalPosition.Y; } else { num2 = (float)(y - 240.0 + 224.0); } if (EmitterMode == EmitterMode.StraightLaser || EmitterMode == EmitterMode.RadialLaser || EmitterMode == EmitterMode.BendLaser) { originalPosition = this.OriginalPosition; num1 = originalPosition.X; originalPosition = this.OriginalPosition; num2 = originalPosition.Y; } PointF OriginalPosition = new PointF(num1 + RanX * (float)Ran.NextPMDouble(), num2 + RanY * (float)Ran.NextPMDouble()); double edi = EmitDirection != -99999.0 ? (EmitDirection + RanEmitDirection * Ran.NextPMDouble() + SubBullet.RanDirection * Ran.NextPMDouble()) * Math.PI / 180.0 : GetDirection(MyPlane) + (RanEmitDirection * Ran.NextPMDouble() + SubBullet.RanDirection * Ran.NextPMDouble()) * Math.PI / 180.0; double num3 = RadiusDirection != -99999.0 ? (RadiusDirection + RanRadiusDirection * Ran.NextPMDouble()) * Math.PI / 180.0 : GetDirection(MyPlane) + RanRadiusDirection * Ran.NextPMDouble() * Math.PI / 180.0; float num4 = EmitRadius + RanRadius * (float)Ran.NextPMDouble(); int num5 = Way + (int)(RanWay * Ran.NextPMDouble()); float num6 = SubBullet.Velocity + SubBullet.RanVelocity * (float)Ran.NextPMDouble(); float num7 = SubBullet.AccelerateCS + SubBullet.RanAccelerate * (float)Ran.NextPMDouble(); double num8 = SubBullet.AccDirection + SubBullet.RanAccDirection; double num9 = Range + RanRange * Ran.NextPMDouble(); if (RDirectionWithDirection) { num3 += edi; } double num10 = num9 * Math.PI / 180.0 / num5; edi -= (num5 - 1) * num10 / 2.0; double num11 = num3 - (num5 - 1) * num10 / 2.0; if (EffectType == 2) { EmitterSaveEnegy3D emitterSaveEnegy3D = new EmitterSaveEnegy3D(StageData, OriginalPosition, CSEffect.ColorValue); StageData.SoundPlay("se_ch02.wav"); } else if (EffectType == 3) { EmitterGiveOutEnegy3D emitterGiveOutEnegy3D = new EmitterGiveOutEnegy3D(StageData, OriginalPosition, CSEffect.ColorValue); StageData.SoundPlay("se_cat00.wav"); StageData.SoundPlay("se_enep02.wav"); } else { for (int index1 = 0; index1 < num5; ++index1) { PointF p = new PointF(OriginalPosition.X + num4 * (float)Math.Cos(num11), OriginalPosition.Y + num4 * (float)Math.Sin(num11)); for (int index2 = 0; index2 < Count; ++index2) { if (EmitterMode == EmitterMode.Bullet || EmitterMode == EmitterMode.StraightLaser || EmitterMode == EmitterMode.RadialLaser || EmitterMode == EmitterMode.BendLaser) { BaseBullet_Touhou b = new BaseBullet_Touhou(StageData); if (CSBullet != null) { b = (BaseBullet_Touhou)CSBullet.Clone(); b.OriginalPosition = p; b.GhostingCount = b.GhostingCount; b.AngleDegree += CSBullet.RanAngle * Ran.NextPMDouble(); } else if (CSLaserS != null) { b = (BaseBullet_Touhou)CSLaserS.Clone(); b.OriginalPosition = p; b.Angle = -1.0 * Math.PI / 2.0; b.Active = true; } else if (CSLaserR != null) { b = (BaseBullet_Touhou)CSLaserR.Clone(); b.OriginalPosition = p; b.Angle = Math.PI / 2.0; b.UnRemoveable = true; b.Active = true; } else if (CSLaserB != null) { b = (BaseBullet_Touhou)CSLaserB.Clone(); b.OriginalPosition = p; b.UnRemoveable = true; b.Active = true; } b.GhostingCount = b.GhostingCount; b.Velocity = num6 - index2 * DeltaV; b.Direction = edi; b.AccelerateCS = num7; b.AccDirection = num8; b.ID = ID; b.LayerID = LayerID; if (MotionBinding) { b.SetBinding(this); } BulletList.Add(b); if (EmitterMode == EmitterMode.Bullet) { CSData.EmitterList.ForEach(em => { if (em.BindingID != ID) { return; } b.UnRemoveable = true; BaseEmitter_CS baseEmitterCs = (BaseEmitter_CS)em.Clone(); StageData.EnemyPlaneList.Add(baseEmitterCs); baseEmitterCs.OriginalPosition = p; baseEmitterCs.LifeTime = SubBullet.LifeTime; baseEmitterCs.ColorValue = SubBullet.ColorValue; baseEmitterCs.TransparentValueF = SubBullet.TransparentValueF; baseEmitterCs.Direction = edi; baseEmitterCs.DestPoint = SubBullet.DestPoint; baseEmitterCs.Active = SubBullet.Active; baseEmitterCs.OutBound = SubBullet.OutBound; if (baseEmitterCs.BindWithDirection) { baseEmitterCs.EmitDirection += edi * 180.0 / Math.PI; } baseEmitterCs.SetBinding(b); if (!baseEmitterCs.DeepBinding) { baseEmitterCs.Time = Time; baseEmitterCs.LifeTime = Math.Min(SubBullet.LifeTime + Time, em.StartTime + em.Duration); } }); } } else if (EmitterMode == EmitterMode.Enemy) { BaseEnemyPlane_Touhou enemy = (BaseEnemyPlane_Touhou)SubBullet.Clone(); enemy.LifeTime = 0; enemy.OriginalPosition = p; enemy.GhostingCount = enemy.GhostingCount; enemy.Velocity = num6 - index2 * DeltaV; enemy.Direction = edi; enemy.AccelerateCS = num7; enemy.AccDirection = num8; enemy.ID = ID; enemy.LayerID = LayerID; if (MotionBinding) { enemy.SetBinding(this); } EnemyPlaneList.Add(enemy); CSData.EmitterList.ForEach(em => { if (em.BindingID != ID) { return; } BaseEmitter_CS baseEmitterCs = (BaseEmitter_CS)em.Clone(); StageData.EnemyPlaneList.Add(baseEmitterCs); baseEmitterCs.OriginalPosition = p; baseEmitterCs.LifeTime = SubBullet.LifeTime; baseEmitterCs.ColorValue = SubBullet.ColorValue; baseEmitterCs.TransparentValueF = SubBullet.TransparentValueF; baseEmitterCs.Direction = edi; baseEmitterCs.DestPoint = SubBullet.DestPoint; baseEmitterCs.Active = SubBullet.Active; baseEmitterCs.OutBound = SubBullet.OutBound; baseEmitterCs.SetBinding(enemy); if (baseEmitterCs.BindWithDirection) { baseEmitterCs.EmitDirection += edi * 180.0 / Math.PI; } if (!baseEmitterCs.DeepBinding) { baseEmitterCs.Time = Time; baseEmitterCs.LifeTime = Math.Min(SubBullet.LifeTime + Time, em.StartTime + em.Duration); } }); } else if (EmitterMode == EmitterMode.Effect) { BaseEffect_CS baseEffectCs = (BaseEffect_CS)CSEffect.Clone(); baseEffectCs.OriginalPosition = p; baseEffectCs.GhostingCount = baseEffectCs.GhostingCount; baseEffectCs.AngleDegree += CSEffect.RanAngle * Ran.NextPMDouble(); baseEffectCs.Velocity = num6 - index2 * DeltaV; baseEffectCs.Direction = edi; baseEffectCs.AccelerateCS = num7; baseEffectCs.AccDirection = num8; baseEffectCs.ID = ID; baseEffectCs.LayerID = LayerID; if (MotionBinding) { baseEffectCs.SetBinding(this); } EffectList.Add(baseEffectCs); } } num11 += num10; edi += num10; if (SpecifySE) { StageData.SoundPlay(SoundName); } else if (EmitterMode == EmitterMode.Bullet) { StageData.SoundPlay("se_tan00a.wav", OriginalPosition.X / BoundRect.Width); } else if (EmitterMode == EmitterMode.StraightLaser || EmitterMode == EmitterMode.RadialLaser) { StageData.SoundPlay("se_lazer00.wav", OriginalPosition.X / BoundRect.Width); } } } }
public override void FireBullet() { //System.Diagnostics.Debug.WriteLine("Shots Fired"); BulletList.Add(new Bullet(new Vector2(shipLocation.X + Width, shipLocation.Y + Height / 2), Globals.GameWindowY / BulletScale, (Globals.GameWindowY / BulletScale) * (int)(bulletTexture.Bounds.Height / bulletTexture.Bounds.Width), 35, 0)); }
/// <summary> /// Update scene logics /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime) { this.camera.Update(gameTime.ElapsedGameTime, ref this.collisionMesh, GamePad.GetState(PlayerIndex.One), Keyboard.GetState()); this.player.Update(gameTime, this.collisionMesh); GamePadState gps = GamePad.GetState(PlayerIndex.One); KeyboardState kbs = Keyboard.GetState(); if (gps.Buttons.Y == ButtonState.Pressed || kbs.IsKeyDown(Keys.Enter)) { if (this.player.ActualGun != null) { Bullet b = this.player.ActualGun.Shot(); if (b != null) { Vector3 position = this.camera.GetWorldVector(3); Vector3 speed = -this.camera.GetWorldVector(2) * 1000.0f; b.Position = position; b.Speed = speed; this.bullets.Add(b); } } } this.CheckCollisions(gameTime); //Manages dead enemies EnemiesList deadEnemies = new EnemiesList(); foreach (KeyValuePair<String, Enemy> kvp in this.enemies) { if (kvp.Value.Dead) { deadEnemies.Add(kvp.Key, kvp.Value); } } foreach (string key in deadEnemies.Keys) { this.enemies.Remove(key); } foreach (Enemy e in this.enemies.Values) { e.Update(gameTime, this.camera.world.Translation, ref this.camera.view, ref this.camera.projection, ref this.collisionMesh); } ///Manages bullets BulletList deadBullets = new BulletList(); foreach (Bullet b in this.bullets) { if (b.Dead) { deadBullets.Add(b); } else { b.Update(gameTime, this.collisionMesh); } } foreach (Bullet b in deadBullets) { this.bullets.Remove(b); } }
protected static void AddBullet(Bullet b) { BulletList.Add(b); }