X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/4fc09567c557a1110180940cca40fd7144921026..8ae8ea0d77ec654dd693b3912562b07a2b539b0f:/SuperPolarity/Actors/MainShip.cs diff --git a/SuperPolarity/Actors/MainShip.cs b/SuperPolarity/Actors/MainShip.cs index bf4f3bb..7eef0b7 100644 --- a/SuperPolarity/Actors/MainShip.cs +++ b/SuperPolarity/Actors/MainShip.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -16,8 +16,6 @@ namespace SuperPolarity public static Color BlueColor; public static Color RedColor; - ParticleEngine particleEngine; - protected bool Shooting; protected int ShotCooldown; @@ -29,25 +27,52 @@ namespace SuperPolarity protected SoundEffect ShootSound; protected SoundEffect Hit; + // Aura stuff + protected Texture2D AuraPoint; + protected double AuraRadius; + protected double AuraAmplitude; + protected double AuraFrequency; + protected double AuraSubAmplitude; + protected double AuraWaveSize; + protected double AuraSubPhase; + protected double AuraSubFrequency; + public double[] EnemyModifications; + public double MaxEnemyModification; + public double EnemyModificationSpread; + public MainShip(SuperPolarity newGame) : base(newGame) {} ~MainShip() { - particleEngine = null; } public override void Initialize(Texture2D texture, Vector2 position) { base.Initialize(texture, position); - MainShip.BlueColor = new Color(211, 230, 234); + MainShip.BlueColor = new Color(71, 182, 226); MainShip.RedColor = new Color(235, 160, 185); + AuraPoint = CreateCircle (2); + + AuraRadius = 75; + AuraAmplitude = 7; + AuraFrequency = 3; + AuraSubAmplitude = 7; + AuraWaveSize = 3; + AuraSubPhase = 0; + AuraSubFrequency = 9 * Math.PI / 180; + MaxEnemyModification = 20; + EnemyModificationSpread = 10; + EnemyModifications = new double[360]; + for ( int i = 0; i < EnemyModifications.Length; i++ ) { + EnemyModifications[i] = 0; + } + PolarityChange = game.Content.Load("Sound\\polaritychange"); ShootSound = game.Content.Load("Sound\\bullet"); Hit = game.Content.Load("Sound\\hit"); - InitParticleEngine(); SetPolarity(Polarity.Positive); ActVelocity = 2.5f; @@ -64,11 +89,6 @@ namespace SuperPolarity BindInput(); } - void InitParticleEngine() - { - particleEngine = ParticleEffectFactory.CreatePolarCircle(Position); - } - void BindInput() { InputController.Bind("moveX", HandleHorizontalMovement); @@ -131,42 +151,28 @@ namespace SuperPolarity public override void SwitchPolarity() { base.SwitchPolarity(); - SwitchParticleEngine(CurrentPolarity); PolarityChange.Play(); game.Player.ResetMultiplier(); } public override void SetPolarity(Polarity newPolarity) { - base.SetPolarity(newPolarity); - SwitchParticleEngine(newPolarity); - } - - protected void SwitchParticleEngine(Polarity polarity) - { - if (polarity == Polarity.Positive) - { - particleEngine.Color = MainShip.RedColor; - } - else if (polarity == Polarity.Negative) - { - particleEngine.Color = MainShip.BlueColor; - } - else - { - particleEngine.Color = Color.Gray; - } + base.SetPolarity(newPolarity);; } - + public override void Update(GameTime gameTime) { base.Update(gameTime); - particleEngine.EmitterLocation = Position; - particleEngine.Update(); ConstrainToEdges(); UpdateImmortality(gameTime); } + public void ResetEnemyModification() { + for ( int i = 0; i < EnemyModifications.Length; i++ ) { + EnemyModifications[i] = 0; + } + } + public void UpdateImmortality(GameTime gameTime) { if (Immortal) @@ -270,15 +276,135 @@ namespace SuperPolarity } } - public override void Draw(SpriteBatch spriteBatch) + public void UpdateEnemyModification(Ship enemy) { + + var dx = enemy.Position.X - Position.X; + var dy = enemy.Position.Y - Position.Y; + var angleInDegrees = ((360 + Math.Round (Math.Atan2 (dy, dx) * 180 / Math.PI)) % 360); + + for (var i = -EnemyModificationSpread; i < EnemyModificationSpread; i++) { + var strength = MaxEnemyModification - Math.Abs (i * MaxEnemyModification / EnemyModificationSpread); + + var index = (int)((360 + angleInDegrees + i) % 360); + + if (enemy.CurrentPolarity == CurrentPolarity) { + EnemyModifications[index] -= strength; + } else { + EnemyModifications[index] += strength; + } + + if (EnemyModifications[index] > MaxEnemyModification) { + EnemyModifications[index] = MaxEnemyModification; + } + + if (EnemyModifications[index] < -MaxEnemyModification) { + EnemyModifications[index] = -MaxEnemyModification; + } + } + } + + public override void Draw(SpriteBatch spriteBatch) { - particleEngine.Draw(spriteBatch); + DrawCircle (spriteBatch); base.Draw(spriteBatch); + //spriteBatch.Draw(BoxTexture, Box, new Color(255, 0, 255, 25)); + } + + protected void DrawCircle(SpriteBatch spriteBatch) { + + var j = AuraWaveSize; + var subWaveRadius = 0.0; + var randomPosition = 0.0; + + for (var i = 0; i < 360; i++) { + var angle = i * Math.PI / 180; + + if (j == AuraWaveSize) { + subWaveRadius = AuraSubAmplitude * Math.Sin (randomPosition + AuraSubPhase); + randomPosition -= (2 * Math.PI / 8); + j = 0; + } + j++; + + var radius = EnemyModifications[i] + subWaveRadius + AuraRadius + AuraAmplitude * Math.Sin (i / AuraFrequency); + var x = Position.X + radius * Math.Cos (angle); + var y = Position.Y + radius * Math.Sin (angle); + + x = Math.Round (x); + y = Math.Round (y); + var pointPosition = new Vector2 ((float)x, (float)y); + + if (CurrentPolarity == Polarity.Positive) { + spriteBatch.Draw (AuraPoint, pointPosition, RedColor); + } else { + spriteBatch.Draw (AuraPoint, pointPosition, BlueColor); + } + } + + AuraSubPhase += AuraSubFrequency; + + /* var r = 50; + var wave = 5; + var frequency = 1.4; + var randomFactor = 5; + var randomAreaSize = 4; + + var j = AuraWaveSize; + var rand = 0; + var randomPosition = 0; + + AuraSubPhase = 0; + + for (var i = 0; i < 360; i++) { + var rad = Math.radians(i); + if (j == AuraWaveSize) { + //rand = Math.random() * 2 * AuraSubAmplitude - AuraSubAmplitude; + rand = AuraSubAmplitude * Math.sin(AuraSubPhase + offset); + AuraSubPhase -= (2 * Math.PI / 8); + j = 0; } + j++; + var radius = polarityModifications[i] + rand + AuraRadius + AuraAmplitude * Math.sin(i / AuraFrequency); + var x = Position.x + radius * Math.cos(rad); + var y = Position.y + radius * Math.sin(rad); + x = Math.round(x); + y = Math.round(y); + + draw + //console.log(i, rad, x, y, dataStart); + }); + + ctx.putImageData(imgData, 0, 0);*/ + } + + protected Texture2D CreateCircle(int radius) + { + int outerRadius = radius * 2 + 2; + Texture2D texture = new Texture2D (game.GraphicsDevice, outerRadius, outerRadius); + + Color[] data = new Color[outerRadius * outerRadius]; + + for (int i = 0; i < data.Length; i++) { + data [i] = Color.Transparent; + } + + double angleStep = 1f / radius; + + for (double angle = 0; angle < Math.PI * 2; angle += angleStep) + { + int x = (int)Math.Round (radius + radius * Math.Cos (angle)); + int y = (int)Math.Round (radius + radius + Math.Sin (angle)); + + data [y * outerRadius + x + 1] = Color.White; + } + + texture.SetData (data); + return texture; + } public override void Collide(Actor other, Rectangle collision) { - if (other.GetType().IsAssignableFrom(typeof(StandardShip)) && + if (other.GetType().IsAssignableFrom(typeof(StandardShip)) && !Immortal) { Die(); @@ -304,7 +430,6 @@ namespace SuperPolarity public override void CleanUp() { base.CleanUp(); - particleEngine = null; InputController.Unbind("moveX", HandleHorizontalMovement); InputController.Unbind("moveY", HandleVerticalMovement); InputController.Unbind("changePolarity", HandleChangePolarity);