Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help with Programming

Started by GodCedric Mar 28, 2009 at 5:45 AM 10 replies 1.7k views
Original Post
GodCedric
GodCedric
Hello, I'm studying to have a job in the game industry. I'm in my first year and now I have to program for my final examns Marvel VS Capcom. Pretty nuts, but I'll work hard for it. My English is not so good, so my appolagies for all the wrong things I am going to say. This forum will surely be watched by me verry often. I watched the other forums and I didn't find anywhere real help about my problem. I allready set the background of the game. Now I want to start to program a fighter. Without collision detection etc yet, just let him walk around, for starters, on the baccground. But my problem is this, how would I best do this for not to come in problems in the future? Do I first make a class 'Fighter', and then another class with 'Megaman'? And then annother class witch called 'moves'? What parameters to give to them? This probably seems basic but I'm just stuck cause I don't see how to make it easier when I start to program another fighter. What can I re-use from my first fighter, witch class? I thank you an approach :D
Wan
Wan
Quote:
Original post by GodCedric
My English is not so good, so my appolagies for all the wrong things I am going to say.

As long as you make the effort to make yourself understandable, no one is going to flame you for not being a native speaker of the English language. It's people that are perfectly capable to write English, but are too lazy to use proper punctuation and start every sentence with "so lol anyway" that most of us don't care for.
Quote:
I watched the other forums and I didn't find anywhere real help about my problem. I allready set the background of the game. Now I want to start to program a fighter. Without collision detection etc yet, just let him walk around, for starters, on the baccground.

Sounds like a good start: it's better to limit the initial requirements and get something to work than trying to implement everything at once and fail.

Quote:
But my problem is this, how would I best do this for not to come in problems in the future?

I think it's not something to worry about too much from the start. You will have to rewrite (refactor) as you progress, it's part of the process. Of course that doesn't mean you shouldn't think about your software design at all, but be careful not over analyze everything from the start. Begin with some prototypes to get a feeling what you want, like you suggested yourself: get something to move on the screen first, than perhaps make it jump or shoot rays out of its eyes, than have more than one character at once, than have them collide or detect when they're hit etc.

Making small prototypes or demos also gives you (who is also the game designer) the chance to try out different game play elements and see if they work. It's something we do in our (professional) work as well.

Quote:
Do I first make a class 'Fighter', and then another class with 'Megaman'?
And then annother class witch called 'moves'?
What parameters to give to them?

Many options here. You can have a base class Fighter and derive specific characters from them (like Megaman). Sometimes it's better to take a more data-driven approach: just have a fighter that be externally configured (perhaps from a configuration file) using parameters like its name, speed, maximum jump height, health and hit points and so on. It's hard to tell what will be the best in your case.

Quote:
This probably seems basic but I'm just stuck cause I don't see how to make it easier when I start to program another fighter. What can I re-use from my first fighter, witch class?

Like I said, don't worry too much about that, get something to work first. Keep things versatile and generic if you can, try to apply appropriate software patterns, but don't get stuck because you want to get it absolutely right the first time. Nobody does.
GodCedric
GodCedric
Allready thanx for the big answer :p

So I started to work further and I have a problem.
This is how I worked,
I made a class "move" and a class "Megaman".
So in the class Megaman I will initialise all the Moves from Megaman.
(for now this is only walk right, walk left,stand still)

Now I want to make a new class fighter...
When I make this class I fill in a String, for now this is Megaman, but if I later want to make a fighter with the class Spiderman I can do this without problem.
Cause the moves will all be the same name, but other bitmaps.

So my code in the class fighter:

if (m_NameFighter == "Megaman")
{
MegamanPtr = new Megaman();
}



Now I want to work with KeyPressed and use the moves from my class Megaman.
But it seems I can't use the moves, ...

switch (cKey)
{
case 'A':
MoveStilstaanLinksPtr->Paint();

//HE SEEMS NOT TO RECOGNISE THIS, HOW COME? :s

break;
case 'P':

break;
}
Wan
Wan
You haven't specified the language you're using, but Ptr postfix probably indicates a pointer, so'll assume it's C++ for now.

Quote:
Original post by GodCedric
Allready thanx for the big answer :p

You're welcome.

Quote:
I made a class "move" and a class "Megaman".
So in the class Megaman I will initialise all the Moves from Megaman.
(for now this is only walk right, walk left,stand still)

Okay.

Quote:
Now I want to make a new class fighter...
When I make this class I fill in a String, for now this is Megaman, but if I later want to make a fighter with the class Spiderman I can do this without problem.

I'm a little confused by this design, perhaps some code (see the FAQ for using the source tags) would make it clearer.

You're creating a Megaman instance who is a fighter (and I damn good one if you ask me) within another, more generic fighter class instance. If you're going that route, wouldn't it make more sense to create a more abstract base fighter class and have the specific fighters (Megaman, Spiderman etc) derive from it, all implementing their own specific behavior?

Quote:
Cause the moves will all be the same name, but other bitmaps.

If they're all the exactly same, then perhaps having move class may be overkill. After all, the actual (references to) images don't have to and probably shouldn't be part of the fighter model ('model' as in software model). But again, I'm not a hundred percent sure without understanding your actual implementation.

Quote:
Now I want to work with KeyPressed and use the moves from my class Megaman.
But it seems I can't use the moves, ...
switch (cKey){  case 'A':   MoveStilstaanLinksPtr->Paint();   //HE SEEMS NOT TO RECOGNISE THIS, HOW COME?  :s   break;case 'P':	  break;}

Have you tried setting a break point to see what the value of cKey is? I don't know what sort of input method you're using, but perhaps cKey doesn't directly translate into an ASCII code.
stormwarestudios
stormwarestudios
Quote:
Original post by GodCedric
switch (cKey)
{
case 'A':
MoveStilstaanLinksPtr->Paint();
}


Sorry if this seems overly simplistic a response, but typically 'A' != 'a'; perhaps you're testing for the wrong ASCII code? Unless you're holding the Shift character down, or Caps Lock is toggled, you'll never get 'A' when you press the 'a' key.
GodCedric
GodCedric
(Sorry for the slow response, partial examns are in progress)

And yes indeed, the language is C++.

It is indeed better to have a class fighter first and then let Megaman, spiderman,... derive from it.
I will adjust it.

But by adjusting it the problem stays the same.
And to make myself more clearer, the problem is not about the cKey.
The problem is about that I don't have access tot MoveStilstaanLinksPtr...
MoveStilstaanLinksPtr is a part of Megaman (not adjusted it, yet), but in my class fighter I don't seem to have access to it.

So is there a reason why I can't acces this?

But I have allready scheduled an appointment whit my teacher tomorow.
So tomorow or the day after I will let you guys now what still is crappy and what has been solved.
Then I will also post code if needed like you requested.

Please still watch this forum cause I still have lot of questions ;)
Sneftel
Sneftel
Moved to For Beginners.
GodCedric
GodCedric
Owkay,

Long time I posted, and so long time I did some work.
But now I'm going back at it.
I changed a lot of code, including the tip I had recieved to make a fighter class and now megamanclass is derived from it ( and other fighters will be soon as the game is more developped).
The problem
So all is good now :D

But now for my new question.
I'm starting to let my Megaman perform some moves on the screen...

void Fighter::KeyPressed(TCHAR cKey)
{
int tempX;
int tempY;
switch(cKey)
{
case VK_LEFT:
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveLoopLinksPtr;
MoveCurrentPtr->SetX(tempX -5);
break;
case VK_RIGHT:
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveLoopRechtsPtr;
MoveCurrentPtr->SetX(tempX +5);

break;
}
}

But now the problem is that he only walks one time (tempX+5) when I press left or right. I can't keep pressing right, I have to push it over and over again.
A sort of buttonsmasher...
How can I make Megaman move as long as the right is pressed?
Rewdew
Rewdew
Save the state of the keys in a variable. This way when you receive WM_KEYDOWN (I suppose), you can save the state as "pressed", and when you receive WM_KEYUP, you save it as "not pressed". Then in your main loop at some point you check the state of each key to see if one of them is pressed...
signal_
signal_
The problem that you're describing with regards to having to repeatedly press a key to move the character used to frustrate me too. Fortunately, there is an easy solution. I will provide the answer in pseudo code:


bool press_a = false;   // Boolean for state of key:bool press_s = false;   // false = not pressed, true = pressed.                        // Initialize to false state (not pressed).while ( keyboardPolling ){     if ( eventType == keypadDown )     {          switch ( keyboardKEY )          {               case key_a: press_a = true; break;               case key_s: press_s = true; break;          }     }     if ( eventType == keypadUp )     {          switch ( keyboardKEY )          {               case key_a: press_a = false; break;               case key_s: press_s = false; break;          }     }}


So, in the above code you need to account for two keyboard events: key press down and key press up; then just set yr keypress boolean to the appropriate value. Then yr movement routine, each frame, can be something like:

if ( press_a )     moveLeft();if ( press_s )     moveRight();


I am not sure what API you're using, but there should be something like this for most APIs: detecting the keyUp and keyDown events.

Edit: Oops. RewDew beat me to it!
shakurshams
shakurshams
Using the message loop for taking input in a game project is not the best choice.
Because it is slower.
Rather if you use the following function you will be able to solve your problem.
Quote:

GetAsyncKeyState(VK_RIGHT) & 0x8000

VK_RIGHT is used just as an example.
You will find more topics on this issue in gamedev.net . just search them.
You can also search in MSDN.
And to add more there is a chapter called "Using DirectX: DirectInput" in Kevin Hawkins & Dave Astle book "OpenGL Game Programming".
I hope it helps.
GodCedric
GodCedric
Owkay, the problem is fixed and how...
You guys are seriously a graet help but because I allready working with a GAME_ENGINE, the answer was easier then you guys explained...
I allready had a function for checking my keyboard...:s


//Here it looks what has been pressed, so buttonsmasher state...
//In this function I can work with Case system...
//I'm not realy working with it but I have put an example in comment to explain...

void Fighter::KeyPressed(TCHAR cKey)
{
if (RechtsBool==true)
{
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveStilstaanRechtsPtr;
MoveCurrentPtr->SetX(tempX);
}
else
{
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveStilstaanLinksPtr;
MoveCurrentPtr->SetX(tempX);
}
/*
case VK_UP:
if (RechtsBool==true)
{
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveSpringRechtsPtr;
MoveCurrentPtr->SetX(tempX);
}
else
{
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveSpringLinksPtr;
MoveCurrentPtr->SetX(tempX);
}
*/

}

//In this function I can look what is being pressed (so what I needed)

void Fighter::CheckKeyboard()
{
if(GAME_ENGINE->IsKeyDown(VK_LEFT))
{
RechtsBool=false;
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveLoopLinksPtr;
MoveCurrentPtr->SetX(tempX -10);

}
if(GAME_ENGINE->IsKeyDown(VK_RIGHT))
{
RechtsBool=true;
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveLoopRechtsPtr;
MoveCurrentPtr->SetX(tempX +10);
}
if(GAME_ENGINE->IsKeyDown(VK_RIGHT)&&GAME_ENGINE->IsKeyDown(VK_UP))
{
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveSpringRechtsPtr;
MoveCurrentPtr->SetX(tempX +10);
}
if(GAME_ENGINE->IsKeyDown(VK_LEFT)&&GAME_ENGINE->IsKeyDown(VK_UP))
{
tempX = MoveCurrentPtr->GetX();
MoveCurrentPtr = MoveSpringLinksPtr;
MoveCurrentPtr->SetX(tempX +10);
}
}

No I can make him run :D
And if I stop pressing he stops.
My new problem is to discover if Megaman is jumping he has to finish his jump...Before he is standing still again.
How do I do that? :s
Cause now when I stop pressing ,he stops jumping immediatly ifcourse.
Also... While pressing right he has to go right (while he's jumping) but if I stop pressing he has to stop going right and just finish the jump.
Please explain with some code :s

PS:
Beginning OpenGL Game Programming: looks very interesting but I can't get it yet.
Seems I would have to wait a month :s

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.