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.

Newcomers DBPro Corner / pixel perfect collision

Author
Message
GameMaker Jason
20
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 1st Feb 2004 18:38
I'm make a snake game with a background and i want to make my snake die if it hits the water or bushes on the background, how do i do this?

just code
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 1st Feb 2004 18:44
Depends if its 3D or 2D, for 3D you could use a distance check, not the best type of collision, but it works:

x#=(object position x(snake)-object position x(bush))^2
y#=(object position y(snake)-object position y(bush))^2
z#=(object position z(snake)-object position z(bush))^2
distance#=sqrt(x#+y#+z#)
if distance# < bushsize/2 then DIE!!!

for 2D you could use position and distance check:

position (great for cubes/square things):
if object position x(snake)>object position x(bush)-(bushsize/2)
if object position x(snake)<object position x(bush)+(bushsize/2)
if object position y(snake)>object position y(bush)-(bushsize/2)
if object position y(snake)<object position y(bush)+(bushsize/2)
DIE!!!
endif
endif
endif
endif

distance (great for spheres/round things):
x#=(object position x(snake)-object position x(bush))^2
y#=(object position y(snake)-object position y(bush))^2
distance#=sqrt(x#+y#)
if distance# < bushsize/2 then DIE!!!


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
Slayer
20
Years of Service
User Offline
Joined: 15th Nov 2003
Location: CA
Posted: 1st Feb 2004 18:44
First get the snakes size x/z then you make a box around it
like this x1=x+5, x2=x-5, z1=z+5, z2=z-5. then you get the position of the water and if x1 or x2 or ect... > or < then water position x/z then hit = 1.

I dont know how to spell
GameMaker Jason
20
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 1st Feb 2004 18:45
this is nothing to do with collision but does the "book beginning in darkbasic" do DBPro and if so how much of the book this DBPro stuff

just code
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 1st Feb 2004 18:46
A thing overlapping something else IS called collision.


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
GameMaker Jason
20
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 1st Feb 2004 18:48
this is a little confusing could you please tell me what all the calculations do?

just code
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 1st Feb 2004 18:55
Ok, first position:

If the snake is inside an area then let it die:
(slayer's variables

x1 = object position x(water)-(object size x(water) / 2)
x2 = object position x(water)+(object size x(water) / 2)
y1 = object position y(water)-(object size y(water) / 2)
y2 = object position y(water)+(object size y(water) / 2)

x3 = object position x(snake)
y3 = object position y(snake)

if x3>x1 and x3<x2
if y3>y1 and y3<y2
print "SNAKE IS INSIDE THE AREA!"
endif
endif


The distance one is a little harder to understand, but I will explain later (dinner now)


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
GameMaker Jason
20
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 1st Feb 2004 18:58
but im using sprites? and it 2D

just code
Cordeval
20
Years of Service
User Offline
Joined: 29th Jan 2004
Location:
Posted: 1st Feb 2004 20:58
Sorry to butt in but collision detection is something I would like advice on.

I am translating a table top 2D game to DBc. The game uses rectangles to represent military units. In the tabletop game, you go to combat resolution when you move your unit into front contact with enemy unit, matching front left to front right corners.

Can you point me towards available code I can review for guidance on moving these rectangles around on a matrix...with collision detection?

Ultimate goal, groups of units on one side moving as though a single "super unit" (use limbs and "glue to limb"?).
Also, eye candy figures that stay within the rectangles, representing the soldiers. If I could have masses moving on the screen, that would be the goal. Think of the commercial game "Shogun: Total War" and the untis of soldiers in the recent movie "Fellowship of the Ring".
GameMaker Jason
20
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 1st Feb 2004 21:14
I have another question, how can i make the level map a bigger size than the screen and when the snake gets 100 pixel away from edge of the screen the screen scrolls to show the rest of the image and not to scroll if there is no more image to scroll to?
im still need a bit more detail in the pixel perfect collison.

just code
GameMaker Jason
20
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 1st Feb 2004 23:51
how can i make my snake head move when i press a direction key and the trailing segments follow the exact same route?

just code
GameMaker Jason
20
Years of Service
User Offline
Joined: 22nd Nov 2003
Location: UK
Posted: 2nd Feb 2004 00:20 Edited at: 2nd Feb 2004 00:33
could i use an array and say if the snake go into that part of the array then die? if so what code would i use?
I also don't know how to put an image/sprite in an array location. how is this done?

just code

Login to post a reply

Server time is: 2024-05-23 01:22:16
Your offset time is: 2024-05-23 01:22:16