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/

Cassiebsg

Thanks :)
I  ended up coding the function last night, and even though it's not pixel perfect (I think) it works good enough for what I need it to do.

But thanks anyway, saved and stored for if it turns out I need the PP perfect. :-D
There are those who believe that life here began out there...

croquetasesina

I'm trying that when two characters come together, the protagonist moves away.

I script thist:

bool IsCollided = false;


function room_RepExec()
{
if (PPColliding.CWithC(cJuan, cPeter) && IsCollided == false) {
  IsCollided = true;
  Display ("CROQUETA");
  cSofi.Walk (86. 119, eBlock);
  IsCollided = false;
}
}
Code: AGS




But it does not stop constantly repeating "CROQUETA" and the character does not move away.
I would like that when two characters come together, they repel each other.

Could anyone help me, please?

Snarky

#22
Code: AGS

bool wasColliding = false;

function room_RepExec()
{
  bool isColliding = PPColliding.CWithC(cJuan, cPeter); 
  if (isColliding && !wasColliding)
  {
      Display ("CROQUETA");
      cSofi.Walk (86, 119, eBlock);
  }
  wasColliding = isColliding;
}

croquetasesina

Thank you so much Snarky, Scavenger help me too with this:

Code: AGS

bool IsCollided = false;

function room_RepExec()
{
if (IsCollided == false) {
if (PPColliding.CWithC(cPeter, cJuan))
{
  Display ("CROQUETA");
  cPeter.Walk (86. 119, eBlock);
IsCollided = true;
}
} 
else IsCollided = false;
}

Snarky


AndreasBlack

#25
Is there a manual for this somewhere? It's not working the link. The basic Syntax i already know, but i would like to know forexample disable temporarely or pause options, if there are any.

actaria

 Hello,

Does anyone have a working link to download the module and the documentation please ?

I would like to try it.

Thanks a lot.

heltenjon

Quote from: actaria on Thu 01/12/2022 14:41:28Hello,

Does anyone have a working link to download the module and the documentation please ?

I would like to try it.

Thanks a lot.
Looks like this one is still up:
Quote from: Mehrdad on Mon 20/06/2016 07:59:45Here you are:
https://www.dropbox.com/s/kn03yyfbzpucosm/PPCollision.zip?dl=0
 

actaria


actaria

Do you also have the documentation ?

I tried to lauch the demo but it's not working maybe because of my AGS version 3.5.1

This is the first time i use a module because i am not satisfied with:
Character.IsCollidingWithChar and AreThingsOverlapping

Do i simply have to copy the ".scm" file to my Adventure game studio directory ?

Thank you

Crimson Wizard

#30
Quote from: actaria on Thu 01/12/2022 16:54:12Do i simply have to copy the ".scm" file to my Adventure game studio directory ?

You need to right click on "Scripts" and select "Import script module", then choose the scm file. The scm file may be anywhere. The Editor will unpack scm into the script files and add to your project.

Because the module is so old, there may be problems with it running in the contemporary version right away. In this case you'll have to adjust some settings in "General Settings - Backwards Compatibility", but I cannot tell which without trying the module first.

actaria

Quote from: Crimson Wizard on Thu 01/12/2022 17:38:57
Quote from: actaria on Thu 01/12/2022 16:54:12Do i simply have to copy the ".scm" file to my Adventure game studio directory ?

You need to right click on "Scripts" and select "Import script module", then choose the scm file. The scm file may be anywhere. The Editor will unpack scm into the script files and add to your project.

Because the module is so old, there may be problems with it running in the contemporary version right away. In this case you'll have to adjust some settings in "General Settings - Backwards Compatibility", but I cannot tell which without trying the module first.


Hello,

Now i will be busy with all that this is perfect  :-D
Let's try to use my 1st module and i will try many backwards compatibilty settings in case it's not working well.

Thanks again Crimson Wizard

actaria

It's working well with script compatibility level 3.5.0 Alpha but not with 3.5.1 i think because of:
GetViewport


actaria

I am now trying to use the module

Code: ags
function room_RepExec()
{ 
if (PPColliding.CWithC(character[0], character[15])) {
cChar1.Say("i am dead");
  }
}

Unfortunately it's not working nothing happens when i collide.
I triple checked the characters ID's.
Both characters got solid properties On

What am I doing wrong, any ideas ?

Thank you.

Crimson Wizard

Quote from: actaria on Thu 01/12/2022 20:04:55I am now trying to use the module

Code: ags
function room_RepExec()
{ 
if (PPColliding.CWithC(character[0], character[15])) {
cChar1.Say("i am dead");
  }
}

I don't exactly know what the problem with this is, but would like to point that you don't have to do "character[0]" and "character[15]". Whenever a function requires a Character* pointer, you may pass a script name, similar to how you are using cChar1 to call "Say":

Code: ags
if (PPColliding.CWithC(cChar1, cAnotherChar)) {

This makes it easier to understand which characters you are refering to.

actaria

O yes ok thank you for the explanation and it's easier than numbers sure thing.

SMF spam blocked by CleanTalk