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 tilesets

Author
Message
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 29th Aug 2011 17:12
to explain this it will be easyer if i give you my code first.

Code:


i want it so when a sprite colides with somthing in the array it deletes it but since i am using the same sprite can i do this because i want it to delete the sprite in the array. i just tried getting a diffrent sprite and if it collides with 3 in the array it deletes 3 but that is not a sprite it is part of a sprite. since i am taking number 1-4 form one sprite.
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 29th Aug 2011 22:37
You can't delete part of an image of an animated sprite, but you can set the number in the array to zero. Then, in the "for" loop where you display the sprite, paste it onto the screen only if map[y][x] is not zero.
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 30th Aug 2011 16:34 Edited at: 30th Aug 2011 16:35
alright so i set the number in the array to zero.

and the for loop i think i did it wrong

i did dbLoadImage("Sprite1.bmp",50);
dbSprite(50,0,0,50);
dbHideSprite(50);

then in the for loop i did dbPasteSprite(50);

here is the full code

i have a feeling that it is totaly wrong what i dind in the for loop
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 30th Aug 2011 23:41
We probably misunderstood each other. I didn't mean all the numbers in the array to zero... Then nothing will be displayed. I meant only the one number that you want to delete. In your original post you said:

Quote: "when a sprite colides with somthing in the array it deletes it "


I thought you want to detect collision between one tile of the sprite map and another sprite (somehow), and when there is a collision, then that tile would disappear from the map. You could do that like this:



Note that "collision detected with map[y][x]" is obviously pseudo-code, since we haven't talked about how you want to detect collisions. But maybe I misunderstood what exactly you would like to do.

In your second program, the sprite is not even an animated sprite any more. Decide if you want to use one animated sprite for your tileset, or you want to use several different sprites (or images). Both ways are possible, I don't know which one is better for the purpose of your program.
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 31st Aug 2011 00:31 Edited at: 31st Aug 2011 00:32
yeah i guess i did mis understand you any ways...

Well i would like to use animated sprites.
Note: i have never used animated sprites so this is all kind of new to me.

Just in case you dont know what my animated sprite is like this is the website i got it from

http://www.darkgdk.us/index.php?page=6

if you scroll down on that website there is an image of a flower or somthing of that nature and there is a 1, 2, 3, and a 4. what im doing now is changing them so they are one solid color. 1 red, 2 green, 3 blue, and 4 yellow.

i have no collision system up yet i want to get one up and that is what i am working on except nothing deletes that i want it to.

So to clarify i want the sprites in the array or part of the sprites in the array to delete but it dosent because
Quote: "You can't delete part of an image of an animated sprite"


so i am kind of stuck i need a collison system.

hopefully i dont make this one confusing sorry i made my my first post confusing.
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 31st Aug 2011 21:19
What I still don't understand is what collision and deletion have to do with each other, because as far as I see, these are two completely different questions.

When you want to "delete" something, I suppose it means that you don't want to see it on the screen any more. That's easy, don't display it. That's what can be achieved by making its place in the array empty. The event that will delete the sprite (collision or something else) is another problem.

I've had another look at your program. Where do the numbers come from? The map array is declared as map[30][30] in size, but you initialize it with much less values, it's only [8][8]. Then in the for loop, you display a part of it, between indexes 4 - 12. Also the coordinates are strange: x * 40, y * 15, when the size of one frame of the sprite that can be downloaded from the web site you linked to, is 16 x 16 pixels (the whole image is 32 x 32 since it has four such frames), it's very small. If you look at the program on the web site, it uses correct numbers. It's difficult to test if you don't adjust the numbers to the data that you are testing with.

I have made a small program to demonstrate what I meant with my deletion idea. This will remove a tile from the map if you click the mouse on that tile. You can keep clicking on the tiles until all of them disappear from the screen, so they are effectively "deleted", although the sprite itself still exists. Here is the program. (I have corrected the numbers too.)



Now, about collision. You usually test collision between two sprites, e.g. a platform sprite and the player sprite, or in this case, the background tiles in the array and a player sprite. There is currently no other sprite in the program that could collide with the tiles in the array, but I suppose there will be, later.

To test for collisions, dbSpriteCollision comes to mind first, but there is a problem: if you use dbPasteSprite, then you cannot use dbSpriteCollision. With dbPasteSprite, only the image is pasted, but you don't have a sprite "physically" in that position, so this won't work. You either have to make a different sprite for each tile in the map (abandoning the animated sprite idea), or you have to solve collision detection in some other way, for example with coordinate calculation. As a start, it's not so difficult to check whether the coordinates of two images overlap with each other.

I hope that helps somewhat. I didn't deal with 2D and sprites much, so I can only offer limited advice, and in any case, program design choices have to be made by you.
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 31st Aug 2011 22:31
I attached here the image that I tested the above program with. I tried to reproduce your four-coloured sprite, but it just occurred to me that I don't know whether you have changed the size of the image, so it's best to make sure that we are using the same thing.

Attachments

Login to view attachments
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 1st Sep 2011 04:57 Edited at: 1st Sep 2011 04:59
Sorry it took so long i was really busy getting school work done.

Here is the game i want to make


i need it so when the ball hits the bricks they break(delete).

and all that other stuff you were talking about with the
Quote: "x * 40, y * 15"
that was the hieght and width of that image so that is why that was like that.

and i wanted the sprite to be 40x15 this way it looked more like a brick not a square its not your fault i just dint inform you on anything i just kind of threw you in here sorry about that.


and i wanted the array more in the top middle portion of the screen so i just made it skip the first couple rows.

i dont want you to feel like you are making the whole game so i will try from here to get it working but if you could tell me do i need to use Sprites not animated sprites? how would i do this?

thanks in advance i really owe you one
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 1st Sep 2011 08:39 Edited at: 1st Sep 2011 09:53
OK sorry that I made such a problem out of the image size and array size, now it's clear.

Both the animated sprite and the separate sprite approach can work, but now that I know the type of game you want to create, I would choose the individual sprites, because the collision test will be easier. The tricky part there is how to break up the tileset into individual sprites. It is possible to make separate images in the image editor, but you can keep the tileset as one image and break it up automatically in the program.

This example will create sprites out of the tileset. I used constants for sprite width/height instead of hardcoded numbers to make it easier to understand and modify, if necessary.



Since the brick sprites do not change their position, and sprites are not deleted by dbCLS(), you can create the sprites only once before the game loop. In the game loop, you can use dbSpriteCollision to test if the ball sprite collides with any of the bricks and if yes, remove that brick sprite with dbDeleteSprite. In this case, the numbers in the map do not need to be modified when a sprite is deleted.
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 1st Sep 2011 09:58
I have edited the above post because at first try, I overcomplicated the sprite ID assignment. This modified solution is simpler.

Quote: "i wanted the array more in the top middle portion of the screen so i just made it skip the first couple rows. "


By starting the map indexes from 4 instead of 0, you also skip useful numbers in the array, so only part of the map will be displayed. That's OK if that is what you want to do, but if the purpose was only to position the tiles in a certain part of the screen, then it's better to index from zero, and add a constant number (the coordinates of the top left corner of the brick area) to the calculated screen coordinates when the sprite is displayed.
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 2nd Sep 2011 02:31
This is what i see when i play this game and i am still using that code here is the code snippet
and was this for the seperate sprites?

Attachments

Login to view attachments
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 3rd Sep 2011 14:02 Edited at: 3rd Sep 2011 14:07
The last code was for individual sprites, and you mixed it with the earlier code for the animated sprite (which also had different image size values). Besides, I mentioned that you only need to create the sprites once before the game loop, not in every loop.

Here is a complete program for you, and attached is the image to test it with. This time I used a more brick-like image set. I have also made a "ball" sprite, which is actually one of the brick images, that moves with the mouse cursor and if you move it into the brick area, then it will delete the bricks. In addition, the bricks are positioned a little further away from the corner of the screen, so that I can also show you how to set the top left corner of the brick area, without skipping indexes in the map array.

Now all you need is the paddle and ball movement code to make this into a playable level. However, I suggest that you look through the program and try to understand what every line does before developing it further.

Attachments

Login to view attachments
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 5th Sep 2011 02:23
alright i looked over it an i understand it all but there is one problem i know what it is(I think) but i dont know how to solve it. the part where it switches levels is in the while loop. if i put that bitmap in it, it is just going to refreash it so how can i make it switch the level but not have the bitmap in the while loop if you need code just ask!
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 24th Sep 2011 01:33
I know this is kinda late but what is the int name of the blocks because

this is when it collides with anything so it deletes background and everything is there a solution?

Always end the name of your child with a vowel, so that when you yell the name will carry. - Bill Cosby
California is a fine place to live - if you happen to be an orange. - Fred Allen
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 25th Sep 2011 10:32
If it collides with the background, then I suppose your background is also a sprite. You can solve this in two ways. The first is to give your background sprite a high number, for example 200, then you can prevent the background sprite from being deleted by checking the sprite ID returned by the collision function:



The other solution is that you make the background a simple image and not a sprite. Images can be displayed on the screen with dbPasteImage.
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 26th Sep 2011 01:29 Edited at: 26th Sep 2011 01:29
Well it doestn delete it but when i start all over it does so i dont know what the problem is here is the Main code


Always end the name of your child with a vowel, so that when you yell the name will carry. - Bill Cosby
California is a fine place to live - if you happen to be an orange. - Fred Allen
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 29th Sep 2011 01:39
Maby the problem is in the ball.cpp file here it is:


Always end the name of your child with a vowel, so that when you yell the name will carry. - Bill Cosby
California is a fine place to live - if you happen to be an orange. - Fred Allen
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 29th Sep 2011 03:12
I got it thank you for all your help Mireben the problem was that the background was a sprite so the code that is above in your last post
told it that if x is greater than 0 and less than a sprite 200 but my sprite was higher so it made it false so it did not delete the blocks so i had to just paste a image it worked so that is good.

Always end the name of your child with a vowel, so that when you yell the name will carry. - Bill Cosby
California is a fine place to live - if you happen to be an orange. - Fred Allen
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 7th Oct 2011 03:01 Edited at: 7th Oct 2011 03:03
I have all the collsion set up (rough ill make it better later) but i cant make it so if all the bricks are gone it finishes the level how would i do this?

thanks in advanced

i allready tried dbSpriteExist and that dint work if you can get ti to work good but then i tried if the map was < 0 that dint work so maby im doing somthing wrong

Always end the name of your child with a vowel, so that when you yell the name will carry. - Bill Cosby
California is a fine place to live - if you happen to be an orange. - Fred Allen
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 17th Oct 2011 23:20
I'm answering a bit late but if you are still looking for a solution to this question: Maybe you can count how many bricks are on the map in total, and then count how many bricks you have deleted. It's easy to increment a counter by 1 every time you call dbDeleteSprite on a brick. When the counter reaches the total number of bricks, then all the tiles are gone and the level can finish.
allan
12
Years of Service
User Offline
Joined: 17th Nov 2011
Location: philippines
Posted: 17th Nov 2011 18:04
ser can i ask for how to use wt the code for collision for bricks in DBP
allan
12
Years of Service
User Offline
Joined: 17th Nov 2011
Location: philippines
Posted: 17th Nov 2011 18:11
ser answer me what is the code for collision for tiles set....?
allan
12
Years of Service
User Offline
Joined: 17th Nov 2011
Location: philippines
Posted: 17th Nov 2011 20:24
guyz plz help to our may problem..

the problem is what is the code of collision for tiles in games..
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 18th Nov 2011 00:57
Sorry i havent been on in a long time so that is why i havent seen you posting. any ways collsion between the tilesets are kind of iffy because i havent been working on it but this is the thing so it bounces off the tilesets.



this piece of code dbSpriteCollision(1004, 0); says if the ball collides with ANYTHING then it will bounce off. further down the code it bounce off at a 45 deggree angle. that is that and if tou want i can try to make a a little code that shows you every thing if you dont understand?

Always end the name of your child with a vowel, so that when you yell the name will carry. - Bill Cosby
California is a fine place to live - if you happen to be an orange. - Fred Allen

Login to post a reply

Server time is: 2024-04-25 08:16:03
Your offset time is: 2024-04-25 08:16:03