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 / dbSpriteCollision with animated Sprite

Author
Message
FrankieV
14
Years of Service
User Offline
Joined: 10th Jun 2010
Location:
Posted: 24th Jun 2010 06:15
I'm trying to make my sprite collision happen between sprite 3 and sprite "a" here. Sprite "a" supposedly being a copy of sprite "i". Sprite "i" is an animation from a cel sheet, a rather large cel sheet. What I tried to do is create a box (sprite a) that followed each instance of sprite "i" and then formed my collision conditional on whether 3 collided with the box which is drawn to the size of the image in the cel sheet. However, at runtime the collision is always true, obviously due to the large cel sheet. Is there anyway around this? I've thought of making a separate image for each of the 16 frames in the cel sheet, but this seems really inefficient. Some ideas from the GDK Gods is mighty appreciated!

the relevant section is near the end in my playGame function:


One more thing...I can't figure out how to return the int value "difficultyLevel" from the menu function. I need to pass this back to the playGame function so I can control how many asteroids are created within the game loop.
Bran flakes91093
15
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 24th Jun 2010 19:13 Edited at: 24th Jun 2010 19:16
1 - This:
will still only increment it by one. If you want to increment/decrement a value more than one digit, use the +=/-= operators. ex. "ufoX += 2;"

2 -
"Case 5" will only be called if the user enters '5', so use the "default" keyword to catch any input that isn't caught by any other cases.

3 - Here,
you have "difficultyLevel decalared as a local variable, so, menu() cannot change the value of it directly. But, you return menu()'s difficultyLevel, so just replace "menu();" with "difficultyLevel = menu();", and you will have the value of difficultyLevel in playGame().

4 - For collision, you seem to be doing it right, but there is one fatal mistake:


The semicolon there makes the if an empty statement, so the compiler ignores it, effectively making collision true each loop.

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
FrankieV
14
Years of Service
User Offline
Joined: 10th Jun 2010
Location:
Posted: 25th Jun 2010 07:53
Everything worked except the collision detection.

I have evolved the program quite a bit now.
It's currently:


Unfortunately, that comes with more problems. The mouseClick and onSprite functions do nothing. And now, the menu wont even display. I get the three sprites for the intro screen, but nothing afterwards. Everything has gone haywire. I need to make sure the string input and file writing are working, and I need to move the ufo sprite into the ufo class along with its appropriate data and methods.

I have the if statement for the mouse detection commented out because it wouldn't work. The rest quit on me after the addition of the getInput and openInputFile functions. This is due in 12 hours and I'm starting to think I dont have a chance.
Bran flakes91093
15
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 25th Jun 2010 18:35


To write/read a string to/from a file, use dbWriteString()/dbReadString() instead of dbWriteFile()/dbReadFile().

The documentation for DarkGDK is here: C:\Program Files\The Game Creators\Dark GDK\Documentation\Dark GDK.chm



Here,
you are returning a char, instead of the string. http://cplusplus.com/doc/tutorial/ntcs/
In addition, the string is local and will destruct itself before the function returns, so either make it global, or use dynamic memory. http://cplusplus.com/doc/tutorial/dynamic/

Sorry, that's all I can do right now, and I'll be busy until sometime tomorrow. Good luck with your project.

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker

Login to post a reply

Server time is: 2024-07-04 10:53:27
Your offset time is: 2024-07-04 10:53:27