Skip to content

Commit

Permalink
NRE solved -- Issue [Projectiles don't delete themselves]
Browse files Browse the repository at this point in the history
  • Loading branch information
Archelaus committed Jan 18, 2012
1 parent 71116e3 commit b861ed8
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 14 deletions.
13 changes: 10 additions & 3 deletions Killit/Killit/Game1.cs
Expand Up @@ -22,13 +22,15 @@ class Game1 : Microsoft.Xna.Framework.Game {


public HUD hud; public HUD hud;
public Entities entities; public Entities entities;
public Projectiles projectiles;


public spriteLib spriteLibrary = new spriteLib(); public spriteLib spriteLibrary = new spriteLib();
public Game1() { public Game1() {
graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
hud = new HUD(this); hud = new HUD(this);
entities = new Entities(this); entities = new Entities(this);
projectiles = new Projectiles(this);
} }


/// <summary> /// <summary>
Expand Down Expand Up @@ -83,6 +85,9 @@ class Game1 : Microsoft.Xna.Framework.Game {
foreach (LivingEntity i in entities.itemsList.ToList()) { foreach (LivingEntity i in entities.itemsList.ToList()) {
i.Update(); i.Update();
} }
foreach (Projectile p in projectiles.itemsList.ToList()) {
p.Update();
}
hud.Update(); hud.Update();
base.Update(gameTime); base.Update(gameTime);
} }
Expand All @@ -97,11 +102,13 @@ class Game1 : Microsoft.Xna.Framework.Game {
// TODO: Add your drawing code here // TODO: Add your drawing code here
spriteBatch.Begin(); spriteBatch.Begin();
foreach (LivingEntity i in entities.itemsList) { foreach (LivingEntity i in entities.itemsList) {
if (i.alive == true) { i.Draw(spriteBatch);
i.Draw(spriteBatch); }
} foreach (Projectile p in projectiles.itemsList.ToList()) {
p.Draw(spriteBatch);
} }
hud.Draw(spriteBatch); hud.Draw(spriteBatch);
spriteBatch.DrawString(spriteFont, projectiles.itemsList.Count.ToString(), new Vector2(0, 0), Color.Black);
spriteBatch.End(); spriteBatch.End();
base.Draw(gameTime); base.Draw(gameTime);
} }
Expand Down
9 changes: 6 additions & 3 deletions Killit/Killit/LivingEntity.cs
Expand Up @@ -26,8 +26,6 @@ class LivingEntity {
public int drawPX = 30; public int drawPX = 30;
public int drawPY = 0; public int drawPY = 0;
public Boolean alive = true; public Boolean alive = true;
public string sFileName = "spritesheet";
public BoundingBox boundingBox;
public Game1 game; public Game1 game;


public Texture2D spriteIndex; public Texture2D spriteIndex;
Expand All @@ -40,13 +38,18 @@ class LivingEntity {
} }


public virtual void loadContent(ContentManager content) { public virtual void loadContent(ContentManager content) {
spriteIndex = content.Load<Texture2D>("Sprites\\" + sFileName); spriteIndex = content.Load<Texture2D>("Sprites\\" + "spritesheet");
if (spriteIndex != null) {
Console.WriteLine("Null here!");
return;
}
} }


public virtual void Update() { public virtual void Update() {
} }


public virtual void Draw(SpriteBatch spriteBatch) { public virtual void Draw(SpriteBatch spriteBatch) {
if (spriteIndex == null) return;
Rectangle size = new Rectangle(0, 0, 32, 32); Rectangle size = new Rectangle(0, 0, 32, 32);
Texture2D newCropped = game.spriteLibrary.Crop(spriteIndex, new Rectangle(drawPX, drawPY, drawX, drawY)); Texture2D newCropped = game.spriteLibrary.Crop(spriteIndex, new Rectangle(drawPX, drawPY, drawX, drawY));
Vector2 center = new Vector2(newCropped.Width / 2, newCropped.Height / 2); Vector2 center = new Vector2(newCropped.Width / 2, newCropped.Height / 2);
Expand Down
9 changes: 8 additions & 1 deletion Killit/Killit/Player.cs
Expand Up @@ -71,7 +71,9 @@ public Player(Vector2 position, Game1 game)
stamina += 0.5f; stamina += 0.5f;
} }
if (mouse.LeftButton == ButtonState.Pressed) { if (mouse.LeftButton == ButtonState.Pressed) {
game.entities.addItem(new Player(new Vector2(0, 0), game)); Projectile p;
game.projectiles.addItem(p = new Projectile(0.01f, rotation, 10, this, position, "advntur"));
p.loadContent(game.Content);
} }


// Movement End // Movement End
Expand All @@ -81,6 +83,11 @@ public Player(Vector2 position, Game1 game)
base.Update(); base.Update();
} }


public override void loadContent(ContentManager content) {
base.loadContent(content);

}



} }
} }
1 change: 1 addition & 0 deletions Killit/Killit/Reax.csproj
Expand Up @@ -126,6 +126,7 @@
<Compile Include="LivingEntity.cs" /> <Compile Include="LivingEntity.cs" />
<Compile Include="Player.cs" /> <Compile Include="Player.cs" />
<Compile Include="proj\Projectile.cs" /> <Compile Include="proj\Projectile.cs" />
<Compile Include="proj\Projectiles.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Game1.cs" /> <Compile Include="Game1.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Killit/Killit/bin/x86/Debug/Killit.application
Expand Up @@ -15,7 +15,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>XjIfN7EeDhlxSh5WR7Zmf5A80U4=</dsig:DigestValue> <dsig:DigestValue>C9Ja6lTqBRkF54NDg2tAmrvLuVw=</dsig:DigestValue>
</hash> </hash>
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
Expand Down
Binary file modified Killit/Killit/bin/x86/Debug/Killit.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions Killit/Killit/bin/x86/Debug/Killit.exe.manifest
Expand Up @@ -93,14 +93,14 @@
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
<dependency> <dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Killit.exe" size="16384"> <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Killit.exe" size="17408">
<assemblyIdentity name="Killit" version="1.0.0.0" language="neutral" processorArchitecture="x86" /> <assemblyIdentity name="Killit" version="1.0.0.0" language="neutral" processorArchitecture="x86" />
<hash> <hash>
<dsig:Transforms> <dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>XTpFv4R0BnFEXryB/89lNTBmpJ8=</dsig:DigestValue> <dsig:DigestValue>/JLpn8xpBA5eGVcnfcTB0SAu0eg=</dsig:DigestValue>
</hash> </hash>
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
Expand Down
Binary file modified Killit/Killit/bin/x86/Debug/Killit.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion Killit/Killit/obj/x86/Debug/Killit.application
Expand Up @@ -15,7 +15,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>XjIfN7EeDhlxSh5WR7Zmf5A80U4=</dsig:DigestValue> <dsig:DigestValue>C9Ja6lTqBRkF54NDg2tAmrvLuVw=</dsig:DigestValue>
</hash> </hash>
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
Expand Down
Binary file modified Killit/Killit/obj/x86/Debug/Killit.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions Killit/Killit/obj/x86/Debug/Killit.exe.manifest
Expand Up @@ -93,14 +93,14 @@
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
<dependency> <dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Killit.exe" size="16384"> <dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Killit.exe" size="17408">
<assemblyIdentity name="Killit" version="1.0.0.0" language="neutral" processorArchitecture="x86" /> <assemblyIdentity name="Killit" version="1.0.0.0" language="neutral" processorArchitecture="x86" />
<hash> <hash>
<dsig:Transforms> <dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" /> <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms> </dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>XTpFv4R0BnFEXryB/89lNTBmpJ8=</dsig:DigestValue> <dsig:DigestValue>/JLpn8xpBA5eGVcnfcTB0SAu0eg=</dsig:DigestValue>
</hash> </hash>
</dependentAssembly> </dependentAssembly>
</dependency> </dependency>
Expand Down
Binary file modified Killit/Killit/obj/x86/Debug/Killit.pdb
Binary file not shown.
5 changes: 4 additions & 1 deletion Killit/Killit/proj/Projectile.cs
Expand Up @@ -33,7 +33,7 @@ class Projectile {
this.direction = direction; this.direction = direction;
this.damage = damage; this.damage = damage;
this.shooter = shooter; this.shooter = shooter;
this.originPosition = originPosition; this.position = originPosition;
this.projectileName = projectileName; this.projectileName = projectileName;


} }
Expand All @@ -59,5 +59,8 @@ class Projectile {
position.Y += pix * (float)newY; position.Y += pix * (float)newY;
} }


public String getProjectileName() {
return projectileName;
}
} }
} }
41 changes: 41 additions & 0 deletions Killit/Killit/proj/Projectiles.cs
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Reax {
class Projectiles {
// FUCK DA POLICE

public List<Projectile> itemsList = new List<Projectile>();
Game1 game;

public Projectiles(Game1 game) {
this.game = game;
}

public void removeItem(Projectile item) {
itemsList.Remove(item);
}

public void addItem(Projectile item) {
itemsList.Add(item);
}

public Projectile getByName(String type) {
foreach (Projectile i in itemsList) {
if (i.getProjectileName() == type) {
return i;
}
}
return null;
}
}
}
Binary file modified Reax.suo
Binary file not shown.

0 comments on commit b861ed8

Please sign in to comment.