MODULE: Pixel-perfect collision detection v1.02

Started by SSH, Fri 28/04/2006 16:09:53

Previous topic - Next topic

SSH

After various people contributed to the thread on pixel-perfect collision detection, I modularised it.

Download PPCollision module here (Requires AGS v2.71 or later!)
Full Documentation here

Simple interface, so I'll just copy the function names here:
// Functions:
//
//  The module allows you to use pixel-perfect collision detection
//  instead of the default rectangle-based collisions of AGS
//
//  PPColliding.CWithC(Character *a, Character *b);
//  PPColliding.CWithO(Character *a, Object *b);
//  PPColliding.OWithC(Object *a, Character *b);
//  PPColliding.OWithO(Object *a, Object *b);
//    Check if a and b are colliding, for different types
//
//  PPColliding.CWithAnything(Character *a);
//  PPColliding.OWithAnything(Object *a);
//    Check if a is colliding with any object or character. Returns
//    the value of GetLocationType for the first collision found, but there
//    may be more than one collision.


With version 1.02, now added extender functions (in AGS 3.0 and up) so that you can use also:

Code: ags

player.PPCollidesWithC(cRoger)
player.PPCollidesWithO(oLadder)
oLadder.PPCollidesWithC(cRoger)

12

GarageGothic

Great work SSH! And good idea to add the WithAnything commands. I wouldn't have thought of that myself.

strazer

#2
Good work!

SSH

Well, anyway, v1.01 is up with 2.71 compatibility in the demo and the module. I think it will run faster in the latest beta, though, given the hoops one has to jump through in older versions to get certain info.
12

Snake

No way :o
This is incredible, SSH :D

I haven't tried yet, no time, but I will as soon as I do... definately. I'd check this forum for a while after somebody mentioned modularising in hopes someone would. I tried using the code that GG gave out (which rocked rose-scented assholes, btw) but I'm too much of an idiot to know how to modify it for my game - plus the new way of AGS' scripting comfuses the shit out of me... so I still do it the old way ;)

SSH, you slap the cat's ass! This is exactly what I needed for my game.


--Snake

PS
I love you.
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

SSH

Quote from: Snake on Tue 09/05/2006 03:16:54
SSH, you slap the cat's ass! This is exactly what I needed for my game.

PS
I love you.

Please, the incident with the Cats' protection league is in the past now and I'd like to move on.
12

SticMann

#6
Great idea for doing the collision detection.  I downloaded the demo game and it works great.  However, it doesn't seem to do collisions between characters as well as it does between obects/characters.  I tried the module in my own game between two characters and I couldn't get it to work. So, I made a new star character in your demo game and the collisions only seem to work sometimes.
my test of the demo files is at http://sticmann.com/ags

Edit:

Finally figured it out.  Just set the second character's base line to 1.  Thanks for the great module!

-Joshua

Kweepa

I was just taking a quick look at the code, and I noticed you create a dynamic sprite from a sprite to get the width and height. Instead, in AGS 2.71, you can just use:
Code: ags

int w = GetGameParameter(GP_SPRITEWIDTH, slot, 0, 0);
int h = GetGameParameter(GP_SPRITEHEIGHT, slot, 0, 0);

Should speed things up a bit :=
Still waiting for Purity of the Surf II

SSH

Yes, but making a dynamic sprite and getting its height and width:

a) Give you them in standard 320x200 cooords, the GetGameParameter varys by resolution (i.e. returns the REAL numbers
b) Works in 2.71 and 2.72
12

Kweepa

Well, that explains that. :=
Does Game.SpriteWidth[] work the same way?
Still waiting for Purity of the Surf II

SSH

Yes, the new one gives you standard numbers, so it could be optimised for 2.72...
12

SSH

I've fixed the baseline issue that SticMann mentioned, and also added extnder functions when using AGS 3.0 and up... new version 1.02 is up.
12

Rui 'Trovatore' Pires

Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SSH

Sorry Rui. Modules should always be availbale if you navigate to them on my site, but I've fixed the link now.
12

Matti

SSH, I just wanted to thank you for that great module. Right now I wouldn't know what to do without it!

Crimson Wizard

I guess I found a small flaw in this module.

When it does pixel-perfect check, it assumes characters are originally Clickable. Non clickable characters and objects won't be tested at all, because GetAtScreenXY is used.
What if an option be added to allow module test non-clickable characters and objects by temporarily set Clickable flag?

GarageGothic

Sounds like a good idea - for most non-adventure games it's irrelevant whether the object/character is clickable or not.

m0ds

#17
In 2.72 I get a parse error at 'this' :

Code: ags

function PPCollidesWithC(this Character *, Character *b) {
  return PPColliding.CWithC(this, b);
}


Not sure how to fix it..?

EDIT - Well for now I've found a workaround.

Cassiebsg

Sorry to dig this thread out of the dead, but does anyone have a link to this module?
Was about to sit and try to code just this, when I thought I should check the forum first for a "how to"...

Anyway, the links on the first page are dead. :~(
There are those who believe that life here began out there...

Mehrdad

Quote from: Cassiebsg on Sun 19/06/2016 19:14:40
Sorry to dig this thread out of the dead, but does anyone have a link to this module?
Was about to sit and try to code just this, when I thought I should check the forum first for a "how to"...

Anyway, the links on the first page are dead. :~(

Here you are:
https://www.dropbox.com/s/kn03yyfbzpucosm/PPCollision.zip?dl=0
My official site: http://www.pershaland.com/

SMF spam blocked by CleanTalk