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 / How to move sprites?

Author
Message
Remmy
15
Years of Service
User Offline
Joined: 31st Aug 2009
Location:
Posted: 31st Aug 2009 21:37 Edited at: 31st Aug 2009 21:51
Hello everyone,

A few days ago, i've installed Dark GDK.
When i've solved the 'Wizard's Problem', i've discovered that Dark GDK is really easy to use, and that the results are incredible!
Now i'm trying to make my second game.
The aim of that game is to evade bouncing balls with the mouse.
The mouse will be also a ball, and when there's collision with the mouse and the other balls, you'll be GAME OVER.
But i don't know how to let the other balls move and bounce in a game-room.
I also don't know how to check if there's collision with another object.
I hope that someone can help me.

This is my code:


EDIT: Sorry for my code, but some things in the code have no use.
That things were just for expirimenting.
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 1st Sep 2009 01:35 Edited at: 1st Sep 2009 01:40
Okay, so for making the other balls move you need to say "dbSprite" every loop. (Or you could use "dbCircle" So if you want to have a bunch of balls, I'd make a vector of classes or structures called balls.

Here's some code. Just so you know, for this to work you need to have #include <vector> at the top of your code. You should also have "using namespace std;" after the includes(that or you could just say std:: before most stuff in iostream and stuff since I think most of that is under the std namespace).



Anyway now you can create random x, y, xspeed, and yspeed's for each one. (this should all be outside your loop)
for this you need to include Time.h at the top.



Now in the loop...
This will draw each circle.



Now you have to update each ball's x and y position, so that the ball's will move. I've also added code so the balls should bounce off the walls






As for collision you'll want something like this...




Sorry about indentation, the forum seems to mess it up.

BTW: You should go into the properties of your project > c/c++ > code generation and instead of Multithreaded debugging (MTd), set it to MT. This fixes a few weird errors I always get when using vectors. I have no idea why.

EDIT: I haven't tried this so if it doesnt work, I made some stupid error like forgetting a semi colon or bracket
Remmy
15
Years of Service
User Offline
Joined: 31st Aug 2009
Location:
Posted: 1st Sep 2009 09:05
Hello puppy of kosh,

Thank you very much for your reply!
I understand all of your code, so it shouldn't be hard for me to try it.
I'll try your method today
And abut the MTd error, i know.
Set it to MT will also fix another error.
If it's MTd, someone without VC++ on his computer can't run the program.
Setting it to MT will fix that weird error.

Greets,
Remmy
Remmy
15
Years of Service
User Offline
Joined: 31st Aug 2009
Location:
Posted: 2nd Sep 2009 18:27
I prefer to work with sprites, because i can make my own shapes instead of balls.
Could someone give an example when using sprites?

Login to post a reply

Server time is: 2024-10-01 12:36:20
Your offset time is: 2024-10-01 12:36:20