Today I am also sending a console game. First look at the figure:
Origin
LZ is a person with serious procrastination. The form of expression is to refresh the blog garden every other time.
Not a few days ago, I saw Master wei "Developing a highly scalable system using Lua scripting language...".
LZ has obsessive-compulsive disorder on things that they don't know. What is Lua, naturally, cannot be ignored.
Some good things. I am idle recently. Do something to train my hands.
As a result, in the blog garden, I turned to such a "console game (for comments)" and recalled my memories of that console game. Click here to view the work of the predecessors.
Hands-on
The overall framework is simple:
Use the C # Game Engine, use lua to develop games, and use LuaInterface to interact with Lua.
Game Engine:
Solve rendering problems (draw points, draw lines, and draw frames on the console)
Respond to the user's keyboard input (the user needs to press the key to control the game)
It is also a host of Lua (Lua is only a language and cannot generate the same host as exe)
Rendering
By exporting the lua function, lua can call the function in C #.
lua.RegisterFunction(m.Name, null, m);
The following functions are implemented:
You can draw points, draw rectangles, draw text, and fill rectangles at the specified position and color on the console.
Response to user input
User input mainly responds to key input. mouse input is not currently supported
keypress((lua==) = lua.GetFunction((func !=
You need to define a "keypress" function in lua. After capturing the user's key input, the function is called back.
Lua
Is to implement the snake, see entry. lua, because in Program. cs, the entry. lua is called as the entry
lua.DoFile("entry.lua");
Focus on the following functions:
function gameInit()
function gameLoop()
GameLoop is a game that regularly refreshes the interface. When the time is reached, C # calls back gameLoop and implements re-drawing and other operations.
Perception
It took about two days to write it. lua is an entry, and the C # console mainly references the implementation of console games.
The main purpose is to learn how to interact with lua in C #. In the future, we can also put the flexibility and flexibility in the lua script.
Download
Code and executable files