Console game engine CGE-snake

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.