Adding weapons to my game?
Moderator: Coders of Rage
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Adding weapons to my game?
I'm just curious as to how you added/would add weapons to your game (if you even use weapons)? Or will it just be casting spells of some sort? Whether or not you use weapons is somewhat irrelevant, I'm just not sure how I should do it.
Would you keep the same character sprites and just display the weapons during the battle phase? Would you not display them anywhere but in the inventory? Or would you have a set of each sprite holding each weapon so that they could walk around carrying it?
Clearly some of these choices require more work than others. I'm comparing Pokemon a game where you're using attacks instead of weapons so the sprite is always the same, to something far more complex like Diablo where they've drawn every frame of every character in every possible position with and without each weapon.
Any Ideas?
Thanks,
-Dan
Would you keep the same character sprites and just display the weapons during the battle phase? Would you not display them anywhere but in the inventory? Or would you have a set of each sprite holding each weapon so that they could walk around carrying it?
Clearly some of these choices require more work than others. I'm comparing Pokemon a game where you're using attacks instead of weapons so the sprite is always the same, to something far more complex like Diablo where they've drawn every frame of every character in every possible position with and without each weapon.
Any Ideas?
Thanks,
-Dan
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Adding weapons to my game?
Hello. First of all, I'd like to say that this is definitely a delimna you're going to face. Pretty much every implementation of this is going to be easy for the programmer. It's going to be just drawing the weapon or drawing the character with the weapon. Big deal, right?
But this is a huge pain in the asshole for artists. One approach will require exponentially more sprites from them. If you want to show your character holding weapons and such out of battle, I'd personally recommend you take a look at Secret of Mana for SNES. It uses the same character sprites, but draws arms+weapons separately. That way you only have one character and an array of different arms depending on what he's holding (sword, spear, bow, whatever).
I thought that Secret of Mana handled it extremely well.
But this is a huge pain in the asshole for artists. One approach will require exponentially more sprites from them. If you want to show your character holding weapons and such out of battle, I'd personally recommend you take a look at Secret of Mana for SNES. It uses the same character sprites, but draws arms+weapons separately. That way you only have one character and an array of different arms depending on what he's holding (sword, spear, bow, whatever).
I thought that Secret of Mana handled it extremely well.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Adding weapons to my game?
Yeah I was thinking of drawing the character and then the weapon on top (didn't think of arms though, hehe). And as for the programmer/artist getting along, I'm both right now so that's the easy part . I guess it comes down to personal preference, and the number of weapons I want to add. Just 5 - 10 weapons shouldn't be hard to add to a 12 frame (3 per direction) 2D 32x32 sprite. It'll be some work, but I think that's probably the direction I'll head at this point. Thanks for the advice.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Adding weapons to my game?
Right. You don't need an 'every possible' combination. Just a few character position templates and then draw the weapon into it. Sort of like FPS weapons.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Adding weapons to my game?
Yeah, the arms of my sprite could almost hold a sword the way they are right now. Holding a gun would need a few adjustments, but there's no deadline for this project.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- trufun202
- Game Developer
- Posts: 1105
- Joined: Sun Sep 21, 2008 12:27 am
- Location: Dallas, TX
- Contact:
Re: Adding weapons to my game?
In one of several abandoned 2D rpgs of mine, I came up with the concept of "mounting" items.
Basically you have an item that inherits from IMountableItem and exposes several common methods including Update() and Draw().
Then, to add mountable items to the player:
then, to update the current frame of the player, and all mounted items:
then, to draw the player, and all mounted items:
But, as Falco mentioned, the real bitch is getting the sprites to line up correctly. I recommend making all the images the same dimensions as the player sprite, this way you don't have to worry about offsets. Just draw all of the mounts at the same X, Y as the player.
Basically you have an item that inherits from IMountableItem and exposes several common methods including Update() and Draw().
Then, to add mountable items to the player:
Code: Select all
player.MountItem(sword);
player.MountItem(shield);
player.MountItem(hat);
Code: Select all
player.Update();
foreach(IMountableItem mount in player.Mounts)
{
mount.Update();
}
Code: Select all
player.Draw();
foreach(IMountableItem mount in player.Mounts)
{
mount.Draw();
}
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Adding weapons to my game?
Hey trufun, thanks for taking the time to reply. Aside from reading about them, I have absolutely no experience with classes, so I'm going to make a stab at coding what I think you're recommending:
Firstly, if you notice any severe newbie errors in this portion would be so kind as to point them out?
Also, how would I do this:
What types are "IMountableItem", "mount", and ".Mounts"? ".Mounts" would have to be an array or vector wouldn't it? And is "IMountableItem" a class?
Sorry if I've gotten this completely wrong, but as I've said this is the first time I've ever tried coding with classes.
-Dan
Code: Select all
class character {
int x;
int y;
public:
int MountItem (std::string);
int Update ();
int Draw ();
};
class mountable {
int x;
int y;
public:
int Update ();
int Draw ();
};
int character::MountItem(std::string ItemName)
{
if( ItemName == "sword" )
{
file.open("sword.bmp");
}
else if( ItemName == "shield" )
{
file.open("shield.bmp");
}
else if( ItemName == "hat" )
{
file.open("hat.bmp");
}else{
return 1;
}
return 0;
}
//character Update()
//set x & y, applysurface()
//character Draw()
//flip surface to screen
//mountable Update()
//set x & y, applysurface()
//mountable Draw()
//flip surface to screen
int main()
{
character player;
mountable sword;
player.MountItem("sword")
player.Update();
sword.Update();
player.Draw();
sword.Draw();
return 0;
}
Also, how would I do this:
Code: Select all
foreach(IMountableItem mount in player.Mounts)
{
mount.Update();
}
Sorry if I've gotten this completely wrong, but as I've said this is the first time I've ever tried coding with classes.
-Dan
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- trufun202
- Game Developer
- Posts: 1105
- Joined: Sun Sep 21, 2008 12:27 am
- Location: Dallas, TX
- Contact:
Re: Adding weapons to my game?
IMountableItem is an interface, and all of the mountable items (such as sword, shield, etc.) are classes that implement that interface. Interfaces allow you to specify which properties and methods are exposed from a class. So, you can work with the object without knowing specifically what *type* of object it is. The same is possible by using an abstract class.
For instance, you can Update() and Draw() all of the player's mounts without knowing if it's a sword, shield, etc.
But...If you're new to classes and OO design, this stuff can get pretty hairy.
What you've got can still get the job done, here are my tweaks:
For instance, you can Update() and Draw() all of the player's mounts without knowing if it's a sword, shield, etc.
But...If you're new to classes and OO design, this stuff can get pretty hairy.
What you've got can still get the job done, here are my tweaks:
Code: Select all
class mountable {
int x;
int y;
std::string fileName; //have the mountable object hold the file
public:
mountable(std::string fileName)
{
this.fileName = fileName;
}
void Init()
{
file.Open(fileName);
}
int Update ();
int Draw ();
};
class character {
int x;
int y;
std::list<mountable> mounts; //Keep a list of mounts for this character
public:
int MountItem (std::string);
int Update ();
int Draw ();
};
int character::MountItem(std::string ItemName)
{
mountable mount;
if( ItemName == "sword" )
{
mount = new mountable("sword.bmp");
}
else if( ItemName == "shield" )
{
mount = new mountable("shield.bmp");
}
else if( ItemName == "hat" )
{
mount = new mountable("hat.bmp");
}
else
return 1;
mount.Init(); //Initialize this item
mounts.insert(mounts.begin(), mount ); //Add this new item to the character's list of mounts
return 0;
}
int character::Update()
{
//TODO Update the player
//Call the Update() method for each of the mounts
std::for_each(mounts.begin(), mounts.end(), std::mem_fun(&mountable::Update));
}
int character::Draw()
{
//TODO Draw the player
//Call the Draw() method for each of the mounts
std::for_each(mounts.begin(), mounts.end(), std::mem_fun(&mountable::Draw));
}
int main()
{
character player;
player.MountItem("sword")
player.Update();
player.Draw();
return 0;
}
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Adding weapons to my game?
Alright, I'm going to do some work with this, probably create a small test application before attempting to actually implement it into the game. I'll update this topic if I have any more questions. Thanks again for your kind efforts to help.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Adding weapons to my game?
You should capitalize class names. "class Mountable". Then you can "Mountable mountable" later.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Re: Adding weapons to my game?
Also, if by any chance you end up using inheritance and in that case you don'tFor instance, you can Update() and Draw() all of the player's mounts without knowing if
it's a sword, shield, etc.
know exactly how many of these different items (sword, shield, etc) are to be implemented
yet (or how many there will be), you should declare member functions like Update() and Draw()
virtual for posterity. I'm not sure if you, dandymcgee, are familiar with polymorphism, but should
really read up on it as its very useful in game programming.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Adding weapons to my game?
Way over my head.. I think I'll take it one step at a time. :P
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- trufun202
- Game Developer
- Posts: 1105
- Joined: Sun Sep 21, 2008 12:27 am
- Location: Dallas, TX
- Contact:
Re: Adding weapons to my game?
Yeah, I wouldn't recommend developing this type of game while you're still trying to learn OO design. For now, stick to what you know.dandymcgee wrote:Way over my head.. I think I'll take it one step at a time. :P
One of my first games was a puzzle game entirely based on a 2D Array. Basically it was a 2D array of integers and each number corresponded to a different colored orb. On Update(), I would traverse the array to check for falling orbs and 3 matching orbs. On Draw(), I had a giant switch statement and displayed different orbs based on the integer value.
This game has actually been really beneficial to me. I've actually written it in 4 or 5 languages. Its something simple that I can throw together quick and get familiar with a new language.