Permalink
Browse files

NRE solved -- Issue [Projectiles don't delete themselves]

  • Loading branch information...
1 parent 71116e3 commit b861ed8b48fc119998af20468020ae96b1b1813c Archelaus committed Jan 18, 2012
View
@@ -22,13 +22,15 @@ class Game1 : Microsoft.Xna.Framework.Game {
public HUD hud;
public Entities entities;
+ public Projectiles projectiles;
public spriteLib spriteLibrary = new spriteLib();
public Game1() {
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
hud = new HUD(this);
entities = new Entities(this);
+ projectiles = new Projectiles(this);
}
/// <summary>
@@ -83,6 +85,9 @@ class Game1 : Microsoft.Xna.Framework.Game {
foreach (LivingEntity i in entities.itemsList.ToList()) {
i.Update();
}
+ foreach (Projectile p in projectiles.itemsList.ToList()) {
+ p.Update();
+ }
hud.Update();
base.Update(gameTime);
}
@@ -97,11 +102,13 @@ class Game1 : Microsoft.Xna.Framework.Game {
// TODO: Add your drawing code here
spriteBatch.Begin();
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);
+ spriteBatch.DrawString(spriteFont, projectiles.itemsList.Count.ToString(), new Vector2(0, 0), Color.Black);
spriteBatch.End();
base.Draw(gameTime);
}
@@ -26,8 +26,6 @@ class LivingEntity {
public int drawPX = 30;
public int drawPY = 0;
public Boolean alive = true;
- public string sFileName = "spritesheet";
- public BoundingBox boundingBox;
public Game1 game;
public Texture2D spriteIndex;
@@ -40,13 +38,18 @@ class LivingEntity {
}
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 Draw(SpriteBatch spriteBatch) {
+ if (spriteIndex == null) return;
Rectangle size = new Rectangle(0, 0, 32, 32);
Texture2D newCropped = game.spriteLibrary.Crop(spriteIndex, new Rectangle(drawPX, drawPY, drawX, drawY));
Vector2 center = new Vector2(newCropped.Width / 2, newCropped.Height / 2);
View
@@ -71,7 +71,9 @@ public Player(Vector2 position, Game1 game)
stamina += 0.5f;
}
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
@@ -81,6 +83,11 @@ public Player(Vector2 position, Game1 game)
base.Update();
}
+ public override void loadContent(ContentManager content) {
+ base.loadContent(content);
+
+ }
+
}
}
@@ -126,6 +126,7 @@
<Compile Include="LivingEntity.cs" />
<Compile Include="Player.cs" />
<Compile Include="proj\Projectile.cs" />
+ <Compile Include="proj\Projectiles.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
<Compile Include="Game1.cs" />
@@ -15,7 +15,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
- <dsig:DigestValue>XjIfN7EeDhlxSh5WR7Zmf5A80U4=</dsig:DigestValue>
+ <dsig:DigestValue>C9Ja6lTqBRkF54NDg2tAmrvLuVw=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Binary file not shown.
@@ -93,14 +93,14 @@
</dependentAssembly>
</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" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
- <dsig:DigestValue>XTpFv4R0BnFEXryB/89lNTBmpJ8=</dsig:DigestValue>
+ <dsig:DigestValue>/JLpn8xpBA5eGVcnfcTB0SAu0eg=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Binary file not shown.
@@ -15,7 +15,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
- <dsig:DigestValue>XjIfN7EeDhlxSh5WR7Zmf5A80U4=</dsig:DigestValue>
+ <dsig:DigestValue>C9Ja6lTqBRkF54NDg2tAmrvLuVw=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Binary file not shown.
@@ -93,14 +93,14 @@
</dependentAssembly>
</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" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
- <dsig:DigestValue>XTpFv4R0BnFEXryB/89lNTBmpJ8=</dsig:DigestValue>
+ <dsig:DigestValue>/JLpn8xpBA5eGVcnfcTB0SAu0eg=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Binary file not shown.
@@ -33,7 +33,7 @@ class Projectile {
this.direction = direction;
this.damage = damage;
this.shooter = shooter;
- this.originPosition = originPosition;
+ this.position = originPosition;
this.projectileName = projectileName;
}
@@ -59,5 +59,8 @@ class Projectile {
position.Y += pix * (float)newY;
}
+ public String getProjectileName() {
+ return projectileName;
+ }
}
}
@@ -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;
+ }
+ }
+}
View
BIN Reax.suo
Binary file not shown.

0 comments on commit b861ed8

Please sign in to comment.