From 1838c80ccb140685d51dd5f0c331d170119bbad0 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Mon, 22 Jul 2019 20:46:33 -0700 Subject: [PATCH] Added in kill zones but also just made it so if enemies or projectiles go too far off the map they die. Also finished making spawners for targets and reworked managers to be stored in a single entity manager. --- .../Interfaces/ISpawner.cs | 22 ++ .../SSCEnemies/EnemyManager.cs | 38 ++++ .../SSCEnemies/KillZone.cs | 48 ++++ .../SSCEnemies/SSCE_Target.cs | 46 +++- .../SSCEnemies/SSCEnemy.cs | 13 ++ .../SSCEnemies/Spawners/Target_Spawner.cs | 207 ++++++++++++++++++ .../SSCEntities/SSCEntityManager.cs | 59 +++++ .../SSCMenus/CharacterSelectScreen.cs | 6 +- .../SeasideScrambleMinigame/SSCPlayer.cs | 2 +- .../SSCProjectiles/SSCProjectile.cs | 5 +- .../SSCProjectiles/SSCProjectileManager.cs | 9 +- .../SeasideScramble.cs | 37 ++-- .../SeasideScrambleMap.cs | 20 ++ .../Framework/Utilities/Vector2Utilities.cs | 2 + GeneralMods/Revitalize/Revitalize.csproj | 4 + 15 files changed, 494 insertions(+), 24 deletions(-) create mode 100644 GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/Interfaces/ISpawner.cs create mode 100644 GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/KillZone.cs create mode 100644 GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/Spawners/Target_Spawner.cs create mode 100644 GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEntities/SSCEntityManager.cs diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/Interfaces/ISpawner.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/Interfaces/ISpawner.cs new file mode 100644 index 00000000..44a261c0 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/Interfaces/ISpawner.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.Interfaces +{ + public interface ISpawner + { + + void update(GameTime Time); + void draw(SpriteBatch b); + bool enabled + { + get;set; + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/EnemyManager.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/EnemyManager.cs index 5ef578b6..ffa85c6d 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/EnemyManager.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/EnemyManager.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Revitalize.Framework.Minigame.SeasideScrambleMinigame.Interfaces; namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies { @@ -13,6 +14,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies public List enemies; private List garbageCollection; + private List spawnerGarbageCollection; + public List spawners; + /// /// Constructor. /// @@ -20,6 +24,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies { this.enemies = new List(); this.garbageCollection = new List(); + + this.spawners = new List(); + this.spawnerGarbageCollection = new List(); } /// @@ -39,12 +46,31 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies this.garbageCollection.Add(enemy); } + public void addSpawner(ISpawner spawner) + { + this.spawners.Add(spawner); + } + public void removeSpawner(ISpawner spawner) + { + this.spawnerGarbageCollection.Add(spawner); + } + /// /// Update all enemies. /// /// public void update(GameTime time) { + + foreach(ISpawner spawner in this.spawnerGarbageCollection) + { + this.spawners.Remove(spawner); + } + foreach(ISpawner spawner in this.spawners) + { + spawner.update(time); + } + foreach(SSCEnemy enemy in this.garbageCollection) { this.enemies.Remove(enemy); @@ -53,7 +79,15 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies { enemy.update(time); if (enemy.shouldDie) this.removeEnemy(enemy); + //Delete enemies that are too far off screen. + Vector2 mapSize = SeasideScramble.self.currentMap.getPixelSize(); + if (enemy.Position.X>mapSize.X*2 || enemy.Position.X<-mapSize.X || enemy.Position.Y>mapSize.Y*2|| enemy.Position.Y < -mapSize.Y) + { + enemy.shouldDie = true; //Silently remove the enemy from the map. + this.removeEnemy(enemy); + } } + } /// @@ -66,6 +100,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies { enemy.draw(b); } + foreach(ISpawner spawner in this.spawners) + { + spawner.draw(b); + } } } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/KillZone.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/KillZone.cs new file mode 100644 index 00000000..8861c6c8 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/KillZone.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; + +namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies +{ + public class KillZone + { + private Vector2 position; + public Rectangle hitBox; + + /// + /// Sets the position of the kill zone as well as the position of the kill zone hit box. + /// + public Vector2 Position + { + get + { + return this.position; + } + set + { + this.position = value; + this.hitBox.X = (int)this.position.X; + this.hitBox.Y = (int)this.position.Y; + } + } + + public KillZone() + { + + } + + public KillZone(Vector2 Position,Rectangle HitBox) + { + this.hitBox = HitBox; + this.Position = Position; + } + + public void onCollision(SSCProjectiles.SSCProjectile projectile) + { + //Do nothing??? + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/SSCE_Target.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/SSCE_Target.cs index a7f8add2..f12976ac 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/SSCE_Target.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/SSCE_Target.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles; +using Revitalize.Framework.Utilities; using StardustCore.Animations; namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies @@ -14,14 +15,25 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies private bool targetHit; + public Vector2 direction; + public float speed; + public Vector2 Velocity + { + get + { + return this.direction * this.speed; + } + } + public SSCE_Target():base() { } - public SSCE_Target(AnimatedSprite Sprite, int MoveSpeed, int MaxHealth, Vector2 HitBoxDimensions,float Scale):base(Sprite,MoveSpeed,MaxHealth,HitBoxDimensions,Scale) + public SSCE_Target(AnimatedSprite Sprite, int MoveSpeed, int MaxHealth, Vector2 HitBoxDimensions,float Scale,Vector2 Direction,float Speed):base(Sprite,MoveSpeed,MaxHealth,HitBoxDimensions,Scale) { - + this.direction = Direction; + this.speed = Speed; } public override void die() @@ -35,14 +47,28 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies this.targetHit = true; } + /// + /// Updates the state of the enemy. + /// + /// public override void update(GameTime time) { if(this.sprite.animation.IsAnimationPlaying==false && this.targetHit) { this.shouldDie = true; } + this.updateMovement(); } + public override void updateMovement() + { + this.Position += this.Velocity; + } + + /// + /// What happens when the target collides with a projectile. + /// + /// public override void onCollision(SSCProjectile other) { if (other is SSCProjectiles.SSCProjectile) @@ -54,6 +80,18 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies public static void Spawn_SSCE_Target(Vector2 Position,Color Color) + { + Spawn_SSCE_Target(Position, Color, Vector2.Zero, 0f); + } + + /// + /// Spawn a target enemy with the given paramaters. + /// + /// + /// + /// + /// + public static void Spawn_SSCE_Target(Vector2 Position, Color Color,Vector2 Direction, float Speed) { SSCE_Target target = new SSCE_Target(new AnimatedSprite("TargetPractice", Position, new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("Enemies", "Target"), new Animation(0, 0, 16, 16), new Dictionary>() { { "None",new List(){ @@ -67,8 +105,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies } } - },"None"), Color), 0, 1, new Vector2(16,16),4f); - SeasideScramble.self.enemies.addEnemy(target); + }, "None"), Color), 0, 1, new Vector2(16, 16), 4f, Direction.UnitVector(), Speed); + SeasideScramble.self.entities.addEnemy(target); } } } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/SSCEnemy.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/SSCEnemy.cs index c392f502..1bc4c28b 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/SSCEnemy.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/SSCEnemy.cs @@ -29,6 +29,14 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies { return this.sprite.position; } + set + { + this.sprite.position = value; + Rectangle hit = this.HitBox; + hit.X = (int)this.Position.X; + hit.Y = (int)this.Position.Y; + this.HitBox = hit; + } } public SSCEnemy() @@ -71,5 +79,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies } + public virtual void updateMovement() + { + + } + } } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/Spawners/Target_Spawner.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/Spawners/Target_Spawner.cs new file mode 100644 index 00000000..68db9691 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEnemies/Spawners/Target_Spawner.cs @@ -0,0 +1,207 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Revitalize.Framework.Minigame.SeasideScrambleMinigame.Interfaces; + +namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies.Spawners +{ + public class Target_Spawner:ISpawner + { + + public Vector2 position; + /// + /// The max time in milliseconds between spawns. + /// + public double maxFrequency; + /// + /// The min time in milliseconds between spawns. + /// + public double minFrequency; + + /// + /// The time until the next spawn. + /// + public double timeUntilNextSpawn; + + /// + /// Randomizes the spawn time between spawns between 0 and this.frequency. + /// + public bool randomizeSpawnTimes; + + public Vector2 spawnDirection; + + public Color spawnColor; + public bool randomizeColor; + /// + /// The max speed a target can travel at. + /// + public float maxSpeed; + public float minSpeed; + + public bool enabled { get; set; } + + public Target_Spawner() + { + + } + + + /// + /// Constructor. + /// + /// The position of the spawner. + /// The direction to spawn targets. + /// The default color of targets that are spawned. + /// Should the color be randomized every time a target is spawned? + /// The max amount of time between spawns. + /// The min amount of time between spawns. + /// Should the frequency between spawns be randomized? + /// + /// + public Target_Spawner(Vector2 Position,Vector2 SpawnDirection ,Color Color,bool RandomizeColor,double MinFrequency,double MaxFrequency,bool RandomizeSpawnTime,float MinSpeed,float MaxSpeed,bool Enabled) + { + this.position = Position; + this.spawnDirection = SpawnDirection; + + this.spawnColor = Color; + this.randomizeColor = RandomizeColor; + + this.minFrequency = MinFrequency; + this.maxFrequency = MaxFrequency; + this.randomizeSpawnTimes = RandomizeSpawnTime; + this.setNextSpawnTime(); + + this.minSpeed = MinSpeed; + this.maxSpeed = MaxSpeed; + this.enabled = Enabled; + } + + /// + /// Sets the time until the next spawn. + /// + private void setNextSpawnTime() + { + if (this.randomizeSpawnTimes) + { + this.timeUntilNextSpawn = SeasideScramble.self.random.NextDouble() * this.maxFrequency; + if (this.timeUntilNextSpawn < this.minFrequency) this.timeUntilNextSpawn = this.minFrequency; + } + else + { + this.timeUntilNextSpawn = this.maxFrequency; + } + } + + /// + /// Update the logic of the spawner. + /// + /// + public void update(GameTime time) + { + if (this.enabled == false) return; + this.timeUntilNextSpawn -= time.ElapsedGameTime.Milliseconds; + if (this.timeUntilNextSpawn <= 0) + { + this.spawn(this.position, this.spawnDirection, this.randomizeColor ? this.getRandomColor() : this.spawnColor, (float)this.getRandomSpeed()); + this.setNextSpawnTime(); + } + } + public void draw(SpriteBatch b) + { + //Do I really want to draw a spawner??? + } + + + public void turnOn() + { + this.enabled = true; + } + + public void turnOff() + { + this.enabled = false; + } + + /// + /// Get a random color for the spawned target. + /// + /// + private Color getRandomColor() + { + int red = (int)(SeasideScramble.self.random.NextDouble() * 255); + int green = (int)(SeasideScramble.self.random.NextDouble() * 255); + int blue = (int)(SeasideScramble.self.random.NextDouble() * 255); + Color c = new Color(red, green, blue); + return c; + } + + /// + /// Get a random speed for the newly spawned target. + /// + /// + private double getRandomSpeed() + { + double speed = this.maxSpeed * SeasideScramble.self.random.NextDouble(); + if (speed < this.minSpeed) speed = this.minSpeed; + return speed; + } + + /// + /// Spawns a target at this position and sends it a specific direction. + /// + /// + /// + /// + public void spawn(SSCEnums.FacingDirection Direction,Color color, float Speed) + { + if(Direction== SSCEnums.FacingDirection.Down) + { + this.spawnDown(this.position, color, Speed); + } + if (Direction == SSCEnums.FacingDirection.Up) + { + this.spawnUp(this.position, color, Speed); + } + if (Direction == SSCEnums.FacingDirection.Right) + { + this.spawnRight(this.position, color, Speed); + } + if (Direction == SSCEnums.FacingDirection.Left) + { + this.spawnLeft(this.position, color, Speed); + } + } + + public void spawn(Vector2 Position,Vector2 Direction,Color Color, float Speed) + { + SSCEnemies.SSCE_Target.Spawn_SSCE_Target(Position, Color, Direction, Speed); + } + + public void spawnStationary(Vector2 Position, Color Color) + { + SSCEnemies.SSCE_Target.Spawn_SSCE_Target(Position, Color); + } + + public void spawnLeft(Vector2 Position, Color Color,float Speed) + { + SSCEnemies.SSCE_Target.Spawn_SSCE_Target(Position, Color,new Vector2(-1,0),Speed); + } + public void spawnRight(Vector2 Position, Color Color, float Speed) + { + SSCEnemies.SSCE_Target.Spawn_SSCE_Target(Position, Color, new Vector2(1, 0), Speed); + } + public void spawnUp(Vector2 Position, Color Color, float Speed) + { + SSCEnemies.SSCE_Target.Spawn_SSCE_Target(Position, Color, new Vector2(0, -1), Speed); + } + public void spawnDown(Vector2 Position, Color Color, float Speed) + { + SSCEnemies.SSCE_Target.Spawn_SSCE_Target(Position, Color, new Vector2(0, 1), Speed); + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEntities/SSCEntityManager.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEntities/SSCEntityManager.cs new file mode 100644 index 00000000..64ab2c09 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCEntities/SSCEntityManager.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Revitalize.Framework.Minigame.SeasideScrambleMinigame.Interfaces; +using Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies; + +namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEntities +{ + public class SSCEntityManager + { + public SSCProjectiles.SSCProjectileManager projectiles; + public SSCEnemies.EnemyManager enemies; + public List killZones; + + public SSCEntityManager() + { + this.projectiles = new SSCProjectiles.SSCProjectileManager(); + this.enemies = new EnemyManager(); + this.killZones = new List(); + } + + public void addProjectile(SSCProjectiles.SSCProjectile projectile) + { + this.projectiles.addProjectile(projectile); + } + + public void addEnemy(SSCEnemies.SSCEnemy enemy) + { + this.enemies.addEnemy(enemy); + } + + public void addSpawner(ISpawner spawner) + { + this.enemies.addSpawner(spawner); + } + + public void addKillZone(KillZone zone) + { + this.killZones.Add(zone); + } + + public void update(GameTime time) + { + this.projectiles.update(time); + this.enemies.update(time); + } + + public void draw(SpriteBatch b) + { + this.projectiles.draw(b); + this.enemies.draw(b); + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs index 2b5cdd96..f515b13e 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCEnemies.Spawners; using Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCStatusEffects; using StardewValley; using StardustCore.Animations; @@ -471,8 +472,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus //p.statusEffects.addStatusEffect(SE_Burn.SpawnBurnEffect(new Vector2(p.HUD.xPositionOnScreen,p.HUD.yPositionOnScreen),10*1000,1000,1.00d,1)); } - SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(100, 100), Color.Blue); - // SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(200, 100), Color.Red); + SeasideScramble.self.entities.addSpawner(new Target_Spawner(new Vector2(-64, 0), new Vector2(1, 0), Color.White, true, 1000, 5000, true, 0.25f, 3f,true)); + //SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(100, 100), Color.Blue); + //SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(200, 100), Color.Red); //SSCEnemies.SSCE_Target.Spawn_SSCE_Target(new Vector2(300, 100), Color.Green); } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs index 24b56872..43b7694b 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs @@ -145,7 +145,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame } this.mouseSensitivity = new Vector2(3f, 3f); - this.gun = new SSCGuns.SSCGun(new StardustCore.Animations.AnimatedSprite("MyFirstGun", this.position, new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("Guns", "BasicGun"), new Animation(0, 0, 16, 16)), Color.White), SeasideScramble.self.projectiles.getDefaultProjectile(this, this.position, Vector2.Zero, 1f, new Rectangle(0, 0, 16, 16), Color.White, 4f, 300), 10, 1000, 3000); + this.gun = new SSCGuns.SSCGun(new StardustCore.Animations.AnimatedSprite("MyFirstGun", this.position, new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("Guns", "BasicGun"), new Animation(0, 0, 16, 16)), Color.White), SeasideScramble.self.entities.projectiles.getDefaultProjectile(this, this.position, Vector2.Zero, 1f, new Rectangle(0, 0, 16, 16), Color.White, 4f, 300), 10, 1000, 3000); this.hitBox = new Rectangle((int)this.position.X, (int)this.position.Y, 64, 64); diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectile.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectile.cs index 0cadbe70..8bf98c38 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectile.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectile.cs @@ -118,8 +118,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles { //Make projectile manager that handles deleting this projectile. //Make projectile manager have a pool of projectiles???? - ModCore.log("Projectile has died."); - SeasideScramble.self.projectiles.deleteProjectile(this); + SeasideScramble.self.entities.projectiles.deleteProjectile(this); } /// @@ -194,7 +193,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles { //AnimatedSprite newSprite = new AnimatedSprite(this.sprite.name, position, new AnimationManager(this.sprite.animation.objectTexture.Copy(), this.sprite.animation.defaultDrawFrame), this.color); SSCProjectile basic = new SSCProjectile(this.owner, new AnimatedSprite("DefaultProjectile", position, new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("Projectiles", "Basic"), new Animation(0, 0, 4, 4)), this.color), new Rectangle(this.hitBox.X,this.hitBox.Y,this.hitBox.Width,this.hitBox.Height), position, direction, this.speed, this.maxLifeSpan, this.scale,this.damage); - SeasideScramble.self.projectiles.addProjectile(basic); + SeasideScramble.self.entities.projectiles.addProjectile(basic); } } } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectileManager.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectileManager.cs index ecb3a106..68876a93 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectileManager.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectileManager.cs @@ -51,7 +51,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles player.onCollision(p); } } - foreach(SSCEnemies.SSCEnemy enemy in SeasideScramble.self.enemies.enemies) + foreach(SSCEnemies.SSCEnemy enemy in SeasideScramble.self.entities.enemies.enemies) { if (p.collidesWith(enemy.HitBox)) { @@ -59,6 +59,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles enemy.onCollision(p); //What happens to the entity. } } + + //Quietly clean up stray projectiles just incase their timer hasn't ticked out yet. + Vector2 mapSize = SeasideScramble.self.currentMap.getPixelSize(); + if (p.position.X > mapSize.X * 2 || p.position.X < -mapSize.X || p.position.Y > mapSize.Y * 2 || p.position.Y < -mapSize.Y) + { + this.deleteProjectile(p); + } } } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs index 7efeb376..eb5278c8 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs @@ -19,13 +19,22 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame /// -a,d for keyboard /// -dpad for p2-4 /// Also add interface for game entity for camera to consistently have a focus target. + /// -Make moving target enemies + /// -Make a sound effect play when they break + /// -Fix positioning of status effects on player HUD + /// -Add effect on player for a more visual representation of status effects. + /// + /// -Make shooting gallary map. + /// -Make More guns /// public class SeasideScramble : StardewValley.Minigames.IMinigame { - + /// + /// A static reference to the game. + /// public static SeasideScramble self; - SeasideScrambleMap currentMap; + public SeasideScrambleMap currentMap; public Dictionary SeasideScrambleMaps; public int currentNumberOfPlayers @@ -49,11 +58,18 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame public Vector2 oldMousePosition; - public SSCProjectiles.SSCProjectileManager projectiles; - public SSCEnemies.EnemyManager enemies; + public SSCEntities.SSCEntityManager entities; public SSCFonts.SSCFont gameFont; + public Random random + { + get + { + return Game1.random; + } + } + public SeasideScramble() { self = this; @@ -63,7 +79,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.LoadTextures(); - this.projectiles = new SSCProjectiles.SSCProjectileManager(); + this.entities = new SSCEntities.SSCEntityManager(); this.LoadMaps(); this.loadStartingMap(); @@ -80,7 +96,6 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.oldMousePosition = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y); this.gameFont = new SSCFonts.SSCFont(new SSCFonts.SSCFontCharacterSheet()); - this.enemies = new SSCEnemies.EnemyManager(); } public SSCPlayer getPlayer(SSCEnums.PlayerID id) @@ -183,14 +198,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame p.drawMouse(b); } } - this.enemies.draw(b); + this.entities.draw(b); this.menuManager.drawAll(b); - this.projectiles.draw(b); - - - b.End(); } @@ -384,11 +395,11 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame { if (player.playerID == SSCEnums.PlayerID.One) this.camera.centerOnPosition(player.position); player.update(time); - this.enemies.update(time); } + this.entities.update(time); } - this.projectiles.update(time); + this.oldMousePosition = new Vector2(Game1.getOldMouseX(), Game1.getOldMouseY()); return false; diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScrambleMap.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScrambleMap.cs index 97a5b781..a45bd563 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScrambleMap.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScrambleMap.cs @@ -84,5 +84,25 @@ AlwaysFront: Objects that are always drawn on top of other layers as well as the return new KeyValuePair(mapAssetKey, map); } + public virtual Vector2 getPixelSize() + { + Layer layer = this.map.GetLayer("Back"); + return new Vector2(layer.TileSize.Width * (layer.LayerWidth/4f) * 4f, layer.TileSize.Height * (layer.LayerHeight/4f) * 4f); + } + public virtual Vector2 getPixelSize(float mapZoomScale) + { + Layer layer = this.map.GetLayer("Back"); + return new Vector2(layer.TileSize.Width * layer.LayerWidth * mapZoomScale, layer.TileSize.Height * layer.LayerWidth * mapZoomScale); + } + + + public void debugInfo() + { + Layer layer = this.map.GetLayer("Back"); + ModCore.log("layer Tile Size: " + new Vector2(layer.TileSize.Width,layer.TileSize.Height)); + ModCore.log("Layer Width/Height: " + new Vector2(layer.LayerWidth, layer.LayerHeight)); + ModCore.log("Size multiplier: 4"); + } + } } diff --git a/GeneralMods/Revitalize/Framework/Utilities/Vector2Utilities.cs b/GeneralMods/Revitalize/Framework/Utilities/Vector2Utilities.cs index ba3b9fb9..24d52f58 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/Vector2Utilities.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/Vector2Utilities.cs @@ -21,7 +21,9 @@ namespace Revitalize.Framework.Utilities /// public static Vector2 UnitVector(this Vector2 vec) { + if (vec == Vector2.Zero) return Vector2.Zero; double mag = Magnitude(vec); + if (mag == 0) return Vector2.Zero; return new Vector2((float)(vec.X / mag),(float)(vec.Y / mag)); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index ce293b21..059e261a 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -66,13 +66,17 @@ + + + +