Open Surge Forum

A fun 2D retro platformer inspired by Sonic games and a game creation system

You are not logged in.

Announcement

Our community has moved to Discord! https://discord.gg/w8JqM7m

#26 2018-07-28 19:10:49

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Alexandre wrote:

So, basically:

1) If he gets underwater, he should play the swimming animation until: a) he gets off water b) he lands on the floor or c) gets hit
2) When playing the swimming animation, he should not be able to attack baddies nor crash item boxes

Outside the water, just use Surge's behavior.

Is that correct?

Yes! smile

Offline

#27 2018-07-29 00:47:47

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,287
Website

Re: Another underwater bug [SOLVED]

Well, here's my attempt at making a swimming object.

Since I don't have Speedy here, I made a companion object for Surge instead. I also used fire1 (jump) instead of fire6 to swim.

It plays very nicely on my system (tested on the update of July 27th). See if you can understand the logic. smile Adapt as needed.

object ".surge_companion"
{
    requires 0.2.0
    always_active

    state "main"
    {
        create_child ".surge_spindash_controller"
        create_child ".surge_nolightwalk_controller"
        create_child ".surge_swim"
        destroy
    }
}

object ".surge_swim"
{
    requires 0.2.0
    always_active

    state "main"
    {
        observe_player "Surge"
        //hide
        change_state "out of water"
    }

    state "out of water"
    {
        on_player_underwater "swimming"
    }

    state "swimming"
    {
        // got hit?
        on_player_gethit "getting hit underwater"

        // killed?
        on_player_death "destroy"

        // landed on the floor?
        attach_to_player 0 32
        if "obstacle_exists(0,0) and player_yspeed() > 0" "underwater but not swimming"

        // play the swimming animation
        springfy_player
        set_player_animation "SD_SURGE" 23
        on_button_pressed "fire1" "swim"

        // got off water?
        on_player_underwater "swimming"
        change_state "out of water"
    }

    state "swim"
    {
        springfy_player
        set_player_animation "SD_SURGE" 23
        set_player_yspeed -90
        change_state "swimming"
    }

    state "underwater but not swimming"
    {
        on_player_jump "swim"
        on_player_underwater "underwater but not swimming"
        change_state "out of water"
    }

    state "getting hit underwater"
    {
        // wait until the getting hit animation stops
        on_player_gethit "getting hit underwater"
        change_state "underwater but not swimming"
    }

    state "destroy"
    {
        destroy
    }
}

Offline

#28 2018-07-29 13:19:15

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Alexandre wrote:

Well, here's my attempt at making a swimming object.

Since I don't have Speedy here, I made a companion object for Surge instead. I also used fire1 (jump) instead of fire6 to swim.

It plays very nicely on my system (tested on the update of July 27th). See if you can understand the logic. smile Adapt as needed.

object ".surge_companion"
{
    requires 0.2.0
    always_active

    state "main"
    {
        create_child ".surge_spindash_controller"
        create_child ".surge_nolightwalk_controller"
        create_child ".surge_swim"
        destroy
    }
}

object ".surge_swim"
{
    requires 0.2.0
    always_active

    state "main"
    {
        observe_player "Surge"
        //hide
        change_state "out of water"
    }

    state "out of water"
    {
        on_player_underwater "swimming"
    }

    state "swimming"
    {
        // got hit?
        on_player_gethit "getting hit underwater"

        // killed?
        on_player_death "destroy"

        // landed on the floor?
        attach_to_player 0 32
        if "obstacle_exists(0,0) and player_yspeed() > 0" "underwater but not swimming"

        // play the swimming animation
        springfy_player
        set_player_animation "SD_SURGE" 23
        on_button_pressed "fire1" "swim"

        // got off water?
        on_player_underwater "swimming"
        change_state "out of water"
    }

    state "swim"
    {
        springfy_player
        set_player_animation "SD_SURGE" 23
        set_player_yspeed -90
        change_state "swimming"
    }

    state "underwater but not swimming"
    {
        on_player_jump "swim"
        on_player_underwater "underwater but not swimming"
        change_state "out of water"
    }

    state "getting hit underwater"
    {
        // wait until the getting hit animation stops
        on_player_gethit "getting hit underwater"
        change_state "underwater but not swimming"
    }

    state "destroy"
    {
        destroy
    }
}

There! Much better! The problem is when I jump to the water, a strange '?' symbol appears. Also, when Speedy is on the ground, he should roll jump and active the swimming skill after pressing fire1 when roll jumps underwater.

And finally, the sprite stops the animation and it should repeat the swimming animation forever until Speedy lands on the floor.

Here's another video:
https://drive.google.com/open?id=1yILRT … MyAPQjRTmf

Offline

#29 2018-07-29 13:49:38

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,287
Website

Re: Another underwater bug [SOLVED]

Yes, all these things you can do. Add a new state or two to handle the case of the roll jump.

Take a look at the "underwater but not swimming" state and see what changes you can do. What can you do?

I jump to the water, a strange '?' symbol appears.

Yes, that's my object. It works as a ground sensor, and I left it there on purpose smile Uncomment the hide command on the main state to make it go away.

Offline

#30 2018-07-29 15:39:41

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Alexandre wrote:

Yes, all these things you can do. Add a new state or two to handle the case of the roll jump.

Take a look at the "underwater but not swimming" state and see what changes you can do. What can you do?

I jump to the water, a strange '?' symbol appears.

Yes, that's my object. It works as a ground sensor, and I left it there on purpose smile Uncomment the hide command on the main state to make it go away.

Sorry If I can't do that much, I'm not so good on this API programmign stuff.

And how can I make the swimming sprite loops on the animation?

As for the rolljump I suppose I could do a state named 'rolljump' but what API can I use for that?

Offline

#31 2018-07-29 16:58:10

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,287
Website

Re: Another underwater bug [SOLVED]

SynfigMaster91 wrote:

I'm not so good on this API programmign stuff.

If I was to do this for you, you would become dependent on me, and I don't want that. Please understand it smile

Nobody was good at it when starting out. smile

SynfigMaster91 wrote:

And how can I make the swimming sprite loops on the animation?

Check the .spr file and see if the animation repeats.

Offline

#32 2018-07-29 19:21:35

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Alexandre wrote:
SynfigMaster91 wrote:

I'm not so good on this API programmign stuff.

If I was to do this for you, you would become dependent on me, and I don't want that. Please understand it smile

Nobody was good at it when starting out. smile

SynfigMaster91 wrote:

And how can I make the swimming sprite loops on the animation?

Check the .spr file and see if the animation repeats.

I understand. It's just there are times when something hard or tricky stands in my way and takes my patience  away, forcing me to give up.

Maybe I can find a tutorial on the wiki.

Offline

#33 2018-07-31 13:21:57

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Sigh... That's it, I give up +summoning my white flag and moving it around+ sad

I tried for myself to make Speedy rolling but no matter how many things I tried nothing works. I tried to make a state named rolljump but it didn't work, it showed an error message.

This is it... If I don't get any professional clues so I least can fix it by myself and learn, I throw the towel and give up forever! Why is fate wanting me to fail in this? sad

Offline

#34 2018-07-31 13:32:38

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Okay, so far I managed to make Speedy still rolling when he jumps TO the water. Now I need to make him roll jump until I press the fire1 button so he swims.

Offline

#35 2018-07-31 13:44:32

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Ugh... mad

I messed up! Why can't I do things right for once?

object ".speedy_swim"
{
    requires 0.2.0
    always_active

    state "main"
    {
        observe_player "Speedy"
        hide
        change_state "out of water"
    }
    
    state "out of water"
    {
        on_player_underwater "dive"
    }
    
    state "dive"
    {
        on_player_underwater "rolljump"
    }

    state "swimming"
    {
        // got hit?
        on_player_gethit "getting hit underwater"
        
        //killed?
        on_player_death "destroy"
        
        // landed on the floor?
        attach_to_player 0 32
        if "obstacle_exists(0,0) and player_yspeed() > 0" "underwater but not swimming"

        // play the swimming animation
        springfy_player
        set_player_animation "SD_SPEEDY" 21
        on_button_pressed "fire1" "swim"

        // got off water?
        on_player_underwater "swimming"
        change_state "out of water"
    }

    state "swim"
    {
        set_player_animation "SD_SPEEDY" 22
        set_player_yspeed -90
        change_state "swimming"
    }

    state "underwater but not swimming"
    {
        on_player_jump "swim"
        on_player_underwater "underwater but not swimming"
        change_state "out of water"
    }

    state "getting hit underwater"
    {
        // wait until the getting hit animation stops
        on_player_gethit "getting hit underwater"
        change_state "underwater but not swimming"
    }

    state "destroy"
    {
        destroy
    }
    
    state "rolljump"
    {
        on_button_pressed "fire1" "swimming"
    }
}

I tried to make he roll jumps when he touches the ground until he swam but nothing! Sigh... what's the point of keep trying if I can't without any clues...

Offline

#36 2018-07-31 15:02:14

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

I mean... I want Speedy roll jumps underwater when he's on the floor and press fire1 to swim.

I hate frustration so much...

Offline

#37 2018-07-31 15:29:47

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Okay... Now I'm better.

I finally fixed my problem! big_smile

Here's the code!

object ".speedy_swim"
{
    requires 0.2.0
    always_active

    state "main"
    {
        observe_player "Speedy"
        hide
        change_state "out of water"
    }
    
    state "out of water"
    {
        on_player_underwater "dive"
    }
    
    state "dive"
    {
        on_button_pressed "fire6" "swimming"
    }

    state "swimming"
    {
        // got hit?
        on_player_gethit "getting hit underwater"
        
        //killed?
        on_player_death "destroy"
        
        // landed on the floor?
        attach_to_player 0 32
        if "obstacle_exists(0,0) and player_yspeed() > 0" "underwater but not swimming"

        // play the swimming animation
        springfy_player
        set_player_animation "SD_SPEEDY" 21
        on_button_pressed "fire6" "swim"

        // got off water?
        on_player_underwater "swimming"
        change_state "out of water"
    }

    state "swim"
    {
        set_player_animation "SD_SPEEDY" 22
        set_player_yspeed -90
        change_state "swimming"
    }

    state "underwater but not swimming"
    {
        on_player_jump "dive"
        on_player_underwater "underwater but not swimming"
        change_state "out of water"
    }

    state "getting hit underwater"
    {
        // wait until the getting hit animation stops
        on_player_gethit "getting hit underwater"
        change_state "underwater but not swimming"
    }

    state "destroy"
    {
        destroy
    }

Alex, I thank you for trying to do this with the fire1 button only but it seems to make more problems, so I switched to press fire6 so Speedy swims. This is the better way so it can stop to have problems. Please understand it smile

Also, I'm sorry about my frustration and that giving up stuff. Sometimes I need to get those things out of my chest sad

But we didn't finish yet! I need to make sure the swimming sprite repeats yet! I check if the value is TRUE and it is. I don't get it why it doesn't repeat the animation.

https://drive.google.com/open?id=1EeyBf … Sm93xBcVO6

Offline

#38 2018-07-31 15:57:41

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

I checked the .spr file of Speedy and the loop of the sprite is TRUE but the why it doesn't repeat the swim animation it must be related to the springfy_player function. I took it away and the sprite repeats itself, but it makes Speedy destroying enemies as he swims. There must be another function that makes the character vunerable to enemies. Something like being hit by a bullet or something?

Offline

#39 2018-07-31 20:34:54

svgmovement
Member
Registered: 2011-11-24
Posts: 209

Re: Another underwater bug [SOLVED]

The code you posted for ".speedy_swim"  uses animations 21 and 22. What is the difference between Speedy's
animation 21 and animation 22?


-- svgmovement

Offline

#40 2018-07-31 21:32:33

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

svgmovement wrote:

The code you posted for ".speedy_swim"  uses animations 21 and 22. What is the difference between Speedy's
animation 21 and animation 22?

That was just to test if using another animation, it could repeat itself without stop but it seemed it not worked.

Offline

#41 2018-08-02 19:46:28

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,287
Website

Re: Another underwater bug [SOLVED]

SynfigMaster91 wrote:

I finally fixed my problem! big_smile

yaaaaay, congratulations!!! smile

SynfigMaster91 wrote:

swim animation it must be related to the springfy_player function

If you see how springs work, e.g., when Surge uses a regular spring, you'll see that the player activates the springing animation at the moment of the propulsion and then stops it when starting to fall.

Since springfy_player player is being called all the time, it turns out that the springing animation will be paused when the player falls, but then the command will make the player be 'springfied' again, pausing the animation again.

What to do, then?

One approach would be: while the player is swimming -> hide the player altogether (set it to a pixel) and use a separate object to set the animation. The code below is a modified version of my previous one; adapt as needed:

    state "swimming"
    {
        hide

        // got hit?
        on_player_gethit "getting hit underwater"

        // killed?
        on_player_death "destroy"

        // landed on the floor?
        attach_to_player 0 0
        if "obstacle_exists(0,32) and player_yspeed() > 0" "underwater but not swimming"

        // play the swimming animation
        springfy_player
        set_player_animation SD_PIXEL 0
        set_animation SD_SURGE 2
        look_at_walking_direction
        show
        on_button_pressed "fire1" "swim"

        // got off water?
        on_player_underwater "swimming"
        hide
        change_state "out of water"
    }

Offline

#42 2018-08-03 15:27:15

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

If you see how springs work, e.g., when Surge uses a regular spring, you'll see that the player activates the springing animation at the moment of the propulsion and then stops it when starting to fall.

Since springfy_player player is being called all the time, it turns out that the springing animation will be paused when the player falls, but then the command will make the player be 'springfied' again, pausing the animation again.

What to do, then?

One approach would be: while the player is swimming -> hide the player altogether (set it to a pixel) and use a separate object to set the animation.

You mean creating a object that makes the animation? I know how to make the obj files but what kind of clues can I use for that?

Offline

#43 2018-08-03 18:17:47

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,287
Website

Re: Another underwater bug [SOLVED]

Yes, I do that in my code (above).

Offline

#44 2018-08-03 18:54:21

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Alexandre wrote:

Yes, I do that in my code (above).

In other words, an object inside the Speedy obj file. I think I get it and I must create a child for it.

But how do I activate an object inside of other?

Offline

#45 2018-08-03 21:07:46

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,287
Website

Re: Another underwater bug [SOLVED]

It's already done in my code. State "swimming" is part of ".surge_swim". I only updated the state.

Offline

#46 2018-08-03 21:12:51

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Alexandre wrote:

It's already done in my code. State "swimming" is part of ".surge_swim". I only updated the state.

Well I tested the whole code but I found the ? Symbol with Speedy. Also the sprite it doesn't get animated, not even when pressing fire6.

What could have been wrong?

Offline

#47 2018-08-03 21:16:50

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,287
Website

Re: Another underwater bug [SOLVED]

You must adapt the code and use your keys (fire6, etc) and your sprites (Speedy). Use the code you were using successfully, but adapt my "swimming" state to your case.

I tested mine using Surge and it worked fine. smile

Offline

#48 2018-08-03 21:26:08

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Alexandre wrote:

You must adapt the code and use your keys (fire6, etc) and your sprites (Speedy). Use the code you were using successfully, but adapt my "swimming" state to your case.

I tested mine using Surge and it worked fine. smile

I copied your code and use Speedy sprite. Or perhaps... did I do something wrong?

Offline

#49 2018-08-21 16:22:58

SynfigMaster91
Member
Registered: 2017-10-10
Posts: 144

Re: Another underwater bug [SOLVED]

Ok, so far I managed to make the sprite loops, but however, there's a little new problem, when I press fire6, if you look closely on the video I'm sharing, you can notice the swim sprite position looks like being down before coming to its normal position.

Check it out:
https://drive.google.com/open?id=1NKTfr … iWVDqS2DJ1

Here's the code:

object ".speedy_companion"
{
    requires 0.2.0
    always_active

    state "main"
    {
        create_child ".speedy_spindash_controller"
        create_child ".speedy_nolightwalk_controller"
        create_child ".speedy_swim"
        destroy
    }
}


object ".speedy_spindash_controller"
{
    requires 0.2.0
    always_active

    state "main"
    {
        hide
        observe_player "speedy"
        change_state "stand by"
        weak_player
    }

    state "stand by"
    {
        on_player_duck "duck"
    }

    state "duck"
    {
        let "$p = 0"
        on_button_pressed "fire1" "charge"
        on_player_duck "duck"
        change_state "stand by"
    }

    state "charge"
    {
        set_player_animation "SD_speedy" "6"
        strong_player
        springfy_player // so that the camera won't go down, since the player is ducking
        disable_player_movement
        play_sample "charge"
        let "$p = min($p+2, 8)"
        change_state "hold"
    }

    state "hold"
    {
        //textout menu.small 0 0 $p
        set_player_animation "SD_speedy" "6"
        let "$p -= 0.234 * floor(8*$p) * dt()"

        // check if there's a platform underneath the player
        attach_to_player 0 20
        unless "obstacle_exists(0,0)" "cancel"

        // create cool particles
        let "$_pixelparticle_anim = 1 + random(3)"
        let "$_pixelparticle_xvel = -player_direction() * (120 + random(60))"
        let "$_pixelparticle_yvel = -60 - random(120)"
        create_child .pixelparticle -player_direction()*7 -2
        let "$_pixelparticle_anim = 1 + random(3)"
        let "$_pixelparticle_xvel = -player_direction() * (120 + random(60))"
        let "$_pixelparticle_yvel = -60 - random(120)"
        create_child .pixelparticle -player_direction()*7 -2
        let "$_pixelparticle_anim = 1 + random(3)"
        let "$_pixelparticle_xvel = -player_direction() * (120 + random(60))"
        let "$_pixelparticle_yvel = -60 - random(120)"
        create_child .pixelparticle -player_direction()*7 -2

        // check if the user wants to charge more, or if we can release the player
        on_button_pressed "fire1" "charge"
        on_button_down "down" "hold"
        change_state "release"
    }

    state "cancel"
    {
        enable_player_movement
        weak_player
        change_state "stand by"
    }

    state "release"
    {
        play_sample "release"
        enable_player_movement
        weak_player
        set_player_xspeed "(480 + 30 * floor($p)) * player_direction()"
        roll_player
        change_state "stand by"
    }
}

object ".speedy_nolightwalk_controller" // his lighting sneakers can't shine when in the air
{
    requires 0.2.0
    always_active

    state "main"
    {
        hide
        observe_player "speedy"
        change_state "stand by"
        weak_player
    }

    state "stand by"
    {
        on_player_in_the_air "air"
    }

    state "air"
    {
        on_player_walk "walking in the air"
        on_player_run "running in the air"
        on_player_brake "braking in the air"
        on_player_in_the_air "air"
        change_state "stand by"
    }

    state "walking in the air"
    {
        on_player_spring "stand by"
        on_player_jump "stand by"
        on_player_gethit "stand by"
        on_player_death "stand by"

        set_player_animation "SD_speedy" 18
        on_player_in_the_air "walking in the air"
        change_state "stand by"
    }

    state "running in the air"
    {
        on_player_spring "stand by"
        on_player_jump "stand by"
        on_player_gethit "stand by"
        on_player_death "stand by"

        set_player_animation "SD_speedy" 19
        on_player_in_the_air "running in the air"
        change_state "stand by"
    }

    state "braking in the air"
    {
        on_player_spring "stand by"
        on_player_jump "stand by"
        on_player_gethit "stand by"
        on_player_death "stand by"

        set_player_animation "SD_speedy" 20
        on_player_in_the_air "braking in the air"
        change_state "stand by"
    }
}

object ".speedy_swim"
{
    requires 0.2.0
    always_active

    state "main"
    {
        observe_player "Speedy"
        hide
        change_state "out of water"
    }
    
    state "out of water"
    {
        on_player_underwater "dive"
    }
    
    state "dive"
    {
        on_button_pressed "fire6" "swimming"
    }

    state "swimming"
    {
        hide

        // got hit?
        on_player_gethit "getting hit underwater"

        // killed?
        on_player_death "destroy"

        // landed on the floor?
        attach_to_player 0 0
        if "obstacle_exists(0,32) and player_yspeed() > 0" "underwater but not swimming"

        // play the swimming animation
        springfy_player
        set_player_animation SD_PIXEL 0
        set_animation SD_SPEEDY 21
        look_at_walking_direction
        show
        on_button_pressed "fire6" "swim"

        // got off water?
        on_player_underwater "swimming"
        hide
        change_state "out of water"
    }

    state "swim"
    {
        springfy_player
        set_player_animation "SD_SPEEDY" 21
        set_player_yspeed -90
        change_state "swimming"
    }

    state "underwater but not swimming"
    {
        on_player_jump "dive"
        on_player_underwater "underwater but not swimming"
        change_state "out of water"
    }

    state "getting hit underwater"
    {
        // wait until the getting hit animation stops
        on_player_gethit "getting hit underwater"
        change_state "underwater but not swimming"
    }

    state "destroy"
    {
        destroy
    }

}

Offline

#50 2018-08-21 17:38:14

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,287
Website

Re: Another underwater bug [SOLVED]

SynfigMaster91 wrote:

Ok, so far I managed to make the sprite loops, but however, there's a little new problem, when I press fire6, if you look closely on the video I'm sharing, you can notice the swim sprite position looks like being down before coming to its normal position.

hmmm, it works if I replace Speedy by a Surge sprite. I wonder if it could be a hot spot problem? (see the .spr file, compare with Surge's). Can you share Speedy with us?

In the meantime, try to replace state "swim" by this:

    state "swim"
    {
        springfy_player
        attach_to_player 0 0
        set_player_animation SD_PIXEL 0
        set_player_yspeed -90
        change_state "swimming"
    }

Offline

Board footer

Powered by FluxBB  hosted by tuxfamily.org