Skip to content

Commit 3be2a7e

Browse files
refactoring (#1)
* refactoring * player name * server * disable fullscreen * server window size
1 parent fa1354f commit 3be2a7e

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ test/*
22

33
*.txt
44

5-
.DS_Store
5+
.DS_Store
6+
7+
*.love

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server:
2+
/Applications/love.app/Contents/MacOS/love game/server
3+
client:
4+
/Applications/love.app/Contents/MacOS/love game/client
5+
build-all: build-server build-client
6+
build-server:
7+
(cd game/server && zip -r server.love .)
8+
build-client:
9+
(cd game/client && zip -r client.love .)

game/client/main.lua

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local zombie = require "zombie"
66
local player = require "player"
77

88
function love.load()
9-
love.window.setFullscreen(true)
9+
love.window.setMode(1000, 600)
1010
GameClient = game.newClient(22122)
1111
love.window.setTitle( "Client")
1212

@@ -113,8 +113,14 @@ function love.draw()
113113
table.sort(sortedByScore, function(a, b) return a[2].score > b[2].score end)
114114
for _, v in pairs(sortedByScore) do
115115
local playerObj = v[2]
116-
if playerObj.id == GameClient.player.id then love.graphics.setColor(1, 0, 0, 1) end
117-
love.graphics.printf(playerObj.name .. " :: Zombies killed: " .. playerObj.score .. ", Accuracy: " .. string.format("%.2f %%", playerObj.accuracy), Fonts.s ,20, love.graphics.getHeight()-height, love.graphics.getWidth(), "left")
116+
local playerName = playerObj.name
117+
if playerObj.id == GameClient.player.id then
118+
love.graphics.setColor(0.2, 0.2, 0.8, 1)
119+
playerName = playerName .. "*"
120+
else
121+
playerName = playerName .. " "
122+
end
123+
love.graphics.printf(playerName .. " :: Zombies killed: " .. playerObj.score .. ", Accuracy: " .. string.format("%.2f %%", playerObj.accuracy), Fonts.s ,20, love.graphics.getHeight()-height, love.graphics.getWidth(), "left")
118124
love.graphics.setColor(0, 0, 0, 1)
119125
height = height - 30
120126
end
@@ -123,6 +129,7 @@ function love.draw()
123129
if GameClient.currentGameState == GameClient.states.SERVER_DISCONNECT then
124130
love.graphics.printf("Disconnected from server.. Game will close soon!", Fonts.l, 0, 50, love.graphics.getWidth(), "center")
125131
end
132+
love.graphics.printf("Press escape to quit", Fonts.xs, 0, 5, love.graphics.getWidth(), "center")
126133
end
127134

128135
function love.keypressed(key)
@@ -132,9 +139,13 @@ function love.keypressed(key)
132139
timestamp = love.timer.getTime(),
133140
})
134141
else
135-
GameClient:resetGame()
136-
GameClient.currentGameState = GameClient.states.CLIENT_PLAY
142+
if GameClient.currentGameState == GameClient.states.GAME_END then
143+
GameClient:resetGame()
144+
GameClient.currentGameState = GameClient.states.CLIENT_PLAY
145+
end
137146
end
147+
elseif key == "escape" then
148+
love.event.quit()
138149
end
139150
end
140151

@@ -145,8 +156,8 @@ function love.keyreleased(key)
145156
end
146157

147158
function love.quit()
148-
print("Thanks for playing!")
149-
if GameClient.client then
150-
GameClient.client:disconnectNow()
151-
end
159+
print("Thanks for playing!")
160+
if GameClient.client then
161+
GameClient.client:disconnectNow()
162+
end
152163
end

game/server/main.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local game = require "game"
55
local zombie = require "zombie"
66

77
function love.load()
8-
love.window.setFullscreen(true)
8+
love.window.setMode(1000, 600)
99
love.window.setTitle("Server")
1010
GameServer = game.newServer(GetIP(), 22122)
1111
end
@@ -41,5 +41,7 @@ end
4141
function love.keypressed( key )
4242
if key == "space" then
4343
zombie.spawn(GameServer)
44+
elseif key == "escape" then
45+
love.event.quit()
4446
end
4547
end

game/zombie.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ local function spawn(server)
2020
zombie.playerToTarget = playerToTarget
2121

2222
local side = math.random(1, 4)
23-
if side == 1 then
23+
if side == 1 then --left
2424
zombie.x = -30
25+
zombie.y = math.random(0, love.graphics.getHeight()) - 30
26+
elseif side == 2 then --right
27+
zombie.x = love.graphics.getWidth() + 30
2528
zombie.y = math.random(0, love.graphics.getHeight())
26-
elseif side == 2 then
27-
zombie.x = love.graphics.getWidth()
28-
zombie.y = math.random(0, love.graphics.getHeight())
29-
elseif side == 3 then
29+
elseif side == 3 then --top
3030
zombie.x = math.random(0, love.graphics.getWidth())
3131
zombie.y = -30
32-
elseif side == 4 then
32+
elseif side == 4 then --down
3333
zombie.x = math.random(0, love.graphics.getWidth())
34-
zombie.y = love.graphics.getHeight()
34+
zombie.y = love.graphics.getHeight() + 30
3535
end
3636

3737
table.insert(server.zombies, zombie)

0 commit comments

Comments
 (0)