From 016a4fb6aad86ca3db0d5b315f24be6bc5579bb6 Mon Sep 17 00:00:00 2001 From: "p.kosyh" Date: Sat, 13 Mar 2010 12:03:45 +0000 Subject: [PATCH] doc update --- doc/writing_games-en.txt | 84 +++++++++++++++++++++++++++++++++++++--- doc/writing_games.txt | 78 +++++++++++++++++++++++++++++++++++-- 2 files changed, 153 insertions(+), 9 deletions(-) diff --git a/doc/writing_games-en.txt b/doc/writing_games-en.txt index f7f2294..3314078 100644 --- a/doc/writing_games-en.txt +++ b/doc/writing_games-en.txt @@ -198,7 +198,7 @@ button = obj { nam = "button", dsc = "There is a big red {button} on the room wall.", act = function (s) - here().dsc = [[The room transformed after I pressed the button. The book-case disappeared along with the table and the chest, and a strange looking device took its place.]]; + here()._dsc = [[The room transformed after I pressed the button. The book-case disappeared along with the table and the chest, and a strange looking device took its place.]]; return true; end, } @@ -837,13 +837,26 @@ pl.Life = 10; pl.Power = 10; status = obj { - nam = 'Life: '..pl.Life..',Power: '..pl.Power, + nam = function(s) + return 'Life: '..pl.Life..',Power: '..pl.Power + end }; inv():add('status'); status.object_type = false From version 0.9.1 you can use stat constructor for status. + +pl.Life = 10; +pl.Power = 10; + +status = stat { + nam = function(s) + return 'Life: '..pl.Life..',Power: '..pl.Power + end +}; +inv():add('status'); + ==== “goto” from the “exit” handler ==== @@ -1022,9 +1035,9 @@ main = room { ==== Keyboard ==== -Since the version 1.1.0 ''instead'' supports the keyboard input. (Only for sdl version.) Use the ''input'' object for this. +Since version 1.1.0 ''instead'' supports keyboard input (works with SDL version only). This can be done using ''input'' object. -input.key(s, pressed, key) -- keyboard handler; pressed -- press or release action; key -- symbolic name of the key; +input.key(s, pressed, key) -- keyboard handler; pressed -- press or release event; key -- symbolic name of the key; Handler can return a ''stead'' interface command. In this case the interpreter doesn't handle a key. For example: @@ -1048,13 +1061,72 @@ main = room { force_dsc = true, nam = 'Keyboard', dsc = function(s) - return 'Exmaple: '..tostring(s._txt); + return 'Example: '..tostring(s._txt); end }; +==== Mouse ==== +Since version 1.1.5 ''instead'' supports mouse click handling (works with SDL version only). This can be done using ''input'' object. + +input.click(s, pressed, mb, x, y, px, py) -- mouse click handler; pressed -- press or release event. mb -- mouse button index (1 is left button), x and y -- mouse cursor coordinates relative to upper left corner of the window. px and py parameters exist if a picture have been clicked, they contain mouse cursor coordinates relative to upper left corner of this picture. + + +Handler can return a ''stead'' interface command. In this case the interpreter doesn't handle a key. +For example: + +input.click = function(s, press, mb, x, y, px, py) + if press and px then + click.x = px; + click.y = py; + click:enable(); + return "look" + end +end + +click = obj { + nam = 'click', + x = 0, + y = 0, + dsc = function(s) + return "You clicked a picture at "..s.x..','..s.y..'.'; + end +}:disable(); + +main = room { + nam = 'test', + pic ='picture.png', + dsc = 'Example.', + obj = { 'click' }, +}; + + +Here is an example of a code layer that implements calling ''click'' method in the current room once the picture is clicked: + +input.click = function(s, press, mb, x, y, px, py) + if press and px then + return "click "..px..','..py; + end +end + +game.action = function(s, cmd, x, y) + if cmd == 'click' then + return call(here(), 'click', x, y); + end +end +---------------------------------------------------------------------- +main = room { + nam = 'test', + pic ='picture.png', + dsc = 'Example.', + click = function(s, x, y) + return "You clicked a picture at "..x..','..y..'.'; + end +}; + + ==== Dynamic object creation ==== -You can use ''new'' и ''delete'' functions to create and remove dynamic objects. An example follows. +You can use ''new'' and ''delete'' functions to create and remove dynamic objects. An example follows. new ("obj { nam = 'test', act = 'test' }") diff --git a/doc/writing_games.txt b/doc/writing_games.txt index e5e7033..6e31938 100644 --- a/doc/writing_games.txt +++ b/doc/writing_games.txt @@ -194,7 +194,7 @@ button = obj { nam = "кнопка", dsc = "На стене комнаты видна большая красная {кнопка}.", act = function (s) - here().dsc = [[После того как я нажал на кнопку, комната преобразилась. Книжный шкаф куда-то исчез вместе со столом и комодом, а на его месте появился странного вида аппарат.]]; + here()._dsc = [[После того как я нажал на кнопку, комната преобразилась. Книжный шкаф куда-то исчез вместе со столом и комодом, а на его месте появился странного вида аппарат.]]; return true; end, } @@ -821,13 +821,26 @@ pl.Life = 10; pl.Power = 10; status = obj { - nam = 'Жизнь: '..pl.Life..',Сила: '..pl.Power, + nam = function(s) + return 'Жизнь: '..pl.Life..',Сила: '..pl.Power + end }; inv():add('status'); status.object_type = false Начиная с версии 0.9.1 вы можете использовать конструктор stat для создания статуса. + +pl.Life = 10; +pl.Power = 10; + +status = stat { + nam = function(s) + return 'Жизнь: '..pl.Life..',Сила: '..pl.Power + end +}; +inv():add('status'); + ==== goto из обработчика exit === @@ -1004,7 +1017,7 @@ main = room { ==== Клавиатура ==== -Начиная с версии 1.1.0 в instead появлилась возможность анализировать ввод с клавиатуры. (Только в графической версии интерпретатора.) Для этого используется объект input. +Начиная с версии 1.1.0 в instead появилась возможность анализировать ввод с клавиатуры (только в графической версии интерпретатора). Для этого используется объект input. input.key(s, pressed, key) -- обработчик клавиатуры; pressed -- нажатие или отжатие. key -- символьное имя клавиши; @@ -1035,6 +1048,65 @@ main = room { }; +==== Мышь ==== +Начиная с версии 1.1.5 в instead появилась возможность анализировать события мыши. (Только в графической версии интерпретатора.) Для этого используется объект input. + +input.click(s, pressed, mb, x, y, px, py) -- обработчик клика мыши; pressed -- нажатие или отжатие. mb -- номер кнопки (1 - левая), x и y -- координаты клика относительно левого верхнего угла. px и py присутствуют, если клик произошел в области картинки сцены и содержит координаты клика относительно левого верхнего угла картинки. + +Обработчик может вернуть команду интерфейса stead, в этом случае клик не будет обработана интерпретатором. + +Например: + +input.click = function(s, press, mb, x, y, px, py) + if press and px then + click.x = px; + click.y = py; + click:enable(); + return "look" + end +end + +click = obj { + nam = 'клик', + x = 0, + y = 0, + dsc = function(s) + return "Вы кликнули по картинке в позиции: "..s.x..','..s.y..'.'; + end +}:disable(); + +main = room { + nam = 'test', + pic ='picture.png', + dsc = 'Демонстрация.', + obj = { 'click' }, +}; + + +Пример прослойки, которая реализует вызов метода click в текущей комнате при клике на картинку: + +input.click = function(s, press, mb, x, y, px, py) + if press and px then + return "click "..px..','..py; + end +end + +game.action = function(s, cmd, x, y) + if cmd == 'click' then + return call(here(), 'click', x, y); + end +end +---------------------------------------------------------------------- +main = room { + nam = 'test', + pic ='picture.png', + dsc = 'Демонстрация.', + click = function(s, x, y) + return "Вы кликнули по картинке в позиции: "..x..','..y..'.'; + end +}; + + ==== Динамическое создание объектов ==== Вы можете использовать функции new и delete для создания и удаления динамических объектов. Примеры: