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-12 13:35:35

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

The small questions about scripts and API

I working on a boss and I have small problems.
I created level and I need that player passed througth level and defeated the boss. The boss must be activated when player will approach him.

How I can get or set X/Y coordinates of the boss or other objects?

And how I can block so that the player does not go beyond the boss arena and then unlock and continue the game?

Last edited by G.E.R. (2018-05-29 07:06:37)

Offline

#2 2018-01-12 14:00:04

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

Re: The small questions about scripts and API

Hi G.E.R.,

Please see the following commands: smile

Offline

#3 2018-01-12 14:03:01

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

I'm already studying this article. It's strange that I did not see her before in Wiki. A lot of questions are really solved.
Sorry for the large number of questions.

Offline

#4 2018-01-12 14:07:28

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

Re: The small questions about scripts and API

No problems, feel free to ask smile

Offline

#5 2018-01-14 10:55:46

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

So, I have this situation.
Boss and other objects is placed on the level.

Object BOSS
<....>

Object A
<....>

Object B
<....>

etc.

I need to specify coordinates of objects A and B depending on the position of the object BOSS. BOSS is moving ----> A and B is moving too.
How I can made it? What API-variable should I use?

Last edited by G.E.R. (2018-01-14 10:56:15)

Offline

#6 2018-01-15 12:23:19

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

Re: The small questions about scripts and API

In the API you're using, you can export data from objects using $_shared_variables (they start with a '_'). Eg: $_boss_x, $_boss_y.

See: http://opensnc.sourceforge.net/wiki/ind … ence#Scope

Offline

#7 2018-03-20 10:56:00

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

I working on "Lifting Basket" object. It looks like on object from Lava Reef
0_19cf8d_26a86c54_S.png

Press UP button - basket go up, press DOWN button - basket go down. Basket moves on rails.
How I can determine an end of rails and stopped basket?

I wrote:

on_button_down "UP" "moveup"
<...>
    state "moveup"
    {
on_collision "Lift_Rail_left" "moveup1"
return_to_previous_state
    }

    state "moveup1"
    {
move 0 -200
change_state "waiting"
    }

but basket leaves the railways. Is it possible to determine the end of the rail in advance?
0_19cf8c_bd632e55_orig

And second question. Can I forbid character to look up and squat while the basket is moving?

Offline

#8 2018-03-27 12:37:14

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

Re: The small questions about scripts and API

G.E.R. wrote:

but basket leaves the railways. Is it possible to determine the end of the rail in advance?

Absolutely. If your railways have fixed length, you can calculate the trajectory of the basket before it moves. If not, the logic is more complicated, but still possible (you can try using collision detectors).

G.E.R. wrote:

And second question. Can I forbid character to look up and squat while the basket is moving?

Make an auxiliary object that handles this logic. This auxiliary object can be a child of the basket, and will only be active if the player is on the basket.

Offline

#9 2018-05-25 13:39:50

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

Knuckles has ability to destroy "breakable" brick when he collision with they. Can I realized it on Open Surge engine? How to give a command to destroy brick?

Offline

#10 2018-05-25 13:50:02

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

Re: The small questions about scripts and API

I don't think you can do it directly with the current API. If I recall correctly, in 0.1.4 this behavior was implemented directly into the engine. When Knuckles was dropped, so was this behavior.

One thing you can do for the time being is to turn your breakable brick into an object, and let it be breakable by touch.

Another really neat trick you can use is to use a regular breakable brick, but put a collision detector on it. When the player touches the brick, make it roll for 1 frame. Then stop the rolling. When the player is rolling, the brick is broken, so that might give you the desired behavior.

Offline

#11 2018-05-25 16:54:01

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

In this case, Knuckles will not have this ability. This is not important for the game.
I studied the API Reference and I want fix bugs and finalize my old projects on next weekend days. Also, I thing that I can add a bonus levels and special stage "warp" object on secret places the levels (as in the original SEGA's games), instead Bonus after BPZ-3.
I have a question: if I placed "warp object" on level (Big Ring, for example) with "push_quest ....", when player will exit from the bonus level and returned in level from "default quest", this level will loaded with all objects. Can we compel the game don't load destroyed enemies, taken rings ect?

Offline

#12 2018-05-26 01:17:37

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

Re: The small questions about scripts and API

G.E.R. wrote:

I have a question: if I placed "warp object" on level (Big Ring, for example) with "push_quest ....", when player will exit from the bonus level and returned in level from "default quest", this level will loaded with all objects. Can we compel the game don't load destroyed enemies, taken rings ect?

No, because the scene and its state gets unloaded from the memory.

Offline

#13 2018-05-28 10:12:49

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

How I can give a command to turn player on right/left ?
illust_1_280518.jpg.png

And is it possible to specify a command so that the engine does not respond on press button?

Last edited by G.E.R. (2018-05-28 10:21:17)

Offline

#14 2018-05-28 13:10:25

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

Re: The small questions about scripts and API

Yes, to do that you have to use the input routines from the API. You can simulate buttons or even change the input map.

http://opensnc.sourceforge.net/wiki/ind … User_input

Offline

#15 2018-05-28 23:03:50

Race the Hedgehog
Member
From: Sao Bernardo do Campo, Brazil
Registered: 2010-12-16
Posts: 163
Website

Re: The small questions about scripts and API

Kinda off-topic but I would find it super useful if we could have a megathread for "questions and answers" and/or "ideas and suggestions" for modding.

Sometimes I find myself in a situation where I have a certain small doubt, just like G.E.R. had it here, but I don't feel like it's such a big problem as to create a new topic, so having a big one just for that would be great.


PunBB bbcode test
Creating and Editing Sprites.

Offline

#16 2018-06-01 08:36:56

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

Alexandre wrote:

No, because the scene and its state gets unloaded from the memory.

I found a solution for this situation. Because bonus is a small room, we can place it room on the level somewhere on bottom or on right and create a script with teleportation, changing music ect. In this way, the player moves from the level to the bonus room, playing the bonus and returning on the level without unloade level. One problem - abysses will cease to work and it will need to place a technical object with "kill_player" scenario.

Offline

#17 2018-06-01 13:27:56

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

Re: The small questions about scripts and API

Nice smile I love the creativity of modders.

A suggestion: place the bonus on the top instead, because then you won't have camera problems when reaching an abyss. Translate your level a few pixels to the bottom if you can (use a text editor)

Offline

#18 2018-06-14 16:40:55

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

How I can to determine which way looks the observed character?

Offline

#19 2018-06-14 18:21:33

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

Re: The small questions about scripts and API

G.E.R. wrote:

How I can to determine which way looks the observed character?

http://opensnc.sourceforge.net/wiki/ind … _functions
http://opensnc.sourceforge.net/wiki/ind … _at_player

Offline

#20 2018-06-19 10:13:45

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

I know about this command, but I don't have idea how how to apply them to player (not object). I found a non-standard output as realise scene "flying Tails + carrynd Sonic" without bugs. You see as Tails carries him friend:
illust_2_190618.jpg.png

but actually, he carry a child object with Sonic's animation, but not the character. At the same time, game set new animation for Sonic (the character) as magenta rectange (the empty frame). Sonic position = Tails position, but Sonic is hided. When "fake Sonic" collision with the floor, this children object destroyed and Sonic get normal animation.

I'll post this script with comments after several tests.

Offline

#21 2018-06-27 09:00:19

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

I ask you to help me with creation enemy:

It's a red ball with a rotated gems:
illust_1_270618.jpg.png

object "Badnik_TetraGem"
<...>
        set_animation SD_TETRA 0
        create_child ".tetragem1" 0 0

        change_state "enemy"
    }
    state "enemy"

<...>

object ".tetragem1"
{
    state "main"
    {
        set_animation SD_TETRA 1
        elliptical_trajectory 26 26 0.25 0.25
.......

It need to create 4 gems on 4 sides of the red ball and rotate it. How to set the starting position of the gems?

Offline

#22 2018-06-27 13:48:16

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

Re: The small questions about scripts and API

G.E.R. wrote:

It need to create 4 gems on 4 sides of the red ball and rotate it. How to set the starting position of the gems?

This is really easy to do in SurgeScript.

In the old API, you can use elliptical_trajectory and set the initialphase to 0, 90, 180 and 270.
http://opensnc.sourceforge.net/wiki/ind … trajectory

Offline

#23 2018-06-27 18:21:15

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

Should I set as -
elliptical_trajectory 26 26 0.25 0.25 0
elliptical_trajectory 26 26 0.25 0.25 90
elliptical_trajectory 26 26 0.25 0.25 180
elliptical_trajectory 26 26 0.25 0.25 270
or differently?

Offline

#24 2018-06-27 21:13:40

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

Re: The small questions about scripts and API

Each gem has a initialphase. For gem i = 0, 1, 2, 3, set

initialphase_x = initialphase_y = 90 * i

For example: for gem 0, set elliptical_trajectory 26 26 0.25 0.25 0 0.

Offline

#25 2018-08-13 11:40:57

G.E.R.
Member
From: Russia, Krasnodar
Registered: 2017-12-26
Posts: 177

Re: The small questions about scripts and API

Alexandre
I have a request to you, can you compile this source code of the project and give me the output .exe file?
https://yadi.sk/d/oihf9QO53aBR8z

Offline

Board footer

Powered by FluxBB  hosted by tuxfamily.org