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

#1 2018-01-11 21:44:55

SGWaS
Member
Registered: 2017-08-29
Posts: 95

Make projectiles hurt objects?

Hi,

Alongside the classic Sonic 2D platforming style in my new project is going to be other characters from various Sega franchises, like Panzer Dragoon and NiGHTS. Right now I'm programming the blue dragon from Panzer into the game (with sprites ripped from Panzer Dragoon Mini on the Game Gear); I've created the companion object, as well as other objects that control the flight (thanks to CarlosTheHedgehog) and the dragon's projectile, a laser.

Is there a way that I could make the laser "invincible" where it would harm any object that collides with it? Can I also make the player vulnerable to any attack as well, even while jumping (I need this to make the dragon get hurt by enemies after flying off)?

Thanks!

Last edited by SGWaS (2018-01-11 22:29:14)


-SGWaS

Offline

#2 2018-01-12 13:55:22

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

Re: Make projectiles hurt objects?

Hi SGWaS,

Cool! smile

SGWaS wrote:

Is there a way that I could make the laser "invincible" where it would harm any object that collides with it?

You'll have to write a script, so your objects will be "harmable".

SGWaS wrote:

Can I also make the player vulnerable to any attack as well, even while jumping (I need this to make the dragon get hurt by enemies after flying off)?

I think KZR made something like that in Shinobi Densetsu; you might want to ask him.

Stop relying on the "enemy" decorator and write your own behaviors.
http://opensnc.sourceforge.net/wiki/ind … hit_player

Offline

#3 2018-01-13 22:47:25

SGWaS
Member
Registered: 2017-08-29
Posts: 95

Re: Make projectiles hurt objects?

Thanks for the help, the dragon and its projectiles work perfectly now. Here's some of the code:

object ".panzer_laser_controller"
{
    always_active
    
    state "main"
    {
        hide
        attach_to_player
        set_animation "SD_LASER" 0
        simulate_button_up "down"
        on_button_pressed "fire6" "shoot"
    }
    
    state "shoot"
    {
        show
        move 500 0
        simulate_button_up "down"
        on_collision "mecharobotnik2" "destroy"
        on_collision "Chomper" "destroy2"
        on_collision "3" "destroy3"
        on_collision "Flying Fish" "destroy4
        on_collision "Quadorb" "destroy5"
        on_collision "Peixudo" "destroy6"
        on_collision "1" "destroy7"
        on_collision "7" "destroy8"
        on_collision "0" "destroy9"
        on_timeout 0.7 "revert"
    }
    
    state "revert"
    {
        simulate_button_up "down"
        change_state "main"
    }
    
    state "destroy"
    {
        simulate_button_up "down"
        change_closest_object_state "mecharobotnik2" "get_hurt"
        create_child ".panzer_laser_controller"
        destroy
    }
    
    state "destroy2"
    {
        simulate_button_up "down"
        change_closest_object_state "Chomper" "destroy2"
        create_child ".panzer_laser_controller"
        destroy
    }
    
    state "destroy3"
    {
        simulate_button_up "down"
        change_closest_object_state "3" "destroy"
        create_child ".panzer_laser_controller"
        destroy
    }
    
        etc, etc...
}

Basically, the object is attached to the player with attach_player; hide is there because the laser sprite is almost as big as the player sprite, so it is only shown when firing off in the "shoot" state. Firing the laser is mapped to the A key, and the dragon's flight is mapped to the S key.

simulate_button_up is used to prevent the player from rolling, as well as jumping, then flying and being able to kill any enemy by just touching them. This also means that the dragon has to take off when in the air, i.e., falling off a ledge, which a dialog box at the beginning will explain.

Also in the "shoot" state are lots of lines that start with on_collision; since the laser can't damage enemies with the enemy command, I've modified every enemy object that appears in the level to have a series of states that mimic the enemy command; these states are only triggered when the laser comes in contact with the object, and thanks to the on_collision command in the "shoot" state and the change_closest_object_state command in one of the "destroy" states, it changes the state of the object it collides with to the states that mimic the enemy command.

object "0"
{
    requires 0.1.4

    state "main"
    {
        // basic enemy properties
        set_animation "SD_JOAN" 0
        enemy 100

        // movement programming
        gravity
        walk 100.0
        look_at_walking_direction
    }
    
    state "destroy"
    {
        play_sample "samples/destroypop.wav"
        change_state "destroy2"
    }
    
    state "destroy2"
    {
        set_animation "SD_EXPLOSION" 0
        on_timeout 0.5 "destroy3"
    }
    
    state "destroy3"
    {
        add_to_score 100
        destroy
    }
}

When the laser does come in contact with the enemy, it changes the state to either the ones that mimic the enemy command, or for enemies with a health meter, changes the state to the one that decreases the health meter. The laser object, when in contact with these enemies, also creates a new laser controller object, then destroys itself. This allows the player to go ballistic on enemies and bosses with a health bar. tongue

However, using this method means I'd have to create a new state in the laser controller for every enemy that appears in the Panzer levels, and I'd have to add new states to such enemies in the levels. Thanks for the help, as always!


-SGWaS

Offline

#4 2018-01-16 00:27:42

KZR
Member
Registered: 2010-07-14
Posts: 1,447
Website

Re: Make projectiles hurt objects?

I see you have sorted it out on your own. I have been away from Surge since it is indeed a great engine from which I learned a lot of game design and development tricks, but it is not naturally fit for my project.
If memory serves me, to make the player vulnerable during a jump you can use either on_player_in_the_air and weak_player together, or set jump to 0 in the chr file and use an object to do on_button_down followed by set_player_yspeed


SD_sml.pngSeD_sml.pngLTot_W_sml.png
https://discord.gg/w8JqM7m ---> Open Surge's Discord server

Offline

#5 2018-01-20 23:55:46

SGWaS
Member
Registered: 2017-08-29
Posts: 95

Re: Make projectiles hurt objects?

KZR wrote:

I see you have sorted it out on your own. I have been away from Surge since it is indeed a great engine from which I learned a lot of game design and development tricks, but it is not naturally fit for my project.
If memory serves me, to make the player vulnerable during a jump you can use either on_player_in_the_air and weak_player together, or set jump to 0 in the chr file and use an object to do on_button_down followed by set_player_yspeed

weak_player is the default setting for the player's strength, so using it to make the player vulnerable wouldn't work, since it would have to jump to start flying. Setting jump to 0 might help for creating the NiGHTS character though. Thanks for the help!


-SGWaS

Offline

#6 2018-01-21 18:42:24

KZR
Member
Registered: 2010-07-14
Posts: 1,447
Website

Re: Make projectiles hurt objects?

then use hurt_player somewhere along the collision code?


SD_sml.pngSeD_sml.pngLTot_W_sml.png
https://discord.gg/w8JqM7m ---> Open Surge's Discord server

Offline

#7 2018-01-29 03:19:05

SGWaS
Member
Registered: 2017-08-29
Posts: 95

Re: Make projectiles hurt objects?

KZR wrote:

then use hurt_player somewhere along the collision code?

Yes, that's somewhat how I'm doing it. on_collision requires the name of the object the character's colliding with, which is why there's separate states for each enemy in the level.


-SGWaS

Offline

Board footer

Powered by FluxBB  hosted by tuxfamily.org