-
Notifications
You must be signed in to change notification settings - Fork 4
/
Game_SquareDiggingWar.lua
148 lines (136 loc) · 4.13 KB
/
Game_SquareDiggingWar.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
--游戏_方块掘战,玩家必须不停的跑跳防止掉下去,玩家有一次机会可以按Shift高跳,此脚本只检测'信号破坏方块2',作者@iPad水晶,QQ:1419427247
-- project.json
-------------------------------
-- {
-- "common":[
-- ],
-- "game": [
-- "Game_SquareDiggingWar.lua"
-- ],
-- "ui": [
-- "Game_SquareDiggingWar.lua"
-- ]
-- }
-------------------------------
local State = {
None = 0,
Start = 1,
}
local GameState = State.None;
local Signal_SuperJump = 3;
--难度列表
local DifficultyList = {
easy = 6, --简单
medium = 5, --中等
difficult = 4, --困难
};
--游戏难度,默认设置为中等
local Difficulty = DifficultyList.medium;
if Game then
local Count = 0;
local Blocks = {};
local Players = {};
function Game.Rule:OnUpdate(time)
Count = Count + 1;
if GameState == State.Start then
for i = 1,#Players do
local block = Game.EntityBlock:Create({
x = Players[i].position.x,
y = Players[i].position.y,
z = Players[i].position.z - 1,
});
if block ~= nil and block.id == 225 and block.onoff == false then
Blocks[#Blocks+1] = {Count + Difficulty - 1,block};
end
if Game.RandomInt(1,Difficulty - 2) == 1 then
local block = Game.EntityBlock:Create({
x = Players[i].position.x + Game.RandomInt(-1,1),
y = Players[i].position.y + Game.RandomInt(-1,1),
z = Players[i].position.z - 1,
});
if block ~= nil and block.id == 225 and block.onoff == false then
Blocks[#Blocks+1] = {Count + Difficulty,block};
end
end
end
end
for i = #Blocks,1,-1 do
if Blocks[i][1] < Count then
Blocks[i][2]:Event({action = "signal"}, true);
table.remove(Blocks,i);
end
end
end
function Game.Rule:OnRoundStart()
Count = 0;
Blocks = {};
BlocksSet = {};
Players = {};
print("回合开始")
GameState = State.Ready;
Game.Rule:Respawn();
for i = 1,24 do
Players[#Players + 1] = Game.Player:Create(i);
if Players[#Players] == nil then
break;
else
Players[#Players].health = 9999;
end
end
end
--收到信号之后给予玩家一个向上的速度
function Game.Rule:OnPlayerSignal(player,signal)
if signal == Signal_SuperJump then
player.velocity = {
x = player.velocity.x,
y = player.velocity.y,
z = 500,
}
end
end
function Game.Rule:OnPlayerDisconnect(player)
for i=1,#Players do
if Players[i] == player then
table.remove(Players,i)
break;
end
end
if #Players == 1 then
Players[1]:Win(false);
end
end
function Game.Rule:OnPlayerKilled (victim, killer, weapontype, hitbox)
if #Players == 1 then
Players[1]:Win(false);
return;
end
for i=1,#Players do
if Players[i] == victim then
table.remove(Players,i)
break;
end
end
if #Players == 1 then
Players[1]:Win(false);
return;
end
end
--使用'脚本调用方块'装置执行此方法时游戏正式开始
function GameStart(self,difficult)
GameState = State.Start;
Game.Rule.respawnable = false;
Difficulty = tonumber(difficult);
end
end
if UI then
local superjump = true;
function UI.Event:OnRoundStart()
superjump = true;
end
function UI.Event:OnKeyDown(inputs)
if superjump == true and inputs[UI.KEY.SHIFT] == true then
UI.Signal(Signal_SuperJump);
superjump = false;
end
end
end