This repository has been archived by the owner on Jan 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplayer.go
670 lines (558 loc) · 22.9 KB
/
player.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
/*
To the extent possible under law, Ian Davis has waived all copyright
and related or neighboring rights to this Amberfell Source Code file.
This work is published from the United Kingdom.
*/
package main
import (
"github.com/banthar/Go-SDL/sdl"
"github.com/banthar/gl"
"math"
// "fmt"
)
type Action uint8
type BlockId uint16
type ItemId BlockId
type Player struct {
MobData
currentAction Action
currentItem ItemId
equippedItems [7]ItemId
inventory [MAX_ITEMS]uint16
distanceTravelled float64
distanceFromStart uint16
interactingBlock *InteractingBlockFace
}
type BlockBreakRecord struct {
pos Vectori
count int
}
func NewPlayer() *Player {
player := &Player{}
player.heading = 0
player.position[XAXIS] = float64(PLAYER_START_X)
player.position[ZAXIS] = float64(PLAYER_START_Z)
player.position[YAXIS] = float64(TheWorld.FindSurface(PLAYER_START_X, PLAYER_START_Z))
player.mass = 5
player.fullEnergy = 30
player.energy = player.fullEnergy
player.fullHealth = 100
player.health = player.fullHealth
player.healingRate = 1
player.attackStrength = 5
player.walkingSpeed = 18
player.sprintSpeed = 26
player.currentAction = ACTION_HAND
player.currentItem = ITEM_NONE
player.equippedItems[0] = ITEM_NONE
player.equippedItems[1] = ITEM_NONE
player.equippedItems[2] = ITEM_NONE
player.equippedItems[3] = ITEM_NONE
player.equippedItems[4] = ITEM_NONE
player.equippedItems[5] = ITEM_NONE
player.equippedItems[6] = ITEM_NONE
return player
}
func (self *Player) W() float64 { return 2*0.25 + 2*0.75*0.25 } // torso width + 2 arm widths
func (self *Player) H() float64 { return 8*0.25 + 0.25 } // body+hat
func (self *Player) D() float64 { return 0.25 } // torso depth
func (self *Player) Act(dt float64) {
if self.velocity.Magnitude() > self.walkingSpeed {
self.energy -= 3 * dt
} else {
self.energy += 1 * dt
}
}
func (self *Player) Draw(center Vectorf, selectedBlockFace *BlockFace) {
pos := Vectorf{self.position[XAXIS], self.position[YAXIS], self.position[ZAXIS]}
gl.PushMatrix()
gl.Translated(self.position[XAXIS], self.position[YAXIS], self.position[ZAXIS])
gl.Rotated(self.Heading(), 0.0, 1.0, 0.0)
// Translate to top of ground block
gl.Translatef(0.0, -0.5, 0.0)
pos[YAXIS] += -0.5
// From http://www.realcolorwheel.com/human.htm
headHeight := float64(0.25)
hatHeight := headHeight
brimHeight := 0.15 * headHeight
brimWidth := 1.5 * headHeight
brimDepth := 1.5 * headHeight
neckHeight := 0.25 * headHeight
torsoWidth := 2 * headHeight
torsoHeight := 3.25 * headHeight
torsoDepth := 1 * headHeight
legHeight := 8*headHeight - torsoHeight - neckHeight - headHeight
legWidth := (torsoWidth - 0.25*headHeight) / 2
legDepth := legWidth
armHeight := 2.75 * headHeight
armWidth := 0.75 * torsoDepth
armDepth := 0.75 * torsoDepth
// lowerArmHeight := 1.25 * headHeight
// handHeight := 0.75 * headHeight
var legAngle, torsoAngle, leftArmAngle, rightArmAngle, step float64
horzSpeed := self.velocity[XAXIS]*self.velocity[XAXIS] + self.velocity[ZAXIS]*self.velocity[ZAXIS]
legAngle = math.Sin(self.walkSequence) * (20 + 45*horzSpeed/(self.sprintSpeed*self.sprintSpeed))
// legAngle = 55 * (math.Abs(self.velocity[XAXIS]) + math.Abs(self.velocity[ZAXIS])) / self.sprintSpeed * math.Sin(self.walkSequence)
torsoAngle = -math.Abs(legAngle / 6)
leftArmAngle = -legAngle * 1.2
rightArmAngle = legAngle * 1.2
step = headHeight * 0.1 * math.Pow(math.Sin(self.walkSequence), 2)
gl.Translated(0.0, step, 0)
pos[YAXIS] += step
// Translate to top of leg
gl.Translated(0.0, legHeight, 0)
pos[YAXIS] += legHeight
// Translate to centre of leg
gl.Rotated(legAngle, 0.0, 0.0, 1.0)
gl.Translated(0.0, -legHeight/2, (legWidth+0.25*headHeight)/2)
pos[YAXIS] += -legHeight / 2
pos[ZAXIS] += (legWidth + 0.25*headHeight) / 2
Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_LEG], textures[TEXTURE_LEG], textures[TEXTURE_LEG_SIDE], textures[TEXTURE_LEG_SIDE], textures[32], textures[32], FACE_NONE)
gl.Translated(0.0, legHeight/2, -(legWidth+0.25*headHeight)/2)
pos[YAXIS] += legHeight / 2
pos[ZAXIS] += -(legWidth + 0.25*headHeight) / 2
gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
gl.Translated(0.0, -legHeight/2, -(legWidth+0.25*headHeight)/2)
pos[YAXIS] += -legHeight / 2
pos[ZAXIS] += -(legWidth + 0.25*headHeight) / 2
Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_LEG], textures[TEXTURE_LEG], textures[TEXTURE_LEG_SIDE], textures[TEXTURE_LEG_SIDE], textures[32], textures[32], FACE_NONE)
gl.Translated(0.0, legHeight/2, (legWidth+0.25*headHeight)/2)
pos[YAXIS] += legHeight / 2
pos[ZAXIS] += (legWidth + 0.25*headHeight) / 2
gl.Rotated(+legAngle, 0.0, 0.0, 1.0)
gl.Rotated(torsoAngle, 0.0, 0.0, 1.0)
// Translate to centre of torso
gl.Translated(0.0, torsoHeight/2, 0.0)
pos[YAXIS] += torsoHeight / 2
Cuboid(pos, torsoWidth, torsoHeight, torsoDepth, textures[TEXTURE_TORSO_FRONT], textures[TEXTURE_TORSO_BACK], textures[TEXTURE_TORSO_LEFT], textures[TEXTURE_TORSO_RIGHT], textures[TEXTURE_TORSO_TOP], textures[TEXTURE_TORSO_TOP], FACE_NONE)
// Translate to shoulders
gl.Translated(0.0, torsoHeight/2, 0.0)
pos[YAXIS] += torsoHeight / 2
gl.Rotated(leftArmAngle, 0.0, 0.0, 1.0)
gl.Translated(0.0, -armHeight/2, torsoWidth/2+armWidth/2)
pos[YAXIS] += -armHeight / 2
pos[ZAXIS] += torsoWidth/2 + armWidth/2
Cuboid(pos, armWidth, armHeight, armDepth, textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM_TOP], textures[TEXTURE_HAND], FACE_NONE)
gl.Translated(0.0, armHeight/2, -torsoWidth/2-armWidth/2)
pos[YAXIS] += armHeight / 2
pos[ZAXIS] += -torsoWidth/2 + armWidth/2
gl.Rotated(-leftArmAngle, 0.0, 0.0, 1.0)
gl.Rotated(rightArmAngle, 0.0, 0.0, 1.0)
gl.Translated(0.0, -armHeight/2, -torsoWidth/2-armWidth/2)
pos[YAXIS] += -armHeight / 2
pos[ZAXIS] += -torsoWidth/2 + armWidth/2
Cuboid(pos, armWidth, armHeight, armDepth, textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM], textures[TEXTURE_ARM_TOP], textures[TEXTURE_HAND], FACE_NONE)
gl.Translated(0.0, armHeight/2, torsoWidth/2+armWidth/2)
pos[YAXIS] += armHeight / 2
pos[ZAXIS] += torsoWidth/2 + armWidth/2
gl.Rotated(-rightArmAngle, 0.0, 0.0, 1.0)
// Translate to centre of head
gl.Translated(0.0, neckHeight+headHeight/2, 0.0)
pos[YAXIS] += neckHeight + headHeight/2
if selectedBlockFace != nil {
blockPos := selectedBlockFace.pos.Vectorf()
headPos := self.position.Add(Vectorf{0, headHeight * 9, 0})
blockDir := blockPos.Minus(headPos)
if self.Facing(blockDir) {
yrot := (math.Atan2(blockDir[XAXIS], blockDir[ZAXIS]) - math.Pi/2) * 180 / math.Pi
zrot, xrot := -12.0, -12.0
gl.Rotated(-self.Heading(), 0.0, 1.0, 0.0)
gl.Rotated(yrot, 0.0, 1.0, 0.0)
gl.Rotated(zrot, 0.0, 0.0, 1.0)
gl.Rotated(xrot, 1.0, 0.0, 0.0)
}
}
Cuboid(pos, headHeight, headHeight, headHeight, textures[TEXTURE_HEAD_FRONT], textures[TEXTURE_HEAD_BACK], textures[TEXTURE_HEAD_LEFT], textures[TEXTURE_HEAD_RIGHT], nil, textures[TEXTURE_HEAD_BOTTOM], FACE_NONE)
// Translate to hat brim
gl.Translated(0.0, headHeight/2+brimHeight/2, 0.0)
pos[YAXIS] += headHeight/2 + brimHeight/2
Cuboid(pos, brimWidth, brimHeight, brimDepth, textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], textures[TEXTURE_BRIM], FACE_NONE)
gl.Translated(0.0, brimHeight/2+hatHeight/2, 0.0)
pos[YAXIS] += headHeight/2 + brimHeight/2
Cuboid(pos, hatHeight, hatHeight, hatHeight, textures[TEXTURE_HAT_FRONT], textures[TEXTURE_HAT_BACK], textures[TEXTURE_HAT_LEFT], textures[TEXTURE_HAT_RIGHT], textures[TEXTURE_HAT_TOP], nil, FACE_NONE)
gl.PopMatrix()
}
func (self *Player) HandleKeys(keys []uint8) {
if keys[sdl.K_w] != 0 {
if self.IsFalling() {
self.velocity[XAXIS] = math.Cos(self.Heading()*math.Pi/180) * self.walkingSpeed / 2
self.velocity[ZAXIS] = -math.Sin(self.Heading()*math.Pi/180) * self.walkingSpeed / 2
} else {
speed := self.walkingSpeed
if self.energy > 5 && (keys[sdl.K_LSHIFT] != 0 || keys[sdl.K_RSHIFT] != 0) {
speed = self.sprintSpeed
}
self.velocity[XAXIS] = math.Cos(self.Heading()*math.Pi/180) * speed
self.velocity[ZAXIS] = -math.Sin(self.Heading()*math.Pi/180) * speed
}
}
if keys[sdl.K_s] != 0 {
if self.IsFalling() {
self.velocity[XAXIS] = -math.Cos(self.Heading()*math.Pi/180) * self.walkingSpeed / 4
self.velocity[ZAXIS] = math.Sin(self.Heading()*math.Pi/180) * self.walkingSpeed / 4
} else {
speed := self.walkingSpeed
if self.energy > 5 && (keys[sdl.K_LSHIFT] != 0 || keys[sdl.K_RSHIFT] != 0) {
speed = self.sprintSpeed
}
self.velocity[XAXIS] = -math.Cos(self.Heading()*math.Pi/180) * speed / 2
self.velocity[ZAXIS] = math.Sin(self.Heading()*math.Pi/180) * speed / 2
}
}
if keys[sdl.K_q] != 0 {
if self.IsFalling() {
self.velocity[XAXIS] = math.Cos((self.Heading()+90)*math.Pi/180) * self.walkingSpeed / 3
self.velocity[ZAXIS] = -math.Sin((self.Heading()+90)*math.Pi/180) * self.walkingSpeed / 3
} else {
self.velocity[XAXIS] = math.Cos((self.Heading()+90)*math.Pi/180) * self.walkingSpeed
self.velocity[ZAXIS] = -math.Sin((self.Heading()+90)*math.Pi/180) * self.walkingSpeed
}
}
if keys[sdl.K_e] != 0 {
if self.IsFalling() {
self.velocity[XAXIS] = -math.Cos((self.Heading()+90)*math.Pi/180) * self.walkingSpeed / 6
self.velocity[ZAXIS] = math.Sin((self.Heading()+90)*math.Pi/180) * self.walkingSpeed / 6
} else {
self.velocity[XAXIS] = -math.Cos((self.Heading()+90)*math.Pi/180) * self.walkingSpeed / 2
self.velocity[ZAXIS] = math.Sin((self.Heading()+90)*math.Pi/180) * self.walkingSpeed / 2
}
}
if keys[sdl.K_a] != 0 {
self.Rotate(22.5 / 2)
// viewport.Roty(-22.5 / 2)
}
if keys[sdl.K_d] != 0 {
self.Rotate(-22.5 / 2)
// viewport.Roty(22.5 / 2)
}
if keys[sdl.K_SPACE] != 0 {
if !self.IsFalling() {
self.velocity[YAXIS] = 7
}
}
}
func (self *Player) CanInteract() bool {
if self.currentAction == ACTION_HAND || self.currentAction == ACTION_BREAK || self.currentItem != ITEM_NONE {
return true
}
return false
}
func (self *Player) Interact(interactingBlockFace *InteractingBlockFace) {
if !self.CanInteract() {
return
}
selectedBlockFace := interactingBlockFace.blockFace
// println("Interacting at ", selectedBlockFace.pos.String())
switch self.currentAction {
case ACTION_HAND:
blockid := TheWorld.Atv(selectedBlockFace.pos)
switch blockid {
case BLOCK_AMBERFELL_PUMP, BLOCK_STEAM_GENERATOR, BLOCK_AMBERFELL_CONDENSER, BLOCK_FURNACE, BLOCK_BEESNEST:
if obj, ok := TheWorld.containerObjects[selectedBlockFace.pos]; ok {
inventory.Show(obj, nil)
}
case BLOCK_CARPENTERS_BENCH:
inventory.Show(nil, NewCarpentersBench(selectedBlockFace.pos))
case BLOCK_FORGE:
inventory.Show(nil, NewForge(selectedBlockFace.pos))
}
case ACTION_BREAK:
block := TheWorld.AtBv(selectedBlockFace.pos)
blocktype := items[ItemId(block.id)]
blockid := block.id
if blockid != BLOCK_AIR {
interactingBlockFace.hitCount++
if blocktype.hitsNeeded != STRENGTH_UNBREAKABLE && interactingBlockFace.hitCount >= blocktype.hitsNeeded/2 {
if interactingBlockFace.hitCount >= blocktype.hitsNeeded {
TheWorld.Setv(selectedBlockFace.pos, BLOCK_AIR)
TheWorld.InvalidateRadius(selectedBlockFace.pos[XAXIS], selectedBlockFace.pos[ZAXIS], 1)
switch blockid {
case BLOCK_CAMPFIRE:
delete(TheWorld.campfires, selectedBlockFace.pos)
delete(TheWorld.lightSources, selectedBlockFace.pos)
delete(TheWorld.timedObjects, selectedBlockFace.pos)
TheWorld.InvalidateRadius(selectedBlockFace.pos[XAXIS], selectedBlockFace.pos[ZAXIS], uint16(CAMPFIRE_INTENSITY))
case BLOCK_AMBERFELL_PUMP:
delete(TheWorld.timedObjects, selectedBlockFace.pos)
delete(TheWorld.containerObjects, selectedBlockFace.pos)
case BLOCK_STEAM_GENERATOR:
delete(TheWorld.timedObjects, selectedBlockFace.pos)
delete(TheWorld.containerObjects, selectedBlockFace.pos)
delete(TheWorld.generatorObjects, selectedBlockFace.pos)
case BLOCK_AMBERFELL_CONDENSER:
delete(TheWorld.timedObjects, selectedBlockFace.pos)
delete(TheWorld.containerObjects, selectedBlockFace.pos)
case BLOCK_FURNACE:
delete(TheWorld.timedObjects, selectedBlockFace.pos)
delete(TheWorld.containerObjects, selectedBlockFace.pos)
case BLOCK_BEESNEST:
delete(TheWorld.timedObjects, selectedBlockFace.pos)
delete(TheWorld.containerObjects, selectedBlockFace.pos)
}
if blocktype.drops != nil {
droppedItem := blocktype.drops.item
if self.inventory[droppedItem] < MAX_ITEMS_IN_INVENTORY {
self.inventory[droppedItem]++
if items[droppedItem].placeable {
self.EquipItem(droppedItem)
}
}
}
interactingBlockFace.hitCount = 0
} else if !block.Damaged() {
block.SetDamaged(true)
TheWorld.SetBv(selectedBlockFace.pos, block)
}
}
}
case ACTION_ITEM0, ACTION_ITEM1, ACTION_ITEM2, ACTION_ITEM3, ACTION_ITEM4:
if self.inventory[self.currentItem] > 0 && items[self.currentItem].placeable {
if selectedBlockFace.face == UP_FACE { // top
selectedBlockFace.pos[YAXIS]++
} else if selectedBlockFace.face == DOWN_FACE { // bottom
selectedBlockFace.pos[YAXIS]--
} else if selectedBlockFace.face == SOUTH_FACE { // front
selectedBlockFace.pos[ZAXIS]++
} else if selectedBlockFace.face == NORTH_FACE { // back
selectedBlockFace.pos[ZAXIS]--
} else if selectedBlockFace.face == EAST_FACE { // left
selectedBlockFace.pos[XAXIS]++
} else if selectedBlockFace.face == WEST_FACE { // right
selectedBlockFace.pos[XAXIS]--
}
if TheWorld.Atv(selectedBlockFace.pos) == BLOCK_AIR && self.currentItem < 256 {
blockid := self.currentItem
switch blockid {
case BLOCK_CAMPFIRE:
// Add a light source
campfire := NewCampFire(selectedBlockFace.pos)
TheWorld.lightSources[selectedBlockFace.pos] = campfire
TheWorld.timedObjects[selectedBlockFace.pos] = campfire
TheWorld.campfires[selectedBlockFace.pos] = campfire
TheWorld.InvalidateRadius(selectedBlockFace.pos[XAXIS], selectedBlockFace.pos[ZAXIS], uint16(CAMPFIRE_INTENSITY))
case BLOCK_AMBERFELL_PUMP:
sourced := false
if selectedBlockFace.pos[YAXIS] > 0 && TheWorld.At(selectedBlockFace.pos[XAXIS], selectedBlockFace.pos[YAXIS]-1, selectedBlockFace.pos[ZAXIS]) == BLOCK_AMBERFELL_SOURCE {
sourced = true
}
pump := NewAmberfellPump(selectedBlockFace.pos, sourced, false)
TheWorld.timedObjects[selectedBlockFace.pos] = pump
TheWorld.containerObjects[selectedBlockFace.pos] = pump
case BLOCK_STEAM_GENERATOR:
gen := NewSteamGenerator(selectedBlockFace.pos)
TheWorld.timedObjects[selectedBlockFace.pos] = gen
TheWorld.containerObjects[selectedBlockFace.pos] = gen
TheWorld.generatorObjects[selectedBlockFace.pos] = gen
case BLOCK_AMBERFELL_CONDENSER:
obj := NewAmberfellCondenser(selectedBlockFace.pos)
TheWorld.timedObjects[selectedBlockFace.pos] = obj
TheWorld.containerObjects[selectedBlockFace.pos] = obj
case BLOCK_FURNACE:
obj := NewFurnace(selectedBlockFace.pos)
TheWorld.timedObjects[selectedBlockFace.pos] = obj
TheWorld.containerObjects[selectedBlockFace.pos] = obj
}
orientation := HeadingToOrientation(self.heading)
block := NewBlock(BlockId(blockid), false, orientation)
TheWorld.SetBv(selectedBlockFace.pos, block)
self.inventory[self.currentItem]--
}
}
}
}
func (self *Player) HandleMouseButton(re *sdl.MouseButtonEvent) {
if re.Button == 1 && re.State == 1 { // LEFT, DOWN
if self.CanInteract() {
selectedBlockFace := viewport.SelectedBlockFace()
if selectedBlockFace != nil {
if self.interactingBlock == nil || self.interactingBlock.blockFace.pos != selectedBlockFace.pos {
self.interactingBlock = new(InteractingBlockFace)
self.interactingBlock.blockFace = selectedBlockFace
self.interactingBlock.hitCount = 0
}
self.Interact(self.interactingBlock)
}
// println("Click:", re.X, re.Y, re.State, re.Button, re.Which)
}
}
}
func (self *Player) HandleKeyboard(re *sdl.KeyboardEvent) {
}
func (self *Player) SelectAction(action int) {
switch action {
case 0:
self.currentAction = ACTION_HAND
self.currentItem = ITEM_NONE
case 1:
self.currentAction = ACTION_BREAK
self.currentItem = ITEM_NONE
case 2:
self.currentAction = ACTION_WEAPON
self.currentItem = ITEM_NONE
case 3:
self.currentAction = ACTION_ITEM0
self.currentItem = self.equippedItems[0]
case 4:
self.currentAction = ACTION_ITEM1
self.currentItem = self.equippedItems[1]
case 5:
self.currentAction = ACTION_ITEM2
self.currentItem = self.equippedItems[2]
case 6:
self.currentAction = ACTION_ITEM3
self.currentItem = self.equippedItems[3]
case 7:
self.currentAction = ACTION_ITEM4
self.currentItem = self.equippedItems[4]
}
}
func (self *Player) EquipItem(itemid ItemId) {
// Check to see if this item is already equipped
for j := 0; j < 5; j++ {
if self.equippedItems[j] == itemid {
return
}
}
// Place it in the first empty slot
for j := 0; j < 5; j++ {
if self.equippedItems[j] == ITEM_NONE {
self.equippedItems[j] = itemid
return
}
}
}
func (self *Player) Update(dt float64) (completed bool) {
self.distanceTravelled += dt * math.Sqrt(math.Pow(self.velocity[XAXIS], 2)+math.Pow(self.velocity[ZAXIS], 2))
self.MobData.Update(dt)
return false
}
func (self *Player) TargetType() uint8 {
return TARGET_PLAYER
}
func (self *Player) DrawWolf(center Vectorf, selectedBlockFace *BlockFace) {
pos := Vectorf{self.position[XAXIS], self.position[YAXIS], self.position[ZAXIS]}
gl.PushMatrix()
gl.Translated(self.position[XAXIS], self.position[YAXIS], self.position[ZAXIS])
gl.Rotated(self.Heading(), 0.0, 1.0, 0.0)
// Translate to top of ground block
gl.Translatef(0.0, -0.5, 0.0)
pos[YAXIS] += -0.5
headHeight := 0.25
headWidth := headHeight
headDepth := headHeight * 2.0
neckHeight := 0.0
torsoWidth := 1.5 * headHeight
torsoHeight := 1.5 * headHeight
torsoDepth := 5 * headHeight
legHeight := 5*headHeight - torsoHeight - neckHeight - headHeight
legWidth := (torsoWidth - 0.25*headHeight) / 2
legDepth := legWidth
// lowerArmHeight := 1.25 * headHeight
// handHeight := 0.75 * headHeight
var legAngle, step float64
horzSpeed := self.velocity[XAXIS]*self.velocity[XAXIS] + self.velocity[ZAXIS]*self.velocity[ZAXIS]
legAngle = math.Sin(self.walkSequence) * (15 + 55*horzSpeed/(self.sprintSpeed*self.sprintSpeed))
headAngle := 30.0
// torsoAngle = -math.Abs(legAngle / 6)
step = headHeight * 0.3 * math.Pow(math.Sin(self.walkSequence), 2)
gl.Translated(0.0, step, 0)
pos[YAXIS] += step
// Translate to top of leg
// Translate to centre of front left leg
gl.Translated(0.0, legHeight, 0)
pos[YAXIS] += legHeight
legDepthOffset := torsoDepth/2 - legWidth/2
legHeightOffset := -legHeight / 2
legWidthOffset := (legWidth + 0.25*headHeight) / 2
// Translate to centre of front left leg
gl.Translated(legDepthOffset, 0, legWidthOffset)
gl.Rotated(legAngle, 0.0, 0.0, 1.0)
gl.Translated(0, legHeightOffset, 0)
pos[XAXIS] += legDepthOffset
pos[YAXIS] += legHeightOffset
pos[ZAXIS] += legWidthOffset
Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], FACE_NONE)
pos[XAXIS] -= legDepthOffset
pos[YAXIS] -= legHeightOffset
pos[ZAXIS] -= legWidthOffset
gl.Translated(0, -legHeightOffset, 0)
gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
gl.Translated(-legDepthOffset, 0, -legWidthOffset)
legWidthOffset = -legWidthOffset
if horzSpeed <= self.walkingSpeed*self.walkingSpeed {
legAngle = -legAngle
}
gl.Translated(legDepthOffset, 0, legWidthOffset)
gl.Rotated(legAngle, 0.0, 0.0, 1.0)
gl.Translated(0, legHeightOffset, 0)
pos[XAXIS] += legDepthOffset
pos[YAXIS] += legHeightOffset
pos[ZAXIS] += legWidthOffset
Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], FACE_NONE)
pos[XAXIS] -= legDepthOffset
pos[YAXIS] -= legHeightOffset
pos[ZAXIS] -= legWidthOffset
gl.Translated(0, -legHeightOffset, 0)
gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
gl.Translated(-legDepthOffset, 0, -legWidthOffset)
legDepthOffset = -legDepthOffset
legWidthOffset = -legWidthOffset
if horzSpeed > self.walkingSpeed*self.walkingSpeed {
legAngle = -legAngle
}
gl.Translated(legDepthOffset, 0, legWidthOffset)
gl.Rotated(legAngle, 0.0, 0.0, 1.0)
gl.Translated(0, legHeightOffset, 0)
pos[XAXIS] += legDepthOffset
pos[YAXIS] += legHeightOffset
pos[ZAXIS] += legWidthOffset
Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], FACE_NONE)
pos[XAXIS] -= legDepthOffset
pos[YAXIS] -= legHeightOffset
pos[ZAXIS] -= legWidthOffset
gl.Translated(0, -legHeightOffset, 0)
gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
gl.Translated(-legDepthOffset, 0, -legWidthOffset)
legWidthOffset = -legWidthOffset
if horzSpeed <= self.walkingSpeed*self.walkingSpeed {
legAngle = -legAngle
}
gl.Translated(legDepthOffset, 0, legWidthOffset)
gl.Rotated(legAngle, 0.0, 0.0, 1.0)
gl.Translated(0, legHeightOffset, 0)
pos[XAXIS] += legDepthOffset
pos[YAXIS] += legHeightOffset
pos[ZAXIS] += legWidthOffset
Cuboid(pos, legWidth, legHeight, legDepth, textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], textures[TEXTURE_WOLF_LEG], FACE_NONE)
pos[XAXIS] -= legDepthOffset
pos[YAXIS] -= legHeightOffset
pos[ZAXIS] -= legWidthOffset
gl.Translated(0, -legHeightOffset, 0)
gl.Rotated(-legAngle, 0.0, 0.0, 1.0)
gl.Translated(-legDepthOffset, 0, -legWidthOffset)
//gl.Rotated(torsoAngle, 0.0, 0.0, 1.0)
// Translate to centre of torso
gl.Translated(0.0, torsoHeight/2, 0.0)
pos[YAXIS] += torsoHeight / 2
Cuboid(pos, torsoWidth, torsoHeight, torsoDepth, textures[TEXTURE_WOLF_TORSO_FRONT], textures[TEXTURE_WOLF_TORSO_BACK], textures[TEXTURE_WOLF_TORSO_SIDE], textures[TEXTURE_WOLF_TORSO_SIDE], textures[TEXTURE_WOLF_TORSO_TOP], textures[TEXTURE_WOLF_TORSO_TOP], FACE_NONE)
// Translate to shoulders
gl.Translated(0.0, torsoHeight/2, 0.0)
pos[YAXIS] += torsoHeight / 2
// Translate to centre of head
gl.Translated(torsoDepth/2+headDepth*0.5, 0.0, 0.0)
pos[XAXIS] += torsoDepth/2 + headDepth*0.5
pos[YAXIS] += 0.0
gl.Rotated(-headAngle, 0.0, 0.0, 1.0)
Cuboid(pos, headWidth, headHeight, headDepth, textures[TEXTURE_WOLF_HEAD_FRONT], textures[TEXTURE_WOLF_HEAD_BACK], textures[TEXTURE_WOLF_HEAD_SIDE], textures[TEXTURE_WOLF_HEAD_SIDE], textures[TEXTURE_WOLF_HEAD_TOP], textures[TEXTURE_WOLF_HEAD_BOTTOM], FACE_NONE)
gl.PopMatrix()
}
func (self *Player) Rotate(angle float64) {
self.heading += angle
if self.heading < 0 {
self.heading += 360
}
if self.heading > 360 {
self.heading -= 360
}
}