Skip to content

Commit b12d1e7

Browse files
committed
Add experience Bar and number
1 parent e08dd6f commit b12d1e7

File tree

8 files changed

+54
-3
lines changed

8 files changed

+54
-3
lines changed

coffee/client/module/InventoryBar.coffee

Lines changed: 1 addition & 1 deletion
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:30px;left:50%;width:#{(@boxSize+2)*@boxes}px;margin-left:-#{@boxSize*@boxes/2}px;height:#{@boxSize}px;"
8+
document.querySelector(@div).style="position:fixed;bottom:50px;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="

coffee/client/module/index.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ init = ()->
7575
inv_bar.setHp(points)
7676
socket.on "food",(points)->
7777
inv_bar.setFood(points)
78+
socket.on "xp",(xp)->
79+
$(".player_xp").text(xp.level)
80+
$(".progress-bar").css("width",xp.progress*100+"%")
7881
socket.on "move", (pos)->
7982
to={x:pos.x-0.5,y:pos.y+17,z:pos.z-0.5}
8083
new TWEEN.Tween camera.position

coffee/server.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ module.exports=(config)->
6060
io.to(socket.id).emit "hp",socketInfo[socket.id].bot.health
6161
io.to(socket.id).emit "food",socketInfo[socket.id].bot.food
6262
return
63+
socketInfo[socket.id].bot.on 'experience',()->
64+
try
65+
io.to(socket.id).emit "xp",socketInfo[socket.id].bot.experience
66+
return
6367
socketInfo[socket.id].bot.on 'blockUpdate',(oldb,newb)->
6468
io.to(socket.id).emit "blockUpdate",[newb.position.x,newb.position.y,newb.position.z,newb.stateId]
6569
return

src/client/cdn/css/main.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,29 @@ canvas {
8585
.player_health{
8686
margin-bottom:5px;
8787
}
88+
.progress{
89+
margin:5px;
90+
margin-right:20px;
91+
margin-left:-3px;
92+
background:#122a08;
93+
border:1px solid black;
94+
}
95+
.progress-bar{
96+
background:#487329;
97+
}
98+
.player_xp{
99+
position:fixed;
100+
transform: translateX(-50%);
101+
left:50%;
102+
bottom:70px;
103+
-webkit-text-stroke: 1px black;
104+
color: #259c45;
105+
text-shadow:
106+
3px 3px 0 #000,
107+
-1px -1px 0 #000,
108+
1px -1px 0 #000,
109+
-1px 1px 0 #000,
110+
1px 1px 0 #000;
111+
font-size:20px;
112+
font-weight:bold;
113+
}

src/client/index.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.19.0/css/mdb.min.css">
1818
<link rel="stylesheet" href="/cdn/css/main.css">
1919

20-
2120
<!-- JS -->
2221
<script type="text/javascript" src="/cdn/js/tween.umd.js"></script>
2322
<script type="text/javascript" src="/cdn/js/jq.js"></script>
@@ -63,6 +62,11 @@ <h1 class="loadingText">Ładowanie zasobów...</h1>
6362
<img class='hp hp_10'>
6463
</span>
6564

65+
<!-- PLAYER XP -->
66+
<span class="player_xp">
67+
1
68+
</span>
69+
6670
<!-- PLAYER FOOD -->
6771
<span class="player_food">
6872
<img class='food food_10'>
@@ -78,6 +82,11 @@ <h1 class="loadingText">Ładowanie zasobów...</h1>
7882
</span>
7983
</div>
8084

85+
<!--EXPERIENCE BAR -->
86+
<div class="progress">
87+
<div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
88+
</div>
89+
8190
<!-- PLAYER ITEMS -->
8291
<div class="player_items">
8392
<img class='inv_box inv_box_1'>

src/client/module/InventoryBar.js

Lines changed: 1 addition & 1 deletion
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: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server.js

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

0 commit comments

Comments
 (0)