Jump to content
  • Advertisement

Machaira

Moderator
  • Content count

    3486
  • Joined

  • Last visited

Community Reputation

1034 Excellent

About Machaira

  • Rank
    Moderator

Personal Information

  • Role
    Game Designer
    Programmer
  • Interests
    Design
    Programming

Social

  • Twitter
    MachXGames
  • Twitch
    MachXGames

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Ideally, you wouldn't check to see if a pickup needs deactivated, it would let you know it's done. Something like this: namespace PickupManager { public class PickupTimerExpireEventHandlerArgs { } public class Pickup { public bool IsTimed; public bool IsActive; public bool AutoActivate; public float Time; public delegate void PickupTimerExpiredEventHandler(); public event PickupTimerExpiredEventHandler TimerExpired; public Pickup() { } public void Update() { if (IsActive) { //update timer Time -= PickupManager.FrameTime; if (Time <= 0.0f) TimerExpired(); } } } public class PickupManager { public Queue<Pickup> Pickups; public static float FrameTime = .1f; public event EventHandler PickupTimeout; public PickupManager() { Pickups = new Queue<Pickup>(); } public void AddPickup(bool isTimed, float time, bool autoActivate) { Pickup pickup = new Pickup() { IsTimed = isTimed }; pickup.TimerExpired += PickupTimerExpired; pickup.AutoActivate = autoActivate; if (Pickups.Count == 0) pickup.IsActive = autoActivate; Pickups.Enqueue(pickup); } public void PickupTimerExpired() { Pickups.Dequeue(); if (PickupTimeout != null) PickupTimeout(this, null); if(Pickups.Count > 0 && Pickups.Peek().AutoActivate) { Pickups.ElementAt(0).IsActive = true; } } public void Update() { if (Pickups.Count > 0) Pickups.Peek().Update(); } } }
  2. After a quick look at the code, why are you calling DeactivatePickUp every frame? Does your system require only one pickup active at a time?
  3. The latter, basically. The actual loop is hidden. All you need worry about is the Update and Draw methods really. If those sprites are to be used for that character instance, sure, otherwise, no. OOP works just fine in C#. Create a character class (old sample class from my RPG book): public delegate void EntityLevelUpDelegate(Entity entity); public class Entity { #region Members private EntityType _type; private string _name; private string _classID; private byte _level; private int _experience; private string _raceID; private short _baseHP; private short _curHP; private byte _diseaseResistance; private byte _poisonResistance; private byte _magicResistance; //Affects is empty for these private List<Damager> _damageResistances; private List<Damager> _damageWeaknesses; //Any misc, offensive, or defensive bonuses (ie. spells cast on character, items, etc. May be positive or negative) private List<Bonus> _defBonuses; private List<Bonus> _offBonuses; private List<Bonus> _miscBonuses; private EntityAlignment _alignment; private EntitySex _sex; private short _age; private List<EntityStat> _stats; private string _portraitFileName; private bool _isVendor; private string _spriteFilename; private Dictionary<int, int> _skills; private int _curSP; private int _baseSP; //used for things like hiding and spells private bool _isVisible; private Object _target; private Dictionary<int, EntitySpell> _spells; private Dictionary<int, int> _spellbook; //key is spell ID, value is the page it's on private int _baseMana; private int _curMana; private bool _inCombat; private Inventory _inventory; //list of items, for a vendor this is what he sells private Money _money; //requires a strength stat private float _maxWeight; private AttackTypes _selectedAttack; #endregion #region Property Functions public EntityType Type { get { return _type; } set { _type = value; } } public string Name { get { return _name; } set { if (!string.IsNullOrEmpty(value)) _name = value; } } public string ClassID { get { return _classID; } set { _classID = value; } } public Byte Level { get { return _level; } set { if (_type > EntityType.Character) _level = value; } } public int Experience { get { return _experience; } set { if (_type > EntityType.Character) _experience = value; } } public short BaseHP { get { return _baseHP; } set { if (_type > EntityType.Character) _baseHP = value; } } public short CurHP { get { return _curHP; } set { if (_type > EntityType.Character) _curHP = value; } } public Byte DiseaseResistance { get { return _diseaseResistance; } set { _diseaseResistance = value; } } public Byte PoisonResistance { get { return _poisonResistance; } set { _poisonResistance = value; } } public Byte MagicResistance { get { return _magicResistance; } set { _magicResistance = value; } } public List<Damager> DamageResistances { get { return _damageResistances; } set { _damageResistances = value; } } public List<Damager> DamageWeaknesses { get { return _damageWeaknesses; } set { _damageWeaknesses = value; } } public List<Bonus> DefensiveBonuses { get { return _defBonuses; } set { _defBonuses = value; } } public List<Bonus> OffensiveBonuses { get { return _offBonuses; } set { _offBonuses = value; } } public List<Bonus> MiscBonuses { get { return _miscBonuses; } set { _miscBonuses = value; } } public EntityAlignment Alignment { get { return _alignment; } set { _alignment = value; } } public EntitySex Sex { get { return _sex; } set { _sex = value; } } public short Age { get { return _age; } set { _age = value; } } public string RaceID { get { return _raceID; } set { _raceID = value; } } public List<EntityStat> Stats { get { return _stats; } set { _stats = value; } } public String PortraitFilename { get { return _portraitFileName; } set { _portraitFileName = value; } } public bool IsVendor { get { return _isVendor; } set { _isVendor = value; } } public string SpriteFilename { get { return _spriteFilename; } set { _spriteFilename = value; } } public Dictionary<int, int> Skills { get { return _skills; } set { _skills = value; } } public int CurSP { get { return _curSP; } set { if (value >= 0) _curSP = value; } } public int BaseSP { get { return _baseSP; } set { if (value >= 0) _baseSP = value; } } public object Target { get { return _target; } set { _target = value; } } public Dictionary<int, EntitySpell> Spells { get { return _spells; } set { _spells = value; } } public int BaseMana { get { return _baseMana; } set { _baseMana = value; } } public int CurMana { get { return _curMana; } set { _curMana = value; } } public bool IsAlive { get { return _curHP > 0; } } public bool InCombat { get { return _inCombat; } set { _inCombat = value; } } public Inventory Inventory { get { return _inventory; } set { _inventory = value; } } public AttackTypes SelectedAttack { get { return _selectedAttack; } set { _selectedAttack = value; } } #endregion public Entity() { _stats = new List<EntityStat>(); } #region Bonus, Resistance, Weakness Functions public short GetTotalOffBonus() { short total = 0; Bonus bns; if (_offBonuses != null) { for (short i = 0; i < _offBonuses.Count; i++) { bns = (Bonus)_offBonuses; total += bns.Amount; } } return total; } public short GetTotalMiscBonus() { short total = 0; Bonus bns; if (_miscBonuses != null) { for (short i = 0; i < _miscBonuses.Count; i++) { bns = (Bonus)_miscBonuses; total += bns.Amount; } } return total; } public short GetTotalDefBonus() { short total = 0; Bonus bns; if (_defBonuses != null) { for (short i = 0; i < _defBonuses.Count; i++) { bns = (Bonus)_defBonuses; total += bns.Amount; } } return total; } public void AddDefensiveBonus(Bonus bonus) { if (_defBonuses == null) _defBonuses = new List<Bonus>(); _defBonuses.Add(bonus); } public void SetDefensiveBonuses(List<Bonus> bonuses) { _defBonuses = new List<Bonus>(); if (bonuses != null) { foreach (Bonus bonus in bonuses) _defBonuses.Add(bonus); } } public void AddOffensiveBonus(Bonus bonus) { if (_offBonuses == null) _offBonuses = new List<Bonus>(); _offBonuses.Add(bonus); } public void SetOffensiveBonuses(List<Bonus> bonuses) { _offBonuses = new List<Bonus>(); if (bonuses != null) { foreach (Bonus bonus in bonuses) _offBonuses.Add(bonus); } } public void AddMiscBonus(Bonus bonus) { if (_miscBonuses == null) _miscBonuses = new List<Bonus>(); _miscBonuses.Add(bonus); } public void SetMiscBonuses(List<Bonus> bonuses) { _miscBonuses = new List<Bonus>(); if (bonuses != null) { foreach (Bonus bonus in bonuses) _miscBonuses.Add(bonus); } } public void AddDamageResistance(Damager resistance) { if (_damageResistances == null) _damageResistances = new List<Damager>(); _damageResistances.Add(resistance); } public void SetDamageResistances(List<Damager> resistances) { _damageResistances = new List<Damager>(); if (resistances != null) { foreach (Damager resistance in resistances) _damageResistances.Add(resistance); } } public void AddDamageWeakness(Damager weakness) { if (_damageWeaknesses == null) _damageWeaknesses = new List<Damager>(); _damageWeaknesses.Add(weakness); } public void SetDamageWeaknesses(List<Damager> weaknesses) { _damageWeaknesses = new List<Damager>(); if (weaknesses != null) { foreach (Damager weakness in weaknesses) _damageWeaknesses.Add(weakness); } } #endregion public int MaxWeight() { int str = 0; //find the strength stat foreach (EntityStat stat in _stats) { if (stat.StatName.ToLower() == "strength") { str = stat.CurrentValue; break; } } return str * 3; } public void AddSkill(int id, int ranks) { if (_skills == null) _skills = new Dictionary<int, int>(); _skills.Add(id, ranks); } public void SetSkills(Dictionary<int, int> skills) { _skills = skills; } public bool HasSkill(int key) { if (_skills != null) return _skills.ContainsKey(key); else return false; } public void Damage(int amount, DamageType type) { //reduce amount based on damagetype protection foreach (Damager damager in _damageResistances) { if (damager.Type == type) amount -= GlobalFunctions.GetRangeAmount(damager.DamageAmount); } _curHP -= (short)amount; if (_curHP <= 0) { //entity is dead } } public void Buff(int amount, BonusType type) { //switch (type) //{ //} } public void UseSkill(int key, Difficulty difficulty) { int result = 0; Entity entity = this; if (GlobalData.Skills[key].Use(ref _target, ref entity, difficulty, ref result)) { switch (GlobalData.Skills[key].Type) { case SkillType.Defensive: { if (_target is Entity) { } break; } case SkillType.NonCombat: { if (_target is Entity) { } break; } case SkillType.Offensive: { if (_target is Entity) { } break; } } } } public int GetSkillValueByID(int id) { if (HasSkillByID(id)) return GlobalFunctions.CalculateSkillBonus(_skills[id]); else return 0; } public bool HasSkillByID(int id) { foreach (int key in _skills.Keys) if (key == id) return true; return false; } public int GetCastingSkillBonus() { int amount = 0; foreach (int id in _skills.Keys) { //TODO: copy function from backup if (GlobalData.Skills[id].Name == "Spellcraft") { amount = _skills[id]; break; } } return amount; } public bool LearnSpell(int id, int skillPointsAllocated) { bool hasSpellcraftSkill = false; foreach (int key in _skills.Keys) { //TODO: copy function from backup if (GlobalData.Skills[key].Name == "Spellcraft") { hasSpellcraftSkill = true; break; } } if (!hasSpellcraftSkill) return false; _spells[id].AllocatePoints(skillPointsAllocated); //get any bonuses for learning spells int amount = 0; return _spells[id].Learn(amount); } public List<EntitySpell> GetPageSpells(int page) { List<EntitySpell> spells = new List<EntitySpell>(); foreach (int key in _spellbook.Keys) { if (_spellbook[key] == page) spells.Add(_spells[key]); } return spells; } //TODO: spellbook member should probably be passed to GUI public void MoveSpell(int id, int page) { //check to see if page has an empty spot int count = 0; foreach (int key in _spellbook.Keys) { if (_spellbook[key] == page) count++; } if (count < Spell.SpellsPerPage) _spellbook[id] = page; } public void AddMoney(ref int amount) { //do check to make sure max weight isn't reached before adding float totalWeight = _money.TotalWeight + Money.GetWeight(amount) + _inventory.TotalWeight(); if (totalWeight < _maxWeight) _money.Add(ref amount); else { //figure out how much can be added } } public bool HasItem(int id) { foreach (EntityItem item in _inventory.Items) { if (item.ID == id) return true; } return false; } public void Update(GameTime gameTime) { //check for mana regain } public void SetAttackType(AttackTypes type) { _selectedAttack = type; } }
  4. Machaira

    How many of you are self-taught/hobbyist programmers

    The only courses I took in programming were back in high school in the early 80s - COBOL, FORTRAN, and BASIC using an Apple 2c. Other than that I'm completely self-taught and I've been programming for a living for about 15 years doing .NET development. I took a C++ refresher course before I started with a company when I was in the industry and ended up helping out the other students since the course taught me nothing I didn't already know. I should go back and get my degree though as it's getting harder to get any further in my career. I still want to go full-time indie game development but that's difficult when you have a family to support.
  5. Machaira

    Code not running and image not loading

    Answered in the SO post
  6. One thing - you shouldn't be passing the ContentManager every Update. Just keep a reference to it. Other than that, if it ain't broke don't fix it.
  7. Machaira

    XNA Tutorials for 2D Game Development?

    There's always the tutorial on the AppHub site - http://create.msdn.com/education/tutorial/2dgame/getting_started
  8. Machaira

    XNA starter

    Have you looked at the tutorial on the AppHub site - http://create.msdn.com/education/tutorial/2dgame/getting_started
  9. Machaira

    Learning something about game development

    I'm pretty much of the same mind as the previous posts. Iterate quickly and in small pieces of the game. At some point you'll have to do a couple of large pieces when you tie various systems together to make sure everything is balanced. As for your current design, the big problem that I see is that you're running the game under 800x600. Even if you're trying to get that retro feel, there's no reason IMO that you should be using anything less than 1024x768. Doing this should immediately fix your current problem even if you don't change anything else. However, you should also be considering giving the player the ability to change resolutions, which means more testing of the UI to ensure it works decently at various resolutions. Some specific things about your current UI: * the message window doesn't need to be that tall by default. Just show one or two lines and give the player the ability to increase the height, even if it's just a button to pop it up to a half-dozen lines high. Give the player the ability to hide the window as well. Hotkeys are your friend! * the window that shows health and other info doesn't appear to need to be as big as it is either, and should be in a corner. Other windows like inventory and such should probably be able to be moved around and overlap each other, just so the player can see more. * If you haven't already done so, consider coding your UI in an OO manner - have a base "Window" class or some such and several interfaces, such as IResizable, IMoveable, IDropTarget etc. and implement as necessary for each window. You're doing great so far, just keep it up and don't get discourage. You're working in the toughest genre of game IMO, so consider each little step you complete a victory.
  10. Not really. Why do you want to do this? What's wrong with just launching the Win32 exe?
  11. Machaira

    What's in an Inventory?

    So it sounds like inventory should be an interface that whatever class needs to can implement. "Can the player carry a bag in a bag in a bag?" Only when they're empty. Otherwise it just doesn't make sense. You then don't have to worry about nested inventories. "But you can carry corpses right?" I'd say no. Why would you? "Now, weight restrictions..." I'm all for these.
  12. Machaira

    Initial Results

    Nice job. The only thing I'd change is if you're using Entity for everything you might want to consider a bit of a redesign. I'd probably do something like: [CODE] public enum CompassPoint { North, East, South, West } public interface IUpdateable { void Update(GameTime gameTime); } public abstract class WorldObject { public int X { get; set; } public int Y { get; set; } public abstract void Draw(); } public class MoveableWorldObject : WorldObject, IUpdateable { protected CompassPoint _moveDirection; protected bool _isMoving; public void Update(GameTime gameTime) { //figure out if object should move, probably NPCs, monsters, etc. } protected void Move() { //calculate moving if applicable if (_isMoving) { switch (_moveDirection) { case CompassPoint.North: { if (Map.Instance.CanMove(X, Y, CompassPoint.North)) Y -= 1; break; } case CompassPoint.East: { if (Map.Instance.CanMove(X, Y, CompassPoint.East)) X += 1; break; } case CompassPoint.South: { if (Map.Instance.CanMove(X, Y, CompassPoint.South)) Y += 1; break; } case CompassPoint.West: { if (Map.Instance.CanMove(X, Y, CompassPoint.West)) X -= 1; break; } } } } public override void Draw() { } } public class Item : WorldObject { //add members for item //items don't necessarily need an Update method public override void Draw() { } } public class Player : MoveableWorldObject, IUpdateable { //only player object needs to poll input public void Update(GameTime gameTime, KeyState keyState) { //look at keys to determine if the object is moving //calculate moving if applicable base.Move(); } public override void Draw() { } } class Map { public static Map Instance; public bool CanMove(int startX, int startY, CompassPoint direction) { bool ret = true; return ret; } } [/CODE] Looking forward to the next post.
  13. Machaira

    Need Help With XNA

    You're doing your drawing backwards. You need to draw the background first, then objects in the foreground - paddle, balls, blocks.
  14. Machaira

    Nick Gravelyn's Tile Editor

    If I'm not mistaken that tutorial series was for XNA 3.1, which has a lot of conversion issues to get to 4.0. Have you looked at the WinForms samples?
  15. Machaira

    xna or mogre

    Why do you want a powerful engine for a Mario game? That's a bit of overkill. You could take a look at the Platformer Starter Kit posts on my blog. If you really want something more powerful, Sunburn is the way to go.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!