Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Character Movement Question

Author
Message
Zizzy
16
Years of Service
User Offline
Joined: 16th Apr 2008
Location:
Posted: 18th Apr 2008 02:13
i've been trying to get character movement to work correctly for some reason if i do:
if(dbScanCode()==17 & dbScanCode()==32)
{
x=x+1;
y=y+1;
}

or:
if(dbScanCode()==17 && dbScanCode()==32)
{
x=x+1;
y=y+1;
}

it doesnt work but w looks like this and this works fine:
if(dbScanCode()==17)
{
y=y+1;
}

so then i tried...:
if(dbScanCode()==17)
{
if(dbScanCode()==32)
{
y=y+1;
x=x+1;
{
y=y+1;
}

also didnt work so then i tried assigning E to make sure my code works and it does...so i dont understand what im missing, this works...:
if(dbScanCode()==18)
{
y=y+1;
x=x+1;
}
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 18th Apr 2008 05:10
Are you hitting two keys at once or one after another? If the latter, are you anticipating tracking them in exactly that order?

You might also look at the nature of dbScanCode(). Does it wait until you get a keypress or does it throw out a zero if no key is being pressed? Maybe you need to work around that.

I might also point out that you can increment and decrement your x and y values by simply stating x++ and y++. You can also do ++x and ++y not to mention decrementing by using --. You can also increment/decrement variables when they're used in an expression but you have to be careful because the value used in the expression depends on whether the ++/-- comes before or after the value.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
kBessa
18
Years of Service
User Offline
Joined: 8th Nov 2006
Location: Manaus, Amazonas, Brazil
Posted: 18th Apr 2008 06:44
You should dbKeyState(key) for this.

If you take a deep look at your code, dbScanCode() only returns the last key pressed, so it will never return 17 and 32 at the same time.

dbKeyState(17)==1 && dbKeyState(32)==1

This should work fine (Sorry, I don't have DGDK C++ Installed now, only DGDK.NET, but I think that's the code.
Zizzy
16
Years of Service
User Offline
Joined: 16th Apr 2008
Location:
Posted: 18th Apr 2008 22:15
how are you guys looking deep into these commands, thats my main problem, documentation isnt that good and when i try to go to the core of where this is programmed it wont let me cuz its in a .lib file.....so i cant really figure out what most of these commands do, which is the main problem im having with Dark GDK, for example with the engine i made from scratch i can go all the way in and know exactly what each thing does, with this program its trial and error though ....
Zizzy
16
Years of Service
User Offline
Joined: 16th Apr 2008
Location:
Posted: 18th Apr 2008 22:30
I've also created code up to the point where my character moves to where the mouse is, unfortunatly its instantly hooking to the mouse forever, is there a timmer i can actually control the speed with? i've tried using the dbTimer and it still happens instently mabey im doing it wrong...so im wondering if anyone knows how to do this
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 18th Apr 2008 22:57
Quote: "how are you guys looking deep into these commands, thats my main problem, documentation isn't that good and"


You're right, the documentation isn't as deep as one might like. There are some things that you sometimes have to make assumptions about and some things you just have to test. I was pretty sure that the dbScanCode () function wasn't going to handle two inputs in one conditional check since it only outputs one value. Timing would have to be everything.

Quote: "I've also created code up to the point where my character moves to where the mouse is, unfortunatly its instantly hooking to the mouse forever, is there a timmer i can actually control the speed with? i've tried using the dbTimer and it still happens instently mabey im doing it wrong...so im wondering if anyone knows how to do this
"


You might take a look at the dbCurveValue() function, though I haven't quite figured out how I'd do it myself with this function. I'd just move incrementally on each cycle through the loop from whatever the current location position of the sprite is in the direction of the mouse. Depending on needed speed you might need to move more than one pixel in that direction. I'm guessing that the dbCurveValue() deals in floats because it may need to deal in non-horizontal/vertical movement.

Quote: "i've found a few more problems with dark gdk to, the input methods are very limited instead of there being MouseReleased and MouseDown it just has MouseClick, no way to control these 2 you can only control MouseDown basically..."


Check out this link http://forum.thegamecreators.com/?m=forum_view&b=22&t=124748&p=3
where somewhere in there I've included a download of a Mouse class I worked out. It was a work around but it was the best I could do considering I don't currently have the ability to trap the mouse status and instigate an action.

Basically you create an object of class Mouse. Each loop through your program you tell the mouse to sync itself. At this point it checks its status against the last time it was synced, notes and stores the changes and then replaces the old status with the new status. You can then query the Mouse object for any changes in the last status. This allows me to know when a button is just clicked or just released. If you ignore checking following a sync you lose the changes.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 19th Apr 2008 01:35 Edited at: 19th Apr 2008 01:36
Your boolean logic is not correct.

You cannot detect multiple keystrokes that way, if that is what you are doing. In your code, the only way the logic will pass the control is if BOTH keys are pressed, not if either is pressed. scancode can only return 1.

Do you mean to use or, perhaps?

You should use what was recommended earlier.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 19th Apr 2008 01:58
Quote: "You cannot detect multiple keystrokes that way, if that is what you are doing. In your code, the only way the logic will pass the control is if BOTH keys are pressed, not if either is pressed. scancode can only return 1."


That's exactly what the OP was trying to do. Notice the code trying to calculate movement on a diagonal.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 19th Apr 2008 03:14 Edited at: 19th Apr 2008 03:17
NVM, just use keystate.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st Apr 2008 19:12
@kBessa -
Quote: "Sorry, I don't have DGDK C++ Installed now, only DGDK.NET"
aahhhhhh

Word to the wise with input - no one is doing it here - but I once tried to make a FULL KEYBOARD monitor with dbKeyState... and quickly came to the realization that it was to much overhead.

Moral? Just test for the keys you anticipate as needed in whatever part of your game your in. Keep it lean

Login to post a reply

Server time is: 2024-11-20 07:30:53
Your offset time is: 2024-11-20 07:30:53