Got projectiles and a projectile manager working!
This commit is contained in:
parent
feb5302c39
commit
71868bd0b6
Binary file not shown.
After Width: | Height: | Size: 79 B |
|
@ -14,11 +14,12 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
{
|
||||
public class SSCPlayer
|
||||
{
|
||||
//TODO: Add gamepad input
|
||||
//TODO: Add movement speed variable
|
||||
//TODO: Add in health
|
||||
//TODO: Add in player HUD
|
||||
//TODO: Add in player cursor
|
||||
//TODO: Make guns
|
||||
//TODO: Make projectiles
|
||||
//TODO: Add in hit boxes
|
||||
public AnimationManager characterSpriteController;
|
||||
public bool flipSprite;
|
||||
public SSCEnums.FacingDirection facingDirection;
|
||||
|
@ -458,7 +459,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
|
||||
private void shoot(Vector2 direction)
|
||||
{
|
||||
ModCore.log("Shoot: " + direction);
|
||||
if (SeasideScramble.self.menuManager.isMenuUp) return;
|
||||
//ModCore.log("Shoot: " + direction);
|
||||
SeasideScramble.self.projectiles.spawnDefaultProjectile(this, this.position, direction, 1f, new Rectangle(0, 0, 16, 16), Color.White, 4f, 300);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
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 StardustCore.Animations;
|
||||
|
||||
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
|
||||
{
|
||||
public class SSCProjectile
|
||||
{
|
||||
public AnimatedSprite sprite;
|
||||
public Vector2 direction;
|
||||
public float speed;
|
||||
public float scale;
|
||||
public Rectangle hitBox;
|
||||
public Vector2 position
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.sprite.position;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.sprite.position = value;
|
||||
}
|
||||
}
|
||||
public Color color
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.sprite.color;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.sprite.color = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int maxLifeSpan;
|
||||
public int currentLifeSpan;
|
||||
|
||||
/// <summary>
|
||||
/// The object that spawned this projectile.
|
||||
/// </summary>
|
||||
public object owner;
|
||||
|
||||
public Vector2 Velocity
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.direction * this.speed;
|
||||
}
|
||||
}
|
||||
|
||||
public SSCProjectile()
|
||||
{
|
||||
|
||||
}
|
||||
public SSCProjectile(object Owner,AnimatedSprite Sprite,Rectangle HitBox ,Vector2 Position,Vector2 Direction, float Speed, int LifeSpan ,float Scale)
|
||||
{
|
||||
this.sprite = Sprite;
|
||||
this.hitBox = HitBox;
|
||||
this.direction = Direction;
|
||||
this.speed = Speed;
|
||||
this.position = Position;
|
||||
this.scale = Scale;
|
||||
this.maxLifeSpan = LifeSpan;
|
||||
this.currentLifeSpan = LifeSpan;
|
||||
this.owner = Owner;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the projectile.
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
public virtual void update(GameTime time)
|
||||
{
|
||||
this.tickLifeSpan();
|
||||
this.updateMovement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the movement for the projectile.
|
||||
/// </summary>
|
||||
public virtual void updateMovement()
|
||||
{
|
||||
this.position += this.Velocity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tick the lifespan of the projectile.
|
||||
/// </summary>
|
||||
public virtual void tickLifeSpan()
|
||||
{
|
||||
if (this.currentLifeSpan <= 0)
|
||||
{
|
||||
this.die();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.currentLifeSpan--;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// What happens when this projectile dies.
|
||||
/// </summary>
|
||||
public virtual void die()
|
||||
{
|
||||
//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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the projectile.
|
||||
/// </summary>
|
||||
/// <param name="b"></param>
|
||||
public virtual void draw(SpriteBatch b)
|
||||
{
|
||||
this.sprite.draw(b, SeasideScramble.GlobalToLocal(SeasideScramble.self.camera.viewport, this.position), this.scale, 0.5f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the projectile collides with something.
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool collidesWith(Vector2 position)
|
||||
{
|
||||
return this.hitBox.Contains(new Point((int)position.X,(int)position.Y));
|
||||
}
|
||||
public bool collidesWith(Rectangle rec)
|
||||
{
|
||||
return this.hitBox.Intersects(rec);
|
||||
}
|
||||
|
||||
public virtual void collisionLogic()
|
||||
{
|
||||
//Do something I guess.
|
||||
this.die();
|
||||
}
|
||||
|
||||
public virtual void onCollision(object other)
|
||||
{
|
||||
if(other is SSCPlayer)
|
||||
{
|
||||
if (this.hasOwner())
|
||||
{
|
||||
if (this.owner == other)
|
||||
{
|
||||
ModCore.log("Can't get hit by own projectile.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
ModCore.log("Big oof. Player hit by projectile.");
|
||||
this.collisionLogic();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this projectile has an owner in the weird case I spawn some without owners.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool hasOwner()
|
||||
{
|
||||
return this.owner != null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
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.SSCProjectiles
|
||||
{
|
||||
public class SSCProjectileManager
|
||||
{
|
||||
public List<SSCProjectile> projectiles;
|
||||
private List<SSCProjectile> garbageCollection;
|
||||
|
||||
public SSCProjectileManager()
|
||||
{
|
||||
this.projectiles = new List<SSCProjectile>();
|
||||
this.garbageCollection = new List<SSCProjectile>();
|
||||
}
|
||||
|
||||
public void addProjectile(SSCProjectile projectile)
|
||||
{
|
||||
this.projectiles.Add(projectile);
|
||||
}
|
||||
|
||||
public void deleteProjectile(SSCProjectile projectile)
|
||||
{
|
||||
this.garbageCollection.Add(projectile);
|
||||
//this.projectiles.Remove(projectile);
|
||||
}
|
||||
|
||||
public void update(GameTime Time)
|
||||
{
|
||||
foreach(SSCProjectile p in this.garbageCollection)
|
||||
{
|
||||
this.projectiles.Remove(p);
|
||||
}
|
||||
this.garbageCollection.Clear();
|
||||
|
||||
foreach(SSCProjectile p in this.projectiles)
|
||||
{
|
||||
p.update(Time);
|
||||
|
||||
//Do collision checking.
|
||||
foreach(SSCPlayer player in SeasideScramble.self.players.Values)
|
||||
{
|
||||
if (p.collidesWith(player.position))
|
||||
{
|
||||
p.onCollision(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(SpriteBatch b)
|
||||
{
|
||||
foreach (SSCProjectile p in this.projectiles)
|
||||
{
|
||||
p.draw(b);
|
||||
}
|
||||
}
|
||||
|
||||
//~~~~~~~~~~~~~~~~~~~~//
|
||||
// Spawning Logic //
|
||||
//~~~~~~~~~~~~~~~~~~~~//
|
||||
#region
|
||||
|
||||
public void spawnDefaultProjectile(object Owner,Vector2 Position,Vector2 Direction,float Speed,Rectangle HitBox,Color Color,float Scale,int LifeSpan=300)
|
||||
{
|
||||
|
||||
SSCProjectile basic = new SSCProjectile(Owner, new StardustCore.Animations.AnimatedSprite("DefaultProjectile", Position, new StardustCore.Animations.AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("Projectiles", "Basic"), new StardustCore.Animations.Animation(0, 0, 4, 4)), Color), HitBox, Position, Direction, Speed, LifeSpan, Scale);
|
||||
this.addProjectile(basic);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -13,9 +13,7 @@ using StardustCore.UIUtilities;
|
|||
namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
||||
{
|
||||
/// <summary>
|
||||
/// TODO: Finish character select screen. Ensure that camera snapping doesn't happen until game starts.
|
||||
/// -Make boxes per character
|
||||
/// -Make prompt to click for p1, press a for p2,3,4
|
||||
/// TODO: Finish character select screen.
|
||||
/// -Make Sound effects happen
|
||||
/// -make prompt for color selection
|
||||
/// -a,d for keyboard
|
||||
|
@ -51,6 +49,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
|
||||
public Vector2 oldMousePosition;
|
||||
|
||||
public SSCProjectiles.SSCProjectileManager projectiles;
|
||||
|
||||
public SeasideScramble()
|
||||
{
|
||||
self = this;
|
||||
|
@ -60,6 +60,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
|
||||
this.LoadTextures();
|
||||
|
||||
this.projectiles = new SSCProjectiles.SSCProjectileManager();
|
||||
|
||||
this.LoadMaps();
|
||||
this.loadStartingMap();
|
||||
this.quitGame = false;
|
||||
|
@ -95,10 +97,13 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
|
||||
TextureManager UIManager = new TextureManager("SSCUI");
|
||||
UIManager.searchForTextures(ModCore.ModHelper, ModCore.Manifest, Path.Combine("Content", "Minigames", "SeasideScramble", "Graphics", "UI"));
|
||||
TextureManager projectileManager = new TextureManager("Projectiles");
|
||||
projectileManager.searchForTextures(ModCore.ModHelper, ModCore.Manifest, Path.Combine("Content", "Minigames", "SeasideScramble", "Graphics", "Projectiles"));
|
||||
|
||||
this.textureUtils.addTextureManager(playerManager);
|
||||
this.textureUtils.addTextureManager(mapTextureManager);
|
||||
this.textureUtils.addTextureManager(UIManager);
|
||||
this.textureUtils.addTextureManager(projectileManager);
|
||||
}
|
||||
|
||||
private void LoadMaps()
|
||||
|
@ -141,10 +146,12 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
/// <param name="b"></param>
|
||||
public void draw(SpriteBatch b)
|
||||
{
|
||||
|
||||
if (this.currentMap != null)
|
||||
{
|
||||
this.currentMap.draw(b);
|
||||
}
|
||||
|
||||
b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null);
|
||||
|
||||
foreach(SSCPlayer p in this.players.Values) {
|
||||
|
@ -162,6 +169,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
}
|
||||
*/
|
||||
this.menuManager.drawAll(b);
|
||||
|
||||
this.projectiles.draw(b);
|
||||
|
||||
b.End();
|
||||
}
|
||||
|
||||
|
@ -356,6 +366,9 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
player.update(time);
|
||||
}
|
||||
}
|
||||
|
||||
this.projectiles.update(time);
|
||||
|
||||
this.oldMousePosition = new Vector2(Game1.getOldMouseX(), Game1.getOldMouseY());
|
||||
return false;
|
||||
//throw new NotImplementedException();
|
||||
|
@ -380,11 +393,22 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
|
|||
ModCore.log("Exit the game!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Translates the position passed in into the relative position on the viewport.
|
||||
/// </summary>
|
||||
/// <param name="viewport"></param>
|
||||
/// <param name="globalPosition"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector2 GlobalToLocal(xTile.Dimensions.Rectangle viewport, Vector2 globalPosition)
|
||||
{
|
||||
return new Vector2(globalPosition.X - (float)viewport.X, globalPosition.Y - (float)viewport.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Translates the position passed in into the relative position on the viewport.
|
||||
/// </summary>
|
||||
/// <param name="globalPosition"></param>
|
||||
/// <returns></returns>
|
||||
public static Vector2 GlobalToLocal(Vector2 globalPosition)
|
||||
{
|
||||
return new Vector2(globalPosition.X - (float)SeasideScramble.self.camera.viewport.X, globalPosition.Y - (float)SeasideScramble.self.camera.viewport.Y);
|
||||
|
|
|
@ -73,6 +73,8 @@
|
|||
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\SSCMenuManager.cs" />
|
||||
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\TitleScreen.cs" />
|
||||
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCPlayer.cs" />
|
||||
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCProjectiles\SSCProjectile.cs" />
|
||||
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCProjectiles\SSCProjectileManager.cs" />
|
||||
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCTextureUtilities.cs" />
|
||||
<Compile Include="Framework\Objects\BasicItemInformation.cs" />
|
||||
<Compile Include="Framework\Objects\CustomObject.cs" />
|
||||
|
@ -134,6 +136,9 @@
|
|||
<Content Include="Content\Minigames\SeasideScramble\Graphics\Player\Junimo.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Minigames\SeasideScramble\Graphics\Projectiles\Basic.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\AButton.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
@ -174,5 +179,8 @@
|
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Framework\Minigame\SeasideScrambleMinigame\SSCGuns\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -83,6 +83,11 @@ namespace StardustCore.Animations
|
|||
this.animation.draw(b, this.position, this.color, scale, SpriteEffects.None, depth);
|
||||
}
|
||||
|
||||
public virtual void draw(SpriteBatch b,Vector2 position ,float scale, float depth)
|
||||
{
|
||||
this.animation.draw(b, position, this.color, scale, SpriteEffects.None, depth);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue