ハンドへルド・ビュー:
-- 8.3.6 上下左右に動けるようにする local x = 130; local y = 100; local step = 10 function on.construction() timer.start(0.01) end function on.timer() platform.window:invalidate() end -- 矢印キーで動かす function on.arrowKey(key) if key == "left" then x = x - step elseif key == "right" then x = x + step elseif key == "up" then y = y - step elseif key == "down" then y = y + step end end -- テン・キーで動かす function on.charIn(char) if char == "4" then x = x - step elseif char == "6" then x = x + step elseif char == "8" then y = y - step elseif char == "2" then y = y + step elseif char == "7" then x = x - step; y = y - step elseif char == "9" then x = x + step; y = y - step elseif char == "1" then x = x - step; y = y + step elseif char == "3" then x = x + step; y = y + step elseif char == "5" then x = 130 ; y = 100 end end function on.paint(gc) gc:fillRect(x, y, 20, 20) end
参考文献:
プログラムはこうして作られるプログラマの頭の中をのぞいてみよう
- 作者: 平山尚(株式会社セガ)
- 出版社/メーカー: 秀和システム
- 発売日: 2013/09/25
- メディア: 単行本
- この商品を含むブログ (5件) を見る