Skip to content

Commit 78bf882

Browse files
committed
inventory Window prototype
1 parent b602787 commit 78bf882

File tree

9 files changed

+252
-200
lines changed

9 files changed

+252
-200
lines changed

coffee/client/module/FirstPersonControls.coffee

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ class FirstPersonControls
1515
@canvas=options.canvas
1616
@camera=options.camera
1717
@socket=options.socket
18-
@gameState="menu"
18+
@setState "menu"
1919
@listen()
20-
$(".com_i").blur()
21-
$(".com").hide()
2220
updatePosition: (e)->
2321
#Updatowanie kursora
2422
if @gameState is "gameLock"
@@ -36,31 +34,35 @@ class FirstPersonControls
3634
#Kliknięcie
3735
_this.keys[z.keyCode] = true
3836

37+
#Klawisz Escape
38+
if z.keyCode is 27 and _this.gameState is "inventory"
39+
_this.setState "menu"
40+
3941
#Klawisz Enter
4042
if z.keyCode is 13 and _this.gameState is "chat"
4143
_this.socket.emit "command",$(".com_i").val()
4244
$(".com_i").val("")
4345

46+
#Klawisz E
47+
if (z.keyCode is 69) and (_this.gameState isnt "chat") and (_this.gameState isnt "menu")
48+
_this.setState "inventory"
49+
4450
#Klawisz T lub /
4551
if (z.keyCode is 84 or z.keyCode is 191) and _this.gameState is "gameLock"
4652
if z.keyCode is 191
4753
$(".com_i").val("/")
48-
_this._Chat()
54+
_this.setState "chat"
4955
z.preventDefault()
5056

5157
#Klawisz `
5258
if z.keyCode is 192
53-
$(".com_i").blur()
54-
$(".com").hide()
5559
z.preventDefault()
56-
if (_this.gameState is "menu") or (_this.gameState is "chat")
57-
_this._Game()
60+
if (_this.gameState is "menu") or (_this.gameState is "chat") or (_this.gameState is "inventory")
61+
_this.setState "game"
5862
else
59-
_this._Menu()
63+
_this.setState "menu"
6064
if z.keyCode is 27 and _this.gameState is "chat"
61-
$(".com_i").blur()
62-
$(".com").hide()
63-
_this._Menu()
65+
_this.setState "menu"
6466

6567
#Wysyłanie state'u do serwera
6668
if _this.kc[z.keyCode] isnt undefined and _this.gameState is "gameLock"
@@ -76,55 +78,66 @@ class FirstPersonControls
7678

7779
return
7880
$(".gameOn").click ->
79-
_this._Game()
81+
_this.setState "game"
8082
return
8183
lockChangeAlert=()->
8284
if document.pointerLockElement is _this.canvas or document.mozPointerLockElement is _this.canvas
8385
#Lock
8486
if _this.gameState is "game"
85-
$(".com_i").blur()
86-
$(".com").hide()
87-
_this.state "gameLock"
88-
$(".gameMenu").css "display", "none"
87+
_this.setState "gameLock"
8988
else
9089
#Unlock
91-
if (_this.gameState is "menu") or (_this.gameState is "gameLock")
92-
$(".com_i").blur()
93-
$(".com").hide()
94-
_this._Menu()
90+
if (_this.gameState is "gameLock") and (_this.gameState isnt "inventory")
91+
_this.setState "menu"
9592
return
9693
document.addEventListener 'pointerlockchange', lockChangeAlert, false
9794
document.addEventListener 'mozpointerlockchange', lockChangeAlert, false
9895
document.addEventListener "mousemove", (e)->
9996
_this.updatePosition(e)
10097
, false
10198
return @
99+
reqLock:()->
100+
@canvas.requestPointerLock()
101+
unLock:()->
102+
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock
103+
document.exitPointerLock()
102104
state:(state)->
103105
@gameState=state
104-
if @gameState is "chat"
105-
$(".chat").addClass("focus")
106-
$(".chat").removeClass("blur")
107-
else
108-
$(".chat").removeClass("focus")
109-
$(".chat").addClass("blur")
110106
console.log "Game state: "+state
111-
_Game:()->
112-
@state "game"
113-
@canvas.requestPointerLock()
114-
_Menu:()->
115-
@state "menu"
116-
$(".gameMenu").css "display", "block"
117-
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock
118-
document.exitPointerLock();
119-
_Chat:()->
120-
if @gameState is "gameLock"
121-
@state "chat"
122-
$(".gameMenu").css "display", "none"
123-
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock
124-
document.exitPointerLock()
125-
$(".com").show()
126-
$(".com_i").focus()
127-
128-
107+
resetState:()->
108+
$(".gameMenu").hide()
109+
$(".chat").removeClass("focus")
110+
$(".chat").addClass("blur")
111+
$(".com_i").blur()
112+
$(".com").hide()
113+
$(".inv_window").hide()
114+
setState:(state)->
115+
@resetState()
116+
switch state
117+
when "game"
118+
@state "game"
119+
@reqLock()
120+
when "gameLock"
121+
@state "gameLock"
122+
when "menu"
123+
@state "menu"
124+
$(".gameMenu").show()
125+
@unLock()
126+
when "chat"
127+
if @gameState is "gameLock"
128+
$(".chat").addClass("focus")
129+
$(".chat").removeClass("blur")
130+
@state "chat"
131+
@unLock()
132+
$(".com").show()
133+
$(".com_i").focus()
134+
when "inventory"
135+
if @gameState isnt "menu"
136+
if @gameState isnt "inventory"
137+
@state "inventory"
138+
$(".inv_window").show()
139+
@unLock()
140+
else
141+
@setState "game"
129142

130143
export {FirstPersonControls}

coffee/client/module/index.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ init = ()->
6969
socket.on "blockUpdate",(block)->
7070
world.setBlock block[0],block[1]+16,block[2],block[3]
7171
return
72-
socket.on "spawn", (sections,x,z,biomes)->
72+
socket.on "spawn", (yaw,pitch)->
7373
console.log "Gracz dołączył do gry!"
7474
$(".initLoading").css "display","none"
75+
camera.rotation.y=yaw
76+
camera.rotation.x=pitch
7577
socket.on "mapChunk", (sections,x,z,biomes)->
7678
world._computeSections sections,x,z,biomes
7779
socket.on "hp",(points)->

coffee/server.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports=(type)->
8080
,100
8181
socketInfo[socket.id].bot.on 'spawn',()->
8282
try
83-
io.to(socket.id).emit "spawn"
83+
io.to(socket.id).emit "spawn",socketInfo[socket.id].bot.entity.yaw,socketInfo[socket.id].bot.entity.pitch
8484
return
8585
socketInfo[socket.id].bot.on 'kicked',(reason,loggedIn)->
8686
try
2.26 KB
Loading

src/client/css/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ canvas {
126126
display: none;
127127
}
128128
.inv_bar{
129+
image-rendering: pixelated;
129130
position:fixed;
130131
bottom:0px;
131132
left:50%;
@@ -193,9 +194,11 @@ canvas {
193194
border: none;
194195
}
195196
.xp_bar_empty{
197+
image-rendering: pixelated;
196198
background-position: 0px -176px;
197199
}
198200
.xp_bar{
201+
image-rendering: pixelated;
199202
background-position: 0px -189px;
200203
}
201204
.player_food{
@@ -204,3 +207,16 @@ canvas {
204207
right:calc(50vw - 245px);
205208
display:block;
206209
}
210+
.inv_window{
211+
image-rendering: pixelated;
212+
z-index:10;
213+
background-image: url("/assets/gui/inventory.png");
214+
background-repeat: no-repeat;
215+
background-size: 600px auto;
216+
position:fixed;
217+
top:50%;
218+
left:50%;
219+
width:412px;
220+
height:388px;
221+
transform: translate(-50%,-50%);
222+
}

0 commit comments

Comments
 (0)