Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Charred_Terra.GameplayScreen
- {
- /// <summary>
- /// A flying object of some sort
- /// </summary>
- class Projectile
- {
- private Vector2 velocity;
- private Vector2 position;
- private bool isExploding = false;
- private float explosionTimeout = .5f; //sane default of .5 seconds, override me
- private float explosionRadius = 0; //default to nothing, must be overridden
- private float explosionMaxDamage = 0; //again, override based on weaponry
- private Texture2D explosionTexture = explosionSprite_Generic; //override just like timeout, radius, and maxdamage
- public HitZone explosionHitZone; //auto-generated from the above
- /// <summary>
- /// Initializes a new moving projectile
- /// </summary>
- /// <param name="position">Initial position</param>
- /// <param name="velocity">Initial velocity</param>
- public Projectile(Vector2 position, Vector2 velocity)
- {
- this.velocity = velocity;
- this.position = position;
- }
- /// <summary>
- /// New stationary projectile
- /// </summary>
- /// <param name="position">Game coordinates to spawn at</param>
- /// <param name="isExploding">Whether it should detonate immediately</param>
- public Projectile(Vector2 position, bool detonate)
- {
- this.position = position;
- this.isExploding = detonate;
- }
- /// <summary>
- /// Handles all updates for the projectile
- /// </summary>
- /// <param name="gameTime">Current globalGT</param>
- /// <returns>Hitzone of the explosion, or null if not exploding</returns>
- public HitZone Update(GameTime gameTime)
- {
- float timeSinceLastFrame = gameTime.ElapsedRealTime.Seconds();
- if (this.isExploding)
- {
- this.explosionTimeout -= timeSinceLastFrame;
- if (this.explosionTimeout <= 0)
- {
- //remove projectile, it's done exploding now
- currentProjectiles.Remove(this);
- return new HitZone(position, explosionRadius);
- }
- }
- else
- {
- //we're not exploding now
- gravityAccel = timeSinceLastFrame * (gravityMultiplier * GRAVITY);
- this.velocity.Y -= gravityAccel;
- this.position = this.position.Add(velocity);
- if (((ushort)position.Y.round() <= terrainMap[(ushort)position.X.round()]))
- //this bit is troublesome - I either need to mess with that here, but...
- {
- this.isExploding = true;
- }
- return null;
- }
- }
- public void Draw(GameTime gameTime)
- {
- if (this.isExploding)
- {
- //draw explosionTexture
- //TODO: animated explosion textures (2 or 3 frames)
- }
- else
- {
- ScreenManager.SpriteBatch.Draw(flyingProjectileSprite, position, Color.White);
- }
- }
- }
- /// <summary>
- /// Describes a zone in which things can be hit
- /// </summary>
- class HitZone
- {
- Vector2 position;
- float radius;
- /// <summary>
- /// Gets a new hitzone
- /// </summary>
- /// <param name="position">Game coordinates to create at</param>
- /// <param name="radius">Radius of hitzone</param>
- public HitZone(Vector2 position, float radius)
- {
- this.position = position;
- this.radius = radius;
- }
- /// <summary>
- /// Gets the damage dealt within another hitzone, if any
- /// </summary>
- /// <param name="other"></param>
- /// <param name="maxDamage"></param>
- /// <returns></returns>
- public float DamageDealt(HitZone other, float maxDamage)
- {
- //all damage falloffs are maxDamage/(distance^2)
- //damage determined by nearest intersecting point
- }
- }
- }
- /*
- * The first weapon, all laid out in a nice template. The overrides below must
- * be supplied (for the weapon to be of any use..), but one might conceivably want
- * to override Update(), for weapons like a bouncer or the ever-popular
- * Death's Head (or MIRV, if you're cheap). Napalm, too, I guess.
- */
- namespace Charred_Terra.GameplayScreen
- {
- class BabyMissile : Projectile
- {
- private override float explosionTime = .2f;
- private override float explosionRadius = 2;
- private override float explosionMaxDamage = 500;
- private override Texture2D explosionTexture = explosionSprite_BabyMissile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement