-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_obj.lua
173 lines (150 loc) · 5.37 KB
/
game_obj.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
--THIS IS THE LUA FILE THAT HOLDS ALL STUFF RELATED TO THE GAME OBJECT -dylan
--A game object sets up and maintains an actual game. It handles things
--like players and some timekeeping.
--Create the Game object class
Game = {}
Game.__index = Game
--DrawEvent and UpdateEvent are in their own files
require("game_drawevent")
require("game_updateevent")
function Game.new(self)
local self = setmetatable({}, Game)
self.gametime=0
--number of cycles elapsed in game; for timekeeping
--Instantiate the first players
-- Note: This mainplayer construct will throw a weird error if it's called wrong
mainplayer = Player.new(mainplayer, "mainplayer", 15, 15, 0, 128, 200)
--self.CreateAnonPlayer(math.floor(love.math.random(xblocks-1)),math.floor(love.math.random(yblocks-1)), math.floor(love.math.random(0,255)), math.floor(love.math.random(0,255)), math.floor(love.math.random(0,255)))
mainplayer.control="human"
--PlayerList[0].name="mainplayer"
--mainplayer = PlayerList[0]
self.CreateAnonPlayer(math.floor(love.math.random(xblocks-1)),math.floor(love.math.random(yblocks-1)), math.floor(love.math.random(0,255)), math.floor(love.math.random(0,255)), math.floor(love.math.random(0,255)))
self.CreateAnonPlayer(math.floor(love.math.random(xblocks-1)),math.floor(love.math.random(yblocks-1)), math.floor(love.math.random(0,255)), math.floor(love.math.random(0,255)), math.floor(love.math.random(0,255)))
--Instantiate some water and chaos
for i=0, xblocks-1 do
for j=0, 30 do
HazardGrid[i][j] = "grassland"
end
end
for i=0, xblocks-1 do
for j=30, yblocks-1 do
HazardGrid[i][j] = "metal"
end
end
for i = 0, xblocks-1 do
HazardGrid[i][yblocks-2] = "water"
HazardGrid[i][yblocks-1] = "water"
end
for j = 0, yblocks-1 do
HazardGrid[xblocks-1][j] = "chaos"
end
for j = 0, yblocks-1 do
HazardGrid[0][j] = "lava"
end
for i = 0, xblocks-1 do
HazardGrid[i][1] = "radioactive"
end
for i=20, 30 do
for j=20,30 do
HazardGrid[i][j] = "forest"
end
end
for i=12, 18 do
for j=12,18 do
HazardGrid[i][j] = "mountain"
end
end
for j=12,18 do
HazardGrid[11][j] = "tallmountain"
end
for i=12,18 do
HazardGrid[i][11] = "stronghold"
end
for i=4, 10 do
for j=20,25 do
HazardGrid[i][j] = "desert"
end
end
for i=34, 40 do
for j=20,24 do
HazardGrid[i][j] = "light"
end
end
for i=34, 40 do
for j=25,30 do
HazardGrid[i][j] = "dark"
end
end
HazardGrid[5][15] = "cave"
HazardGrid[6][15] = "cave"
HazardGrid[7][15] = "cave"
HazardGrid[8][15] = "cave"
HazardGrid[25][20] = "stonehead"
HazardGrid[26][20] = "stonehead"
HazardGrid[27][20] = "stonehead"
HazardGrid[28][20] = "stonehead"
for i = 0, xblocks-1 do
HazardGrid[i][3] = "tundra"
end
return self
end
function Game.HazardUpdate()
for i = 0, xblocks-1 do
for j = 0, yblocks-1 do
-- chaos block effect that changes tile colors a lot
if (OwnerGrid[i][j]~="nobody" and ((i<xblocks-1 and HazardGrid[i+1][j] == "chaos") or (i>0 and HazardGrid[i-1][j] == "chaos") or (j>0 and HazardGrid[i][j-1] == "chaos") or (j<yblocks-1 and HazardGrid[i][j+1] == "chaos"))) then
ColorGrid[i][j][0] = ColorGrid[i][j][0] + love.math.random(-8,8)
ColorGrid[i][j][1] = ColorGrid[i][j][1] + love.math.random(-8,8)
ColorGrid[i][j][2] = ColorGrid[i][j][2] + love.math.random(-8,8)
ColorGrid[i][j][0] = math.min(math.abs(ColorGrid[i][j][0]),255)
ColorGrid[i][j][1] = math.min(math.abs(ColorGrid[i][j][1]),255)
ColorGrid[i][j][2] = math.min(math.abs(ColorGrid[i][j][2]),255)
end
-- depopulation effect (like lava)
local DeathDieRoll = love.math.random(1,400000)
if (OwnerGrid[i][j]~="nobody" and ((i<xblocks-1 and GetDepop(i+1,j) > 0)) and DeathDieRoll<=GetDepop(i+1,j)) then
depop(i,j)
end
if (OwnerGrid[i][j]~="nobody" and ((i>0 and GetDepop(i-1,j) > 0)) and DeathDieRoll<=GetDepop(i-1,j)) then
depop(i,j)
end
if (OwnerGrid[i][j]~="nobody" and ((j>0 and GetDepop(i,j-1) > 0)) and DeathDieRoll<=GetDepop(i,j-1)) then
depop(i,j)
end
if (OwnerGrid[i][j]~="nobody" and ((j<yblocks-1 and GetDepop(i,j+1) > 0)) and DeathDieRoll<=GetDepop(i,j+1)) then
depop(i,j)
end
if (OwnerGrid[i][j]~="nobody" and ((GetDepop(i,j) > 0)) and DeathDieRoll<=GetDepop(i,j)) then
depop(i,j)
end
end
end
end
--creates a new NPC player at given position and gives it an automatic name
function Game.CreateAnonPlayer(xpos,ypos,red,green,blue)
local name = "player" .. table.getn(PlayerList)
local makeplayer = Player.new(makeplayer, name, xpos, ypos, red, green, blue)
return makeplayer
end
function Game.PlayerCleanup(self)
local action = false --flips to true if the routine has to eliminate any players
for i = 1, PlayerNumber do
if (PlayerList[i].GetLandExtent(PlayerList[i])==0 and PlayerList[i].alive==1 ) then
PlayerList[i].alive=0 --checks for all players with no more territory and "deactivates" them
action = true
end
if (PlayerList[i].GetLandExtent(PlayerList[i])>=1 and OwnerGrid[PlayerList[i].originx][PlayerList[i].originy]~=PlayerList[i].name) then
PlayerList[i].PickNewTown(PlayerList[i])
end
end
if (action == true) then love.audio.play(deathsound) end
end
function Game.GetLandTotal (self) --function to determine how much land is controlled by players in total
local counter=0
for i=0, xblocks-1 do
for j=0, yblocks-1 do
if (OwnerGrid[i][j] ~= "nobody") then counter = counter+1 end
end
end
return counter
end