Advertisement

2d platformer "coding game"

Started by May 20, 2023 11:26 AM
4 comments, last by Iamac4 1 year, 6 months ago

I plan to create a 2d platformer coding game that has a code editor in which the user interacts to make the character move. My question is how to create another object in which I am able to design a "code editor" like, inside my current scene. I am not sure if that's the right thing I should call, anyway I recently learn Unity game engine.

what I've planning to do is like this:

https://www.dropbox.com/s/sz80cbinm3m5axz/Sample_of_GameDesign1.png?dl=0

None

You could use a standard Unity UI textbox to start with. Later on you would probably want to roll something custom so that you can have syntax highlighting and whatnot.

Evaluating the code is going to be the more difficult part. You could embed Lua for this, there are C# bindings for its C API and it's very portable so it shouldn't be too hard to use in a Unity game.

Advertisement

Please keep in mind that Lua is a full programming language, and capable of doing anything that the user is allowed to do, such as opening files, deleting files, sending data to a external server, etc. Please be aware of the security risks if you give the game to others.

Not necessarily. You can create a Lua state without the standard library or with only parts of the standard library (like maths) and leave out the parts like IO that might he harmful. Lua tends to be pretty customisable as far as scripting languages go.

Okay, I am working on it rn the objective is the user must write or input things on the text field when if its true the movement function is invoked, the scenario seems like that. Just wanna make sure that everything goes on the button click when the input field value was true then it points to the "movement class" which contains the movement functions.

Example 2:

https://www.dropbox.com/s/6kuufabv7xcnidk/Design_phase1.1.PNG?dl=0

player movement class:

public class movementFunct1 : MonoBehaviour
{
    public float speed = 5f;
    private float direction = 0f;
    private Rigidbody2D player;
    // Start is called before the first frame update
    void Start()
    {
        player = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        direction = Input.GetAxis("Horizontal");
        if(direction >0f){
            player.velocity = new Vector2(direction * speed, player.velocity.y);
        }
        else if(direction < 0f){
            player.velocity = new Vector2(direction * speed, player.velocity.y);
        }
        else{
            player.velocity = new Vector2(0, player.velocity.y);
        }
    }
}

None

This topic is closed to new replies.

Advertisement