-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInuhh.rb
2848 lines (2662 loc) · 120 KB
/
Inuhh.rb
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
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$LOAD_PATH << "."
require 'rubygems'
require 'gosu'
include Gosu
EDITOR = false
SHIPEDIA = false
# For future worlds
WORLD_6_ALLOWED = false
WORLD_6_DIALOG = "5 - Horror Island"
WORLD_6_U_DIALOG = "5 - ?????"
WORLD_7_ALLOWED = false
WORLD_7_DIALOG = "6 - ??????????"
module ZOrder
Background, Behind_Tiles, Tiles, Warps, Gems, Mud, Enemies, Player, Foreground, UI, UI_Extended = *0..10
end
require "lib/Level.rb"
class Residuum
attr_reader :x, :y
attr_accessor :counter
def initialize(x, y, counter, window, image)
@x,@y,@counter = x,y,counter
@image = image
end
def draw
@image.draw(@x, @y, ZOrder::Mud)
end
end
class Projectile < Entity
attr_reader :broken, :owner, :type, :x, :y, :vx, :vy
attr_accessor :damage
def initialize(type, x, y, vx, vy, ax, ay, owner, lifetime, damage, window, image, silent=false)
super()
@type = type
@xsize, @ysize = Projectiles::XSizes[type], Projectiles::YSizes[type]
@x, @y = x, y+2*@ysize
@vx, @vy = vx, vy
@ax, @ay = ax, ay
@ax0 = ax
@ay0 = ay
@owner = owner
@destruction = Projectiles::Destruction[type]
@drop = Projectiles::Drops[type]
@lifetime = lifetime
@damage = damage
@window = window
@map = @window.map
@image = image
if (@window.inuhh.x - @x).abs < 500 && (@window.inuhh.y - @y).abs < 400 && !silent then
@window.play_sound(Projectiles::Sounds[type], 1, 0.9+rand*0.2)
end
end
def break # Please do not use it private... causes are obvious. Rename could fix this.
return if @broken
@broken = true
@window.gems.push(Object_Datas::C_Index[@drop].new(@window.valimgs[@drop], @x, @y)) if @drop
end
def destroy
@drop = nil
@broken = true
end
def break_particle # Better use this
return if @broken
@broken = true
@window.gems.push(Object_Datas::C_Index[@drop].new(@window.valimgs[@drop], @x, @y)) if @drop
end
def check_enemies
@window.enemies.each do |e|
if @owner != Projectiles::ENEMY && Collider.test_collision(self, e) then
hit = e.at_shot(self)
dv = [@damage - e.defense, 0].max + Projectiles::Shi_Plus[@type]
dv = 0 if !hit
dv = 0 if e.bulletproof
dv = 0 if e.waterproof && @type == Projectiles::Water
if !e.waterproof || @type != Projectiles::Water then
#@x >= e.x ? e.force_knockback(-10-dv) : e.force_knockback(10+dv)
@vx > 0 ? e.force_knockback(10+dv) : e.force_knockback(-10-dv)
end
dv = e.reduction if e.reduction && dv > e.reduction
if e.invul == 0 then
e.damage(dv)
@window.messages.push([dv, e.x-e.xsize+10, e.y-e.ysize-30, 20, true, 2.0+(dv-1)/30.0, 2.0+(dv-1)/30.0, 0xff00ff00]) if (!e.waterproof || @type != Projectiles::Water)
end
@damage = 0
if @owner == Projectiles::INUHH then
if !e.living then
value = e.score
@window.messages.push([value, e.x-e.xsize, e.y-e.ysize, 100, true, 2.0+(value/50000.0), 2.0+(value/50000.0), 0xffffff00])
@window.inuhh.increase_stat(Stats::Score, value)
@window.play_sound("smash")
@window.residues.push(Residuum.new(e.x-e.xsize, e.y-2*e.ysize, (e.boss ? 200 : 50), @window, e.mud))
end
end
@broken = true if !@destruction || @damage == 0
end
end
end
def would_fit(offs_x, offs_y) # Automatically destroys projectiles and map tiles
expr = true
return would_fit_maxi(offs_x, offs_y) if @xsize >= 25 || @ysize >= 25
sx = @xsize
sy = @ysize
0.upto((@ysize/sy).floor) do |t|
((-@xsize/(2*sx))+1).floor.upto((@xsize/(2*sx)).floor) do |u|
edge_y = t == 0 ? 0 : 1
edge_x = 0
rx = @x + offs_x + sx - (@xsize>25 ? 25 : 0) + u*2*sx - edge_x
ry = @y + offs_y - 2*sy*(t) + edge_y
expr &&= !@map.solid?(rx, ry)
expr &&= !@map.solid?(rx+1, ry)
test_wall(rx, ry)
test_wall(rx+1, ry)
end
end
return expr
end
def would_fit_maxi(offs_x, offs_y)
# Check at the center/top and center/bottom for map collisions
expr = true
0.upto((@ysize/25).floor) do |t|
((-@xsize/50)+1).floor.upto((@xsize/50).floor) do |u|
edge_y = t == 0 ? 0 : 1
edge_x = 0
rx = @x + offs_x + 25 - (@xsize>25 ? 25 : 0) + u*50 - edge_x
ry = @y + offs_y - 50*(t) + edge_y
expr &&= !@map.solid?(rx, ry)
expr &&= !@map.solid?(rx - 49, ry)
test_wall(rx, ry)
test_wall(rx - 49, ry)
end
end
return expr
end
def test_wall(nx, ny)
if @map.solid?(nx, ny) then
if !@map.bulletproof(nx, ny) || @destruction then
@window.add_tile(nx, ny, nil)
@window.play_sound("detonation", 1, 1.3) if !@destruction || rand(100) == 0
@damage -= 1
end
break_particle if !@destruction || @damage == 0
end
end
def update
if @type == Projectiles::Homing then
@ax = (@window.inuhh.x < @x ? -1.0 : 1.0)*@ax0
@ay = (@window.inuhh.y < @y ? -1.0 : 1.0)*@ay0
end
@vx += @ax
@vy += @ay
if would_fit(@vx, @vy) then
@x += @vx
@y += @vy
end
@lifetime -= 1 if @lifetime
break_particle if @lifetime && @lifetime <= 0
break_particle if @damage <= 0
check_enemies
end
def draw
return if @broken
if @vx <= 0 then
offs_x = -@xsize
factor = 1.0
else
offs_x = @xsize
factor = -1.0
end
@image.draw(@x + offs_x - factor, @y - @ysize*2 + 1 - factor, ZOrder::Foreground, factor, 1.0)
end
end
# Player class.
class Inuhh < Entity
attr_reader :dir, :stats, :collectibles, :boosts, :riding_entity, :drunken, :item, :item_amount, :vy, :invincible, :inv_inv
def initialize(window, x, y, dir=nil)
super()
@x, @y = x, y
@xsize = 20
@ysize = 15
@gxsize = 25
@gysize = 25
@drunken = false
@collectibles = []
@stats = []
@boosts = []
@riding = false
@riding_entity = nil
@inv_inv = 0 # Invisible invincibility
@pushed_from_riding = 0
@flying = false
reset_stat(Stats::Score, 0)
reset_stat(Stats::Strength, 1)
reset_stat(Stats::Defense, 0)
reset_stat(Stats::Speed, 0)
reset_boost(Stats::Strength, 0, 0)
reset_boost(Stats::Speed, 0, 0)
reset_collectible(Objects::Coin, 0)
reset_collectible(Objects::Gem, 0)
reset_collectible(Objects::Shi_Coin, 0)
reset_collectible(Objects::Fruit, 0)
@dir = (dir ? (:right) : (:left))
@invincible = 0
@water_delay = 0
@water_flag = false
@water_boost = nil
@combo = 0
@item = nil
@item_amount = 0
@ice = false
if Difficulty.get > Difficulty::NORMAL then
reset_stat(Stats::Max_Lifes, 3)
reset_stat(Stats::Max_Energy, 3)
elsif Difficulty.get > Difficulty::EASY then
reset_stat(Stats::Max_Lifes, 4)
reset_stat(Stats::Max_Energy, 3)
else
reset_stat(Stats::Max_Lifes, 5)
reset_stat(Stats::Max_Energy, 4)
end
full_heal
@vy = 0 # Vertical velocity
@vx = 0
@jumping = 0
@running = false
@window = window
@map = window.map
# Load all animation frames
reset_images
# This always points to the frame that is currently drawn.
# This is set in update, and used in draw.
@cur_image = @standing
end
def reset_images
if Time.now.month == 12 && [24, 25, 26].index(Time.now.day) then
change_images("XMas")
elsif (Time.now.month == 12 && Time.now.day == 31) || (Time.now.month == 1 && Time.now.day == 1) then
change_images("Newyear")
else
@standing, @walk1, @walk2, @jump =
*Image.load_tiles(@window, Pics::Inuhh, 2*@gxsize, 2*@gysize, false)
end
end
def change_images(name)
@standing, @walk1, @walk2, @jump =
*Image.load_tiles(@window, Pics::Folder_Forms + "#{name}.png", 2*@gxsize, 2*@gysize, false)
end
def delete_items
@item = nil
@item_amount = 0
reset_images
end
def set_item(collectible, amount)
@item = collectible
@item_amount = amount
if @item.transform then
change_images(@item.transform)
else
reset_images
end
end
def add_item(collectible, amount)
if collectible.class != @item.class then
set_item(collectible, amount)
else
@item_amount += amount
end
end
def use_item
return if !@item
success = @item.use(@window, self)
if success then
@item_amount -= 1
if @item_amount <= 0 then
reset_images
@item = nil
end
end
end
def in_air
return false if @riding
return @jumping > 0 || @vy != 0 || @flying
end
def shift_up(value)
value.times do
if @map.solid?(@x, @y-50) then
damage(false)
else
@y -= 50
end
end
end
def update_timers
@boosts.each do |b|
if b then
b[1] -= 1
b[0] = 0 if b[1] < 0
b[2] = 0 if b[1] < 0
end
end
end
def toggle_fly
@flying = !@flying
end
def reset_collectible(nr, value)
@collectibles[nr] = value
end
def reset_stat(nr, value)
@stats[nr] = value
end
def reset_boost(nr, value, time)
@boosts[nr] = [value, time]
end
def pay_shi_coins(value)
@collectibles[Objects::Shi_Coin] -= value
end
def get_collectible(nr, amount)
@collectibles[nr] += amount
end
def increase_stat(nr, amount)
@stats[nr] += amount
@stats[Stats::Energy] = [@stats[Stats::Max_Energy], @stats[Stats::Energy]].min
if nr == Stats::Score && @window.minigame_flag then
@window.increase_minigame_score(amount)
end
end
def manipulate_energy(value)
@stats[Stats::Energy] = value
end
def damage(value)
if !value then
@stats[Stats::Energy] = 0
return
end
@stats[Stats::Energy] -= value
if @stats[Stats::Energy] < 0 then
@stats[Stats::Energy] = 0
end
if @stats[Stats::Energy] > 0 then
if value > 0 then
@window.play_sound("growl #{rand(4)+1}")
else
@window.play_sound("guard")
end
end
end
def lose_life
@stats[Stats::Lifes] -= 1
end
def suicide
@stats[Stats::Lifes] = 0
end
def boost(nr, amount, time)
@boosts[nr] = [amount, time, time]
end
def preset(collectibles, stats)
reset_stat(Stats::Score, stats[Stats::Score])
reset_stat(Stats::Max_Energy, stats[Stats::Max_Energy])
reset_stat(Stats::Max_Lifes, stats[Stats::Max_Lifes])
reset_stat(Stats::Strength, stats[Stats::Strength])
reset_stat(Stats::Defense, stats[Stats::Defense])
reset_stat(Stats::Lifes, [stats[Stats::Lifes],stats[Stats::Max_Lifes]].max)
reset_collectible(Objects::Coin, collectibles[Objects::Coin])
reset_collectible(Objects::Gem, collectibles[Objects::Gem])
reset_collectible(Objects::Shi_Coin, collectibles[Objects::Shi_Coin])
reset_collectible(Objects::Fruit, collectibles[Objects::Fruit])
end
def new_map(map)
@map = map
end
def draw
# Flip vertically when facing to the left.
if @dir == :left then
offs_x = -25
factor = 1.0
else
offs_x = 25
factor = -1.0
end
@cur_image.draw(@x + offs_x, @y - 49, ZOrder::Player, factor, 1.0, (@drunken ? 0xff33ff66 : 0xffffffff)) if @invincible%2==0
if @item then
@item.draw_in_inventory(@window, self)
end
end
# Could the object be placed at x + offs_x/y + offs_y without being stuck?
def would_fit(offs_x, offs_y)
return !@map.solid?(@x + offs_x + @xsize, @y + offs_y) && !@map.solid?(@x + offs_x + @xsize, @y + offs_y - 2*@ysize) && !@map.solid?(@x + offs_x - @xsize, @y + offs_y) && !@map.solid?(@x + offs_x - @xsize, @y + offs_y - 2*@ysize)
# Check at the center/top and center/bottom for map collisions
end
def make_drunk(value)
@drunken = value
end
def change_to_jump_img
@cur_image = @jump
end
def update(move_x)
@pushed_from_riding -= 1 if @pushed_from_riding > 0
if @map.water(@x, @y) && !@water_flag && @water_delay <= 0 then
@water_flag = true
@water_delay = 10
@window.play_sound("water")
end
if @map.poison(@x, @y) then
@drunken = 10 if !@drunken
@drunken += 2 if @drunken
@drunken = 2000 if @drunken && @drunken > 2000
elsif @map.water(@x, @y) && @drunken then
@drunken -= 4
end
@water_delay -= 1
update_timers
if @drunken then
move_x += (rand(15)-7)*(rand(4) == 0 ? 1 : 0)
@drunken -= 1
@drunken = false if @drunken <= 0
end
move_x /= (@water_boost ? 2.5/@water_boost : 2.5) if @map.water(@x, @y)
move_x *= 2 if @running
move_x *= (1.0+@boosts[Stats::Speed][0])
move_x = move_x.to_i
@invincible = [0, @invincible-1].max
@inv_inv = 0
# Select image depending on action
if (move_x == 0)
@cur_image = @standing
else
@cur_image = [@walk1, @walk2, @standing][(milliseconds / 175).floor % 3]
end
if (@vy < 0)
@cur_image = @jump
end
if would_fit((@dir == :left ? -1 : 1),0) && (@map.ice(@x - @xsize, @y + 1) || @map.ice(@x + @xsize, @y + 1)) then
@ice = true if !@ice
else
@ice = false
end
# Directional walking, horizontal movement
move_x = (@dir == :left ? -5 : 5) if @ice
if move_x > 0 then
@dir = :right
move_x.times { if would_fit(1, 0) then @x += 1 end }
end
if move_x < 0 then
@dir = :left
(-move_x).times { if would_fit(-1, 0) then @x -= 1 end }
end
# Acceleration/gravity
# By adding 1 each frame, and (ideally) adding vy to y, the player's
# jumping curve will be the parabole we want it to be.
@vy += 1
@vy = [@vy, 3].min if @map.water(@x, @y)
@vx -= (@vx == 0 ? 0 : (@vx/@vx.abs).floor)
# Vertical movement
if @vy > 0 then
@vy.to_i.times { if would_fit(0, 1) then @y += 1 else @vy = 0 end }
end
if @vy < 0 then
(-@vy).to_i.times { if would_fit(0, -1) then @y -= 1 else @vy = 0 end }
end
if @vx > 0 then
@vx.to_i.times { if would_fit(1, 0) then @x += 1 else @vx = 0 end }
end
if @vx < 0 then
(-@vx).to_i.times { if would_fit(-1, 0) then @x -= 1 else @vx = 0 end }
end
if !would_fit(0, 0) then # Kill Inuhh if stuck
Debug.output("Stuck")
damage(1000)
end
if @riding then
spd = (@riding_entity.speed*(@riding_entity.dir == :right ? 1 : -1)).to_i
grav = @riding_entity.vy.to_i
if would_fit(0, @riding_entity.y - 2*@riding_entity.ysize + 5 - @y) then
@y = @riding_entity.y - 2*@riding_entity.ysize + 5
else
@riding = false
@riding_entity = nil
end
@y = @y.to_i
if grav > 0 && @riding then
grav.times { if would_fit(0, 1) then @y += 1 else end }
end
if grav < 0 && @riding then
(-grav).times { if would_fit(0, -1) then @y -= 1 else end }
end
if spd > 0 && @riding then
spd.times { if would_fit(1, 0) then @x += 1 else end }
end
if spd < 0 && @riding then
(-spd).times { if would_fit(-1, 0) then @x -= 1 else end }
end
while @riding && (@x-@riding_entity.x).abs > 2*@riding_entity.xsize/3 && would_fit((@x-@riding_entity.x)/(@x-@riding_entity.x), 0) do
@x -= (@x-@riding_entity.x)/(@x-@riding_entity.x).abs
end
if @riding && (@x-@riding_entity.x).abs > 2*@riding_entity.xsize/3 then
@riding = false
@riding_entity = nil
end
@vy = 0 if @riding
if @riding && !(@riding_entity.living) then
@riding = false
@riding_entity = nil
end
end
if @map.lethal(@x, @y) || @map.lethal(@x, @y - @ysize - 1) || @map.lethal(@x, @y + 1) || @map.lethal(@x + @xsize + 1, @y) || @map.lethal(@x - @xsize - 1, @y) then
damage(1000)
end
cond_left = @map.lethal(@x - @xsize, @y + 1)
cond_right = @map.lethal(@x + @xsize, @y + 1)
cond_left_s = @map.solid?(@x - @xsize, @y + 1)
cond_right_s = @map.solid?(@x + @xsize, @y + 1)
if (cond_left && cond_right) then
damage(1000)
end
if (cond_right && !cond_left_s) || (cond_left && !cond_right_s) then
damage(1000)
end
end
def run
@running = true
end
def stop_running
@running = false
end
def steal_coins(value)
loss = [-value, -@collectibles[Objects::Coin]].max
get_collectible(Objects::Coin, loss)
@window.messages.push([loss.to_s + Strings::Coins, @x-25, @y, 100, true, 2.0, 2.0, 0xffff8800]) if loss < 0
return -loss
end
def try_to_jump
if @map.water(@x, @y) then
if @map.water(@x, @y-5) && @water_delay <= 0 && @water_flag then
@vy = -5
elsif @water_delay <= 0 && @water_flag then
@water_flag = false
@water_delay = 10
@vy = -12
@window.play_sound("water")
end
@combo = 0
elsif @map.solid?(@x - @xsize, @y + 1) || @map.solid?(@x + @xsize, @y + 1) || @flying || @riding then
@jumping = 8
@vy = -12 + (@riding ? @riding_entity.vy : 0)
@combo = 0
elsif @jumping > 0
@vy -= 1
@jumping -= 1
end
@riding = false
@riding_entity = nil
end
def stop_jumping
@jumping = 0
end
def knockback(strength)
@vx = strength
@pushed_from_riding = 10 if @riding
@riding = false
@riding_entity = nil
end
def check_projectiles(projectiles)
projectiles.each do |p|
if test_collision(p) && p.owner != Projectiles::INUHH && @invincible == 0 && @inv_inv == 0 then
@invincible = 100
defense = @stats[Stats::Defense]
dv = [p.damage-defense+Projectiles::Inuhh_Plus[p.type], 0].max
damage(dv)
@x < p.x ? knockback(-10-(p.damage-1)) : knockback(10+(p.damage-1))
@window.messages.push([dv, p.x+10, p.y-30, 20, true, 2.0+(dv-1)/10.0, 2.0+(dv-1)/10.0, 0xffff0000])
p.break
end
end
end
def fly
@flying = true
end
def collect_gems(gems)
# Same as in the tutorial game.
gems.reject! do |c|
if (c.x - @x).abs < 2*@xsize && (c.y - @y + @ysize).abs < 2*@ysize
c.collect(@window, self)
!c.constant
end
end
if @collectibles[Objects::Coin] >= 100 then
@window.messages.push([Strings::One_Life, @x-25, @y-50, 100, true, 2.0, 2.0, 0xff0088ff])
increase_stat(Stats::Lifes, 1)
get_collectible(Objects::Coin, -100)
end
if @collectibles[Objects::Fruit] >= 3 then
@window.messages.push(["+ 1", @x-25, @y, 100, true, 2.0, 2.0, 0xff0088ff])
increase_stat(Stats::Energy, 1)
get_collectible(Objects::Fruit, -3)
end
end
def warp(warps)
# Same as in the tutorial game.
warps.each do |w|
if (w.x - @x).abs < @xsize && (w.y - @y).abs < @ysize # Spheric hitbox maybe
return w.destination
end
end
return false
end
def kill(minigame_flag = false)
if minigame_flag then
manipulate_energy(1)
else
heal
lose_life
end
end
def set_water_boost(value)
@water_boost = value
end
def heal
reset_stat(Stats::Energy, @stats[Stats::Max_Energy])
end
def full_heal
heal
reset_stat(Stats::Lifes, @stats[Stats::Max_Lifes])
end
def reset_boosts
@boosts.each do |b|
if b then
b[0] = 0
b[1] = 0
b[2] = 0
end
end
end
def reset(x, y, dir=nil, full_reset=true)
@riding = false
@drunken = false
@x, @y = x, y
@dir = (dir ? (:right) : (:left))
@invincible = 0
@inv_inv = 0
@pushed_from_riding = 0
@water_boost = nil
@vy = 0
@vx = 0
if full_reset then
@item = nil
@item_amount = 0
reset_boosts
@flying = false
reset_images
end
@combo = 0
@cur_image = @standing
@water_delay = 0
end
def test_collision(entity)
return Collider::test_collision(self, entity)
#return Collider::elliptic(@xsize, @ysize, entity.xsize, entity.ysize, @x-entity.x, @y-@ysize-entity.y+entity.ysize)
end
def damage_enemy(e)
debug_plus = (@window.debug_strength_flag ? 99 : 0)
damage_value = [0, @stats[Stats::Strength] + debug_plus + @boosts[Stats::Strength][0] - e.defense].max
damage_value = [damage_value, e.reduction].min if e.reduction
if e.riding then
@riding = true if @vy > e.vy && @pushed_from_riding == 0
@riding_entity = e if @vy > e.vy && @pushed_from_riding == 0
elsif @pushed_from_riding == 0
if e.invul == 0 then
e.damage(damage_value)
@vy = (@map.water(@x, @y)? -8 : -20)
@jumping = 0
#@window.sounds["jump"].play
e.at_jumped_on
@window.messages.push([damage_value, e.x-e.xsize+10, e.y-e.ysize-30, 20, true, 2.0+(damage_value-1)/30.0, 2.0+(damage_value-1)/30.0, 0xff00ff00])
else
@vy = (@map.water(@x, @y)? -8 : -20)
@jumping = 0
end
end
if !e.living then
value = (@combo >= 10 ? e.score*100 : e.score*(@combo+1))
score_size = (@combo >= 10 ? 3.0 : 2.0+(value/50000.0))
score_color = (@combo >= 10 ? 0xff8888ff : 0xffffff00)
@window.add_statistics(Statistics::Enemies_Jumped, 1)
@window.messages.push([value, e.x-e.xsize, e.y-e.ysize, 100, true, score_size, score_size, score_color])
increase_stat(Stats::Score, value)
@combo += 1
@inv_inv = 1
@window.set_statistics(Statistics::Max_Combo, @combo) if @combo > @window.other_option_param(Other::Statistics, Statistics::Max_Combo, 0)
@window.play_sound("smash", 1, [1+((@combo-1)*0.1),2].min) # The higher the combo, the higher the pitch... until maximum
@window.residues.push(Residuum.new(e.x-e.xsize, e.y-2*e.ysize, 50, @window, e.mud))
end
end
def spike_damage(e)
if @invincible == 0 && @inv_inv == 0 || e.destiny then
@invincible = 100
e.at_collision
defense = @stats[Stats::Defense]
dv = [e.spike_strength-defense, 0].max
dv = [dv, e.minsdamage].max if e.minsdamage
damage(dv)
@x < e.x ? knockback(-10-(e.strength-1+e.knockback)) : knockback(10+(e.strength-1+e.knockback))
@window.messages.push([dv, e.x-e.xsize+10, e.y-e.ysize-30, 20, true, 2.0+(dv-1)/10.0, 2.0+(dv-1)/10.0, (dv == 666 ? 0xffaa0000 : 0xffff0000)])
end
end
def normal_damage(e)
@invincible = 100
e.at_collision
defense = @stats[Stats::Defense]
dv = [e.strength-defense, 0].max
dv = [dv, e.mindamage].max if e.mindamage
damage(dv)
@x < e.x ? knockback(-10-(e.strength-1+e.knockback)) : knockback(10+(e.strength-1+e.knockback))
@window.messages.push([dv, e.x-e.xsize+10, e.y-e.ysize-30, 20, true, 2.0+(dv-1)/10.0, 2.0+(dv-1)/10.0, (dv == 666 ? 0xff660000 : 0xffff0000)])
end
def colliding(enemies)
enemies.each do |e|
next if e.transparent
if !e.dangerous && test_collision(e) && e.z.abs < 10
if @y-@ysize < e.y-e.ysize && would_fit(0, -1) then
if @vy-e.vy > 0 then
if !e.spike then
damage_enemy(e)
else
spike_damage(e)
end
elsif @riding && @invincible == 0 && @inv_inv == 0 && e != @riding_entity || e.destiny then
e.at_collision
elsif !@riding && @invincible == 0 && @inv_inv == 0 then
if @y < e.y - e.ysize then
if !e.spike then
damage_enemy(e)
else
spike_damage(e)
end
else
e.at_collision
end
end
elsif @invincible == 0 && @inv_inv == 0 || e.destiny
e.at_collision
end
elsif test_collision(e) && e.z.abs < 10 then
if @y-@ysize < e.y-e.ysize && would_fit(0, -1) then
if @vy-e.vy > 0 then
if !e.spike then
damage_enemy(e)
else
spike_damage(e)
end
elsif @riding && @invincible == 0 && @inv_inv == 0 && e != @riding_entity || e.destiny then
normal_damage(e)
elsif !@riding && @invincible == 0 && @inv_inv == 0 then
if @y < e.y - e.ysize then
if !e.spike then
damage_enemy(e)
else
spike_damage(e)
end
else
normal_damage(e)
end
end
elsif @invincible == 0 && @inv_inv == 0 || e.destiny
normal_damage(e)
end
end
end
end
end
class World_Inuhh
def initialize(window, x, y)
@window = window
@x,@y = x,y
@image = Image.new(Pics::World_Inuhh, tileable: true)
end
def move(x, y)
@x,@y = x,y
end
def draw
@image.draw(@x, @y, ZOrder::Player, 0.5, 0.5)
end
end
# Map class holds and draws tiles and gems.
class Map
attr_reader :width, :height, :gems, :initial_enemies, :player_yield, :warps, :spawners, :triggers, :signposts, :tileset
def initialize(window, filename, section)
# Load 60x60 tiles, 5px overlap in all four directions.
@window = window
@tileset = Image.load_tiles(Pics::Tileset, 60, 60, tileable: true)
@anim_tileset = Image.load_tiles(Pics::Anim_Tileset, 60, 60, tileable: true)
@valimgs = Image.load_tiles(Pics::Objects, 50, 50, tileable: true)
warp_img = Image.new(Pics::Warp, tileable: true)
final_warp_img = Image.new(Pics::Final, tileable: true)
secret_warp_img = Image.new(Pics::Secret, tileable: true)
signpost_img = Image.new(Pics::Signpost, tileable: true)
@gems = []
#filename = "test.iwf"
lines = File.readlines(filename).map { |line| line.chomp }
f = File.open(filename, "r")
@check = Marshal.load(f)
while @check != section do
@check = Marshal.load(f)
end
first = Marshal.load(f)
if first.is_a? String then
@version = first
@width = Marshal.load(f)
else
@width = first
end
@height = Marshal.load(f)
@initial_enemies = []
@player_yield = []
@spawners = []
@triggers = []
@signposts = []
@warps = []
@tiles = []
@ftiles = []
0.upto(@width-1) do |x|
@tiles[x] = []
@ftiles[x] = []
end
0.upto(@width-1) do |x|
0.upto(@height-1) do |y|
d = Marshal.load(f)
if d.is_a? Array then # Custom behaviour tiles will follow soon.
@tiles[d[0]][d[1]]=d[2].tile
else
add_tile(x, y, d)
end
end
end
pinp = Marshal.load(f)
@player_yield = [pinp[0] * 50 + 25, pinp[1] * 50 + 49, pinp[2]]
inp = Marshal.load(f)
while inp != "END" do
if inp[3] == "G" then
@gems.push(Object_Datas::C_Index[inp[2].type].new(@valimgs[inp[2].type], inp[0] * 50 + 25, inp[1] * 50 + 25))
elsif inp[3] == "E" then
if inp[2].is_a? Integer then
dirs = [:right, :left]
@initial_enemies.push([inp[0] * 50 + 25, inp[1] * 50 + 49, inp[2], dirs[inp[4]], inp[5]])
else # Old format, only for compability
@initial_enemies.push([inp[0] * 50 + 25, inp[1] * 50 + 49, inp[2].type, inp[4]])
end
elsif inp[3] == "W" then
if inp[2].is_a? Array then
dest = inp[2].join
warppic = (dest[0] == "!" ? (!Level::Story.index((dest[1..-1].split("-"))[0..1].join("-")) ? secret_warp_img : final_warp_img) : warp_img)
@warps.push(Warp.new(warppic, inp[0] * 50 + 25, inp[1] * 50 + 49, dest))
else # Old format, not supported anymore.
@warps.push(Warp.new((inp[2].destination[0] == "!" ? final_warp_img : warp_img), inp[0] * 50 + 25, inp[1] * 50 + 49, inp[2].destination))
end
elsif inp[3] == "S" then
@spawners.push([inp[0] * 50, inp[1] * 50, inp[2], inp[4], inp[5], inp[6], inp[7], inp[8]])
elsif inp[3] == "P" then
@signposts.push([inp[0] * 50, inp[1] * 50, inp[2]])
elsif inp[3] == "F" then
add_fg_tile(inp[0], inp[1], inp[2])
end
inp = Marshal.load(f)
end
f.close
end
def add_tile(x, y, tile)
@tiles[x][y] = tile
end
def add_fg_tile(x, y, tile)
@ftiles[x][y] = tile
end
def draw(camx, camy)
# Very primitive drawing function:
# Draws all the tiles, some off-screen, some on-screen.
(camx..camx+15).each do |x|
if @tiles[x] then
(camy..camy+10).each do |y|
tile = @tiles[x][y]
if tile then
anim = Tile_Datas::Index[tile].animation
# Draw the tile with an offset (tile images have some overlap)
# Scrolling is implemented here just as in the game objects.
if anim && (milliseconds+x*100-y*77) % 1000> 500 then
@anim_tileset[tile].draw(x * 50 - 5, y * 50 - 5, ZOrder::Tiles)
else
@tileset[tile].draw(x * 50 - 5, y * 50 - 5, ZOrder::Tiles)
end
end
if @ftiles[x][y] then
@tileset[@ftiles[x][y]].draw(x * 50, y * 50 - 5, ZOrder::Foreground)
end
end
end
end
end
# Solid at a given pixel position?
def solid?(x, y)
return true if x < 0 || y < 0 || x >= @width*50
return false if !@tiles[(x / 50).floor][(y / 50).floor]
return Tile_Datas::Index[@tiles[(x / 50).floor][(y / 50).floor]].solid
end
def keyhole(x, y)
return false if invalid(x, y)
return false if !@tiles[(x / 50).floor][(y / 50).floor]
return Tile_Datas::Index[@tiles[(x / 50).floor][(y / 50).floor]].tile == Tiles::Keyhole
end