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.

DarkBASIC Professional Discussion / [Help]Accepting a sprite as function arg/Collision

Author
Message
Tsproggy
14
Years of Service
User Offline
Joined: 2nd Jan 2012
Location: Reno, Nevada
Posted: 5th Jan 2012 03:38
Hello,

My name is Troy and I'm new here. This is by far the most fun game engine I've ever had the pleasure of using. I've been having fun making this little Pac-man game for my first working project. I like to start small but I'm having a bit of a problem. I can't get Sprite Collision or Sprite Hit to work for the life of me.

So I've decided I will have to just make an alternative collision detector function by adding a square range around my sprite that's as big as it's height/width and return a 1 when something intersects with it. But here is my problem, I don't know how to accept a sprite as one of my function's arguments.

I come from a Visual Studio background so I'm most used to doing something along the lines of:



Here is my code so far:


I only include all of it so if anyone sees fit they could possibly instruct me on any mistakes I've made as i'm open to ideas because I am new to all this. My main programming languages are C# and Visual Basic but I find DarkBASIC to be very fun

I haven't failed 1,000 times! I've just found 1,000 ways something won't work.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Jan 2012 15:04
Hi

Sprites are first created with the commands [Create Animated Sprite] or [Sprite]; which gives the new sprite an Identity number, it is this identity number you use to refer to the sprite in your function.

Sprite Collision and Sprite Hit should work fine; in the following example the If statement should be seen as true if both sprites are 10 in size.


Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 5th Jan 2012 15:35
As mentioned above, sprites are given numbers. Simply write your function with any integer parameter. Use that parameter to check for collision with that number

Writing your own function may be better than using the built in commands. I don't work with 2d so not sure how well they work
Tsproggy
14
Years of Service
User Offline
Joined: 2nd Jan 2012
Location: Reno, Nevada
Posted: 5th Jan 2012 23:42
Thank you, and yes I've tried every variation of Sprite Hit and Sprite Collision I can think of.. Either it doesn't return anything at all or it returns a number that never changes.

I haven't failed 1,000 times! I've just found 1,000 ways something won't work.
Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 6th Jan 2012 03:19 Edited at: 6th Jan 2012 03:20
i'd say perhaps you aren't using the commands correctly but either way what i'd be doing is writing a few arrays either in 'blocks' or actual pixels. Your block may be 5x5 pixels but whatever the principle is the same
Every time something moves, find it's size and then fill in the array with the object number

I.E.

Occupant(68).X to Occupant(78).X = 31
and
Occupant(31).Y to Occupant(41).Y = 31

meaning that from blocks 68-78 on the X axis and 31-41 on the Y axis are occupied by object number 31. When any other object moves, first to check to see if the value in that block is >0. If so nothing else can move there

I did this example in a 3d game using 2d tile coordinates and it had perfect sliding collision. The only problem with it is if you want exceptions for certain objects, i.e. ammo laying on the ground must be counted as an object but not block movement there. I didn't complete that part but I think I would have gone with a string instead of integer value with 0's for padding
I.E. 1 object on a space would return "0038", 3 objects would return "003800120126" and then simply divide the length of the string by 4 and check the properties of the unit (defined by user defined types. i.e. Unit(38).Type=0 & Unit(12).Type=0 for no collision, but Unit(126).Type=1 meaning it blocks this space, only type 0's can be placed down until 126 moves away)

Login to post a reply

Server time is: 2026-07-10 01:31:06
Your offset time is: 2026-07-10 01:31:06