A better CollisionFree

Game Editor comments and discussion.

Re: A better CollisionFree

Postby skydereign » Fri Sep 07, 2012 8:34 am

Code: Select all
strcmp(RIGHTO->name, "platform")

This will return a 0 if the strings are the same. That is what strcmp does. An if statement only triggers when the condition within it is non-zero. Now you don't want to change strcmp, but we know that strcmp returns a 0 if they are the same. So all we need to do to make the statement true by checking if it is equal to 0.
Code: Select all
if(strcmp("test", "test")==0)
{
    // this if statement always runs since the strings are identical
}
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 » Sat Sep 08, 2012 5:58 am

By your code, are you implying:
Code: Select all
if(strcmp("platform", "platform")==0)
{
    // this if statement always runs since the strings are identical
}

or
Code: Select all
if(strcmp(RIGHTO->name, "platform")==0)
{
    // this if statement always runs since the strings are identical
}
? The former seems state the obvious, that platform is platform, and since that's always equal to 0 Floober is unable to move right.
The latter seems like it should work, RIGHTO being the actor a few pixels to the right of Floober, and since RIGHTO is pointing to the name of it's getactor, "platform", it is equal, so it does equal 0, so if state is 2 Floober should stop, but for some reason he still doesn't. Could you please check out a demo and see what you can make of it? :mrgreen:
http://www.filedropper.com/bembal
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 » Sat Sep 08, 2012 6:50 am

supatails wrote:By your code, are you implying:
Code: Select all
if(strcmp("platform", "platform")==0)
{
    // this if statement always runs since the strings are identical
}

or
Code: Select all
if(strcmp(RIGHTO->name, "platform")==0)
{
    // this if statement always runs since the strings are identical
}
? The former seems state the obvious

Yes it is obvious that platform is equal to platform, all that code is showing is that if you want to use strcmp in a way that triggers if the strings are the same, you use strcmp()==0. Now that you understand that, the next problem with your code is due to the position of an actor being at its center. The getactor code you are using is getting the player actor, since 5 pixels to the right of the center of the player is still the player. This can be shown easy enough by adding something like RIGHTO->r-=5; in the key right event. That just reduces the red of the actor that the getactor call retrieves. Now you don't want getactor(x+5, y) but rather getactor(x+width/2+5, y).
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 » Sat Sep 08, 2012 2:08 pm

Oh man thank you it works! :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 supatails » Sun Sep 09, 2012 5:50 am

Okay just one last problem involving collisions and junk:
So while sliding up the wall, I need the game to detect whether or not there is wall above and to the right of him, so when he arrives at a corner he will slide back onto solid ground. I'm having alot of trouble with the game detecting this, and any help would be greatly appreciated.
Here's what the problem looks like:
Image
Here's the code I've been using but it doesn't seem to work:
Code: Select all

Actor *slapright=getactor(x!=x+width/2+5, y!=y-height/2-5);

switch(state)
{
    case 18:
    if (strcmp(slapright->name, "platform")==0)
    {
        ChangeAnimation("Event Actor", "floober_slap_right_on", FORWARD);
        state=24;
        grav=3;
    }
    break;
}

by this code it should check if there is nothing 5 pixels up and to the right of Floober, and then play the animation, but it's not detecting anything for x. It has, however, worked when I tell it to check for y only.
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 » Sun Sep 09, 2012 6:56 am

I'd be interested to know how you would explain that first line of code. variable!=something will always return a 0 or a 1. So your get actor code will always get the actor around the origin. That isn't what you want the getactor to do. Instead you want to get the actor in the up right direction of the player, and check if it is the platform or not.
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 » Sun Sep 09, 2012 3:19 pm

Oh I'm trying to tell it: If there isn't "platform" above and to the right of you, then play the animation.
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 » Sat Sep 15, 2012 10:49 pm

I'm still having trouble with the same problem. I can't for the life of me get floober to change his state only if there is nothing up-right of him. Would one of you kindly look at a demo and see if you can figure out the problem?
http://www.filedropper.com/gubgurr
The code I'm messing with is Floober>Key Down>up(the first one)>script editor>
Code: Select all
Actor *ABOVE=getactor(x,y-1);
Actor *slapright=getactor(x+width/2+5, y-height/2-5); //this defines that slapright will detect what actor, if any, is located 5 pixels
// up and to the right of the event actor
switch(state)
{
    case 8:
    case 10:
    if (strcmp(ABOVE->name, "platform"))
    {
        ChangeAnimation("Event Actor", "floober_shlop_right1", NO_CHANGE);
        state=12;
    }
    break;
 
    case 9: //if you're squished facing left
    case 11: //or sliding to the left
        if (strcmp(ABOVE->name, "platform"))
        {
            ChangeAnimation("Event Actor", "floober_shlop_left1", NO_CHANGE);
            state=13;
        }
    break;

}

switch(state)
{
    case 18:
    if (strcmp(slapright->name, "platform")!=0) //if the name of the actor 5 pixels up and to the right of floober is named platform,
// then the string =0. If it doesn't =0, then change the state.
    {
        ChangeAnimation("Event Actor", "floober_slap_right_on", FORWARD);
        state=24;
        grav=3;
    }
    break;
}
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 » Sun Sep 16, 2012 9:33 am

Your ABOVE Actor* suffers from the same problem I mentioned before. This one to be precise.
skydereign wrote:Now you don't want getactor(x+5, y) but rather getactor(x+width/2+5, y).

Your slapright getactor call is done properly. A few things to note. Using more than one script editor event for your keydown event (or any event) just makes it harder to get the full picture. It is cleaner and much easier to deal with if all of that code goes into one event. Especially in this case, where they are all just different cases of the switch(state). It's also faster if you have all of the cases in the same switch statement.

Now one thing I forgot to mention might screw up positing (which seems to be the case in this event) is that the xy variable is at the sprites center. That means getactor(x, y) will not always get floober, and getactor(x+width/2+1, y) will not always get the actor to the right of floober. This happens when the sprite isn't centered, which is the case for your stuck to the wall animations. You'll need to center those animations, use a box colliding actor, or accommodate by not using width/2 but rather a actual image width/2. Another problem is that your tiles aren't completely filled in. This means that even if you get the pixel one to the right and one above of the player's sprite box, the getactor may register as no platform even when there is.

If you fix those problems, it should be easier to get to work. But as always, if you are still having problems just ask.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: A better CollisionFree

Postby infoleather » Thu Oct 11, 2012 4:02 am

The lucky not use strcmp might just broke all my stuff, who knows the right path.
Everything happens to everybody sooner or later if there is time enough.
infoleather
 
Posts: 2
Joined: Wed Oct 10, 2012 2:26 am
Score: 0 Give a positive score

Previous

Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest