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 / My first DarkGDK game!!

Author
Message
Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 20th Apr 2010 21:47
Hello, I've been experimenting with DarkGDK and made a very simple game. (I've also decided that DarkGDK will be my DX wrapper of choice). It's a very simple game, all that happens is it spawns a red dot that continually shoots at the player. I plan on eventually making this game multiplayer with DarkNet and will write both a dedicated server program and peer to peer LAN functions. I'm just wondering what you all make of it, I'll upload my source files if anyone's interested at all but in general i was just wondering what people think of it as a first attempt at game programming.

Screenie:


Games attached below if you want to try it out.

Things that I want to do:
Menu
Multiplayer LAN
Multiplayer dedicated server/direct IP
Actual AI
Highscores (maybe, if people are interested..)

All comments and criticism welcome =)

Attachments

Login to view attachments
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 20th Apr 2010 23:44
Good start, is there any way I can fire back?

Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 21st Apr 2010 00:00
you simply click where you want to aim, the player always looks at the cursor =)
Bran flakes91093
15
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 21st Apr 2010 02:26
Cool! I've been making a game that is sort of like this.

Just two things:

1 - Is this a debug build of the program?

It's pretty hefty (1.95 MB), because it has a bunch of debugging information in it, which is just extra bulk to the user.

When your program is ready for release, build it in release mode (change the drop-down menu at the top to release and then build like normal) and then distribute the executable found in the release folder instead of the debug folder.

2 - There's a memory leak.

I'm guessing you used dbStr to write the text to the screen like so:

That code will produce a memory leak because dbStr allocates memory for each call, so when you don't delete the memory pointed to by the pointer it returns, it gets leaked.

Use it like this:


Or use sprintf:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/


That's it

"A computer once beat me at chess, but it was no match for me at kick boxing."
Emo Philips
Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 21st Apr 2010 04:24
I've made the changes you mentioned, assuming that this is fine:


the debug build works fine, but when I run the release version (through the VC++ debugger, it crashes straight away otherwise =s) i get this error:
Quote: "Unhandled exception at 0x0000012e in RedDotArena.exe: 0xC0000005: Access violation"


which I'm guessing it's trying to tell me an array is out of bounds (or that's the most likely problem).

I think i've narrowed it down to this bit of code:

AND

as the error only happens (when debugging at least) when I click the mouse and that's the only part of my program which does anything when the user clicks the mouse, however it might be another part of the program as it crashes right away when I run it outside of the debugger. It's probably something to do with my creation of bullets as when I comment out all the functions to do with deleting and creating bullets it works fine while debugging, but still crashes straight away when I run it out of the debugger.

note: During all this I was making a release build, the debug build works 100%
Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 21st Apr 2010 04:41
Never mind, I solved it =) I didn't realize that VC++ didn't copy the external files to the release folder and that was what was causing the errors. I'll upload a better bin file tomorrow after I've added some AI.

Thanks for pointing out the memory leak again, it's not nice knowing that a little program like that has the potential to crash some lower spec'ed PCs due to my poor programming.
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 21st Apr 2010 08:37 Edited at: 21st Apr 2010 08:52
Your changes to dbStr are still not quite good, because you use dbStr several times and delete the returned string only once. You need to delete[] it every time after using dbStr because it always returns a new string.

That's why it is better to use sprintf, then you don't need to worry about deletion all the time.

By the way you don't need a char pointer to use dbText with a static string. Instead of this:



this should work:

haliop
User Banned
Posted: 21st Apr 2010 18:04
awesome job man.
Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 21st Apr 2010 19:15
so this should work?:


also, im now having a problem with this bit of code:

(I know its this code as it only happens when this bit of code is run)
this is the output from the debugger:

note: this only happens to the release build, the debug build works fine.

I'm presuming again that an array is out of bounds, but I cant tell where. This is obviously a vital part to the game so needs to be fixed before I can do anything more to it. I'd happily post my full source code if needed.
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 21st Apr 2010 20:01 Edited at: 21st Apr 2010 20:03
please do post the entire code, it looks like an out of bounds array. on debug mode this type of error doesnt crash, on release mode it does. remember that, when you create an array, such as int Array[25], you have 25 variables, starting from Array[0] to Array[24], if you try to write to Array[25] you are modifying another value which is not actually in the array...

EDIT: Dont use dbStr!!! you should avoid it..

hi
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 21st Apr 2010 20:33


note that if you want to re-use str, dont use it after delete[], instead, try the following:



you might want to see how sprintf works, see here: http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 21st Apr 2010 21:08
okay, I've uploaded my source and the files needed for it to run. I'll look into using sprintf as well. =)

Attachments

Login to view attachments
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 22nd Apr 2010 06:33 Edited at: 22nd Apr 2010 06:37
i fixed it. wasnt an out of bounds array... dont know what it was exactly but i did some changes. youll see what i changed. it now compiles and runs in release mode. sorry i changed the solutions name and some things you should always have your main loop at the last lines of your code... so it can search for all of the things it needs above it.

hi

Attachments

Login to view attachments
Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 22nd Apr 2010 20:14
Ah, okidoke =).

I cant see everything you changed except moving functions around and moving where they're called.

also, I've always been taught (by my tutor, books and internet tutorials) to lay out a source like this for maintainability:


Anyway, thank you very much for getting it to work =)
Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 22nd Apr 2010 22:25
well, it must be that im not used to create my prototype functions until i test them and see it works hehe as yoou can see i deleted them too

hi
Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 22nd Apr 2010 23:26
Well if it works for you then there's no problem =) anyway, I'm off to another thread as I'm having problems with DarkNet, I seem incapable of getting things to work for me recently -.-

Login to post a reply

Server time is: 2024-07-07 01:32:38
Your offset time is: 2024-07-07 01:32:38