Post Reply 
GML code problem: enemy centering focus
Author Message
EXtremeXPerience Offline
(uhhrmmm...)
***
Registered

Posts: 71
Joined: Sep 2016
Reputation: 0

Post: #1
GML code problem: enemy centering focus
A sample problem I encountered just days ago... and still I can't solve this problem!

Basically, I have this script, embedded already with the program, named centerEnemyScript, and this is how the code looks:

Not a problem for me, but checking out with debugs, I encountered this! MM - Ill

When the enemy is on the right, and you're just pixels away on his left side, he doesn't jump left. Otherwise, it does well. Anyway to solve this code problem? MM - What
03-01-2017 02:50 PM
Find all posts by this user Quote this message in a reply
Smedis2 Offline
Obscurity Fanatic
*****
Registered

Posts: 351
Joined: Jun 2014
Reputation: 14
Reggae AwardAuto Award
Post: #2
RE: GML code problem: enemy centering focus
if (megamanexistsorwhatever)
{
if x <= megaManObj.x + sprite_width / 2 //Greater or equal? That's a bit odd.
{
sprite_index = argument0; \\What does this do?
}
if x > megaManObj.x + sprite_width / 2 //Are you sure the Sprite_width / 2 isn't screwing it up? Try getting the player's X position instead, unless you have the offsetting done weirdly.
{
sprite_index = argument1; //What does this do?
}
}

CHECK OUT STUFF I MAKE OVER AT
[Image: d03b37145145880c6532998fa3a49c20.png]
Here's my TWITTER
(This post was last modified: 03-01-2017 08:24 PM by Smedis2.)
03-01-2017 08:15 PM
Visit this user's website Find all posts by this user Quote this message in a reply
EXtremeXPerience Offline
(uhhrmmm...)
***
Registered

Posts: 71
Joined: Sep 2016
Reputation: 0

Post: #3
RE: GML code problem: enemy centering focus
(03-01-2017 08:15 PM)Smedis2 Wrote:  

Oooops... sorry, I forgot to elaborate.

The script centerEnemyScript(argument1,argument0) //definitely means...

Actually, smedis2, I want the enemy to face MegaMan in the right direction and with most accurate position. For example, MegaMan's width sprite is 42 and enemy's sprite is 32, I want the enemy to face MegaMan left with (x + 5), when MegaMan advance by 1 pixel, or simply (x + 6), the enemy faces right. Did you get it?
(This post was last modified: 04-01-2017 03:09 AM by EXtremeXPerience.)
04-01-2017 03:08 AM
Find all posts by this user Quote this message in a reply
EXtremeXPerience Offline
(uhhrmmm...)
***
Registered

Posts: 71
Joined: Sep 2016
Reputation: 0

Post: #4
RE: GML code problem: enemy centering focus
Update: What I need is precision in this code.

Need to have a update re. fixing this code. Anyone?

[Image: self1_by_megamanno99-dakh6k5.png]
09-01-2017 03:52 AM
Find all posts by this user Quote this message in a reply
Lamda Offline
Ace of Spades
*****
Registered

Posts: 954
Joined: May 2012
Reputation: 64
Roll Caskett AwardTempo AwardRubber Mega Man AwardChiptune AwardPixel Master AwardAce AwardRevo Remix ContributorSIBRE ContributorC^2 Super Moderator AwardIris AwardDoc Robot Award
Post: #5
RE: GML code problem: enemy centering focus
I don't know why you're relying on multiple sprite files when image_xscale can do what you're wanting without the need for them, so...

(I am assuming your base sprite faces right. If it faces left, swap the image_xscale values.)

//Step Event
Code:
if instance_exists(megaManObj)
    {
        if x>=megaManObj.x+(sprite_index/2)
            {
                image_xscale=1
            }
        if x<=megaManObj.x-(sprite_width/2)
            {
                image_xscale=-1
            }
    }
        else
    {
        image_xscale=choose(-1,1)
    }

//Draw Event
Code:
draw_sprite_ext(sprite_index,-1,x,y,image_xscale,image_yscale,image_angle,c_white,image_alpha)

Now, if you'd rather use sprites for each direction, use the following instead.

//Step Event
Code:
if instance_exists(megaManObj)
    {
        if x>=megaManObj.x+(sprite_index/2)
            {
                sprite_index=sprFaceLeft
            }
        if x<=megaManObj.x-(sprite_width/2)
            {
                sprite_index=spFaceRight
            }
    }
        else
    {
        sprite_index=choose(sprFaceLeft,spFaceRight)
    }

Quote:Game making in 6 steps:
1: Get assets and program
2: Smash the two together until stuff happens
3: Beat your face into your keyboard when stuff breaks/doesn't want to work
4: Continue beating your face into your keyboard until you've smashed the right code
5: Rejoice that it works and move on to the next thing
6: Go back to Step 2 and repeat
09-01-2017 07:42 AM
Find all posts by this user Quote this message in a reply
EXtremeXPerience Offline
(uhhrmmm...)
***
Registered

Posts: 71
Joined: Sep 2016
Reputation: 0

Post: #6
RE: GML code problem: enemy centering focus
(09-01-2017 07:42 AM)Lamda Wrote:  

It still doesn't solve my problem. Confused

Lemme get straight to the point.

09-01-2017 12:16 PM
Find all posts by this user Quote this message in a reply
Lamda Offline
Ace of Spades
*****
Registered

Posts: 954
Joined: May 2012
Reputation: 64
Roll Caskett AwardTempo AwardRubber Mega Man AwardChiptune AwardPixel Master AwardAce AwardRevo Remix ContributorSIBRE ContributorC^2 Super Moderator AwardIris AwardDoc Robot Award
Post: #7
RE: GML code problem: enemy centering focus
You're doing an abysmal job of explaining what the hell you want, then.

Can't help you if I don't understand what you're wanting or what's not working. All you keep doing is quoting pixel dimensions and talking about Ballade turning precisely. Neither of those things tell anyone what you want him to do versus what he's doing wrong.

Now, if I'm reading this last post right and you want him to turn precisely, then I know you didn't test the code I gave you because I know for a fact that's what it does (tested it myself multiples times before posting it).

Quote:Game making in 6 steps:
1: Get assets and program
2: Smash the two together until stuff happens
3: Beat your face into your keyboard when stuff breaks/doesn't want to work
4: Continue beating your face into your keyboard until you've smashed the right code
5: Rejoice that it works and move on to the next thing
6: Go back to Step 2 and repeat
09-01-2017 01:27 PM
Find all posts by this user Quote this message in a reply
Rhythm Offline
Rhythm is Gonna Get Ya
*******
Co-Admin

Posts: 975
Joined: May 2012
Reputation: 38
Booblight AwardAuto AwardRush AwardBeat AwardTempo AwardInafune AwardAce AwardC^2 Super Moderator AwardRevo Remix ContributorSIBRE ContributorDeadchat AwardSaga AwardBnG Award
Post: #8
RE: GML code problem: enemy centering focus
[Image: flip1_by_megamanno99-dausjwy.png]

why is his ankle broken?

[Image: 67617b7e1d6Ur.png]
09-01-2017 01:54 PM
Visit this user's website Find all posts by this user Quote this message in a reply
EXtremeXPerience Offline
(uhhrmmm...)
***
Registered

Posts: 71
Joined: Sep 2016
Reputation: 0

Post: #9
RE: GML code problem: enemy centering focus
(09-01-2017 01:27 PM)Lamda Wrote:  You're doing an abysmal job of explaining what the hell you want, then.

Can't help you if I don't understand what you're wanting or what's not working. All you keep doing is quoting pixel dimensions and talking about Ballade turning precisely. Neither of those things tell anyone what you want him to do versus what he's doing wrong.

Now, if I'm reading this last post right and you want him to turn precisely, then I know you didn't test the code I gave you because I know for a fact that's what it does (tested it myself multiples times before posting it).

I tested it already, calculated it a few times and re-run it many times before I replied, making sure that the code works, but it still ain't.

...and mind, I reply if I am "really sure" of what I am doing. Would you think I reply here if I am sure of the answers? Probably not... so keep your cool! Wink I am not barbaric like what you think.

(09-01-2017 01:54 PM)Rhythm Wrote:  [Image: flip1_by_megamanno99-dausjwy.png]

why is his ankle broken?

Actually, it's the Neo-Geo version of MegaMan sprite re-colored, so you see why some sprites look odd.
09-01-2017 03:19 PM
Find all posts by this user Quote this message in a reply
Lamda Offline
Ace of Spades
*****
Registered

Posts: 954
Joined: May 2012
Reputation: 64
Roll Caskett AwardTempo AwardRubber Mega Man AwardChiptune AwardPixel Master AwardAce AwardRevo Remix ContributorSIBRE ContributorC^2 Super Moderator AwardIris AwardDoc Robot Award
Post: #10
RE: GML code problem: enemy centering focus
Well, there's the problem. I typo'd and put sprite_index instead of sprite_width.

Anyway, if it's precise checking you want, change sprite_width/2 to sprite_width/32.

[Image: W0AAOFo.gif]

Works just fine.

Quote:Game making in 6 steps:
1: Get assets and program
2: Smash the two together until stuff happens
3: Beat your face into your keyboard when stuff breaks/doesn't want to work
4: Continue beating your face into your keyboard until you've smashed the right code
5: Rejoice that it works and move on to the next thing
6: Go back to Step 2 and repeat
09-01-2017 04:23 PM
Find all posts by this user Quote this message in a reply
Valo Offline
Nooblet Tour guide
*****
Registered

Posts: 625
Joined: May 2012
Reputation: 24
Iris AwardDeadchat AwardRush AwardUDON AwardRevo Remix ContributorSIBRE ContributorZero AwardInafune AwardRubber Mega Man AwardPixel Master Award
Post: #11
RE: GML code problem: enemy centering focus
Thats not a recolored neo geo megaman at all

[Image: RF8iZPq.png]
10-01-2017 04:22 AM
Find all posts by this user Quote this message in a reply
EXtremeXPerience Offline
(uhhrmmm...)
***
Registered

Posts: 71
Joined: Sep 2016
Reputation: 0

Post: #12
Lightbulb RE: GML code problem: enemy centering focus
(09-01-2017 04:23 PM)Lamda Wrote:  

Coding is finally done. Credits to yah! Smile
17-02-2017 04:53 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread:
2 Guest(s)

Return to TopReturn to Content