6. In the Action Define dialog that appears, set Message to "Release", Function to "DoScript", Object to "begin game", click OK button. We've just defined a action for overlay, let it do a script when mouse released on it.

7. Ok, press F5 to run the scene, you can start walk around by clicking the overlay.

But we want to hide the menu when walking around:

1. Select the "Begin Game" overlay and right-click on it, click "Define Script Variable..." on the context menu.
2. In the Script Variables List dialog, rename the selected variable to "menu_begingame" (click on the name to start edit).
3. Add a line to the codes of "begin game" script:

Code:

menu_begingame.hide(true)

so this code will hide the overlay when run the script.

[section end]

Last edited by Vincent on Wed Jul 18, 2007 10:50 am; edited 1 time in total

3. You should see a small blue cross in Textures Browse Window, select it and right-click, select "Define Script Variable..." on
the popup menu; you should see a variable named "cross_tga" in the Script Variables List dialog that appears.

4. In Awakening's main menu, select View > Edit User Script File... , the User Script File of the scene will appears in Windows Notepad; you can edit it in other program too, the usr file locates with same folder to scene file.

5. Add two lines in OnSize() function:

Code:

wincx=cx
wincy=cy

6. Add below codes in Render2D() function:

Code:

if (IsGameMode()) then
draw.setbkcolor(COLOR_WHITE)
local cp=point.new(wincx/2,wincy/2)
local halfsize=16
local r=rect.new(cp.x-halfsize,cp.y-halfsize,cp.x+halfsize,cp.y+halfsize)
draw.stretchblt(r,cross_tga)
end

run the scene, click Begin Game, a blue cross will appears on the center of window.

local xcenter=wincx/2
local ycenter=wincy/2
local xoffset=x-xcenter
local yoffset=y-ycenter
if (xoffset==0 and yoffset==0) then return end

if (IsGameMode() and not IsPause()) then
local rot=camera.getRotation()
rot.x=rot.x+yoffset*cameraRotateStep*0.1
rot.y=rot.y+xoffset*cameraRotateStep*0.1
if (rot.x>80) then rot.x=80 end
if (rot.x<-80) then rot.x=-80 end
camera.setRotation(rot)

local x=xcenter
local y=ycenter
x,y=wnd.ClientToScreen(GetMainWnd(),x,y)
wnd.SetCursorPos(x,y)
end

III. Hide & Show default arrow cursor
we want to hide the arrow cursor when playing game, also need a method to show the cursor again.

By default, the Winds3D Player have some accelerator keys like Esc, Space, etc; these keys may conflict with your game input setting, so there is a function for disabling accelerator: EnableAccel(). Another problem is the default player movement keys, like F,C,W,S,A,D etc, also may not accord with your wish; so the SetInputStyle() function let you disable/enable all or some of these controls.

1. Disable accelerator keys
New a Script named "_SCENE_BEGIN", and edit it's code as below:

Code:

EnableAccel(false)

Scene Player will do the "_SCENE_BEGIN" script when scene begin.

2. Enable W,S,A,D controls
Add a line to the "begin game" script:

Code:

SetInputStyle( ModifyStyle(GetInputStyle(),0,INPUT_STYLE_WSAD) )

the default movement keys also can be changed int the standalone Winds3D Player (File > Configure Input...), but fixed in web3d player.

[section end]

Last edited by Vincent on Fri Jul 20, 2007 5:19 am; edited 5 times in total

thx

liverol

Joined: 29 Jun 2007

Posts: 45

Posted: Wed Jul 18, 2007 2:14 pm

code in mousemove() function is helpful,wait for next section.

nigec

Joined: 04 Jul 2007

Posts: 212

Posted: Wed Jul 18, 2007 6:05 pm

thanks Vincent, that was really helpful..

Part 3: Shoot

Vincent

Joined: 25 Dec 2006

Posts: 297

Posted: Fri Jul 20, 2007 7:37 am

In this section, we'll simulate gun shooting, bullet flying and colliding in game.

Before the next step, create a new folder (assume named "simplefps" below) in your disk; and save the scene to the folder with name "fps.sce".

I. Temporary Object

Let's consider such sort of objects in game, they appear sometime, and exist just for a period of time, when the life time out, they should disappear; for example, a bullet will appear when shooting, and it should disappear once hit something. So we write a class for this sort of temporary objects - "tempobj" :

In the "simplefps" folder, create a text file with name "tempobj.lua", and edit it's content as below:

Code:

-- temporary object

local function _new(t)

local fLifeTime=5;

local getLifeTime = function() return fLifeTime; end
local setLifeTime = function(lt) fLifeTime=lt; end

local frameMove = function(timed)
fLifeTime=fLifeTime-timed
if (fLifeTime<=0) then
return true;
end
return false;
end
local deleteThis = function()
error('this function must be overloaded!')
end

if (type(t)~='table') then t={} end
t.getLifeTime=getLifeTime
t.setLifeTime=setLifeTime
t.frameMove=frameMove
t.deleteThis=deleteThis

return t
end

-- export ----
tempobj = {
new = _new
}

II. Bullet

The bullet class is derived from tempobj, create a text file and save with name "bullet.lua" in same folder, codes is here:

Code:

require 'tempobj'

local function _new()
local bul=tempobj.new(scene.createMovTar())

bul.setNoBounce(true) -- no bounce
bul.pointed(true) -- is point

bul.deleteThis = function()
scene.deleteMovTar(bul)
end

return bul
end

-- export ----
bullet = {
new = _new
}

we use a pointed movtar as bullet's physics figure, and delete it when bullet die.

III. My Player

We need append functions to the predefined "player" class.

In the "simplefps" folder, create a text file with name "myplayer.lua", and edit it's content as below:

Last edited by Vincent on Sat Jul 21, 2007 3:25 am; edited 1 time in total

Part 4: Shoot continued

Vincent

Joined: 25 Dec 2006

Posts: 297

Posted: Sat Jul 21, 2007 3:12 am

I. Spot

When a bullet hitting a wall, it should produce a spot on the wall.

1. Find the "bspot.tga" in the QinEmperor's textures and copy it to Awakening's textures folder.

2. In the "bullet.lua" , add a line to the beginning of the "_new()" function:

Code:

local nSpotTexture=texturelist.addTexture("\\bspot.tga")

this code load the "bspot.tga" file to scene, and save the texture id to a local variable - nSpotTexture. it's a good practice to declare variables as "local" as possible, keep the global namespace clean!

local blockobj=t.getBlockObject()
if (blockobj) then
if (UD_SURFACE==blockobj.getClassID()) then
-- spot
local spot=scene.buildSpot(blockobj,t.getStop()-blockobj.getLmOrg(),5,COLOR_WHITE,true)
if (spot) then
spot.setTexture(nSpotTexture)
spot.setLifeTime(16)
end

-- add spark codes here --

end
end

bul.setLifeTime(0)
end

The bullet class's hierarchy tree is movtar < tempobj < bullet, the movtar class has a callback function "OnCollide", when a movable target colliding with other objects, it'll call this function to do a notice. So by writing codes in this function, we can do something when a bullet hitting something.

The first line "local t=trace.new(ptrace)" constructs a "trace" instance by passed handle - "ptrace"; then we use the trace instance to get the touched object; if the object is a surface, then build a spot on it.

The last line "bul.setLifeTime(0)" kill the bullet object, so the bullet will disappear.

Now, try to fire in game again, do you find those pretty spots?

II. Spark

When a bullet colliding with hard object it should emit sparks; we use particle system to simulate that.

1. Find the "spark.bmp" in the QinEmperor's textures and copy it to Awakening's textures folder.

2. In the "bullet.lua" , add a line to the beginning of the "_new()" function: