Skip to content

Commit d136124

Browse files
committed
player looking at mouse in inventory
1 parent da35c49 commit d136124

File tree

15 files changed

+178
-6
lines changed

15 files changed

+178
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

coffee/client/module/FirstPersonControls.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class FirstPersonControls
1111
16:"sneak"
1212
82:"sprint"
1313
}
14+
@pii=options.pii
1415
@fov=options.fov
1516
@keys={}
1617
@canvas=options.canvas
@@ -121,6 +122,10 @@ class FirstPersonControls
121122
document.exitPointerLock()
122123
state:(state)->
123124
@gameState=state
125+
if state is "inventory"
126+
@pii.show()
127+
else
128+
@pii.hide()
124129
# console.log "Game state: "+state
125130
resetState:()->
126131
$(".chat").removeClass("focus")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as THREE from './build/three.module.js'
2+
class PlayerInInventory
3+
constructor:(options)->
4+
@canvas=options.canvas
5+
@al=options.al
6+
@renderer=new THREE.WebGLRenderer {
7+
canvas:@canvas
8+
PixelRatio:window.devicePixelRatio
9+
}
10+
@scene=new THREE.Scene
11+
@scene.background = new THREE.Color "black"
12+
light = new THREE.AmbientLight( 0xffffff )
13+
@scene.add( light );
14+
15+
player=@al.get "player"
16+
playerTex=@al.get "playerTex"
17+
18+
playerTex.magFilter=THREE.NearestFilter;
19+
player.children[0].material.map=playerTex;
20+
@scene.add( player )
21+
@camera = new THREE.PerspectiveCamera 70, 140/204, 0.1, 1000
22+
@camera.rotation.order="YXZ"
23+
@camera.position.z = 210
24+
@camera.position.y = 120
25+
$(window).mousemove (z)->
26+
xoff=z.pageX-window.innerWidth/2+112
27+
yoff=z.pageY-window.innerHeight/2+170
28+
left=xoff/(window.innerWidth/2-112)
29+
right=xoff/(window.innerWidth/2+112)
30+
top=yoff/(window.innerHeight/2-170)
31+
bottom=yoff/(window.innerHeight/2+170)
32+
wych_x=Math.PI/3
33+
wych_y=Math.PI/4
34+
if xoff>0
35+
player.rotation.y=wych_x*right
36+
else
37+
player.rotation.y=wych_x*left
38+
if yoff>0
39+
player.children[1].children[0].children[2].children[0].children[0].rotation.x=wych_y*bottom
40+
else
41+
player.children[1].children[0].children[2].children[0].children[0].rotation.x=wych_y*top
42+
render:()->
43+
@renderer.render @scene, @camera
44+
show:()->
45+
@canvas.style.display="block"
46+
hide:()->
47+
@canvas.style.display="none"
48+
export {PlayerInInventory}

coffee/client/module/World/World.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class World
9898
#Kasowanie Meshy, które mają znacznik .todel
9999
for i of cellBlackList
100100
if cellBlackList[i] is true
101-
console.log @cellMesh[i]
102101
@cellMesh[i].geometry.dispose()
103102
@cellMesh[i].material.dispose()
104103
@scene.remove @cellMesh[i]

coffee/client/module/index.coffee

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ import {RandomNick} from './RandomNick.js'
1111
import {GUI} from './jsm/libs/dat.gui.module.js'
1212
import {Chat} from './Chat.js'
1313
import {Entities} from './Entities.js'
14+
import {PlayerInInventory} from './PlayerInInventory.js'
1415

1516
class Game
1617
constructor:(options)->
1718
_this=@
1819
@al=options.al
1920
@canvas=document.querySelector '#c'
21+
@pcanvas=document.querySelector '#c_player'
22+
23+
@pii=new PlayerInInventory {
24+
canvas:@pcanvas
25+
al:@al
26+
}
27+
2028
@renderer=new THREE.WebGLRenderer {
2129
canvas:@canvas
2230
PixelRatio:window.devicePixelRatio
@@ -66,6 +74,7 @@ class Game
6674
socket:@socket
6775
TWEEN
6876
fov:70
77+
pii:@pii
6978
}
7079

7180
@chat=new Chat {
@@ -188,6 +197,8 @@ class Game
188197

189198
TWEEN.update()
190199
@renderer.render @scene, @camera
200+
if @FPC.gameState is "inventory"
201+
@pii.render()
191202
@inv_bar.tick()
192203
return
193204
new AssetLoader (al)->

src/client/assets/assetLoader.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,13 @@
1818
"blocksTex":{
1919
"path":"assets/blocks/blocks.json",
2020
"type":"text"
21+
},
22+
"player":{
23+
"path":"assets/models/player.fbx",
24+
"type":"fbx"
25+
},
26+
"playerTex":{
27+
"path":"assets/models/player.png",
28+
"type":"texture"
2129
}
2230
}
1.02 MB
Binary file not shown.
106 KB
Binary file not shown.
1.32 KB
Loading

src/client/css/style.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11

22
body { margin: 0; background:black;}
3-
canvas {
3+
#c {
44
display: block;
55
width:100%;
66
height:100%;
77
position:fixed;
88
top:0px;
99
left:0px
1010
}
11+
#c_player{
12+
display:block;
13+
position:fixed;
14+
width:140px;
15+
height:204px;
16+
top:calc(50% - 220px);
17+
left:calc(50% - 180px);
18+
z-index:9999;
19+
}
1120

1221
.cross{
1322
z-index:9;
@@ -213,6 +222,7 @@ canvas {
213222
background-repeat: no-repeat;
214223
background-size: 750px auto;
215224
position:fixed;
225+
image-rendering:pixelated;
216226
top:50%;
217227
left:50%;
218228
width:515px;
@@ -248,6 +258,7 @@ canvas {
248258
background-position: 0px -61px;
249259
background-size: 700px auto;
250260
position:fixed;
261+
image-rendering:pixelated;
251262
bottom:-4px;
252263
width:66px;
253264
height:66px;

0 commit comments

Comments
 (0)