A better CollisionFree

Game Editor comments and discussion.

A better CollisionFree

Postby supatails » Mon Sep 03, 2012 7:16 am

I really want to make a new variable, much like collisionfree, that will allow me to specify which actor it is detecting, as opposed to every possible pixel in the game.
For example, in a game I'm making, the main character can squish down and slide under small areas, and if the ceiling is too low, the character won't pop back up to normal size unless there is enough room.
Code: Select all
switch(state)
{
    case 8:
    case 10:
    if (CollisionFree("Event Actor", x, y-5))
    {
        ChangeAnimation("Event Actor", "floober_shlop_right1", NO_CHANGE);
        state=12;
    }
    break;
 
    case 9:
    case 11:
    if (CollisionFree("Event Actor", x, y-5))
    {
        ChangeAnimation("Event Actor", "floober_shlop_left1", NO_CHANGE);
        state=13;
    }
    break;
}


BUT, because of this, if there is any object I am passing by, say a lamp post for example, or a plant, or any background object, I am still unable to pop up off of the ground due to the fact that this collisionfree event isn't specified, it applies to all objects in-game.

I would greatly appreciate it if anyone could help me develop a new variable just like CollisionFree, but with one extra option. Here's the basic idea:

Code: Select all
 int CollisionFree2(char *actorName, int x, int y, //name of collision actor )

also, if anyone wouldn't mind telling me, what is char, does char refer to the main character? and what is actorName? I don't see that defined anywhere at all? And why would you multiply char by actorName? XD
Sorry for all of these questions, and thanks for the help guys! :mrgreen:
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: A better CollisionFree

Postby AliceXIII » Mon Sep 03, 2012 1:41 pm

char is a variable type like an int, float, and double..

char initializes a new variable for text storage, actorName in this instance is the char variable created to store the text in..

if you want to create custom functions you'll at least need to know the basic variable types in programming and there uses i would recommend reading a beginning C book and it'll easily explain all the data types and how to use them..

and what your looking for could be achieved using the getActor function after your if CollisionFree check something like this:
Code: Select all
if (CollisionFree("Event Actor", x, y-5))
{
    Actor *COLLIDE=getActor(x,y-5);
    if(COLLIDE=="desired actor")
    {
        ChangeAnimation("Event Actor", "floober_shlop_right1", NO_CHANGE);
        state=12;
    }
}
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: A better CollisionFree

Postby supatails » Mon Sep 03, 2012 6:13 pm

That's a really cool idea, and by looking at it I feel like it really should work, but upon trying it, here is my result:
Code: Select all
switch(state)
{
    case 8:
    case 10:
    if (CollisionFree("Event Actor", x, y-5))
    {
        Actor *COLLIDE=getactor( x, y-5);
        if (COLLIDE=="platform")
        {
            ChangeAnimation("Event Actor", "floober_shlop_right1", NO_CHANGE);

On lines 8 and 20, the
Code: Select all
if (COLLIDE=="platform")
, it gives me this error:
Mixed pointer operation
What does this imply? Is there any way around it? Thanks for the help btw!
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: A better CollisionFree

Postby AliceXIII » Tue Sep 04, 2012 1:12 pm

this is due to me not being specific enough in my explanation of pointer use, which is my bad.. :P
Code: Select all
Actor *COLLIDE=getactor(x,y-5); //This is whats called a pointer your able to access actors with it


thing is to actually use it you must point to something in the actors struct like so:
Code: Select all
if(COLLIDE->name=="desired actor")
{
    //code here
}

the -> is the operator used with pointers to point to specific actor traits like their name, transp, etc., etc.

it wont give you the error cause you'll be using the pointer correctly then sorry for the confusion i overlook things sometimes :)
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: A better CollisionFree

Postby supatails » Tue Sep 04, 2012 4:53 pm

:mrgreen: This is embarrassing, but I've tried this code in just about every combination and there's always something wrong upon testing it out.
for example, if my code is:
Code: Select all
switch(state)
{
    case 9: //if you're squished facing left
    case 11: //or sliding to the left
    if (CollisionFree("Event Actor", x, y-5)) //and there's nothing 5 pixels above you
    {
        Actor *COLLIDE=getactor(x,y-5); //make a pointer names COLLIDE, which will getactor 5 pixels above you
        if (COLLIDE->name=="platform") //if platform is 5 pixels above you
        {
            ChangeAnimation("Event Actor", "floober_shlop_left1", NO_CHANGE); //change animation to popping up off the ground facing left
            state=13; //change state to popping up off the ground facing left
        }
    }
    break; //end the execution here

}

This won't let me pop back up off the ground at all. I think it's because CollisionFree and COLLIDE are a contradiction. CollisionFree is telling Floober to pop up if there's nothing above him, while COLLIDE is telling Floober top pop up if platform is above him. So I changed it to this:
Code: Select all
Actor *COLLIDE=getactor(x,y-5); //make a pointer names COLLIDE, which will getactor 5 pixels above you
switch(state)
{
    case 9: //if you're squished facing left
    case 11: //or sliding to the left
        if (COLLIDE->name!="platform") //and the actor 5 pixels above you isn't named platform
        {
            ChangeAnimation("Event Actor", "floober_shlop_left1", NO_CHANGE);
            state=13;
        }
    break;

}

but now I'm able to pop up, even if the actor above me is named platform! So then I add an else statement telling it not to pop up, which doesn't do anything, so I add this if statement to the code:
Code: Select all
Actor *COLLIDE=getactor(x,y-5); //make a pointer names COLLIDE, which will getactor 5 pixels above you
switch(state)
{
    case 9: //if you're squished facing left
    case 11: //or sliding to the left
        if (COLLIDE->name!="platform") //and the actor 5 pixels above you isn't named platform
        {
            ChangeAnimation("Event Actor", "floober_shlop_left1", NO_CHANGE);
            state=13;
        }
        if (COLLIDE->name=="platform") //if the actor 5 pixels above you IS named platform
        {
            state=9; //don't really do anything, your state remains the same
        }
    break;
}

is there something I'm missing? Sorry for making this so hard on you.
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: A better CollisionFree

Postby lcl » Tue Sep 04, 2012 5:25 pm

It is Alice who here is missing something..
It's the fact that strings can't be compared like that, but you will have to use strcmp() (strcmp is shortening for string compare)

So, the if (COLLIDE->name == "desired actor")
should be:

Code: Select all
if (!strcmp(COLLIDE->name, "desired actor"))


If you wonder what that ! is, it does the same as writing strcmp(COLLIDE->name, "desired actor")==0
And why it has to be 0? Well, because strcmp returns 0 when the strings are equal. =)

I hope this helped you.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: A better CollisionFree

Postby AliceXIII » Tue Sep 04, 2012 5:39 pm

odd i've never compared strings in that way and all my crap works :P

and ten times out of ten i'll miss something..

but im still perplexed with the fact i've gotten away with not using strcmp maybe all my stuffs just broke in the right way to work who knows...
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: A better CollisionFree

Postby skydereign » Tue Sep 04, 2012 7:28 pm

AliceXIII wrote:odd i've never compared strings in that way and all my crap works :P

Either you have been using real pointer comparison (which can do what you want, but only in special cases), or all your string comparisons were not needed.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A better CollisionFree

Postby AliceXIII » Tue Sep 04, 2012 9:12 pm

most likely the latter because i do all of my work using pointers and integer value checking rather than check the actual text of something..

i like to use clones and pointers with getclone() so that i have more precise control over my stuff..

like in this instance i would have made an platform actor cloned it how many times needed then just used platforms actual animation at the time to check whether floober needed to be squished or not just me though..
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: A better CollisionFree

Postby supatails » Wed Sep 05, 2012 4:06 am

Thank you guys so much! You really helped me get past a major obstacle that was preventing me from continuing with this game! I appreciate the help AliceXIII, I gave you a point for helping me out! Also congrats on 30 points, now you get the free GE or whatever. :mrgreen: Also thanks lcl!
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: A better CollisionFree

Postby AliceXIII » Wed Sep 05, 2012 12:51 pm

actually i don't even know whether makslane still gives out free copies of GE anymore..

either way i've always planned on purchasing a license if i wanted to do commercial stuff so i could support GE :)

but, thank you for the point and i hope to see your game completed one day cause we need more of those around here!
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: A better CollisionFree

Postby supatails » Wed Sep 05, 2012 3:58 pm

Yeah unlike all of my previous childhood attempts, I'm actually planning on going through with this. I'm hoping that college can teach me some useful stuff as well, but with this game rather than copying other peoples code like I always did before, I'm making an effort to learn how to code myself.
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: A better CollisionFree

Postby supatails » Thu Sep 06, 2012 2:40 am

Wait guys, I'm having trouble with something. I've been trying to prevent running into the wall, because it looks stupid, so I set up a code like this:
KEY DOWN>RIGHT
Code: Select all
Actor *RIGHTO;
RIGHTO=getactor( x+1, y);
switch(state)
{
    case 2: // if you're walking to the right
    if (strcmp(RIGHTO->name, "platform")) // and if the actor 5 pixels to the right of you is named "platform"
    {
        ChangeAnimation("Event Actor", "floober_idle_right1", FORWARD); //play idle animation
        state=0; // and return to the idle position
    }
    break;
}

I have no clue why this wouldn't work, but no matter what, Floober is unable to move to the right.
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: A better CollisionFree

Postby skydereign » Thu Sep 06, 2012 6:29 am

You are using strcmp incorrectly. Most functions are true if they return any non-zero value, but strcmp returns a 0 if the two strings are equal. So in your code the if statement is true when RIGHTO->name is not equal to platform, which is the reverse of what you want.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A better CollisionFree

Postby supatails » Fri Sep 07, 2012 8:30 am

I'm sorry but I'm having some trouble wrapping my mind around this concept. So strcmp compares every character in both strings, and if all of the characters are identical then it returns 0. BUT because it is a zero, the rest of the code assumes it is false, so that means I need a setup which allows the strcmp to return a non-zero integer, like 1 or 8 or something, IF they are both platform. I dunno, I'm lost... I tried:
Code: Select all
if (strcmp(RIGHTO->name, "platform") != 0)
which doesn't do what I entended, it's as if it ignores the code, so then I tried this:
Code: Select all
if (!strcmp(RIGHTO->name, "platform"))
which doesn't work either because it also cancels out the line of code.
I'm stumped on how to set state to 0 and change animation to idle if the platform is directly next to you and you try walking into it. Sorry I'm so difficult to teach! XD
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Next

Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest