-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wkndrfile
956 lines (742 loc) · 24.2 KB
/
Wkndrfile
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
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
# vi:syntax=ruby
class ArmatureAnimation
def initialize
reset
end
def start(cx, cy, cz, tx, ty, tz)
reset
@max_time = 0.2379
@cx = cx
@cy = cy
@cz = cz
@tx = tx
@ty = ty
@tz = tz
@px = cx
@py = cy
@pz = cz
@state = :started
#Wkndr.log! [:xstart, cx, cy, cz, tx, ty, tz]
end
def state
@state
end
def age
@current_time
end
def iterate(dt)
@current_time += dt
return if(self.state == :reset)
if self.state == :idling && @py < 0.0 && self.age > 1.0
reset
return
end
phase_percent = ((@current_time / @max_time) / 1.0)
#if phase_percent < 0.333
# in_thirds = (phase_percent / 0.333)
# @px = @cx
# @py = @cy - (in_thirds * ((@cy - 1.0)))
# @pz = @cz
# #Wkndr.log! [:downward, @py, phase_percent, in_thirds]
# @state = :downwards
#elsif phase_percent < 0.666
# in_thirds = ((phase_percent - 0.333) / 0.333)
# #@px = @cx - (in_thirds * (@cx - @tx))
# #@pz = @cz - (in_thirds * (@cz - @tz))
# @px = @cx - (in_thirds * (@cx - @tx))
# @pz = @cz - (in_thirds * (@cz - @tz))
# #Wkndr.log! [:across, phase_percent, in_thirds]
# @state = :across
#elsif phase_percent < 0.999
# in_thirds = ((phase_percent - 0.666) / 0.333)
# @px = @tx
# #@py = @ty # - (in_thirds * ((@ty - 1.0)))
# @py = (in_thirds * @ty)
# @pz = @tz
# #Wkndr.log! [:upwards, @py, phase_percent, in_thirds]
# @state = :upwards
###elsif phase_percent < 1.1
if phase_percent < 1.0
@px = @cx - (phase_percent * (@cx - @tx))
@py = @cy - (phase_percent * (@cy - @ty))
@pz = @cz - (phase_percent * (@cz - @tz))
else
@px = @tx
@py = @ty
@pz = @tz
@state = :idling
#else
# reset
end
end
def reset
@current_time = 0
@state = :reset
end
def output
return @px, @py, @pz
end
end
class ShapeProxy
def initialize(gl, batcher, count)
@count = count
@xhapes = []
@count.times { |i|
@xhapes << batcher.at(gl, i)
}
reset
end
def reset
@current_shape = 0
end
def deltap(*args)
@xhapes[@current_shape].deltap(*args)
end
def deltas(*args)
@xhapes[@current_shape].deltas(*args)
end
def deltar(*args)
@xhapes[@current_shape].deltar(*args)
end
def next
@current_shape += 1
end
def current_shape
@current_shape
end
def count
@count
end
end
class ExGameEngine
PRIMARY = 0x000000FF
def player_position
@player_position
end
def initialize(distance, maze_level, cube, shapes, batcher, shape_batchers, direction)
@distance = distance
#if maze_level < 1
# raise
## maze_level = 10
#end
#@anm = ArmatureAnimation.new
#(-1.0, 0.0, -1.0, 0.0, 0.0, 0.0)
@maze_level = maze_level
@players = {}
@cube = cube
@shapes = shapes
@batcher = batcher
@shape_batchers = shape_batchers
#@shaped = 0
@px = 0
@py = 0
@cpx = -1
@cpy = -1
@at_exit_time = 0.0
@floor_position = 0.125
@player_position = [0.0,@floor_position-0.025,0.0]
if direction == :level_down
@start_at_exit = true
elsif direction == :level_up
@player_position = [-0.40,@floor_position-0.025,0.0]
end
#@pressing = false
@player_velocity = [0.0, 0.0, 0.0]
# COLLISION detection
@top_left_min = [1.1, 1.1]
@top_left_max = [0.1, 0.1]
@top_right_min = [-0.1, 1.1]
@top_right_max = [-1.1, 0.1]
@bottom_left_min = [1.1, -0.1]
@bottom_left_max = [0.1, -1.1]
@bottom_right_min = [-0.1, -0.1]
@bottom_right_max = [-1.1, -1.1]
############fooo
@no_left_min = [1.1, 0.1]
@no_left_max = [0.1, -0.1]
@no_right_min = [-0.1, 0.1]
@no_right_max = [-1.1, -0.1]
@no_up_min = [0.1, 1.1]
@no_up_max = [-0.1, 0.1]
@no_down_min = [0.1, -0.1]
@no_down_max = [-0.1, -1.1]
## left to right
@lne_x1 = 0.0
@lne_y1 = -1.0
@lne_x2 = 0.0
@lne_y2 = 1.0
# up to down
@lin_x1 = -1.0
@lin_y1 = 0.0
@lin_x2 = 1.0
@lin_y2 = 0.0
# COLLISION detection
@maze_draw_distance = distance
#@cool_down = [99, 99]
@time_since_last_hop = 99
#@time_since_last_input = [99, 99]
@ticks = 0
@sent = 0
@player_min = [0, 0]
@player_max = [0, 0]
@anm = {}
@shapes.each { |k,v|
@anm[k] = []
#0.times {
# @anm[k] << ArmatureAnimation.new
#}
}
end
def player_position
@player_position
end
def player_speed
((@player_velocity[0].abs + @player_velocity[1].abs) * 0.5)
end
def self.process_time(gl, global_time, delta_time)
@camera.update(gl, global_time, delta_time, 2.0, 5.0, @game.player_position)
case @game.update(gl, global_time, delta_time)
when :level_up
@start_game_proc.call(@game.level + 1, :level_up)
when :level_down
@start_game_proc.call(@game.level - 1, :level_down)
end
@camera.target_fov = [[(@camera.target_fov || 40.0) + (@game.player_speed * 13.0 * delta_time) - (5.0 * delta_time), 40.0].max, 90.0].min
end
def self.draw_threed(gl)
@camera.lookat(gl, @game.player_position, @camera.target_fov || 40.0)
#(@game.level > 3) ? 100.0 : (@game.level * 20.0))
#@camera.lookat(gl, @game.player_position, 100.9)
#(@game.level > 3) ? 190.0 : (@game.level * 20.0))
@game.draw_threed(gl, @camera)
end
def self.draw_twod(gl)
@game.draw_twod(gl)
end
#(gl, distance, chic, shapes, @batche, shape_batchers)
def self.start(gl, distance, cube, shapes, batcher, shape_batchers, starting_level = 3, direction = :level_up)
#Wkndr.log! [:prev, @start_game_proc]
@start_game_proc ||= Proc.new { |maze_level, direction_inner|
#Wkndr.log! [:after, maze_level, direction_inner]
begin
@camera = GameCamera.new(2.0, 1.3)
@game = self.new(distance, maze_level, cube, shapes, batcher, shape_batchers, direction_inner)
#Wkndr.log! ["maze_for_lcoation", $HEX]
gl.emit({"maze_for_location" => {"hex" => $HEX, "maze_id" => @game.level, "location" => @game.player_position, "distance" => distance}})
rescue => wtf
Wkndr.log! [:wtf, wtf]
end
#Wkndr.log! [:after2, maze_level, direction_inner]
#if maze_level > 0
# Wkndr.log! [:mkmaze, @game.level]
# gl.emit({"mkmaze" => @game.level})
#end
}
#Wkndr.log! [@start_game_proc, starting_level, direction]
@start_game_proc.call(starting_level, direction)
end
def self.event(channel, msg)
if @game
case channel
#when "spawn"
# @game.spawn!(msg)
when "position"
@game.track_other_players!(msg)
when "chunk_msg"
#Wkndr.log! [:chu, msg]
@game.load_maze!(*msg)
end
end
end
def level
@maze_level
end
def load_maze!(hex, l, s, e, flatb)
@ach ||= {}
@cch ||= {}
@last_xyz ||= []
#Wkndr.log! [:load_mz, hex, $HEX]
return if hex != $HEX
if @maze_level == l
@maze_s = s
@maze_exit = e
@maze_entrance = [-1, 0]
@maze ||= {}
new_keys = flatb.keys.collect { |c| h = c.inspect; @cch[h] = c; h }
new_xyz = new_keys - @last_xyz
old_xyz = @last_xyz - new_keys
@last_xyz = new_keys
new_xyz.each { |xxyy_s|
xxyy = @cch[xxyy_s]
xx, yy = *xxyy
@maze[xx] ||= {}
#if !@got_spawn && xx == 0 && yy == 0 && @maze[xx][yy] == nil
# @got_spawn = true
#end
@maze[xx][yy] = b = flatb[xxyy]
#theta = Math.atan2(@player_position[2], @player_position[0]) - Math.atan2(yy.to_f, xx.to_f)
distance = [xx.to_f - @player_position[0], yy.to_f - @player_position[2]]
#norm = Math.sqrt(distance[0] ** 2 + distance[1] ** 2)
direction = [distance[0], distance[1]]
rx = @player_position[0] + (3.79 * direction[0])
ry = @player_position[2] + (3.79 * direction[1])
started = false
if @ach[xxyy] == nil
@anm[b].sort_by { |aa|
-aa.age
}.each { |anm|
if anm.state == :reset || (anm.output[1] < -0.0 && anm.state == :idling)
@ach[xxyy] = anm
if xx == 0 && yy == 0
anm.start(xx, -10.0, yy, xx, 0.0, yy)
else
anm.start(rx, -1.0, ry, xx, 0.0, yy)
end
started = true
break
end
}
if !started
extra_buffer = ArmatureAnimation.new
@anm[b] << extra_buffer
@ach[xxyy] = extra_buffer
if xx == 0 && yy == 0
extra_buffer.start(xx, -10.0, yy, xx, 0.0, yy)
else
extra_buffer.start(rx, -1.0, ry, xx, 0.0, yy)
end
end
end
}
old_xyz.each { |xxyy_s|
xxyy = @cch[xxyy_s]
oxx, oyy = *xxyy
if anm = @ach[xxyy]
@ach.delete(xxyy)
odistance = [oxx.to_f - @player_position[0], oyy.to_f - @player_position[2]]
odirection = [odistance[0], odistance[1]]
orx = oxx + (3.79 * odirection[0])
ory = oyy + (3.79 * odirection[1])
if oxx == 0 && oyy == 0 #NOTE: special case for 0,0
anm.start(oxx, 0.0, oyy, oxx, -10.0, oyy)
else
anm.start(*anm.output, orx, -1.0, ory)
end
end
}
if @start_at_exit
@start_at_exit = false
@player_position = [@maze_exit[0] - 0.60,@floor_position-0.025, @maze_exit[1]]
end
end
end
def update(gl, global_time, delta_time)
#mx, my, l = nil
#gl.mousep { |xyl|
# mx, my, l = *xyl
#}
@anm.each { |b, anms|
anms.each { |anm| anm.iterate(delta_time) }
}
@last_delta_time = delta_time
@last_global_time = global_time
@ticks += 1
#@shaped = (global_time * 0.1).to_i % 15
#px = py = nx = ny = 0
#got_lr = got_ud = false
#no_bounce_reset = 0
#allow_up = false
#allow_down = false
#allow_left = false
#allow_right = false
arrow_keys = gl.keyspressed(KEY_W, KEY_A, KEY_S, KEY_D, KEY_UP, KEY_DOWN)
speed = 9.711 #10.357
friction = 4.7911 #3.597
rfx = 0.999
rfy = 0.999
this_direction = speed
intended_forces = [0, 0]
had_pressed = false
arrow_keys.each do |arrow_key|
case arrow_key
when KEY_W
had_pressed = true
intended_forces[1] = this_direction
when KEY_S
had_pressed = true
intended_forces[1] = -this_direction
when KEY_A
had_pressed = true
intended_forces[0] = this_direction
when KEY_D
had_pressed = true
intended_forces[0] = -this_direction
end
end
nx = @player_position[0] + (@player_velocity[0] * delta_time)
ny = @player_position[2] + (@player_velocity[2] * delta_time)
@player_velocity[0] += ((intended_forces[0] * 1.0) - (@player_velocity[0] * friction)) * delta_time
@player_velocity[2] += ((intended_forces[1] * 1.0) - (@player_velocity[2] * friction)) * delta_time
px = @player_position[0].round
py = @player_position[2].round
maze_current = [px, py]
##NOTE: maze exit code
if @maze_level > 0
if @maze_exit == maze_current
@at_exit_time += delta_time
if @at_exit_time > 0.0
return :level_up
end
elsif @maze_entrance == maze_current
@at_exit_time += delta_time
if @at_exit_time > 0.0
return :level_down
end
else
@at_exit_time = 0.0
end
end
if false
#DEBUG physics
@player_position[0] = nx
@player_position[2] = ny
#DEBUG physics
else
### SIMPLE COLLISION ###########################333
#TODO: make this a function, send all player movement through it
at_left_right_limit = nil
at_up_down_limit = nil
allow_up = false
allow_down = false
allow_left = false
allow_right = false
bounced = false
player_at_shape = false
if @maze
if px >= 0 && px < @maze_s && py >= 0 && py < @maze_s
if @maze[px.to_i] && @maze[px.to_i][py.to_i]
player_at_shape = (@maze[px.to_i][py.to_i] & PRIMARY)
end
end
end
case player_at_shape
when 15 # 0
allow_up = allow_down = allow_left = allow_right = true
when 13
allow_down = allow_left = allow_right = true
when 14
allow_up = allow_left = allow_right = true
when 7
allow_up = allow_down = allow_left = true
when 11
allow_up = allow_down = allow_right = true
when 8
allow_right = true
when 4
allow_left = true
when 2
allow_up = true
when 1
allow_down = true
when 3
allow_down = allow_up = true
#TODO
#includes left right crossing bits
#TODO
when 12 # IS REALLY left-right from maze
allow_left = allow_right = true
when 6
allow_up = allow_left = true
when 5
allow_down = allow_left = true
when 9
allow_down = allow_right = true
when 10
allow_up = allow_right = true
end
at_left_right_limit = ((nx - px))
at_up_down_limit = ((ny - py))
@player_min[0] = at_left_right_limit + 0.05
@player_min[1] = at_up_down_limit + 0.05
@player_max[0] = at_left_right_limit - 0.05
@player_max[1] = at_up_down_limit - 0.05
bounced = false
if ab = AABB.test(@top_left_min, @top_left_max, @player_min, @player_max)
bounced = ab
end
if ab = AABB.test(@bottom_left_min, @bottom_left_max, @player_min, @player_max)
bounced = ab
end
if ab = AABB.test(@bottom_right_min, @bottom_right_max, @player_min, @player_max)
bounced = ab
end
if ab = AABB.test(@top_right_min, @top_right_max, @player_min, @player_max)
bounced = ab
end
if !allow_left && ab = AABB.test(@no_left_min, @no_left_max, @player_min, @player_max)
bounced = ab
end
if !allow_right && ab = AABB.test(@no_right_min, @no_right_max, @player_min, @player_max)
bounced = ab
end
if !allow_up && ab = AABB.test(@no_up_min, @no_up_max, @player_min, @player_max)
bounced = ab
end
if !allow_down && ab = AABB.test(@no_down_min, @no_down_max, @player_min, @player_max)
bounced = ab
end
if !player_at_shape
@player_velocity[0] = -@player_velocity[0]
@player_velocity[2] = -@player_velocity[2]
@player_position[0] += @player_velocity[0] * delta_time
@player_position[2] += @player_velocity[2] * delta_time
else
if bounced
if bounced == :y
line_x1, line_y1, line_x2, line_y2 = @lne_x1, @lne_y1, @lne_x2, @lne_y2
end
if bounced == :x
line_x1, line_y1, line_x2, line_y2 = @lin_x1, @lin_y1, @lin_x2, @lin_y2
end
normalY = line_x2 - line_x1
normalX = line_y1 - line_y2
normalLength = Math.sqrt(normalX * normalX + normalY * normalY)
normalX = normalX / normalLength
normalY = normalY / normalLength
rayTipX = @player_velocity[0]
rayTipY = @player_velocity[2]
rayX = rayTipX
rayY = rayTipY
dotProduct = (rayX * normalX) + (rayY * normalY)
dotNormalX = dotProduct * normalX
dotNormalY = dotProduct * normalY
reflectedRayTipX = rayTipX - (dotNormalX * 2)
reflectedRayTipY = rayTipY - (dotNormalY * 2)
@player_velocity[0] = ((reflectedRayTipX * rfx) + (0.0))
@player_velocity[2] = ((reflectedRayTipY * rfy) + (0.0))
@player_velocity[0] = 0.799 * @player_velocity[0] + (((Math.rand * 0.33)) * -dotNormalX)
@player_velocity[2] = 0.799 * @player_velocity[2] + (((Math.rand * 0.33)) * -dotNormalY)
#@player_velocity[0] = 0.499 * @player_velocity[0] + (((Math.rand * 0.33)) * -dotNormalX)
#@player_velocity[2] = 0.499 * @player_velocity[2] + (((Math.rand * 0.33)) * -dotNormalY)
else
@player_position[0] = nx
@player_position[2] = ny
end
end
### SIMPLE COLLISION ###########################333
end
### MAZE LOADING ###
need_new_maze = false
if px != @cpx
@cpx = px
need_new_maze = true
end
if py != @cpy
@cpy = py
need_new_maze = true
end
if need_new_maze
gl.emit({"maze_for_location" => {"hex" => $HEX, "maze_id" => self.level, "location" => @player_position, "distance" => @distance}})
end
@px = px
@py = py
### MULTIPLAYER ###
@players.each { |key, rpv|
player_position, player_velocity, xintended_forces = *rpv
npx = player_position[0] + (player_velocity[0] * delta_time)
npy = player_position[2] + (player_velocity[2] * delta_time)
player_velocity[0] += ((xintended_forces[0] * 1.0) - (player_velocity[0] * (friction * 1.79))) * delta_time
player_velocity[2] += ((xintended_forces[1] * 1.0) - (player_velocity[2] * (friction * 1.79))) * delta_time
player_position[0] = npx
player_position[2] = npy
}
hop_timeout = 0.333
@time_since_last_hop += delta_time
if bounced || @time_since_last_hop > hop_timeout || ((had_pressed) && @time_since_last_hop > (hop_timeout * 0.5))
@time_since_last_hop = 0
gl.emit({"position" => {$HEX => [@maze_level, @player_position, @player_velocity, intended_forces]}})
@sent += 1
end
:keep_running
end
def draw_threed(gl, camera)
@camera_angle = camera.angle
#@shapes.each { |i, shape|
# shape.reset
#}
#Simple draw bits
#if @maze_level > 0
# if @maze && @px && @py
# ((@px-(@maze_draw_distance))..(@px+@maze_draw_distance)).each do |x|
# ((@py-(@maze_draw_distance))..(@py+@maze_draw_distance)).each do |y|
# if x>=0 && x<@maze_s && y>=0 && y<@maze_s
# if @maze[x] && @maze[x][y]
# cell = @maze[x][y]
# unless cell == 0
# primary = (cell & PRIMARY)
# if shape = @shapes[primary]
# shape.deltar(0.0, 1.0, 0.0, 0.0)
# shape.deltap(x, 0, y)
# shape.deltas(1.0, 1.0, 1.0)
# #shape.next
# shape.draw(false)
# end
# end
# end
# end
# end
# end
# end
#end
@anm.each { |b, anms|
shape = @shapes[b]
anms.each { |anm|
if anm.state != :reset
shape.deltar(0.0, 1.0, 0.0, 0.0)
shape.deltap(*anm.output)
shape.deltas(1.0, 1.0, 1.0)
#shape.next
shape.draw(false)
end
}
}
#else
# ((@px-(@maze_draw_distance))..(@px+@maze_draw_distance)).each do |x|
# ((@py-(@maze_draw_distance))..(@py+@maze_draw_distance)).each do |y|
# shape = @shapes[0]
# shape.deltar(0.0, 1.0, 0.0, 0.0)
# shape.deltap(x, -0.125, y)
# shape.deltas(1.0, 1.0, 1.0)
# #shape.next
# shape.draw(false)
# end
# end
#end
#@shape_batchers.each { |i, batcher|
# batcher.draw(@shapes[i].current_shape)
#}
#@cube.reset
@cube.deltar(0.0, 1.0, 0.0, Math.atan2(@player_velocity[0], @player_velocity[2]) * (180.0/3.1457))
@cube.deltap(*@player_position)
@cube.deltas(0.125, 0.125, 0.125)
#@cube.next
@cube.draw(false)
#@batcher.draw(@cube.current_shape)
### MULTIPLAYER ###
@players.each { |key, rpv|
player_position, player_velocity = *rpv
@cube.deltar(0.0, 1.0, 0.0, (Math.atan2(player_velocity[0], player_velocity[2]) * (180.0/3.14)) + 0.0)
@cube.deltap(*player_position)
@cube.deltas(0.125, 0.125, 0.125)
#@cube.next
#@batcher.draw(@cube.current_shape)
@cube.draw(false)
}
end
def draw_twod(gl)
#gl.label(game_status)
end
def game_status
@maze_level.to_s + " | " +
#@ticks.to_s + " | " +
("%03.2f" % (1.0 / (@last_delta_time || 1.0))) + " | " +
("%04.1f" % (@last_global_time || 0.0))
#+ " | " +
#@sent.to_s + " | " +
#@pressing.to_s + " | " +
#("%04.1f" % @camera_angle)
end
def track_other_players!(msg)
player_updated = msg.keys
player_updated.each { |player|
next if player == $HEX
maze_level, player_position, player_velocity, intended_forces = msg[player]
if @maze_level == maze_level
@players.merge!({player => [player_position, player_velocity, intended_forces]})
end
}
end
end
Wkndr.nonce("chicken") {
Wkndr.client_side("chicken") { |gl|
gl.open_default_view!
distance = 4
a = (((distance) * 2) + 1)
b = a * a
store = {}
chicken_model = Model.new(gl, "resources/chicken.glb", 0.125)
@batcher = CubicBatchingSystem.new(store, chicken_model, 32)
#@proxy = ShapeProxy.new(gl, @batcher, 32)
shape_batchers = {}
shapes = {}
16.times { |i|
shape_file = "resources/maze-#{i}.glb"
m = Model.new(gl, shape_file, 1.0)
batcher = CubicBatchingSystem.new(@store, m, b)
#shapes[i] = ShapeProxy.new(gl, batcher, b)
shape_batchers[i] = batcher
shapes[i] = m
}
ExGameEngine.start(gl, distance, chicken_model, shapes, @batcher, shape_batchers)
}
}
=begin
world {
gravity
// This function sets the velocity that interpenetrating objects will separate at. The default value is infinity.
dWorldSetContactMaxCorrectingVel(World, 0.9);
// This function sets the depth of the surface layer around the world objects. Contacts are allowed to sink into
// each other up to this depth. Setting it to a small value reduces the amount of jittering between contacting
// objects, the default value is 0.
dWorldSetContactSurfaceLayer(World, 0.001);
// To save some CPU time we set the auto disable flag to 1. This means that objects that have come to rest (based
// on their current linear and angular velocity) will no longer participate in the simulation, unless acted upon
// by a moving object. If you do not want to use this feature then set the flag to 0. You can also manually enable
// or disable objects using dBodyEnable and dBodyDisable, see the docs for more info on this.
dWorldSetAutoDisableFlag(World, 1);
space {
object {
body
Object.Body = dBodyCreate(World);
// Next we set the position of the new body
dBodySetPosition(Object.Body, 0, 10, -5);
//// At this point we could add our own user data using dBodySetData but in this example it isn't used.
//size_t i = 0;
//dBodySetData(Object.Body, (void*)i);
geometry {
// Here we create the actual geom object using dCreateBox. Note that this also adds the geom to our
// collision space and sets the size of the geom to that of our box mass.
Object.Geom[0] = dCreateBox(Space, sides[0], sides[1], sides[2]);
// And lastly we want to associate the body with the geom using dGeomSetBody. Setting a body on a geom automatically
// combines the position vector and rotation matrix of the body and geom so that setting the position or orientation
// of one will set the value for both objects. The ODE docs have a lot more to say about the geom functions.
dGeomSetBody(Object.Geom[0], Object.Body);
}
}
object {
}
plane
}
}
world {
space {
tiles(*(0..16))
}
server-size {
dSpaceCollide(Space, 0, &nearCallback);
// Now we advance the simulation by calling dWorldQuickStep. This is a faster version of dWorldStep but it is also
// slightly less accurate. As well as the World object ID we also pass a step size value. In each step the simulation
// is updated by a certain number of smaller steps or iterations. The default number of iterations is 20 but you can
// change this by calling dWorldSetQuickStepNumIterations.
dWorldQuickStep(World, 0.05);
// Remove all temporary collision joints now that the world has been stepped
dJointGroupEmpty(contactgroup);
}
=end
Wkndr.run(ExGameEngine)
=begin
maze_for_location
maze_at_location
fires when near border between chunks
proximity to next chunk of world
=end