Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

NichuNaizam/N-Sharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

N-Sharp - A fully custom scripting language written in C++

N-Sharp, a fully custom interpreted and dynamically typed scripting language with OpenGL backend written in C++ mainly focused on Game development ease without Game Engines

Syntax

Including another N-Sharp file

using NS.Graphics
using NS.Vec2
using NS.Physics
using NS.Input
// ect
// using path.to.file.nsfile

Declaring a variable

// int
var variableName = 123

// float
var variableName = 123.0

// string
var variableName = "Hello"

// bool
var variableName = true

Declaring a function

function add(num1, num2)
{
    var sum = num1 + num2
    return sum
}

Functions

System

NS.System.PrintLine(arguments...)
Returns NULL
Print something to stdout
NS.System.Print(arguments...)
Returns NULL
Print something to stdout without newline
NS.System.ReadLine()
Returns string
Reads a full line from stdin
NS.System.SetTextColor(colorName)
Returns NULL
Sets the text color to the colorName
NS.System.GetTime()
Returns float
Returns the uptime of the script in milliseconds

Graphics

DO THIS FIRST
using NS.Graphics
Includes the N-Sharp Graphics class

Graphics.Init(width, height, title)
Returns NULL
Initializes the OpenGL context and creates a window
Graphics.WindowShouldClose()
Returns bool
Checks if the window should exit and returns it
Graphics.Begin()
Returns NULL
Prepares the graphics engine for rendering
Graphics.Clear(r, g, b)
Returns NULL
Clears the screen with the rgb color given as parameter
Graphics.End()
returns NULL
Draws the final picture onto the window

Input

DO THIS FIRST
using NS.Input
Includes the N-Sharp Input class

Input.IsKeyDown(keyname)
Returns bool
Returns true if the key is being held down

Input.IsKeyPressed(keyname)
Returns bool
Return true during the frame the key was pressed

Input.IsMouseButtonDown(buttoncode)
Returns bool
Returns true when the mouse button is being held down

Input.GetMousePosition()
Returns vec2
Returns the mouse position as Vector2

Input.GetMouseScroll()
Returns vec2
Returns the mouse scroll as Vector2

Vector2

DO THIS FIRST
using NS.Vec2
Includes the N-Sharp Vec2 class

Vec2.Create(x, y)
Returns vec2
Creates a new Vector2 with the given x and y

Vec2.GetX(vec2)
Returns float
Returns the current x value of the given vector

Vec2.GetY(vec2)
Returns float
Returns the current y value of the given vector

Vec2.Compare(vec1, vec2)
Returns bool
Compares two of the given vectors and returns true if it contains the same value

Vec2.Add(vec1, vec2)
Returns vec2
Returns the sum of vec1 and vec2

Physics

DO THIS FIRST
using NS.Physics
Includes the N-Sharp Physics class

Physics.DoesCollide(position1, scale1, position2, scale2)
Returns bool
Checks for collision between the two rects

Sample Programs

Sample Console Program

// Declaring variables
var name = ""
var color = ""

// Reading data
NS.System.PrintLine("Please enter your name: ")
name = NS.System.ReadLine()
NS.System.PrintLine("Please enter your favorite color: ")
color = NS.System.ReadLine()

// Setting text color
NS.System.SetTextColor(color)

// Printing out name
NS.System.PrintLine(name, ", Welcome to N-Sharp.")

Sample Window Program

// Including the N-Sharp Graphics class
using NS.Graphics

// Declaring variables
var windowWidth = 800
var windowHeight = 600
var windowTitle = "Test"

// Main function
function main()
{
	// Initializing the OpenGL Context and creating a window
	Graphics.Init(windowWidth, windowHeight, windowTitle)

	// Game Loop until window closes
	while (!Graphics.WindowShouldClose())
	{
		// Preparing the graphics engine for rendering
		Graphics.Begin()
		// Clearing the screen with white color
		Graphics.Clear(1, 1, 1)
		
		// Telling the graphics engine that we have done our drawing
		Graphics.End()
	}
}

// Calling the main function
main()