AreThingsOverlapping() working "too well" ;) - (see the EDIT in the 5th post)

Started by Snake, Mon 03/04/2006 19:27:30

Previous topic - Next topic

Snake

Hey guys,

I decided to post this in the beginners forum since, well, I am a beginner pretty much. I haven't released any games, eh? Maybe this doesn't belong here, but with my luck it's a simple solution.

Simple question for a simple mind, I guess. Way too extreme for me, but child's play for you guys. Am I right?

Let me tell you what I'm doing first. I'm making an AGS game version of "Paper War". A game where you draw a dot, fold the paper over, trace it and it comes out on the other side. I've been wanting to do this for my nephews lately since their into games a bit and they've played paper war with me and love it.



Brief History on Paper War:
When I was in the second grade, a sixth grader showed me this game, and it was very simple - it was kinda like Battleship. Draw like five ships on each folded side and go from there. Whomever blows up the other side first, obviously wins. Since then I've evolved it into people, different characters with different weapons, rules and lots of sweet-ass bonus type things that go along with it. It turned into a semi-complex game which is, for some stupid reason, extremely fun.
Now I'd like to make it into an AGS game.



What I need to do is, make it so when you choose a particular character to attack with, the cursor turns into that character's weapon's bullets. Fine. Easy. But;
Currently, as far as I know, there's only ONE hotspot position for each cursor. So in order for the different look of bullets to work on enemies, I'm guessing that I need to somehow detect where the mouse was clicked (mouse.x, mouse.y), than place an object or character there. This way I can run the script where it knows when each "bullet character" or "bullet object" (whichever I use) is colliding with the enemy character - then run the result afterwords.

Here's what I mean if you're confused:
A shotgun in this game has 7 small bullets in a cluster. A very good advantage since there's more than one bullet and is easier to hit the enemy when he's moving around (since there's a cluster of bullets obviously) - instead of just ONE bullet from the regular gun.

Am I making sence?

If not let me know, and thanks for any help,


--Snake

PS
Incase any of you are wondering, LE is still in the works, just feel like doing something different for once.
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Radiant

Yes, you are making sense, and that would work well if the amount of bullets simultaneously on-screen does not exceed the object limit (30 or so, IIRC).

So what is your question?

In the on_mouse_click() function, you can set a character or object at the x,y coordinates.

You can use repeatedly_execute() to move the bullets or do collission checking with AreObjectsOverlapping ().

Snake

#2
Sorry about that, got a little carried away and never put my actual question down :-[

Like I was saying with the ShotGun:
You click on the ShotGun Guy character and the cursor changes to the shot gun bullets cursor. Now what I need to do is make it so when you click on the enemy you want to shoot, have the bullets "drop down" on the screen and check wether they are colliding.

I did a test this afternoon real quick after I posted. I got as far as placing the bullets on the screen using this code:
-I'm going to use characters for the bullets
-Also, all 7 bullets are one sprite...

This is when the player clicks on the screen:
if (GetCursorMode()==8){
Ã,  character[SG].room=1;
Ã,  character[SG].x = mouse.x;
Ã,  character[SG].y = mouse.y;
Ã,  }


This works great.

I've got this in the room's Repeatedly Execute:
if (AreCharactersColliding(SG, EGO)==1) {
Ã,  Display("HIT!");
Ã,  character[SG].room=-1;
Ã,  }


I've tested it by only hiting EGO with one of the bullets in the cluster, but it doesn't do anything. I'm guessing it has something to do with the baselines? I'm wondering this because when the bullets are set, they'll be drawn behind EGO.
I tried setting his baseline to ZERO, but that didn't make a difference either... I know I'm missing something obvious here.

Thanks again,


--Snake

--EDIT--
I'm using v2.56d if that has anything to do with it. I didn't notice any AreCharactersOverlapping(); command.
--EDIT 2--
I payed attention this time and realized that setting EGO's baseline to zero made it at his feet. So I tried setting it to 200, which made the bullets drawn over him, but it still won't detect a collision unless the hotspot position on the cursor touches...?
--EDIT 3--
Isn't it possible to have characters "flat" on the screen as though they are drawn on paper? This way there would be a collision no matter what since they are always touching...
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Radiant

"colliding" in this context means their feet are touching. The function you want is AreThingsOverlapping (); which likely has a different name in v2.5 (we're up to v2.7 now). ATO does a boundary check.
Alternatively, make the bullet a non-clickable character, and check for GetCharacterAt (character[BULLET].x, character[BULLET].y);  GCA does a pixel-wise check.


Snake

QuoteAlternatively, make the bullet a non-clickable character, and check for GetCharacterAt (character[BULLET].x, character[BULLET].y);Ã,  GCA does a pixel-wise check.
Tried this and what it does, mysteriously, is as soon as the room loads (SG character is initialy in room -1) it displays "HIT!" before any actions take place. I don't understand this since the SG bullet character is initialy in room -1, and you must click the mouse with mode 8 to place SG in room 1 - from here Repeatedly Execute takes over with the collision testing. Also, EGO and SG are non-clickable characters (forgot to mention that earlier.
So I stuck with the colliding command to shut that nonsence off.

Would anyone know what version of AGS has the AreCharactersOverlapping( ); command in it?...besides the newer versions - the new coding scares the shit out of me ;) Do you have to command that way now with everything, or does it still support the old way? I'm a little out dated as you can tell. I remember reading an update a while ago with the new style and it confused me :O Or maybe I'm just seeing something different and nothing really has changed... I should just download the latest finished version.

If anyone is wondering exactly what I need, I'll write a short blurb to catch you up:
In the test room so far I've got...
You select a character to shoot with. The cursor changes into the character's bullets (HandGun, ShotGun, MachineGun, etc...).
For now it's just simply switching to cursor mode 8 (ShotGun).
Good so far.
Now when the player clicks on the screen the character according to WHAT bullets are being used (ex; ShotGun(SG) sprite) is placed where the player clicked.
Good so far.
Now would be a good time to detect wether one of the bullets (different section of the same character sprite) are hitting the enemy character or not.
In Repeatedly Execute I've got:
if (AreCharactersColliding(SG, EGO)==1) {
Ã,  Display("HIT!");
Ã,  character[SG].room=-1;
Ã,  }


Now of course this is only detecting when the hotspot position on the mouse is clicked on the enemy character's baseline. If only I can say screw the damn baseline and have the enemy sprite "lay flat" on the screen like a carpet, I'd probably be golden.

Thanks for any help - or anyone who wants to tell me I'm an idiot ;)


||-- E D I T --||
Before I left last night I downloaded the latest version of AGS and this morning tried out the AreThingsOverlapping(); command.
It works.
But since this is ME wanting to use it, there's a problem.

QUESTION: Aren't clear portions on a sprite supposed to be nonexistant? You're not supposed to be able to click them right?
I did a test and made a 2 bullet sprite and had them far apart in a line. A sure miss if you put each bullet on either side of EGO without them touching him, right? Sheit. It still detects it. AUGH!
Any suggestion?


Thanks again,

--Snake

||-- END OF EDIT --||
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

SSH

The manual says that that function only checks rectangles and is not "pixel perfect"
12

Snake

QuoteThe manual says that that function only checks rectangles and is not "pixel perfect"
What? What the hell good is that?? ;) Shit. I missed that part while reading I guess.

Ah, well. I'll try a different way I have in mind, if not, this game idea's trash. Again.

Thanks for all the previous help, Radiant!

||-- E D I T --||
I've come up with a simple fix which is good enough.
I've done this:
AreThingsOverlapping(SG,EGO)>5)
...and it's close enough.
What I can do for the enemy characters on the screen is just simply make them in more of a rectangular form - and I'll be doing this game in 640x400 anyway for more field space - so any HITs when they should have been a MISS happen, it won't be as easy to tell like with 320x200. Pretty much the only guns that show more than one bullet at a time when you shoot are ShotGuns and MachineGuns. Also, no bullets are going to be that far apart like in my test game anyway.
Thanks again,

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

Matt Damon

Make a tiny "ghost" object matching the location of the bullet or offset by a bit and test for its collision instead.

Matt out-- peace!

SMF spam blocked by CleanTalk