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.

AppGameKit Classic Chat / Side scrolling game & collisions

Author
Message
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 23rd Jul 2013 00:17
Hi
Could you please suggest me, good methods for detecting character collisions with walls in a side scrolling game?
I am thinking of making a classic side scrolling game, having the player's character jumping around using the 2D physics features of AGK
LittlePIC
13
Years of Service
User Offline
Joined: 19th Oct 2011
Location:
Posted: 23rd Jul 2013 05:37
GetSpriteHit() and GetSpriteHitTest() pretty much covers everything you need
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 23rd Jul 2013 09:13 Edited at: 23rd Jul 2013 09:14
walls are static and the player is dynamic in physics,
you have a auto collision.

this are useful:

SetSpriteGroup
GetSpriteGroup
SetSpritePhysicsIsSensor < for collecting items
---------
GetSpriteFirstContact
GetSpriteNextContact
GetSpriteContactSpriteID2
GetSpriteContactWorldX
GetSpriteContactWorldY
---------
GetContactSpriteID1
GetContactSpriteID2
GetContactWorldX
GetContactWorldY
GetFirstContact
GetNextContact
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 23rd Jul 2013 18:44
Thanks
The physics is the way I'll go.
I imagine a first scrolling polyline that will serve as ground and another scrolling polyline as a roof. As the sprite will go left or right, these polylines should be scrolled respectively and the sprite should be able to be collided with them.
Is there any way to define such a polyline for sprite collisions?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 23rd Jul 2013 19:08
u can define a polygon CreateDummySprite ,SetSpriteShapePolygon
for moving SetViewOffset
george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 23rd Jul 2013 19:11
Thanks a lot Markus.
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 23rd Jul 2013 19:16
Although physics is an easy way to get started, you will probably run into other issues, dependant on what you are doing, sprite shapes and such. I have a little sprite collision tutorial available, which gives you an idea how to use getspritecollision() command.

Still for a platformer, physics is pretty nice, and does do a lot of the hard work for you!

george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 23rd Jul 2013 23:03
Actually I don't like physics because I want to have full motion control of all sprites relating their interaction within the game environment. But I don't know how to detect a collision of a rectangular shape (sprites) with a polyline.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Jul 2013 09:32 Edited at: 24th Jul 2013 09:33
just make one (or more) sprite with shape = polyline .
alternate you can read about "Line-line intersection".
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 26th Jul 2013 00:36
Is polyline a new command I have missed? Or do you mean a basic sprite shape?
Manually, just use getspritecollision(sprite1,sprite2), or getspritehit(x,y), x and y being the co-ordinates, which return the sprite hit.
Obviously there's more to it than that, but with those commands you can easily make a platformer. For instance if the sprite isn't colliding with a platform, simply add to the sprites y position until it does. That will give you very basic artificial gravity.

The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 27th Jul 2013 20:53
G, i assume e your are using a tiled scrolling background....this is the most memory and speed efficient:

Lets assume for this you are scrolling horizontally;

If player moves right
If we at the beginning of the map (the far left as drawn)
If player is on the left side of the screen
If (Check map collision( moving right speed)) = false //no collision with solid tile
Move player right by speed
Else
If ( Check map collision(moving right speed)) = false
Scroll map by speed left
Endif
Endif
Endif
Endif

You can also add code for visually pixel perfect collisions....ie...
If (check map collision(moving right speed)) = true. // we have hit a solid tile
Find map coords of solid tile in pixels
Find difference between player x and solid tile x
Move player / scroll map number of pixels different
Endif


Please note this assumes you are using square tiles....if not use physics all the way!

Just my thoughts....

www.bitmanip.com
All the juicy you could ever dream of!
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 27th Jul 2013 20:58
Better formatting of pseudo code

If player moves right
If we at the beginning of the map (the far left as drawn)
If player is on the left side of the screen
If (Check map collision( moving right speed)) = false //no collision with solid tile
Move player right by speed
Else
If ( Check map collision(moving right speed)) = false
Scroll map by speed left
Endif
Endif
Endif
Endif

//You can also add code for visually pixel perfect collisions....ie...

If (check map collision(moving right speed)) = true. // we have hit a solid tile
Find map coords of solid tile in pixels
Find difference between player x and solid tile x
Move player / scroll map number of pixels different
Endif


//Please note this assumes you are using square tiles....if not use physics all the way!




www.bitmanip.com
All the juicy you could ever dream of!

Login to post a reply

Server time is: 2024-11-24 18:30:15
Your offset time is: 2024-11-24 18:30:15