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 / Moving character with arrows

Author
Message
Beeny95
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: U.K.
Posted: 8th Mar 2008 09:50 Edited at: 11th Mar 2008 00:34
Hi I'm Beeny95,
So I have been using DarkGDK with C++ for a bit but I was making a 2D RPG and I was wondering how to get a sprite to move with the arrow keys. Thanks.

Your signature has been erased by a mod
CoffeeGrunt
17
Years of Service
User Offline
Joined: 5th Oct 2007
Location: England
Posted: 8th Mar 2008 11:38
First, change your signature now! You can't post your age on these forums, sorry......

Secondly, you'll have to find an ASCII code template for keyboards, and use that in tandem with dbMoveSprite....

Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 8th Mar 2008 13:03
weirdest and most confusing explination ever coffee xD

To move a sprite around you must change the X and Y values of where you draw the sprite. Store them off in two variables, say:

int nSpriteX = 0;
int nSpriteY = 0;

and then use the arrow keys to add to or subtract from those values. You can use dbKeyState and dbScanCode and the ascii codes coffee mentioned to do this, but if you just want arrow keys then there are easier commands to do that. you can use dbLeftKey(), dbRightKey(), dbUpKey() and dbDownKey().

for example, to move the sprite left and right:



Try the same with the up and down keys and modify the nSpriteY variable instead to move it up and down. Then just draw the sprite to nSpriteX and nSpriteY! You can replace 4 with any "speed" you want.

Try playing with that until you understand it

Fusspawn
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 8th Mar 2008 15:54
Ive attached the keycode list in a headerfile, Its not my work ( Think it was Jason P Sage who posted it )

but i find it handy to use .

Stuck in the land of the confused! and loving it!

Attachments

Login to view attachments
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Mar 2008 16:00
Yeah - it was, note for the record there are DIRECTX ones you can use too - but I found the naming kinda ... Vulgar... um... I like how you changed the long "ScanCode" to simply KEY... I'm going to do that search-n-replace here as EASY to Read #1 for me, but Less to type is an Added Bonus! (Especially when still easy to read LOL)

Thanx

Fusspawn
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 8th Mar 2008 16:01
Hehe i saw that and it made more sense to do so,
Key seemed more valid than ScanCode.

Stuck in the land of the confused! and loving it!
Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 8th Mar 2008 18:57
@coffee - Why cant we post age on the forum?

Niels Henriksen
Working on a (MMO)RPG right now in LightEngine (thanks kBessa)
CoffeeGrunt
17
Years of Service
User Offline
Joined: 5th Oct 2007
Location: England
Posted: 8th Mar 2008 19:04
Y'know, possibility of perverts watching and all that....

It's in the AUP..

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Mar 2008 19:05 Edited at: 8th Mar 2008 19:10
I think its for minors - for their own protection. TGC seems to understand and help enforce that there are literally Pre-teens on to Old men... (And ladies...) on these forums and that these pages are public, publicly searchable, anyone can join, people post their emails etc... its just an effort to save the young'ns from wackos thats all.

I personally Encourage the young'ns to get coding... MY Own kids so far aren't interested - but my step daughters ...well... I still have HOPE LOL

[edit] Look at our post times Coffee... Wasn't disagreeing as it reads... had the same sentiment[/edit]

CoffeeGrunt
17
Years of Service
User Offline
Joined: 5th Oct 2007
Location: England
Posted: 8th Mar 2008 19:07
I'm "young", not telling you how young though......

I'm trying to learn coding in C++, I think I might try and learn C# first though, as the learning curve from FPSC for me is too damn big....

Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 8th Mar 2008 19:48
hehe... then its ok... Im also young... (in mind).

@jason - you need to learn your kids programming so they can help you with Iron Infantry 2

Niels Henriksen
Working on a (MMO)RPG right now in LightEngine (thanks kBessa)
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 9th Mar 2008 12:54
for anyone that cares heres my KeyCodes.h that i use. Its been posted on the forums a few times over the years but always seems to get lost It doesnt have the numpad defs in it (never used it >> but it does have keys like TIDLE (console key) mapped.



Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 10th Mar 2008 04:06 Edited at: 10th Mar 2008 04:08
@Sephnroth

Your links are broken to the tutorials .zip and .rar

DarkSDK/WinAPI Tutorial

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 10th Mar 2008 21:41
yeah sorry about that - we're moving web servers and that tutorial has become "lost" somewhere -_- I will be searching old hdd's for it soon, although if someone who previously downloaded it could send it to me that would be useful.

Mind you, the tutorial is old and a bit out of date - it was designed with visual studio 6 in mind.

I am in the middle of writing a new DGDK tutorial but its not to do with winapi intergration this time - just beginners game programming.

AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 10th Mar 2008 23:00
Rather than simply define key variables with their corresponding scancodes, I like to define them with the corresponding dbKeyState( ) functions like so:



In my oppinion, it makes my code easier to understand, and it's less typing for me.

Login to post a reply

Server time is: 2024-11-20 05:17:55
Your offset time is: 2024-11-20 05:17:55