GithubHelp home page GithubHelp logo

joseph-early / blueprint-platformer Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 53.06 MB

Exploration game where you explore levels however objects in the world are incomplete and you must script them using Lua to solve puzzles and advance.

License: MIT License

C# 92.24% ShaderLab 6.61% HLSL 1.15%
game learn-to-code moonsharp unity 2d 2d-game csharp lua platformer platformer-game puzzle puzzle-game

blueprint-platformer's Introduction

Blueprint Platformer

Exploration game where you explore levels however objects in the world are incomplete and you must script them using Lua to solve puzzles and advance.

Sections

Game systems - Basic Overview

  • 2D, side-scroller player controller
    • Move left and right
    • Health
  • Dialogue manager
    • Invokes scripted scene with begin, continue and update methods
  • Lua Manager
  • Audio manager

Third-party Libraries

This game uses the following libraries:

API Documentation

NOTE: The API is subject to change during development!

Adding new functions which can be invoked by Lua

Inside the Scripts/Lua.Modules, create a module file using this template:

using UnityEngine;

namespace Lua.Modules
{
    public class ModuleName : MonoBehaviour
    {
    }
}

To create an example method, you must provide a return type (optionally with parameters) e.g. (ensure that the method is static and public):
Note: There is a way to bypass giving a return type if you use a parameter (see Lua.Modules.Miscellaneous and Print however this is not recommended)

// Example method 
public static int ExampleMethod(string message)
{
    UnityEngine.Debug.Log(message);

    return 0; // 0 - Success
}

To expose the method so it can be used in Lua, there are two more steps. Inside Lua.LuaManager, there is a region called "Expose". In there, create either a Func or Action with a reference to the functions in your module e.g.

// Miscellaneous
script.Globals["ExampleMethod"] = (Func<string, int>)ModuleName.ExampleMethod;

Finally, it is required to add a toggle to the method inside of Lua.LuaControllable if the method requires the use of either Utils.ReturnLuaObject or LuaControllable.CheckOperationLegality. To do this, go inside Lua.LuaControllable and then inside the region " Serialize fields for enabling allowed functions on an object". Then create a boolean value (private and SerializeField) with the exact name of the function created (requiring your function be named uniquely among all exposed methods) e.g.

[SerializeField] private bool ExampleMethod = false;

To use the method LuaControllable.CheckOperationLegality, you must also use Utils.ReturnLuaObject as LuaControllable.CheckOperationLegality requires a reference to that game object and its LuaController.

First the method created requires a string parameter (first parameter is the standard) such as this: public static int SetPositionRelative(string controllerName, float x, float y)

Secondary, a reference to the game object wanted can be obtained using "Utils.ReturnLuaObject" (requiring all game objects to have a unique name set in their Lua.LuaControllable serialized field)

And finally, it is possible to check if a command is allowed on that object using LuaControllable.CheckOperationLegality. This method should be called with the value System.Reflection.MethodBase.GetCurrentMethod().Name.

And example of all of this from one of basic modules:

// String name used in Lua
public static int SetPositionRelative(string controllerName, float x, float y)
{
    // Get a reference to the controller
    var controller = Utils.ReturnLuaObject(controllerName);

    // Check the controller is not null
    // System.Reflection.MethodBase.GetCurrentMethod().Name is required to be passed
    if (controller.controller != null)
    {
        // Check the operation is allowed
        switch (controller.controller.CheckOperationLegality(System.Reflection.MethodBase.GetCurrentMethod().Name))
        {
            case false:
                return 2; // 2 - Illegal operation
            case null:
                return 3; // 3 - Unknown operation
        }

        // Any code here

        return 0; // 0 - Command success
    }

    return 1; // 1 - Command failed
}

blueprint-platformer's People

Contributors

azfoxxo avatar joseph-early avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.