Skip to content

Commit 608a73c

Browse files
committed
real Minecraft health hearts
1 parent 54848b1 commit 608a73c

File tree

18 files changed

+61
-11
lines changed

18 files changed

+61
-11
lines changed

coffee/client/module/InventoryBar.coffee

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class InventoryBar
55
@padding=options.padding
66
@boxes=9
77
@activeBox=1
8-
document.querySelector(@div).style="position:fixed;bottom:3px;left:50%;width:#{(@boxSize+2)*@boxes}px;margin-left:-#{@boxSize*@boxes/2}px;height:#{@boxSize}px;"
8+
document.querySelector(@div).style="position:fixed;bottom:30px;left:50%;width:#{(@boxSize+2)*@boxes}px;margin-left:-#{@boxSize*@boxes/2}px;height:#{@boxSize}px;"
99
setBox: (number,imageSrc)->
1010
if imageSrc is null
1111
imageSrc = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
@@ -43,6 +43,14 @@ class InventoryBar
4343
for i in [0..images.length-1]
4444
@setBox i+1,images[i]
4545
return @
46+
setHealth: (points)->
47+
for i in [1..10]
48+
document.querySelector(".he_#{i}").src="assets/images/heart/black.png"
49+
if points isnt 0
50+
for i in [1..(points+points%2)/2]
51+
document.querySelector(".he_#{i}").src="assets/images/heart/red.png"
52+
if points%2 is 1
53+
document.querySelector(".he_#{(points+points%2)/2}").src="assets/images/heart/half.png"
4654
listen: ->
4755
_this=@
4856
$(window).on 'wheel', (event) ->
@@ -53,5 +61,5 @@ class InventoryBar
5361
$(document).keydown (z) ->
5462
_this.directBoxChange(z)
5563
return @
56-
64+
5765
export {InventoryBar}

coffee/client/module/index.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ 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)
7476
socket.on "move", (pos)->
7577
to={x:pos.x-0.5,y:pos.y+17,z:pos.z-0.5}
7678
new TWEEN.Tween camera.position
@@ -94,6 +96,7 @@ init = ()->
9496
"assets/images/tnt.png"
9597
]).setFocusOnly(1).listen()
9698

99+
97100
FPC = new FirstPersonControls {
98101
canvas
99102
camera

coffee/server.coffee

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ module.exports=(config)->
5555
try
5656
io.to(socket.id).emit "move",socketInfo[socket.id].bot.entity.position
5757
return
58+
socketInfo[socket.id].bot.on 'health',()->
59+
try
60+
io.to(socket.id).emit "health",socketInfo[socket.id].bot.health
61+
return
5862

5963
socketInfo[socket.id].bot.on 'blockUpdate',(oldb,newb)->
6064
io.to(socket.id).emit "blockUpdate",[newb.position.x,newb.position.y,newb.position.z,newb.stateId]
@@ -69,10 +73,9 @@ module.exports=(config)->
6973
socketInfo[socket.id].bot.look data...
7074
return
7175
socket.on "disconnect", ->
72-
console.log "[-] "+socketInfo[socket.id].nick
73-
7476
#end bot session
7577
try
78+
console.log "[-] "+socketInfo[socket.id].nick
7679
socketInfo[socket.id].bot.end()
7780
#delete socketinfo
7881
delete socketInfo[socket.id]
-75.9 KB
Binary file not shown.
589 Bytes
Loading
667 Bytes
Loading
665 Bytes
Loading
-7.61 KB
Binary file not shown.
-861 Bytes
Binary file not shown.
-1.29 KB
Binary file not shown.

0 commit comments

Comments
 (0)