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 / Trying again.

Author
Message
Scarface
18
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 17th Jan 2009 08:00 Edited at: 28th Mar 2012 13:26
Well I'm back again, to give programming another shot, but I'm already confused as to why my code isn't working.



Basically I've come to the conclusion that the game crashes when it gets to alien movement function call in the main loop:

x_dir = move_aliens( x_dir );

But I've looked over and over the function many times and don't see any reason for it to crash the game, the loop only reiterates 11 times...

Any advice would be helpful.

- Scarface
SushiBox
16
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Ohio
Posted: 17th Jan 2009 08:07
Well first of all, you have. bool move_aliens( int x_dir ) but your returning an integer.

Then I also noticed you "declare" your functions up in the global scope.



You don't need to do this, just in your loop, declare the function when you need it. I have never put my functions "under" the main, so if you get an error without declaring them globally, throw them up on top. :/

Hope this helps, if it still crashes ill have another look with some cleaner source.

www.Helios-Online.net
Scarface
18
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 17th Jan 2009 09:32
Quote: "Well first of all, you have. bool move_aliens( int x_dir ) but your returning an integer."


It returns a 1 or a 0 which is a boolean value true or false, it makes no difference as the value is the same, this is not the problem.

Quote: "Then I also noticed you "declare" your functions up in the global scope.

You don't need to do this, just in your loop, declare the function when you need it. I have never put my functions "under" the main, so if you get an error without declaring them globally, throw them up on top. :/"


There is nothing wrong with declaring a function before the main, and then defining it after, sometimes it's necessary if a function needs to call another function, and this is not the problem either.

- Scarface
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 17th Jan 2009 12:14
Did you run it with debugging? That should tell you exactly where it crashes. I can't see any obvious errors but if you provided basic media it'd be easier to test. While it's likely not related to the issue you don't have to create animated sprites for everything, you can just dbLoadImage() for single frame things then reference them from dbSprite() so you don't load the same thing many times.

Scarface
18
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 17th Jan 2009 14:15
Quote: "Did you run it with debugging? That should tell you exactly where it crashes. "


Yup, crashes exactly where I said, on the function move_aliens call within the main loop.

Quote: "I can't see any obvious errors but if you provided basic media it'd be easier to test. "


I'm just using the media from the Dark Invaders tutorial, I'll upload it here in case you don't have it.

Quote: "While it's likely not related to the issue you don't have to create animated sprites for everything, you can just dbLoadImage() for single frame things then reference them from dbSprite() so you don't load the same thing many times."


Ahh thanks for the tip, I was wondering about that ^^

- Scarface

Attachments

Login to view attachments
marlou
15
Years of Service
User Offline
Joined: 17th Jan 2009
Location:
Posted: 17th Jan 2009 15:51
if ( obj = 3 && x >= RIGHT_BOUNDRY - x_offset )[/code
Isn't this 495-320=175
and
if ( obj = 3 && x <= LEFT_BOUNDRY )
Left boundary is 20..

Some positions seem to go overboard initially.
switch ( obj )
{// positions
case 1: x = 20; y = 20; break;
case 2: x = 180; y = 20; break;
case 3: x = 340; y = 20; break;
case 4: x = 20; y = 90; break;
case 5: x = 180; y = 90; break;
case 6: x = 340; y = 90; break;
case 7: x = 20; y = 160; break;
case 8: x = 180; y = 160; break;
case 9: x = 340; y = 160; break;
}

When a person has nothing but a dream, can he dare to dream.
atomic knights
16
Years of Service
User Offline
Joined: 12th Apr 2008
Location: On my laptop
Posted: 17th Jan 2009 16:16
I didn't look at the logic but as a very long time C programmer the following jumps out at me In the IF statements you have:

if ( obj = 3 && x <= LEFT_BOUNDRY )

you probably mean
if ( obj == 3 && x <= LEFT_BOUNDRY )

the first case sets obj to 3 while the second compares it to 3.

hope this helps
Scarface
18
Years of Service
User Offline
Joined: 21st Oct 2006
Location:
Posted: 17th Jan 2009 16:49 Edited at: 17th Jan 2009 16:55
Quote: "I didn't look at the logic but as a very long time C programmer the following jumps out at me In the IF statements you have:

if ( obj = 3 && x <= LEFT_BOUNDRY )

you probably mean
if ( obj == 3 && x <= LEFT_BOUNDRY )

the first case sets obj to 3 while the second compares it to 3.

hope this helps "


D'oh yeah that was the cause of the crash, how the hell did I do that haha thanks bro ^^

Now on to more problems that I've caused when cleaning up my code, like the aliens moving around randomly on the screen lol

Any other advice on my code structure? And am I really cut out to be a programmer, in your opinions? I don't wanna waste my time on something that I'm probably never gonna be good at.

- Scarface
atomic knights
16
Years of Service
User Offline
Joined: 12th Apr 2008
Location: On my laptop
Posted: 17th Jan 2009 17:26
Programming is like playing a musical instrument. You don't pick up a guitar and wind up on MTV (unless you pay lots money to the guard at the studio door ) It does take practice.

The fact that you persevered through this bug is a good sign Programming can be frustrating.

Programming is a thought process not a typing process. You design, think, write some things down. Last thing you do is turn the computer on.

DarkGDK can be a very frustrating environment due to lack of documentation and the interaction between the routines but on the other side, the reward for getting the program right is great

Set aside a few hours and sit down on the floor of your local bookstore and partially read some C++ books. Eventually you will find a book where the text and code samples make sense to you. It is best if the book contains the magic phrase 'data structures' as you seem to have the base syntax down for C. You want a book that will get you into class and objects quickly.

Most of all, keep writing code.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 17th Jan 2009 19:52
Quote: "Last thing you do is turn the computer on."


Um... I disagree with that part. Programming is a thought process, but requires a lot of iterative testing of itty bits of code to make sure you're thinking on the right track. It's definately a thought process though - but one where you need to keep validating through constant testing... even (especially) the little bits you might take for granted you KNOW when you might not know as well as you think you do.

--Jason

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 17th Jan 2009 20:28
I need some more peanut butter. Jason, can you mail me some peanut butter?

Programming takes lots of peanut butter.
atomic knights
16
Years of Service
User Offline
Joined: 12th Apr 2008
Location: On my laptop
Posted: 17th Jan 2009 22:41
Jason is right. Writing a program is often like a construction project where you build support, scaffolding, temporary pieces, etc that 'discarded' when the final project is done.

He says
Quote: "but requires a lot of iterative testing of itty bits of code to make sure you're thinking on the right track."


and the key is
Quote: "you're thinking on the right track."


I think he would agree that you always need a plan whether is working on the main project, testing something, debugging, or trying to figure out what &^%$ the documentation is saying (or failed to say) about something.

Also, spend time reading code. Take some of the examples / samples that came with DarkGDK, read them and see what happens when you change things.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 17th Jan 2009 22:55

Login to post a reply

Server time is: 2024-11-25 11:48:58
Your offset time is: 2024-11-25 11:48:58