Jump to content

Posted by GlshchnkLx, in gamedev 14 June 2016 · 527 views

Hello everybody. Today I probably will start the first lesson dedicated to developing games with LeadWerks Game Engine 4.1.

Table of contents:
  • Introduction
  • Requirements
  • Project preparation
  • Setting up the project
  • Level creation (Prototype)
  • Ball Script

This lesson is to create a game where the main character is a ball (or other primitive). By the way, there is such a lesson ( "Marble Game") in the official documentation.


Before we begin, I would say the main requirements for the correct execution of the lesson:
  • You must dial the code themselves. This will allow you to understand the basic design principles.
  • Carefully read the text of the lesson and follow all the steps. It is very important.
  • Treat with understanding the author. I am a simple man, and I can make mistakes.
Well. Now you can start a lesson.

Project preparation

Start LeadWerks 4.1 and open the "Project Manager" (how?)


For the tutorial, I'll use an empty project ( "Blank Project"). The name you can choose any, I chose "BallGame".


After the final creation, we make some modifications to the workspace. We need to add some starter content. For the tutorial, I'll take it from a template "Advanced First-Person Shooter". We need a folder with materials.

Open this folder ({Steam Folder}/steamapps/common/Leadwerks/Templates/Advanced First-Person Shooter/) (If you change the directory LW then open it)

And copy the folder "Materials" folder in your workspace.

Well done if you have completed all the stages of preparation. It remains only to make a game )))

Setting up the project

Open your workspace (project) in LW.


Now we'll do a few simple actions to configure our project. We will make a simple splash screen and other simple decorations.

Open the file "Main.lua" ( "Scripts / Main.lua") in the script editor (how?)


Now we have to modify the "Main.lua". I will not talk about work with Lua principles in LW (You can read about this in the Tutorial). I'll just write code and specify where to insert it (I'll refer to a reading material about this)

All functions that are available to us, you can find in the API.

To implement a simple splash screen, we need the following themes: A lot of material had accumulated. But not everything is so terrible.

Will definitely start writing screen)

Go to the 20th line of the code. It is especially this place? It's simple. All code up to this initialisere LW, and already runs code after the first level and run all in normal mode.

Now I will write all of the code that you have to understand yourself to write, and later I will comment on it.

--simple splash screen (only example)
tempFont = context:GetFont() --Current Font/ We save for restore after display
local font = Font:Load("Fonts/Arial.ttf",36) --Font for display

local X = window:GetWidth() * 0.45 --the definition of the center of Width
local Y = window:GetHeight() *0.5 --the definition of the center of Height(
local A = 0 --Alpha
local AStep = 0.005 --increment step
local TimeScreen = 2.5 --Time in sec for display
TimeScreen = TimeScreen * 1000
context:SetColor(1,1,1,0) --Start Color
while window:KeyDown(Key.Space)==false do --Space for skip
context:DrawText(title .." with Leadwerks",X,Y) --Text
Time:Delay(TimeScreen / (1 / AStep))
A = A + AStep
context:Sync(false) --Out on the screen

if (A >= 1) then


The result is bad. But this is only a simple example. At desire it is possible to complicate the code and will be all good)


Now let's do the automatic detection of screen resolution (run full screen)

Go to line 10. There will be a similar piece of code


The values of the parameters screenwidth and screenheight define the starting desktop resolution. We can ask the system to know the current desktop resolution.

insert before line 10 the following code:

screen = System:GetGraphicsMode(System:CountGraphicsModes()-1)
screenwidth = screen.x
screenheight = screen.y

Now modify the line


in the following line


And 9 line write "System:GetProperty("fullscreen",1)" instead of "System:GetProperty("fullscreen")"


I know that experienced developers will tell you what to do, but we're just learning. In normal projects you can't do that)

How much we have done. But even more lies ahead.

Level creation (Prototype)

In this part of the lesson, I'm not going to tell you anything. A lot of articles on this subject is on the Internet. I'll give a couple of links and it will show a prototype)

The appropriate lessons LeadWerks you can find here

To build a level, I will use primitives. Character is a ball, the levels are composed of platforms.

Here's what I got (Show me what you have left)


Are you pleased with the result? If not, then understand that you do not like your level and correct.

Level ready. Make the character (ball)

Ball Script

Read the tutorial

Now you have an idea how to do it. And I'll show you my implementation.

Create a script of the player (Similar to that of a tutorial) ("Scripts/Player/BallPlayer.lua")


It will be the main file for us. Through him we will make the control of the character/ camera / other.

I will do as always. Write all the code and tell you how it works. So I'll give links to topics which will include (But will not give references to the functions themselves. You have to find yourself)

--Script Settings
Script.Mass = 10 --int (MassPlayer)
Script.Speed = 25.0 --float (Speed Mul)
Script.EnergyToJump = 1500.0 --float (It is for jump)
function Script:Start()
self.Force = self.Mass * self.Speed --Created Force Multiple
self.Direction = Vec3(0,0,0) --Helpfull (Determines where we are going)
self.entity:SetMass(self.Mass) --Created Mass
self.camera = Camera:Create()
self.camera:SetRotation(45, 0, 0)
self.camera:Move(0,0, -4)
self.light = PointLight:Create()
--For Jump
self.ETJ = self.EnergyToJump
function Script:UpdateWorld()
--The cursor displacement (rotation camera)
self.offsetx = window:GetMousePosition().x - window:GetWidth()/2
self.offsety = window:GetMousePosition().y - window:GetHeight()/2
--Camera Rotation with offset
self.camera:SetRotation(self.offsety/10 + self.camera:GetRotation().x, self.offsetx/10 + self.camera:GetRotation().y, 0, false)
--Generate points for a jump
if self.ETJ < self.EnergyToJump then
self.ETJ = self.ETJ + self.EnergyToJump * 0.005
self.camera:Move(0,0, window:GetMousePosition().z - 4)
--Direction for move
self.Direction.x = -Math:Sin(self.camera:GetRotation(true).y)
self.Direction.z = Math:Cos(self.camera:GetRotation(true).y)
if window:KeyDown(Key.W) then self.entity:AddForce(self.Direction * self.Force,true) end
if window:KeyDown(Key.A) then self.entity:AddForce(Vec3(self.Direction.z, 0, self.Direction.x) * self.Force * -1 ,true) end
if window:KeyDown(Key.D) then self.entity:AddForce(Vec3(self.Direction.z, 0, self.Direction.x) * self.Force,true) end
if window:KeyDown(Key.S) then self.entity:AddForce(self.Direction * self.Force * -1 ,true) end
if (self.ETJ - 100) > 0 then
if window:KeyDown(Key.Space) then
self.ETJ = self.ETJ - 100
self.entity:AddForce(Vec3(0, self.Mass, 0) * self.Force * 0.7 ,true)
window:SetMousePosition(window:GetWidth()/2, window:GetHeight()/2, 0)

function Script:PostRender(context)
context:DrawText("Energy to jump" .. self.ETJ,2,2)

Apply this script to the ball physics and play.

The lesson was over. You made a simple game. Now you can finish the leveling/ points/ achievements to sell on Steam.

Here are screenshots of my result:


I hope you will find useful this tutorial. In the future, I can tell you other things)

Thank you.  Now, I haven't yet looked at the tutorial but I think any effort to build teaching materials should be applauded.
Then I'll write more (as return for their workplace)

March 2017

2627282930 31  

Recent Entries

Recent Comments

Search My Blog