00001 -- game interface: main game script loop 00002 -- author: Li,Xizhi 00003 -- date: 2005-4-9 00004 -- description: this script (gameinterface.lua) is activated every 0.5 sec by AI simulator. 00005 -- it uses a finite state machine.State nil is the inital game state. state 0 is idle. 00006 00007 00008 --main_state=nil; -- this is for us programmers 00009 --main_state="kids"; -- this is for kids UI 00010 NPL.load("(gl)script/mainstate.lua"); -- this file can change the main loop or set the main_state value 00011 NPL.load("(gl)script/lang/lang.lua"); -- localization init 00012 00013 --ParaScene.SetGlobalWater(true, 86); 00014 --ParaUI.SetCursorFromFile(":IDR_DEFAULT_CURSOR"); 00015 00016 local function activate() 00017 if(main_state==0) then 00018 -- this is the main game loop 00019 elseif(main_state==nil) then 00020 -- global assets and init scene loading 00021 ParaAsset.OpenArchive ("xmodels/ParaWorldDemo.zip"); -- open mpg archive 00022 ParaAsset.OpenArchive ("xmodels/character.zip"); 00023 -- ParaAsset.LoadSound ("click", "sound/PopupInfo.wav", true); 00024 00025 -- the global terrain is now created in each scene load file. 00026 -- please see the CreateWorld function in loadscene2.lua 00027 00028 -- reset global terrain,sky, fog 00029 ParaScene.CreateSkyBox ("MySkyBox", ParaAsset.LoadStaticMesh ("", "model/Skybox/skybox3/skybox3.x"), 160,160,160, 0); 00030 ParaScene.SetFog(true, "0.7 0.7 1.0", 40.0, 120.0, 0.7); 00031 --ParaScene.SetFog(true, "1.0 1.0 1.0", 10.0, 50.0, 1.0); 00032 00033 -- activate the game start up menu. 00034 NPL.load("script/commonDialog.lua", false); 00035 NPL.activate("(gl)script/pol_intro.lua", "INTRO_state=\"show\";"); 00036 main_state=0; 00037 00038 -- Change Mouse Texture, now updated 00039 --ParaAsset.LoadTexture("__cursor","cursor.png",1); 00040 --ParaUI.SetCursorTexture("__cursor","255 255 255", 255); 00041 --ParaUI.SetCursorFromFile("cursor.tga"); 00042 00043 elseif(main_state=="demo_release") then 00044 -- for demo release. it uses a different game loop script. 00045 NPL.activate("(gl)script/demo4zju/main.lua", ""); 00046 main_state=0; 00047 elseif(main_state=="kids") then 00048 -- for kids UI 00049 NPL.activate("(gl)script/kids/main.lua", ""); 00050 main_state=0; 00051 00052 elseif(main_state=="3DMapSystem") then 00053 -- for 3D map system 00054 NPL.activate("(gl)script/kids/3DMapSystem_main.lua", ""); 00055 00056 elseif(main_state=="testproject") then 00057 -- for kids UI 00058 NPL.activate("(gl)script/test_project.lua", ""); 00059 main_state=0; 00060 elseif(main_state=="andy_test") then 00061 -- for kids UI 00062 NPL.activate("(gl)script/andy_test.lua", ""); 00063 main_state=0; 00064 elseif(main_state=="lwltest") then 00065 -- for test UI 00066 NPL.activate("(gl)script/lwltest.lua", ""); 00067 00068 main_state=0; 00069 end 00070 end 00071 NPL.this(activate); 00072 00073 -- ParaWorld will call this function, when the user press "`" key 00074 function ShowConsole() 00075 -- create the command line console window 00076 ParaUI.Destroy ("ConsoleWnd"); 00077 00078 end 00079 00080 -- command list: 00081 -- "camera": bring player to current camera location 00082 -- "debug": show object bounding box, report and turn off shadow. 00083 -- "demo": hide bounding box, report and turn on shadow. 00084 -- "play": hide bounding box, report and turn off shadow. 00085 function ProcessKeyStrokes() 00086 if(sensor_name == "ConsoleWnd") then 00087 if(lineinput == nil) then 00088 lineinput = ""; 00089 end 00090 00091 if (keystring == "`") then 00092 -- close the console window 00093 ParaUI.Destroy ("ConsoleWnd"); 00094 else 00095 if (keystring == "\r") then 00096 -- process the command, and clear the line 00097 if (lineinput == "camera") then 00098 local player = ParaScene.GetObject("<player>"); 00099 local x,y,z; 00100 x,y,z = ParaCamera.GetPosition(); 00101 -- create a static physics mesh 00102 player:SetPosition(x, y, z); 00103 elseif (lineinput == "debug") then 00104 ParaScene.Execute("show OBB"); 00105 ParaScene.Execute("show report"); 00106 ParaScene.SetShadow(0); 00107 elseif (lineinput == "demo") then 00108 ParaScene.Execute("hide OBB"); 00109 ParaScene.Execute("hide report"); 00110 ParaScene.SetShadow(1); 00111 elseif (lineinput == "play") then 00112 ParaScene.Execute("hide OBB"); 00113 ParaScene.Execute("hide report"); 00114 ParaScene.SetShadow(0); 00115 end 00116 lineinput = ""; 00117 elseif(keystring == "\b") then 00118 -- delete the previous character 00119 local len = string.len(lineinput); 00120 if(len>0) then 00121 lineinput = string.sub(lineinput, 1, len-1); 00122 end 00123 elseif(keystring ~= nil) then 00124 -- append the letters to the line input 00125 lineinput = string.format("%s%s", lineinput, keystring); 00126 end 00127 -- display the line input 00128 local ConsoleWnd = ParaUI.GetUIObject("ConsoleWnd"); 00129 if(ConsoleWnd:IsValid() == true ) then 00130 ConsoleWnd:SetText(lineinput, "255 255 255", ""); 00131 end 00132 end 00133 sensor_name = nil; 00134 end 00135 end