Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: SSH on Fri 28/04/2006 16:09:53

Title: MODULE: Pixel-perfect collision detection v1.02
Post by: SSH on Fri 28/04/2006 16:09:53
After various people contributed to the thread on pixel-perfect collision detection (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=26019), I modularised it.

Download PPCollision module here (http://ssh.me.uk/modules/PPCollision.zip) (Requires AGS v2.71 or later!)
Full Documentation here (http://ssh.me.uk/moddoc/PPCollision)

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:


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

Title: Re: MODULE: Pixel-perfect collision detection v1.00
Post by: GarageGothic on Fri 28/04/2006 17:43:32
Great work SSH! And good idea to add the WithAnything commands. I wouldn't have thought of that myself.
Title: Re: MODULE: Pixel-perfect collision detection v1.00
Post by: strazer on Fri 28/04/2006 19:35:30
Good work!
Title: Re: MODULE: Pixel-perfect collision detection v1.01
Post by: SSH on Tue 02/05/2006 10:27:22
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.
Title: Re: MODULE: Pixel-perfect collision detection v1.01
Post by: Snake on Tue 09/05/2006 03:16:54
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.
Title: Re: MODULE: Pixel-perfect collision detection v1.01
Post by: SSH on Tue 09/05/2006 07:52:37
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.
Title: Re: MODULE: Pixel-perfect collision detection v1.01
Post by: on Sat 03/06/2006 19:48:43
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
Title: Re: MODULE: Pixel-perfect collision detection v1.01
Post by: Kweepa on Tue 06/06/2006 00:20:29
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:

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

Should speed things up a bit :=
Title: Re: MODULE: Pixel-perfect collision detection v1.01
Post by: SSH on Tue 06/06/2006 08:18:59
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
Title: Re: MODULE: Pixel-perfect collision detection v1.01
Post by: Kweepa on Tue 06/06/2006 15:28:20
Well, that explains that. :=
Does Game.SpriteWidth[] work the same way?
Title: Re: MODULE: Pixel-perfect collision detection v1.01
Post by: SSH on Tue 06/06/2006 20:24:47
Yes, the new one gives you standard numbers, so it could be optimised for 2.72...
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: SSH on Wed 07/05/2008 12:19:18
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.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: Rui 'Trovatore' Pires on Wed 07/05/2008 23:28:07
404? :'(
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: SSH on Thu 08/05/2008 10:59:27
Sorry Rui. Modules should always be availbale if you navigate to them on my site, but I've fixed the link now.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: Matti on Wed 04/02/2009 16:33:50
SSH, I just wanted to thank you for that great module. Right now I wouldn't know what to do without it!
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: Crimson Wizard on Mon 28/12/2009 17:55:55
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?
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: GarageGothic on Mon 28/12/2009 18:11:06
Sounds like a good idea - for most non-adventure games it's irrelevant whether the object/character is clickable or not.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: on Sat 12/11/2011 13:48:56
In 2.72 I get a parse error at 'this' :


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.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: 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. :~(
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: Mehrdad on Mon 20/06/2016 07:59:45
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
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: Cassiebsg on Mon 20/06/2016 15:40:27
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
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: croquetasesina on Tue 16/04/2019 11:38:28
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) Select




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?
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: Snarky on Tue 16/04/2019 11:49:08
Code (AGS) Select

bool wasColliding = false;

function room_RepExec()
{
  bool isColliding = PPColliding.CWithC(cJuan, cPeter);
  if (isColliding && !wasColliding)
  {
      Display ("CROQUETA");
      cSofi.Walk (86, 119, eBlock);
  }
  wasColliding = isColliding;
}
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: croquetasesina on Tue 16/04/2019 11:55:52
Thank you so much Snarky, Scavenger help me too with this:

Code (AGS) Select

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;
}
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: Snarky on Tue 16/04/2019 12:18:08
My version is better.  :-D
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: AndreasBlack on Wed 11/11/2020 19:19:19
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.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: actaria on Thu 01/12/2022 14:41:28
 Hello,

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

I would like to try it.

Thanks a lot.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: heltenjon on Thu 01/12/2022 15:42:09
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
 
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: actaria on Thu 01/12/2022 16:14:23
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
 

This is really kind heltenjon thanks a lot  :-D
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: actaria on Thu 01/12/2022 16:54:12
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
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: 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.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: actaria on Thu 01/12/2022 17:48:01
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
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: actaria on Thu 01/12/2022 18:09:16
It's working well with script compatibility level 3.5.0 Alpha but not with 3.5.1 i think because of:
GetViewport

Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: actaria on Thu 01/12/2022 20:04:55
I am now trying to use the module

Code (ags) Select
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.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: Crimson Wizard on Thu 01/12/2022 20:39:28
Quote from: actaria on Thu 01/12/2022 20:04:55I am now trying to use the module

Code (ags) Select
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) Select
if (PPColliding.CWithC(cChar1, cAnotherChar)) {

This makes it easier to understand which characters you are refering to.
Title: Re: MODULE: Pixel-perfect collision detection v1.02
Post by: actaria on Thu 01/12/2022 20:57:40
O yes ok thank you for the explanation and it's easier than numbers sure thing.