作者realkillman (天下第一人)
看板BBSLua
標題[Lua ] 動作遊戲試做
時間Sat Aug 30 22:08:11 2008
很爛的實驗品
用的是國中生就寫的出來的方法
不過還有很多問題要解決
這是一份 BBSLua 程式,可在 PTT2 上
按 L 開始執行
(若出現錯誤或無反應,請先試著重登)
若您中途想中斷程式執行,按下 Ctrl-C 即可
相關資訊請見 PTT2 BBSLua 板
--#BBSLUA
-- Interface: 0.119
-- Title: Action game
-- Notes:
-- Author:realkillman
-- Version:0.1
-- Date:20080830
-- License: MIT License
FPS = 30
-- F = ma
-- s = s0 + vt
-- v = v0 + at
-- a = F/m
beGround = true
beWin = false
m = 0.1
s = {0, 0}
v = {0, 0}
maxv = 12
a = {0, 0}
G = {-10, 0}
F = {0, 0}
f = 0
map = {}
clearmap = {}
WIDTH, HEIGHT = 23, 23
for i = 0, HEIGHT do
map[i] = {}
clearmap[i] = {}
for j = 0, WIDTH do
map[i][j] = 0
clearmap[i][j] = 0
end
end
input = 0
function SetBox(x, y, w, h)
for i = y, y + h do
if i > HEIGHT then break end
for j = x, x + w do
if j > WIDTH then break end
map[i][j] = 1
end
end
end
function Map()
SetBox(0, 19, 2, 1)
SetBox(5, 19, 2, 1)
SetBox(9, 19, 2, 1)
SetBox(13, 19, 2, 1)
SetBox(20, 16, 3, 1)
SetBox(0, 13, 14, 1)
SetBox(5, 9, 15, 1)
SetBox(0, 5, 15, 1)
SetBox(5, 1, 15, 1)
map[23][0] = 2
end
Map()
function round(a)
if a < 0.5 and a > -0.5 then return 0
elseif a > 0 then return math.floor(a + 0.5)
else return math.floor(a - 0.5)
end
end
function Draw()
bbs.move(0, 0)
for i = HEIGHT, 0, -1 do
for j = 0, WIDTH do
if (map[i][j] >= 0) then
bbs.outs(bbs.ANSI_COLOR(47 - map[i][j])..' '..bbs.ANSI_RESET)
else
bbs.outs(' ')
end
end
bbs.print()
end
bbs.move(round(HEIGHT - s[1]), round(s[2]))
bbs.outs("A")
bbs.move(0, 40)
bbs.outs(a[1]..' '..a[2])
bbs.move(1, 40)
bbs.outs(v[1]..' '..v[2])
bbs.move(2, 40)
bbs.outs("上下左右空白鍵")
bbs.move(3, 40)
bbs.outs("目標:最上面的方塊")
end
function Caculate()
local t = 1 / FPS
nexts = {0, 0}
F = {F[1] + G[1], F[2] + G[2]}
a = {F[1] / m, F[2] / m}
temp = {round(s[1]), round(s[2])}
-- 腳踏實地
if a[1] < 0 and (temp[1] <= 0 or map[temp[1] - 1][temp[2]] ~= 0) then
a[1] = 0
beGround = true
else
beGround = false
end
v = {v[1] + a[1] * t, v[2] + a[2] * t}
if v[2] > maxv then v[2] = maxv
elseif v[2] < -maxv then v[2] = -maxv
end
nexts = {s[1] + v[1] * t, s[2] + v[2] * t}
-- constraint
temp = {round(nexts[1]), round(nexts[2])}
if (temp[1] < 0 or temp[1] > HEIGHT) then
--v[1] = 0
nexts[1] = s[1]
end
if (temp[2] < 0 or temp[2] > WIDTH) then
--v[2] = 0
nexts[2] = s[2]
end
temp = {round(nexts[1]), round(nexts[2])}
prev = {round(s[1]), round(s[2])}
if (map[temp[1]][temp[2]] == 1) then
if (prev[1] - temp[1] ~= 0) then
v[1] = 0
end
if (prev[2] - temp[2] ~= 0) then
v[2] = 0
end
elseif (map[temp[1]][temp[2]] == 2) then
beWin = true
else
s = {nexts[1], nexts[2]}
end
--
F = {0, 0}
end
repeat
input = nil
inputlist = {}
input = bbs.kball(1 / FPS)
if (input) then
if (input == ' ' or input == 'UP') then
if (beGround) then
F[1] = 100
end
elseif (input == 'RIGHT') then
F[2] = 400
elseif (input == 'LEFT') then
F[2] = -400
end
end
Caculate()
Draw()
if (beWin) then
bbs.sleep(2)
input = 'q'
bbs.pause("Game Over")
end
until (input == 'Q' or input == 'q')
--#BBSLUA
--
http://www.wretch.cc/blog/killman
http://www.wretch.cc/album/killman
--
※ 發信站: 批踢踢兔(ptt2.cc)
◆ From: 123.192.210.108
→ bbs1221617:可惡..推 08/31 00:20
→ looli:...上不去...推 08/31 10:14
→ realkillman:恩~ 我可以保證一定上的去 因為我上去過^^a推 08/31 10:37
→ k860326:我破關了+1推 08/31 11:29
→ photokao:過了 ^^a推 08/31 11:37
→ mTwTm:破了 您謙虛了 國中生就寫的出來方法推 08/31 13:08
→ realkillman:那改成高中生好了 F=ma應該是高中生比較了解^^a推 08/31 13:32
→ Kinra:那個縫隙比看起來還容易摔進去XDrz推 08/31 13:37
→ endlessdream:推推 09/02 16:24
→ sfwejfish:破了>"<推 09/03 15:43
→ bbasa:破了 >"<推 09/03 16:20
※ acersh:轉錄至某隱形看板 09/05 13:44
→ skydragon:破了xD推 09/07 01:16
→ youtien:好難..推 09/07 20:16
→ chris:耶很快就破了 好強呀推 09/08 21:16
→ herman602:破了推 09/11 14:15
→ lin214:好難....推 09/14 22:59
→ acersh:win推 09/28 20:22
→ XZXie:好好玩 XD推 10/02 12:55
→ upu:破了推 10/04 14:46
→ Ekaterine:破了XD推 12/02 22:39