-
Notifications
You must be signed in to change notification settings - Fork 28
/
level.go
784 lines (651 loc) · 17.7 KB
/
level.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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
// Copyright 2017 Daniel Salvadori. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/g3n/engine/core"
"github.com/g3n/engine/light"
"github.com/g3n/engine/math32"
"github.com/g3n/engine/window"
"strings"
)
type CELL_TYPE string
const (
START CELL_TYPE = "s"
BLOCK CELL_TYPE = "]"
BOX CELL_TYPE = "x"
PAD CELL_TYPE = "o"
ELEVATOR CELL_TYPE = "e"
ELEVATOR_SHAFT CELL_TYPE = "-"
NONE CELL_TYPE = "."
)
type GridCell struct {
loc GridLoc
obj IMapObj
}
type GridLoc struct {
z, x, y int
}
func (l *GridLoc) Equals(v math32.Vector3) bool {
return l.z == int(v.Z) && l.x == int(v.X) && l.y == int(v.Y)
}
func (l *GridLoc) Vec3() *math32.Vector3 {
return math32.NewVector3(float32(l.x), float32(l.y), float32(l.z))
}
// LevelData contains all the logical information about a level
type LevelData struct {
grid [][][]GridCell
gopherInit GridLoc
boxesInit []GridLoc
pads []GridLoc
center math32.Vector3
}
func (ld *LevelData) Get(loc GridLoc) IMapObj {
return ld.grid[loc.z][loc.x][loc.y].obj
}
func (ld *LevelData) Set(loc GridLoc, gc IMapObj) {
ld.grid[loc.z][loc.x][loc.y].obj = gc
}
func (ld *LevelData) initLoc(loc GridLoc) {
ld.grid[loc.z][loc.x][loc.y].loc = loc
}
func (ld *LevelData) IsPad(pl GridLoc) bool {
for _, a := range ld.pads {
if a == pl {
return true
}
}
return false
}
func ParseLevel(data string) (*LevelData, error) {
ld := new(LevelData)
// Pad row-wise
rows := strings.Split(data, "\n")
for i, row := range rows {
rows[i] = ". " + row + " ."
}
// Pad column-wise
ncols := len(strings.Fields(rows[0]))
padding_row := strings.Repeat(". ", ncols)
rows = append([]string{padding_row}, rows...)
rows = append(rows, padding_row)
nrows := len(rows)
// Calculate max number of floors
cells := strings.Fields(data)
nfloors := 1
for _, c := range cells {
if len(c) > nfloors {
nfloors = len(c)
}
}
ADD_TO_NFLOORS := 2
nfloors += ADD_TO_NFLOORS // necessary
// Initialize slices
ld.grid = make([][][]GridCell, nrows)
for i, _ := range ld.grid {
ld.grid[i] = make([][]GridCell, ncols)
for j, _ := range ld.grid[i] {
ld.grid[i][j] = make([]GridCell, nfloors)
}
}
// Calculate center of level
ld.center.SetZ(float32(nrows)/2 - 0.5)
ld.center.SetY(float32(nfloors-ADD_TO_NFLOORS)/2 - 0.5)
ld.center.SetX(float32(ncols)/2 - 0.5)
for i, row := range rows {
cells := strings.Fields(row)
for j, cell := range cells {
for k, c := range cell {
loc := GridLoc{i, j, k}
ld.initLoc(loc)
cc := CELL_TYPE(c)
if cc != NONE {
switch cc {
case START:
ld.gopherInit = loc
ld.Set(loc, NewGopher(loc))
case BLOCK:
ld.Set(loc, NewBlock(loc))
case BOX:
box := NewBox(loc)
ld.boxesInit = append(ld.boxesInit, loc)
ld.Set(loc, box)
case PAD:
ld.pads = append(ld.pads, loc)
ld.Set(loc, NewPad(loc))
case ELEVATOR:
// Calculate number of floors
var high int
for high = k; (high+1) < len(cell) && string(cell[high+1]) == string(ELEVATOR_SHAFT); high++ {
}
elev := NewElevator(loc, k, high)
ld.Set(loc, elev)
}
}
}
}
}
return ld, nil
}
// Level stores all the operational data for a level
type Level struct {
game *Gokoban
scene *core.Node
data *LevelData
style *LevelStyle
gopher *Gopher
boxes []*Box
elevators []*Elevator
gopherNodeTranslate *core.Node
gopherNodeRotate *core.Node
toAnimate []*Animation
animating bool
resetAnim bool
}
// NewLevel returns a pointer to a new Level object
func NewLevel(g *Gokoban, ld *LevelData, ls *LevelStyle) *Level {
l := new(Level)
l.game = g
l.data = ld
l.style = ls
l.animating = false
l.scene = core.NewNode()
l.scene.SetPosition(-ld.center.X, -ld.center.Y, -ld.center.Z)
l.gopherNodeTranslate = core.NewNode()
l.scene.Add(l.gopherNodeTranslate)
l.gopherNodeRotate = core.NewNode()
l.gopherNodeTranslate.Add(l.gopherNodeRotate)
log.Debug("Starting NewLevel loop")
for i, row := range ld.grid {
for j, cell := range row {
for k, c := range cell {
if c.obj != nil {
switch obj := c.obj.(type) {
case *Gopher:
l.gopher = obj
l.gopherNodeTranslate.SetPositionVec(c.loc.Vec3())
obj.SetNode(l.gopherNodeTranslate)
case *Block:
mesh := ls.makeBlock()
obj.SetMesh(mesh)
l.scene.Add(mesh)
case *Box:
l.boxes = append(l.boxes, obj)
mesh := ls.makeRedBox()
light := light.NewPoint(l.style.boxLightColorOff, 1.0)
obj.SetMeshAndLight(mesh, light)
l.scene.Add(mesh)
case *Pad:
light := light.NewPoint(&math32.Color{1, 1, 0}, 1.0)
padPos := c.loc.Vec3()
//padPos.Y -= 0.2
light.SetPositionVec(padPos)
l.scene.Add(light)
// Remove pad as logical object from map
ld.Set(c.loc, nil)
// if block below, change texture
if b, ok := ld.grid[i][j][k-1].obj.(*Block); ok {
b.mesh.AddGroupMaterial(ls.padMaterial, 2)
a := 2
if a > 0 {
}
}
// TODO (maybe)
// else if blocks around, use texture on all existing sides
// else if no blocks around create transparent small cube mesh indicating objective
case *Elevator:
l.elevators = append(l.elevators, obj)
mesh := ls.makeElevator()
obj.SetMesh(mesh)
l.scene.Add(mesh)
light := light.NewPoint(&math32.Color{0, 0, 1}, 1.0)
mesh.Add(light)
}
}
}
}
}
// Add a single point light above the level
light := light.NewPoint(&math32.Color{1, 1, 1}, 8.0)
light.SetPosition(l.data.center.X, l.data.center.Y*2+2, l.data.center.Z)
l.scene.Add(light)
return l
}
// Restart restarts the level
func (l *Level) Restart(playSound bool) {
log.Debug("Restart")
l.animating = false
l.resetAnim = true
l.game.ui.restartButton.SetEnabled(false)
// Stop all sounds
l.game.audio.gopherWalk.Stop()
l.game.audio.gopherBump.Stop()
l.game.audio.gopherFallEnd.Stop()
l.game.audio.gopherFallStart.Stop()
l.game.audio.boxPush.Stop()
l.game.audio.boxOnPad.Stop()
l.game.audio.boxOffPad.Stop()
l.game.audio.boxFallEnd.Stop()
l.game.audio.boxFallStart.Stop()
l.game.audio.elevatorUp.Stop()
l.game.audio.elevatorDown.Stop()
l.game.audio.levelDone.Stop()
l.game.audio.levelFail.Stop()
if playSound && l.game.steps != 0 {
l.game.audio.levelRestart.Play()
}
l.game.steps = 0
l.SetPosition(l.gopher, l.data.gopherInit)
for i, box := range l.boxes {
l.boxOffPad(box, false)
l.SetPosition(box, l.data.boxesInit[i])
}
for _, elev := range l.elevators {
lowLoc := elev.Location()
lowLoc.y = elev.low
l.SetPosition(elev, lowLoc)
}
}
// SetPosition moves an object in the data grid along with its node to the desired position
func (l *Level) SetPosition(obj IMapObj, dest GridLoc) {
l.data.Set(obj.Location(), nil)
obj.SetLocation(dest)
l.data.Set(obj.Location(), obj)
obj.GetNode().SetPositionVec(dest.Vec3())
}
// onKey handles keyboard events for the level
func (l *Level) onKey(evname string, ev interface{}) {
if !l.game.gopherLocked {
xd := int(l.game.stepDelta.X)
zd := int(l.game.stepDelta.Y)
kev := ev.(*window.KeyEvent)
switch kev.Key {
case window.KeyW, window.KeyUp:
log.Debug("Up")
l.step(zd, xd)
case window.KeyS, window.KeyDown:
log.Debug("Down")
l.step(-zd, -xd)
case window.KeyA, window.KeyLeft:
log.Debug("Left")
l.step(-xd, zd)
case window.KeyD, window.KeyRight:
log.Debug("Right")
l.step(xd, -zd)
}
}
}
// Update updates all ongoing animations for the level
func (l *Level) Update(timeDelta float64) {
if l.resetAnim {
l.resetAnim = false
l.toAnimate = make([]*Animation, 0)
}
newToAnimate := l.toAnimate
l.toAnimate = make([]*Animation, 0)
for _, anim := range newToAnimate {
if !l.resetAnim {
still_animating := anim.Update(timeDelta)
if still_animating {
// copy to new slice
l.toAnimate = append(l.toAnimate, anim)
}
}
}
}
// animate queues a movement animation for an object and also moves the object in the grid
func (l *Level) animate(obj IMapObj, dest GridLoc, delete bool, cb func(interface{})) {
log.Debug("Queueing animation %+v %+v", obj, dest)
// Queue animation
anim := NewAnimation(obj.GetNode(), dest.Vec3(), cb, obj)
l.toAnimate = append(l.toAnimate, anim)
// Move in matrix
oloc := obj.Location()
l.data.Set(oloc, nil)
if !delete {
l.data.Set(dest, obj)
obj.SetLocation(dest)
}
}
// getCellRelativeToLoc returns the object and location
// relative to the provided location using the provided deltas
func (l *Level) getCellRelativeToLoc(p GridLoc, zd, xd, yd int) (IMapObj, GridLoc) {
cell_loc := p
cell_loc.x += xd
cell_loc.y += yd
cell_loc.z += zd
return l.data.Get(cell_loc), cell_loc
}
// getCellRelativeTo returns the object and location
// relative to the location of the provided object using the provided deltas
func (l *Level) getCellRelativeTo(c IMapObj, zd, xd, yd int) (IMapObj, GridLoc) {
cell_loc := c.Location()
cell_loc.x += xd
cell_loc.y += yd
cell_loc.z += zd
return l.data.Get(cell_loc), cell_loc
}
// step processes a gopher step to the provided direction
func (l *Level) step(zd, xd int) {
// Only process step if not already animating another
// TODO else - add to queue?
if !l.animating {
l.game.ui.restartButton.SetEnabled(true)
// Rotate gopher
if xd > 0 {
l.gopherNodeRotate.SetRotationY(0)
}
if xd < 0 {
l.gopherNodeRotate.SetRotationY(math32.Pi)
}
if zd > 0 {
l.gopherNodeRotate.SetRotationY(math32.Pi * 3 / 2)
}
if zd < 0 {
l.gopherNodeRotate.SetRotationY(math32.Pi / 2)
}
// Check if can move
c, cl := l.getCellRelativeTo(l.gopher, zd, xd, 0)
if c != nil {
if c.IsPushable() {
// Check if box can be pushed (if there is space behind it)
cn, cnl := l.getCellRelativeTo(l.gopher, 2*zd, 2*xd, 0)
if cn == nil {
l.pushBox(c, cnl)
l.moveGopherTo(cl)
} else {
l.wallBump()
}
} else {
l.wallBump()
}
} else {
l.moveGopherTo(cl)
}
}
}
func (l *Level) wallBump() {
log.Debug("Hit wall")
l.game.audio.gopherBump.Play()
}
// moveGopherTo moves the gopher and sets up the appropriate callbacks
func (l *Level) moveGopherTo(pos GridLoc) {
l.game.steps++
l.animating = true
floor, _ := l.getCellRelativeToLoc(pos, 0, 0, -1)
if floor == nil {
l.game.audio.gopherFallStart.Play()
} else {
l.game.audio.gopherWalk.Play()
}
oldloc := l.gopher.Location()
l.animate(l.gopher, pos, false, func(obj interface{}) {
l.moveAwayFrom(oldloc)
l.afterMove(obj)
})
}
// levelComplete returns true if all the boxes are on pads
func (l *Level) levelComplete() bool {
for _, p := range l.data.pads {
if _, ok := l.data.Get(p).(*Box); !ok {
return false
}
}
return true
}
// boxOnPad handles what happens when a box enters a pad
func (l *Level) boxOnPad(box *Box, playSound bool) {
log.Debug("Box on pad")
if box.light.Color() == *l.style.boxLightColorOff {
if playSound {
box.Add(l.game.audio.boxOnPad)
l.game.audio.boxOnPad.Play()
}
log.Debug("...replacing mesh and changing light color")
l.scene.Remove(box.mesh)
newMesh := l.style.makeGreenBox()
box.light.SetColor(l.style.boxLightColorOn)
box.SetMeshAndLight(newMesh, box.light)
l.scene.Add(newMesh)
if l.levelComplete() {
l.game.audio.levelDone.Play()
l.game.LevelComplete()
}
}
}
// boxOffPad handles what happens when a box leaves a pad
func (l *Level) boxOffPad(box *Box, playSound bool) {
log.Debug("Box off pad")
if box.light.Color() == *l.style.boxLightColorOn {
if playSound {
box.Add(l.game.audio.boxOffPad)
l.game.audio.boxOffPad.Play()
}
log.Debug("...replacing mesh and changing light color")
l.scene.Remove(box.mesh)
newMesh := l.style.makeRedBox()
box.light.SetColor(l.style.boxLightColorOff)
box.SetMeshAndLight(newMesh, box.light)
l.scene.Add(newMesh)
}
}
// afterFallSound
func (l *Level) afterFallSound(o interface{}, numFloors int) {
obj := o.(IMapObj)
floor, _ := l.getCellRelativeTo(obj, 0, 0, -1)
if _, objIsGopher := obj.(*Gopher); objIsGopher && numFloors >= 1 {
l.game.audio.gopherFallEnd.Play()
} else if box, objIsBox := obj.(*Box); objIsBox {
if _, floorIsGopher := floor.(*Gopher); floorIsGopher {
l.game.audio.gopherHurt.Play()
} else { //if !l.data.IsPad(obj.Location()) {
box.Add(l.game.audio.boxFallEnd)
l.game.audio.boxFallEnd.Play()
}
}
}
// afterNewFloor
func (l *Level) afterNewFloor(obj interface{}) {
log.Debug("afterNewFloor")
l.animating = false
o := obj.(IMapObj)
box, isBox := obj.(*Box)
floor, _ := l.getCellRelativeTo(o, 0, 0, -1)
if elev, ok := floor.(*Elevator); ok {
l.elevate(elev)
} else if isBox && l.data.IsPad(box.loc) {
l.boxOnPad(box, true)
}
}
// fall
func (l *Level) fall(obj IMapObj, playSound bool) {
log.Debug("fall")
l.animating = true
if playSound {
if box, ok := obj.(*Box); ok {
box.Add(l.game.audio.boxFallStart)
l.game.audio.boxFallStart.Play()
}
}
var cb func(obj interface{})
posStart := obj.Location()
pfall := l.posAfterFallFrom(posStart)
floors := posStart.y - pfall.y
del := false
if pfall.y == 0 {
log.Debug("...out of game")
// If it's the gopher falling - lock it
if _, ok := obj.(*Gopher); ok {
l.game.gopherLocked = true
l.game.arrowNode.SetVisible(false)
}
del = true
pfall.y = -20
l.game.audio.levelFail.Play()
cb = func(obj interface{}) {
log.Debug("Done falling out of game")
l.game.RestartLevel(true)
}
} else {
log.Debug("...still in game")
cb = func(obj interface{}) {
log.Debug("Done falling in game")
if playSound {
l.afterFallSound(obj, floors)
}
l.afterNewFloor(obj)
}
}
l.animate(obj, pfall, del, cb)
}
func (l *Level) posAfterFallFrom(pos GridLoc) GridLoc {
pos.y--
for ; pos.y >= 0 && l.data.Get(pos) == nil; pos.y-- {
}
pos.y++
return pos
}
// afterMove
func (l *Level) afterMove(obj interface{}) {
log.Debug("afterMove")
l.animating = false
o := obj.(IMapObj)
floor, _ := l.getCellRelativeTo(o, 0, 0, -1)
if floor == nil {
l.fall(o, true)
} else {
l.afterNewFloor(o)
}
}
// pushBox
func (l *Level) pushBox(box IMapObj, dest GridLoc) {
log.Debug("pushBox")
box.GetNode().Add(l.game.audio.boxPush)
l.game.audio.boxPush.Play()
toMove := make([]IMapObj, 0)
toFall := make([]IMapObj, 0)
foundBarrier := false
// Check if leaving pad
if l.data.IsPad(box.Location()) && !l.data.IsPad(dest) {
boxObj := box.(*Box)
l.boxOffPad(boxObj, true)
}
// Iterate through piled boxes
for box != nil && box.IsPushable() {
if foundBarrier == false && l.data.Get(dest) == nil {
toMove = append(toMove, box)
} else {
foundBarrier = true
toFall = append(toFall, box)
}
// Update current box and destination
box, _ = l.getCellRelativeTo(box, 0, 0, 1)
dest.y++
}
// Move boxes toMove, adding a callback to the first one for boxes toFall
for i, box := range toMove {
cb := func(obj interface{}) {
l.afterMove(obj)
}
if i == 0 {
cb = func(obj interface{}) {
l.afterMove(obj)
for j, boxToFall := range toFall {
l.fall(boxToFall, j == 0) // only play sound for the first one
}
}
}
l.animate(box, GridLoc{dest.z, dest.x, box.Location().y}, false, cb)
}
}
// moveAwayFrom
func (l *Level) moveAwayFrom(pos GridLoc) {
log.Debug("moveAwayFrom %+v", pos)
floor, _ := l.getCellRelativeToLoc(pos, 0, 0, -1)
if elev, ok := floor.(*Elevator); ok {
log.Debug("Stepped out from elevator %+v", pos)
l.lowerElev(elev)
}
ceil, _ := l.getCellRelativeToLoc(pos, 0, 0, 1)
if ceil != nil {
if ceil.IsPushable() {
log.Debug("Stepped out from under box(es) %+v", pos)
box := ceil
for box != nil && box.IsPushable() {
box_above, _ := l.getCellRelativeTo(box, 0, 0, 1)
l.fall(box, true) // TODO only true for the first one
box = box_above
}
} else if elev, ok := ceil.(*Elevator); ok {
cargo := l.getCargo(elev)
if len(cargo) == 0 {
l.lowerElev(elev)
}
}
}
}
// lowerElev lowers the specified elevator as far as it can go
func (l *Level) lowerElev(elev *Elevator) {
log.Debug("lowerElev %+v", elev)
newloc := elev.loc
for newloc.y = elev.loc.y - 1; newloc.y >= elev.low && l.data.Get(newloc) == nil; newloc.y-- {
}
newloc.y++
if newloc.y != elev.loc.y {
log.Debug("Lowering elevator")
elev.Add(l.game.audio.elevatorDown)
l.game.audio.elevatorDown.Play()
l.animate(elev, newloc, false, func(obj interface{}) {
l.game.audio.elevatorDown.Stop()
})
}
}
// getCargo returns the list of objects on top of the specified elevator
func (l *Level) getCargo(elev *Elevator) []IMapObj {
cargo := make([]IMapObj, 0)
for y := 1; ; y++ {
c, _ := l.getCellRelativeTo(elev, 0, 0, y)
if c == nil || !c.IsPushable() {
break
} else {
cargo = append(cargo, c)
}
}
return cargo
}
// elevate moves elevator and cargo up as far as it can go
func (l *Level) elevate(elev *Elevator) {
log.Debug("elevate %+v", elev)
var spaces_above_cargo int
max_elevation := elev.high - elev.loc.y
if max_elevation > 0 {
elev.Add(l.game.audio.elevatorUp)
l.game.audio.elevatorUp.Play()
l.animating = true
cargo := l.getCargo(elev)
last := cargo[len(cargo)-1]
// Iterate above cargo, and calculate how many floors we can move up
for y := 1; spaces_above_cargo < max_elevation; y++ {
c, _ := l.getCellRelativeTo(last, 0, 0, y)
if c == nil {
spaces_above_cargo++
} else {
break
}
}
log.Debug("Elevating %v", spaces_above_cargo)
// Move elevator and cargo up (need to move highest/last things first)
for i := len(cargo) - 1; i >= 0; i-- {
c := cargo[i]
up := c.Location()
up.y += spaces_above_cargo
l.animate(c, up, false, nil)
}
up := elev.Location()
up.y += spaces_above_cargo
l.animate(elev, up, false, func(interface{}) {
l.game.audio.elevatorUp.Stop()
l.animating = false
})
}
}