Advertisement
tari

tari

Sep 21st, 2008
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.81 KB | None | 0 0
  1. namespace Charred_Terra.GameplayScreen
  2. {
  3.     /// <summary>
  4.     /// A flying object of some sort
  5.     /// </summary>
  6.     class Projectile
  7.     {
  8.         private Vector2 velocity;
  9.         private Vector2 position;
  10.         private bool isExploding = false;
  11.         private float explosionTimeout = .5f; //sane default of .5 seconds, override me
  12.         private float explosionRadius = 0; //default to nothing, must be overridden
  13.         private float explosionMaxDamage = 0; //again, override based on weaponry
  14.         private Texture2D explosionTexture = explosionSprite_Generic; //override just like timeout, radius, and maxdamage
  15.         public HitZone explosionHitZone; //auto-generated from the above
  16.         /// <summary>
  17.         /// Initializes a new moving projectile
  18.         /// </summary>
  19.         /// <param name="position">Initial position</param>
  20.         /// <param name="velocity">Initial velocity</param>
  21.         public Projectile(Vector2 position, Vector2 velocity)
  22.         {
  23.             this.velocity = velocity;
  24.             this.position = position;
  25.         }
  26.         /// <summary>
  27.         /// New stationary projectile
  28.         /// </summary>
  29.         /// <param name="position">Game coordinates to spawn at</param>
  30.         /// <param name="isExploding">Whether it should detonate immediately</param>
  31.         public Projectile(Vector2 position, bool detonate)
  32.         {
  33.             this.position = position;
  34.             this.isExploding = detonate;
  35.         }
  36.         /// <summary>
  37.         /// Handles all updates for the projectile
  38.         /// </summary>
  39.         /// <param name="gameTime">Current globalGT</param>
  40.         /// <returns>Hitzone of the explosion, or null if not exploding</returns>
  41.         public HitZone Update(GameTime gameTime)
  42.         {
  43.             float timeSinceLastFrame = gameTime.ElapsedRealTime.Seconds();
  44.             if (this.isExploding)
  45.             {
  46.                 this.explosionTimeout -= timeSinceLastFrame;
  47.                 if (this.explosionTimeout <= 0)
  48.                 {
  49.                     //remove projectile, it's done exploding now
  50.                     currentProjectiles.Remove(this);
  51.                     return new HitZone(position, explosionRadius);
  52.                 }
  53.             }
  54.             else
  55.             {
  56.                 //we're not exploding now
  57.                 gravityAccel = timeSinceLastFrame * (gravityMultiplier * GRAVITY);
  58.                 this.velocity.Y -= gravityAccel;
  59.                 this.position = this.position.Add(velocity);
  60.                 if (((ushort)position.Y.round() <= terrainMap[(ushort)position.X.round()]))
  61.                 //this bit is troublesome - I either need to mess with that here, but...
  62.                 {
  63.                     this.isExploding = true;
  64.                 }
  65.                 return null;
  66.             }
  67.         }
  68.         public void Draw(GameTime gameTime)
  69.         {
  70.             if (this.isExploding)
  71.             {
  72.                 //draw explosionTexture
  73.                 //TODO: animated explosion textures (2 or 3 frames)
  74.             }
  75.             else
  76.             {
  77.                 ScreenManager.SpriteBatch.Draw(flyingProjectileSprite, position, Color.White);
  78.             }
  79.         }
  80.     }
  81.     /// <summary>
  82.     /// Describes a zone in which things can be hit
  83.     /// </summary>
  84.     class HitZone
  85.     {
  86.         Vector2 position;
  87.         float radius;
  88.         /// <summary>
  89.         /// Gets a new hitzone
  90.         /// </summary>
  91.         /// <param name="position">Game coordinates to create at</param>
  92.         /// <param name="radius">Radius of hitzone</param>
  93.         public HitZone(Vector2 position, float radius)
  94.         {
  95.             this.position = position;
  96.             this.radius = radius;
  97.         }
  98.         /// <summary>
  99.         /// Gets the damage dealt within another hitzone, if any
  100.         /// </summary>
  101.         /// <param name="other"></param>
  102.         /// <param name="maxDamage"></param>
  103.         /// <returns></returns>
  104.         public float DamageDealt(HitZone other, float maxDamage)
  105.         {
  106.             //all damage falloffs are maxDamage/(distance^2)
  107.             //damage determined by nearest intersecting point
  108.         }
  109.     }
  110. }
  111.  
  112. /*
  113.  * The first weapon, all laid out in a nice template.  The overrides below must
  114.  * be supplied (for the weapon to be of any use..), but one might conceivably want
  115.  * to override Update(), for weapons like a bouncer or the ever-popular
  116.  * Death's Head (or MIRV, if you're cheap).  Napalm, too, I guess.
  117.  */
  118. namespace Charred_Terra.GameplayScreen
  119. {
  120.     class BabyMissile : Projectile
  121.     {
  122.         private override float explosionTime = .2f;
  123.         private override float explosionRadius = 2;
  124.         private override float explosionMaxDamage = 500;
  125.         private override Texture2D explosionTexture = explosionSprite_BabyMissile;
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement