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 / Collision with background maze game

Author
Message
Michael Harrison
14
Years of Service
User Offline
Joined: 29th Jan 2010
Location:
Posted: 30th Jan 2010 00:36
Hello,

I've recently started C++ and I was hoping to make a maze game. The user will rotate the maze with the 'left' and 'right' arrow keys and the ball will move accordingly. I can do that with a load of physics, no bother. But when I create the 'maze' image the background - the free space where the ball moves around in isn't free at all. So when I place the ball in the maze it is always touching a wall and won't move at all.

Here's the code


Is there a way of setting the background to transparent in the "dbSetImageColorKey(255,0,255);" or do I need to do I need to save the picture in a special way? Or is there something I can do in the collision line "if(dbSpriteCollision(1,2))"?

I have plenty of question, just no answers. I really need some answers

Thanks.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 30th Jan 2010 11:27
It won't work if your whole maze is one sprite. There is no pixel-perfect sprite collision, meaning that you cannot make the ball collide with non-white areas of the background and not collide with the white parts. What you need to do is make a map of the maze and construct it from small pieces (wall sprites), so that in the areas where collision should not happen, there will be no wall sprite.

The other way would be to write your own functions which check the screen coordinates of the ball and not let it move to areas which are forbidden. Then you cannot use sprite collision. Sorry, none of these is really easy, but it can be done with a bit of planning.

Maybe you can have a look at a little program that I posted some time ago in the Dark GDK coding challenges thread.

http://forum.thegamecreators.com/?m=forum_view&t=150933&b=22&p=2

Post 10th Oct 2009 12:06. This is a 2D side-scroller which creates a level from a map. It's not finished (collision is missing), but at least it can give you a starting idea.
Michael Harrison
14
Years of Service
User Offline
Joined: 29th Jan 2010
Location:
Posted: 30th Jan 2010 12:57
Thanks,

I did think about this. I had a one pixel image and I would resize it. I stopped doing it because I thought it would be too hard. Also when I rotate the maze all the small image swould rotate around there own point so the maze wouldn't rotate as a whole. To solve this I would need to make a point, in the centre of my maze that all the maze pieces rotate around. Could someone tell me how to do this? I think I might need to offset all the pieces to the same location. Would that work?
Michael Harrison
14
Years of Service
User Offline
Joined: 29th Jan 2010
Location:
Posted: 30th Jan 2010 14:21
I realised that this maze game is going to be impossible to make. when a sprite is rotated it's collision boundaries also change.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 30th Jan 2010 20:28
that can be easily fixed, make another sprite ( use dbSetSpriteAlpha ( ) to make it invisible ) and place it on the rotated sprite, without rotating the invisible sprite, and check collision for the invisible sprite not the main one

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 30th Jan 2010 23:20 Edited at: 30th Jan 2010 23:20
Don't position your map sprites with x and y co-ords, position them using an angle and a distance from the centre of your map.

The hard part is creating the function that turns angle and distance into real x and y co-ordinates.
I'm pretty sure I could do this if you don't think you can do it, its just a bit of trig.

Using an angle-distance system should solve your problem by default, you just change the angle, the distance for each sprite is always the same.

Theres a chance I have misunderstood the problem as I don't use sprites but I'm pretty sure the theory is sound.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 31st Jan 2010 09:59 Edited at: 31st Jan 2010 10:02
Another idea is to make it 3D, with textured plains (or cubes, so they will be suitable for collision detection), watched from above, and then you can rotate only the camera instead of rotating the whole maze. But I'd make everything 3D so that's not an impartial opinion.

Sticking to 2D, I'd probably try to keep the maze one picture as it is now, and calculate the ball movement in the program. Knowing ball position and direction angle, it should be possible to check the maze bitmap colour (wall or empty) at the next planned ball position. I'm sure it's quite difficult to do but should be possible.
NewProgrammer
14
Years of Service
User Offline
Joined: 8th Feb 2010
Location:
Posted: 8th Feb 2010 14:09
how to create 3D background? do i need a 3d image and upload it

Login to post a reply

Server time is: 2024-10-01 23:38:05
Your offset time is: 2024-10-01 23:38:05