Skip to content

Commit e08dd6f

Browse files
committed
Add food hungers
1 parent 608a73c commit e08dd6f

File tree

11 files changed

+111
-32
lines changed

11 files changed

+111
-32
lines changed

coffee/client/module/InventoryBar.coffee

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,24 @@ class InventoryBar
4343
for i in [0..images.length-1]
4444
@setBox i+1,images[i]
4545
return @
46-
setHealth: (points)->
46+
setHp: (points)->
4747
for i in [1..10]
48-
document.querySelector(".he_#{i}").src="assets/images/heart/black.png"
48+
document.querySelector(".hp_#{i}").src="assets/images/heart/black.png"
4949
if points isnt 0
5050
for i in [1..(points+points%2)/2]
51-
document.querySelector(".he_#{i}").src="assets/images/heart/red.png"
51+
document.querySelector(".hp_#{i}").src="assets/images/heart/red.png"
5252
if points%2 is 1
53-
document.querySelector(".he_#{(points+points%2)/2}").src="assets/images/heart/half.png"
53+
document.querySelector(".hp_#{(points+points%2)/2}").src="assets/images/heart/half.png"
54+
return
55+
setFood: (points)->
56+
for i in [1..10]
57+
document.querySelector(".food_#{i}").src="assets/images/hunger/black.png"
58+
if points isnt 0
59+
for i in [1..(points+points%2)/2]
60+
document.querySelector(".food_#{i}").src="assets/images/hunger/full.png"
61+
if points%2 is 1
62+
document.querySelector(".food_#{(points+points%2)/2}").src="assets/images/hunger/half.png"
63+
return
5464
listen: ->
5565
_this=@
5666
$(window).on 'wheel', (event) ->
@@ -61,5 +71,4 @@ class InventoryBar
6171
$(document).keydown (z) ->
6272
_this.directBoxChange(z)
6373
return @
64-
6574
export {InventoryBar}

coffee/client/module/index.coffee

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ init = ()->
7171
return
7272
socket.on "mapChunk", (sections,x,z)->
7373
world._computeSections sections,x,z
74-
socket.on "health",(points)->
75-
inv_bar.setHealth(points)
74+
socket.on "hp",(points)->
75+
inv_bar.setHp(points)
76+
socket.on "food",(points)->
77+
inv_bar.setFood(points)
7678
socket.on "move", (pos)->
7779
to={x:pos.x-0.5,y:pos.y+17,z:pos.z-0.5}
7880
new TWEEN.Tween camera.position
@@ -96,7 +98,6 @@ init = ()->
9698
"assets/images/tnt.png"
9799
]).setFocusOnly(1).listen()
98100

99-
100101
FPC = new FirstPersonControls {
101102
canvas
102103
camera

coffee/server.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ module.exports=(config)->
5757
return
5858
socketInfo[socket.id].bot.on 'health',()->
5959
try
60-
io.to(socket.id).emit "health",socketInfo[socket.id].bot.health
60+
io.to(socket.id).emit "hp",socketInfo[socket.id].bot.health
61+
io.to(socket.id).emit "food",socketInfo[socket.id].bot.food
6162
return
62-
6363
socketInfo[socket.id].bot.on 'blockUpdate',(oldb,newb)->
6464
io.to(socket.id).emit "blockUpdate",[newb.position.x,newb.position.y,newb.position.z,newb.stateId]
6565
return
588 Bytes
Loading
678 Bytes
Loading
681 Bytes
Loading

src/client/cdn/css/main.css

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,26 @@ canvas {
6262
border:1px solid black;
6363
width:60px;
6464
height:60px;
65+
margin:-2px;
6566
}
66-
.health{
67-
width:19px;
68-
height:19px;
67+
.player_hp{
68+
margin:1px;
69+
margin-bottom:3px;
70+
}
71+
.hp{
72+
width:21px;
73+
height:21px;
74+
margin:-1px;
75+
}
76+
.food{
77+
width:21px;
78+
height:21px;
6979
margin:-1px;
7080
}
81+
.player_food{
82+
float:right;
83+
margin-right:30px;
84+
}
85+
.player_health{
86+
margin-bottom:5px;
87+
}

src/client/index.html

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,51 @@ <h1 class="loadingText">Ładowanie zasobów...</h1>
4545

4646
<!-- INVENTORY BAR -->
4747
<div class="inventoryBar">
48-
<img class='health he_1'>
49-
<img class='health he_2'>
50-
<img class='health he_3'>
51-
<img class='health he_4'>
52-
<img class='health he_5'>
53-
<img class='health he_6'>
54-
<img class='health he_7'>
55-
<img class='health he_8'>
56-
<img class='health he_9'>
57-
<img class='health he_10'>
58-
<br>
59-
<img class='inv_box inv_box_1'><img class='inv_box inv_box_2'><img class='inv_box inv_box_3'><img class='inv_box inv_box_4'><img class='inv_box inv_box_5'><img class='inv_box inv_box_6'><img class='inv_box inv_box_7'><img class='inv_box inv_box_8'><img class='inv_box inv_box_9'>
48+
49+
<!-- PLAYER HEALTH -->
50+
<div class="player_health">
51+
52+
<!-- PLAYER HP -->
53+
<span class="player_hp">
54+
<img class='hp hp_1'>
55+
<img class='hp hp_2'>
56+
<img class='hp hp_3'>
57+
<img class='hp hp_4'>
58+
<img class='hp hp_5'>
59+
<img class='hp hp_6'>
60+
<img class='hp hp_7'>
61+
<img class='hp hp_8'>
62+
<img class='hp hp_9'>
63+
<img class='hp hp_10'>
64+
</span>
65+
66+
<!-- PLAYER FOOD -->
67+
<span class="player_food">
68+
<img class='food food_10'>
69+
<img class='food food_9'>
70+
<img class='food food_8'>
71+
<img class='food food_7'>
72+
<img class='food food_6'>
73+
<img class='food food_5'>
74+
<img class='food food_4'>
75+
<img class='food food_3'>
76+
<img class='food food_2'>
77+
<img class='food food_1'>
78+
</span>
79+
</div>
80+
81+
<!-- PLAYER ITEMS -->
82+
<div class="player_items">
83+
<img class='inv_box inv_box_1'>
84+
<img class='inv_box inv_box_2'>
85+
<img class='inv_box inv_box_3'>
86+
<img class='inv_box inv_box_4'>
87+
<img class='inv_box inv_box_5'>
88+
<img class='inv_box inv_box_6'>
89+
<img class='inv_box inv_box_7'>
90+
<img class='inv_box inv_box_8'>
91+
<img class='inv_box inv_box_9'>
92+
</div>
6093
</div>
6194

6295
<!-- GAME MENU -->

src/client/module/InventoryBar.js

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/module/index.js

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)