Master Game Community

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Master Game Community

Master Game Productions (MGP) presents Master Game Community (MGC). A forum for all your Game Maker needs.


3 posters

    Actions in Intersect Boundary/Outside Room events?

    avatar
    Hadasui
    Member


    Posts : 1
    Reputation : 0
    Join date : 2010-12-04

    Actions in Intersect Boundary/Outside Room events? Empty Actions in Intersect Boundary/Outside Room events?

    Post by Hadasui Sat Dec 04, 2010 11:55 am

    Greetings!
    :medieval:
    I'm trying to get my player object to reverse direction when going off screen, but it's not quite working.
    I was using the [Reverse Horizontal] and [Reverse Vertical] actions in the [Outside Room] event, and it actually works...partly.

    When I move off of the screen, it reverses based on the direction that I came from, but does not reverse the sprite so that it faces the new direction (so, I fly off of the left side of the screen, facing left, it reverses the object so that I travel to the right after the reverse...but the sprite still faces left).

    I understand that GM can't understand that I need to reverse the sprite, so what I wanted to do was create a script that did it, sort of like this (silly psuedocode):

    If player object goes off the top side of the screen
    {
    Divide player object's sprite by 2 // 360 subimages for player sprite, 0 faces up.
    Reverse player object's direction
    }
    If player object goes off the left side of the screen
    {
    Divide player object's sprite by 2 // 360 subimages for player sprite, 0 faces up.
    Reverse player object's direction
    }
    If player object goes off the bottom side of the screen
    {
    Divide player object's sprite by 2 // 360 subimages for player sprite, 0 faces up.
    Reverse player object's direction
    }
    If player object goes off the right side of the screen
    {
    Divide player object's sprite by 2 // 360 subimages for player sprite, 0 faces up.
    Reverse player object's direction
    }



    The thing is, I can't seem to find any kind of boundary detection in the help file or here in the forums. I understand that "Outside Room" event, by definition, detects this...but I'm trying to find out which direction the player was facing so that I can try to reverse it...and since I can't find any properties relating to this, I can't attempt it in an IF statement :blink:

    Does anyone have any thoughts on how to accomplish this?
    MasterOfKings
    MasterOfKings
    MGC Master


    Posts : 67
    Reputation : 0
    Join date : 2010-04-01

    Actions in Intersect Boundary/Outside Room events? Empty Re: Actions in Intersect Boundary/Outside Room events?

    Post by MasterOfKings Sat Dec 04, 2010 11:05 pm

    The boundaries are defined by x/y co-ordinates. They aren't proper places that GM knows of (it claims to, but it's just a check). For your pseudocode, simply check where the player's position is; if it's below (x and/or y) 0, then do the proper reversal. The easiest way to check for the bottom and right of screen is to use room_width and room_height.

    However, in saying that, why don't you just prevent it leaving the room? By only allowing movement if it's within certain limits (say, x = 16 and room_width-16; y = 16 and room_height-16). That way, you won't need to worry about reversal.

    -MoK

    PS: Welcome to MGC!
    Nocturne
    Nocturne
    Nocturne Games


    Posts : 17
    Reputation : 2
    Join date : 2010-09-16
    Age : 50
    Location : Spain

    Actions in Intersect Boundary/Outside Room events? Empty Re: Actions in Intersect Boundary/Outside Room events?

    Post by Nocturne Sun Dec 05, 2010 12:13 pm

    Welcome to the MGC, Hadasui! For your problem, there are various solutions... But before i start, I´d like to say that 360 sub-images is LOADS! You could probably get away with just 36 and no-one will notice. Anyway, what i would do is have a little code in the step event that uses the direction to set the image_index... like this...

    Code:

    //THIS GOES IN THE CREATE EVENT
    num=floor(360/image_number);

    //THIS GOES IN THE STEP EVENT
    image_index = floor(direction div num);

    Oh, and for this to work the sprite has to start facing right (which is 0º in GM) and then rotated counter-clockwise...

    Hope that helps!

    Sponsored content


    Actions in Intersect Boundary/Outside Room events? Empty Re: Actions in Intersect Boundary/Outside Room events?

    Post by Sponsored content


      Current date/time is Thu Mar 28, 2024 5:21 am