-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSafeZoneSystem.lua
More file actions
56 lines (46 loc) · 1.69 KB
/
SafeZoneSystem.lua
File metadata and controls
56 lines (46 loc) · 1.69 KB
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
-- SafeZoneSystem.lua
-- Safe Zone Class
SafeZone = {}
function SafeZone:new(x, y, width, height)
local obj = {x = x, y = y, width = width, height = height, players = {}, meteors = {}}
setmetatable(obj, self)
self.__index = self
return obj
end
function SafeZone:isInSafeZone(player)
return player.x > self.x and player.x < (self.x + self.width) and \
player.y > self.y and player.y < (self.y + self.height)
end
function SafeZone:enter(player)
table.insert(self.players, player)
player.isProtected = true -- Protect player from damage
print(player.name .. " has entered the safe zone.")
end
function SafeZone:exit(player)
for i, p in ipairs(self.players) do
if p == player then
table.remove(self.players, i)
player.isProtected = false
print(player.name .. " has exited the safe zone.")
break
end
end
end
function SafeZone:markSpawnArea()
-- Code to visually mark the spawn area (e.g., draw a rectangle on the screen)
print("Spawn area marked at: " .. self.x .. ", " .. self.y)
end
function SafeZone:preventMeteors()
for i, meteor in ipairs(self.meteors) do
if self:isInSafeZone(meteor) then
print("Meteor intercepted at safe zone.")
table.remove(self.meteors, i)
end
end
end
-- Example Usage
local safeZone = SafeZone:new(100, 100, 200, 200)
safeZone:markSpawnArea()
-- Place this within your game loop to check for meteors
-- safeZone:preventMeteors() -- Call this function to prevent meteors from falling in the safe zone
-- Call safeZone:enter(player) and safeZone:exit(player) to manage player protection as they enter or leave the safe zone.