-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretrograde.p8
1286 lines (1149 loc) · 48.3 KB
/
retrograde.p8
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
pico-8 cartridge // http://www.pico-8.com
version 36
__lua__
global = {
state = 0, -- 0: menu, 1: gameplay, 2: endscreen, [3: help, 4: settings]
transition = false,
levelEndReached = false,
transition_y = 0,
transition_number = 0,
trans = {
x = 0,
y = 0
},
gravity = 0.6,
camShake = false,
camShakeTime = 0,
offset = 0.1,
animation_queue = {}
}
player = {
x = 1*8,
y = 1*8,
ax = 0,
ay = 0,
acceleration = 1,
jumpForce = 6,
maxSpeed = 3,
isGrounded = false,
isStomping = false,
stompStun = 0,
airtime = 0;
canJump = false;
isFlipped = false,
maxFall = 5,
powerUp = 0, --0 base, 1 rock, 2 fire, 3 air
life = 3,
colorPairs = {{5,13},{5,13},{8,14},{9,10}},
canDash = false,
dashDuration = 2,
nextDash = 0,
nextFireball = 0,
speedInv = 0,
status = "",
coins = 0,
score = 0,
currScore = {
x = 0,
y = 0,
val = 0,
lifetime = 0
},
stompCount = 0
}
crect = {
x,
y
}
cam = {
x = 0,
y = 0
}
particles = {}
enemies = {}
enemyProjectiles = {}
foliage = {}
pickups = {}
scores = {}
foliageId = {192,208,240}
mapContainer = {
"240,16,16,16,16,16,16,16,16,16,16,16,16,16,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,64,4,34,0,0,0,0,0,0,0,0,0,0,0,0,0,208,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,48,4,34,0,0,0,0,0,0,0,0,0,0,0,0,48,48,5,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,34,0,0,0,0,0,0,0,0,6,49,0,0,0,240,2,34,0,0,0,0,0,0,0,0,118,50,0,0,0,0,52,34,0,0,0,0,0,0,0,0,22,51,0,0,0,240,4,34,0,0,0,0,0,0,0,48,48,48,0,0,0,0,5,34,0,0,0,0,0,0,48,48,48,48,114,0,192,1,5,34,0,0,0,0,48,48,48,48,48,48,114,0,122,2,2,34,0,0,0,48,48,48,48,48,48,48,114,0,38,2,4,34,0,0,0,48,48,48,48,48,48,48,114,0,192,3,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,128,4,34,0,0,0,0,0,0,0,0,0,0,0,0,0,240,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,52,34,0,0,0,0,0,0,0,0,0,0,0,0,0,240,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,34,0,0,54,0,0,0,0,0,0,132,49,0,0,1,21,34,0,0,0,0,0,0,114,114,0,0,50,0,0,2,37,34,0,0,0,0,0,0,114,114,0,0,53,0,48,4,37,34,0,0,0,0,0,0,0,0,0,0,51,0,0,3,19,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,114,114,54,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,17,33,0,0,0,0,0,0,0,0,0,0,0,0,132,2,36,34,0,0,0,0,0,0,0,0,0,114,114,0,208,2,37,34,114,114,54,0,0,0,0,0,0,0,0,0,0,2,37,34,0,0,0,0,0,0,0,0,0,114,114,0,240,52,37,34,0,0,0,0,0,0,0,0,0,0,0,0,0,2,36,34,0,0,0,0,0,0,0,0,0,0,0,0,1,21,37,34,114,114,54,0,0,0,0,0,0,0,0,132,2,18,19,35,0,0,0,0,0,0,0,0,114,114,0,0,2,34,114,49,0,0,0,0,0,0,0,0,0,0,0,0,2,34,114,50,0,0,0,0,0,0,0,0,0,0,0,1,21,34,114,50,0,0,0,0,0,0,0,0,0,0,132,2,18,35,114,50,0,0,114,54,0,0,0,114,114,0,6,2,34,0,0,50,0,0,0,0,0,0,0,0,0,0,208,2,34,0,132,50,0,0,0,0,0,0,0,0,0,0,0,3,35,0,0,50,0,0,0,0,114,54,0,0,0,0,0,0,0,0,0,50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,54,0,0,0,0,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,208,50,0,0,0,0,0,0,0,0,0,0,0,0,0,48,48,50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,2,17,17,33,0,0,0,0,0,0,0,0,0,0,0,0,2,18,18,34,0,0,0,0,0,0,0,0,0,0,0,208,3,19,20,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,128,4,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,52,34,0,0,0,0,0,0,0,0,0,0,0,0,0,240,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,48,5,34,0,0,0,0,0,0,0,0,0,0,0,0,48,48,2,34,0,0,0,0,0,0,0,0,0,0,0,0,0,48,4,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,34,0,0,0,0,0,0,0,0,0,0,0,0,0,132,2,34,0,0,0,0,0,0,0,0,0,38,54,0,0,0,5,34,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,208,49,0,0,0,0,0,0,0,0,0,0,0,0,0,114,0,50,0,0,0,0,0,0,0,0,0,0,0,0,0,114,0,2,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49,0,0,0,0,0,0,0,0,0,0,0,0,0,114,208,2,16,16,16,0,0,0,0,0,0,0,0,0,0,114,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,17,17,17,17,33,0,0,0,0,0,0,0,0,0,192,2,37,37,18,37,34,17,17,17,17,17,17,33,0,0,132,2,37,37,37,37,34,37,37,19,19,19,19,34,0,0,0,2,37,37,37,36,34,37,34,0,0,0,0,50,0,0,0,2,37,18,37,37,34,37,34,0,0,0,127,50,0,0,0,2,37,37,37,37,34,37,34,0,0,0,0,51,0,0,208,2,37,37,37,37,34,37,34,0,0,0,0,0,0,0,0,2,36,37,37,18,34,37,34,0,0,0,0,0,0,0,132,2,37,37,37,37,34,37,34,0,0,0,0,0,192,49,0,2,18,37,37,37,34,37,37,17,17,17,17,17,17,21,17,21,37,37,37,36,34,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,35,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"
}
function parseMap(_mapString)
local mapString = _mapString
local actualMap = {}
local actualToken = ""
while #mapString > 0 do
local firstToken = sub(mapString,1,1)
local cut = 2
if (firstToken != ",") then
local workString = sub(mapString,2)
local secondToken = sub(workString,1,1)
if (secondToken != ",") then
local workString = sub(mapString,3)
local thirdToken = sub(workString,1,1)
if (thirdToken != ",") then
local actualToken = firstToken..secondToken..thirdToken
add(actualMap,actualToken)
cut = 4
else
local actualToken = firstToken..secondToken
add(actualMap,actualToken)
cut = 3
end
else
add(actualMap,firstToken)
cut = 2
end
end
mapString = sub(mapString,cut)
end
return actualMap
end
function codeMap()
local mapstring = ""
for x=0,127 do
for y=0,15 do
mapstring = mapstring..mget(x,y)..","
end
end
--add(mapstring,12)
--printh(tostr(mapstring))
printh(mapstring)
end
function load_map(_index)
for x = 0,127 do
for y=0,15 do
mset(x,y,0)
end
end
mapString = parseMap(mapContainer[_index])
printh(mapContainer[_index])
x = 0
y = 0
for id in all(mapString) do
id = tonum(id)
--walls
if (0 < id) and (id < 64) then
mset (y, x, id)
end
-- coins
if (id == 114) then
add_pickup (y, x, 0)
end
-- fire flower
if (id == 118) then
add_pickup (y, x, 1)
end
-- volt flower
if (id == 122) then
add_pickup (y, x, 2)
end
-- egg
if (id == 127) then
add_pickup (y, x, 99)
end
--foliageId = {192,208,240}
if (id == 192) or (id == 208) or (id == 240) then
add_foliage(y, x, id)
end
-- enemies
if (id == 128) or (id == 132) then
add_enemy (y, x, id)
end
if (id == 64) then
player.x = y*8
player.y = x*8
end
x+=1
if (x > 15) then
x = 0
y+=1
end
end
end
function _init()
codeMap()
end
function add_particle(_x,_y,_maxAge,_color,_type,_goal,_velocity)
local goal = _goal
if goal == nil then
goal = {
x = 0,
y = 0
}
end
local part = {
x = _x,
y = _y,
lifeTime = 0,
maxAge = _maxAge,
tpe = _type,
color_range = _color,
clr = _color[1],
dest = {
x = goal.x,
y = goal.y
},
velocity = {
x = _velocity.x,
y = _velocity.y
}
}
add(particles,part)
end
function add_enemy(_x,_y,_spr)
if _spr == 128 then
local enemy = {
x = _x*8,
y = _y*8,
ay = 0,
defspeed = 1,
speed = 1,
spr = _spr,
hitspr = _spr+2,
type = 0,
animspeed = 6
}
add(enemies,enemy)
elseif _spr == 132 then
local enemy = {
x = _x*8,
y = _y*8,
ay = 0,
defspeed = 1,
speed = 0.5,
spr = _spr,
hitspr = _spr+2,
type = 1,
animspeed = 6
}
add(enemies,enemy)
end
end
function add_foliage(_x,_y,_spr)
local fol = {
x = _x*8,
y = _y*8,
spr = _spr
}
add(foliage,fol)
end
function add_pickup(_x,_y,_tpe)
local pickup = {
x = _x*8,
y = _y*8,
tpe = _tpe,
deleteTime = nil
}
-- coin
if pickup.tpe == 0 then
pickup.spr = 114
pickup.animLength = 4
pickup.animSpeed = 6
-- fire flower
elseif pickup.tpe == 1 then
pickup.spr = 118
pickup.animLength = 4
pickup.animSpeed = 12
-- Volt flower
elseif pickup.tpe == 2 then
pickup.spr = 122
pickup.animLength = 5
pickup.animSpeed = 14
elseif pickup.tpe == 99 then
pickup.spr = 127
pickup.animLength = 1
end
add(pickups,pickup)
end
function animate(object,starterFrame,frameCount,animSpeed,flipped,isPlayer)
if(not object.tickCount) then
object.tickCount=0
end
if(not object.spriteOffset) then
object.spriteOffset=0
end
object.tickCount+=1
if(object.tickCount%(flr(30/animSpeed))==0) then
object.spriteOffset+=1
if (object.spriteOffset>=frameCount) then
object.spriteOffset=0
end
end
object.actualframe=starterFrame+object.spriteOffset
if object.actualframe >= starterFrame+frameCount then
object.actualframe = starterFrame
end
print(object.spriteOffset,2,2,1)
-- 3 is treant
if (isPlayer) then
local colors = player.colorPairs[player.powerUp+1]
for x=0,(frameCount*8-1),1 do
for y=0,7,1 do
local xPos = ((starterFrame-64)*8)+x
if sget( xPos, 32 + y) == 15 then
sset( xPos, 32 + y, colors[1])
end
if sget( xPos, 32 + y) == 14 then
sset( xPos, 32 + y, colors[2])
end
end
end
end
spr(object.actualframe,object.x,object.y,1,1,flipped)
if (isPlayer) then
local colors = player.colorPairs[player.powerUp+1]
for x=0,(frameCount*8-1),1 do
for y=0,7,1 do
local xPos = ((starterFrame-64)*8)+x
if sget( xPos, 32 + y) == colors[1] then
sset( xPos, 32 + y, 15)
end
if sget( xPos, 32 + y) == colors[2] then
sset( xPos, 32 + y, 14)
end
end
end
end
pal()
end
function create_animation(object,starting_frame,number_of_frames,speed,ticks,persistent,lifetime)
local obj = {
x = object.x,
y = object.y,
}
local anim = {
object = obj,
starting_frame = starting_frame,
number_of_frames = number_of_frames,
speed = speed,
ticks = ticks,
presistent = persistent,
lifetime = lifetime
}
add(global.animation_queue,anim)
end
function add_score (_x, _y, _txt, _color, _lifetime)
local score = {
x = _x,
y = _y,
txt = _txt,
color = _color,
lifetime = time() + _lifetime
}
add(scores, score)
end
function collide_rect(r1,r2)
if ( (r1.x1 > r2.x2) or
(r2.x1 > r1.x2) or
(r1.y1 > r2.y2) or
(r2.y1 > r1.y2)) then
return false
end
return true
end
function to_rect(x,y,h,w)
local r = {
x1 = x,
x2 = x + w - 1,
y1 = y,
y2 = y + h - 1
}
return r
end
function collide_roof(obj, width, height)
--check for collision at multiple points along the top
--of the sprite: left, center, and right.
for i=1,width-1,2 do
if fget(mget((obj.x+i)/8,(obj.y)/8),0) then
return true
end
end
return false
end
function collide_side(obj,width)
local offset=width/3
for i=-(width/3),(width/3),2 do
--if obj.ax>0 then
if fget(mget((obj.x+(offset))/8,(obj.y+i)/8),0) then
obj.ax=0
obj.x=(flr(((obj.x+(offset))/8))*8)-(offset)
return true
end
--elseif obj.ax<0 then
if fget(mget((obj.x-(offset))/8,(obj.y+i)/8),0) then
obj.ax=0
obj.x=(flr((obj.x-(offset))/8)*8)+8+(offset)
return true
end
-- end
end
--didn't hit a solid tile.
return false
end
--check if pushing into floor tile and resolve.
--requires obj.ax,obj.x,obj.y,obj.grounded,obj.airtime and
--assumes tile flag 0 or 1 == solid
function collide_floor(obj,width,height)
--only check for ground when falling.
if obj.ay<0 then
return false
end
local landed=false
--check for collision at multiple points along the bottom
--of the sprite: left, center, and right.
for i=1,width-1,2 do
local tile=mget((obj.x+i)/8,(obj.y+(height))/8)
if fget(tile,0) or (fget(tile,1) and obj.ay>=0) then
landed=true
end
end
return landed
end
function control_player()
local dashing = player.canDash
local startx = player.x
if (player.stompStun > time()) then
--player.status = "stun"
elseif (player.isStomping) then
--player.status = "stomp"
else
--player.status = "chill"
end
if (not player.isStomping) and (not (player.stompStun > time())) then
if btn(0) then
player.ax -= player.acceleration
player.isFlipped = true
elseif btn(1) then
player.ax += player.acceleration
player.isFlipped = false
elseif (btn(3) and (not player.isGrounded)) then
player.ax = 0
player.ay = 2
sfx(0)
player.isStomping = true
else
player.ax = 0
end
if btnp(4) then
player.powerUp += 1
if player.powerUp > 3 then
player.powerUp = 0
end
end
if btnp(5) then
if player.powerUp == 3 then
if time() > player.nextDash then
player.canDash = true
player.nextDash = time() + player.dashDuration
player.speedInv = time() + 0.3
end
end
if player.powerUp == 2 then
if time > player.nextFireball then
add_fireball(player.x, player.y, player.ax, player.isFlipped)
player.nextFireball = time() + 1
end
end
end
end
if time() > player.speedInv then
player.canDash = false
end
if player.ax > 0 then
if player.ax > player.maxSpeed then
player.ax = player.maxSpeed
end
elseif player.ax < 0 then
if player.ax < -player.maxSpeed then
player.ax = -player.maxSpeed
end
end
if dashing then
player.ax = 6
local vel = {
x = sin(rnd(1)),
y = sin(rnd(1))/4
}
if player.flip then
add_particle(player.x+7,player.y+1,5,{10,9,6},3,nil,vel)
add_particle(player.x+7,player.y+3,5,{10,9,6},3,nil,vel)
add_particle(player.x+7,player.y+5,5,{10,9,6},3,nil,vel)
else
add_particle(player.x,player.y+1,5,{10,9,6},3,nil,vel)
add_particle(player.x,player.y+3,5,{10,9,6},3,nil,vel)
add_particle(player.x,player.y+5,5,{10,9,6},3,nil,vel)
end
if player.isFlipped then
player.ax = -6
end
end
-- move player through x
player.x += player.ax
-- check collision
local xoffset=0
if player.ax >0 then xoffset=7 end
local possible_wall_tile = mget((player.x+xoffset)/8,(player.y+7)/8)
if fget(possible_wall_tile,0) then
player.x = startx
end
--normalize vertical speed add gravity
if not (player.isGrounded) then
player.ay += global.gravity
if player.ay > player.maxFall then
player.ay = player.maxFall
end
end
-- move player
player.y += player.ay
player.isGrounded = false
if btn(2) and (player.isGrounded or player.airtime < 4) then
if player.canJump then
player.ay -= player.jumpForce
player.canJump = false
end
end
-- hit floor
if collide_floor(player, 8, 8) then
if player.isStomping and fget(mget(flr((player.x+2)/8),flr((player.y+8)/8)),1) and (btn(3)) then
mset(flr((player.x+2)/8),flr((player.y+8)/8), 0)
for xVel =-1,-0.2,0.2 do
local vel = {
x = xVel+sin(rnd(1)),
y = xVel+sin(rnd(1))/4
}
--function add_particle(_x,_y,_maxAge,_color,_type,_goal,_velocity)
add_particle(player.x+4,player.y+8,10,{9,4,6},1,nil,vel)
vel.x = vel.x * -1
add_particle(player.x+4,player.y+8,10,{9,4,6},1,nil,vel)
global.camShake = true
global.camShakeTime = time() + 0.5
global.offset = 0.1
sfx(1)
end
elseif player.isStomping then
--add particles
--small stun
player.stompStun = time() + 0.5
player.isStomping = false
for xVel =-1,-0.2,0.2 do
local vel = {
x = xVel,
y = xVel/4
}
--function add_particle(_x,_y,_maxAge,_color,_type,_goal,_velocity)
add_particle(player.x+4,player.y+8,10,{2,5,6},1,nil,vel)
vel.x = vel.x * -1
add_particle(player.x+4,player.y+8,10,{2,5,6},1,nil,vel)
end
global.camShake = true
global.camShakeTime = time() + 0.5
global.offset = 0.1
sfx(1)
end
-- place player on top
--player.status = "coll"
player.y = flr((player.y)/8)*8
player.ay = 0
player.isGrounded = true
player.airtime = 0
player.canJump = true
player.stompCount = 0
else
--player.status = "nocoll"
player.airtime += 1
end
-- hit ceiling
if player.ay < 0 then
--player.status = "jump"
-- check for solide tile
if collide_roof(player, 8, 8) then
player.y = flr((player.y+8)/8)*8
player.ay = 0
end
end
if (player.ay > 0) and (not player.isStomping) and (not (player.stompStun > time())) then
--player.status = "fall"
end
end
-- 0: menu, 1: gameplay, 2: endscreen, [3: help, 4: settings]
function _update ()
if not (global.transition == true) then
if global.state == 0 then
update_menu()
elseif global.state == 1 then
update_game()
elseif global.state == 2 then
camera(0,0)
update_end_screen()
end
end
end
function update_menu()
if btnp(5) then
print(control,64-(#control*2),40,9)
-- enter the game
global.state = 1
global.transition = true
global.trans.x = 0
global.trans.y = 0
load_map(1)
sfx(0)
end
end
function update_game()
control_player()
update_particles()
update_enemies()
check_stomp()
update_scores()
--update_bouncers()
update_pickup()
if player.life <= 0 then
-- set our state to endscreen
global.state = 2
global.endScreenMessage = endScreenMessages[flr(rnd(#endScreenMessages)+1)]
global.transition = true
global.trans.x = player.x-64
global.trans.y = player.y-64
--camera(0,0)
end
if time() > global.camShakeTime then
global.camShake = false
end
end
function update_particles()
if not (#particles == 0) then
for particle in all(particles) do
-- lifetime and color changes
if particle.lifeTime > particle.maxAge then
del(particles,particle)
else
if #particle.color_range == 1 then
particle.clr = particle.color_range[1]
else
local idx = particle.lifeTime / particle.maxAge
idx = 1 + flr(idx*#particle.color_range)
if idx > #particle.color_range then idx = #particle.color_range end
particle.clr = particle.color_range[idx]
--if (particle.clr == 0) then particle.clr = 5 end
end
end
particle.lifeTime +=1
if not (particle.velocity == nil) then
particle.x += particle.velocity.x
particle.y += particle.velocity.y
end
end
end
end
function move_enemy(object,w,h)
next_wall = 0
next_floor = 0
-- type 0
if object.type == 0 then
if object.speed > 0 then
next_wall = mget(object.x/8+(1*sgn(object.speed)),object.y/8)
end
if object.speed < 0 then
next_wall = mget(ceil(object.x/8)+(1*sgn(object.speed)),object.y/8)
end
if(fget(next_wall)==1) then
object.speed = object.speed * (-1)
end
next_floor = mget(flr(object.x/8),(object.y/8)+1)
if fget(next_floor,0) == false then
object.ay += global.gravity
else
object.ay = 0
end
end
-- type 1
if object.type == 1 then
if object.speed > 0 then
next_floor = mget(object.x/8+(1*sgn(object.speed)),object.y/8+1)
end
if object.speed < 0 then
next_floor = mget(ceil(object.x/8)+(1*sgn(object.speed)),object.y/8+1)
end
if(fget(next_floor) == 0) then
object.speed = object.speed * (-1)
end
if object.speed > 0 then
next_wall = mget(object.x/8+(1*sgn(object.speed)),object.y/8)
end
if object.speed < 0 then
next_wall = mget(ceil(object.x/8)+(1*sgn(object.speed)),object.y/8)
end
if(fget(next_wall)==1) then
object.speed = object.speed * (-1)
end
next_wall = mget(flr(object.x/8),flr((object.y+object.ay)/8)+1)
if(fget(next_wall,0) == 0) then
object.ay += global.gravity
else
object.ay = 0
end
end
object.x += object.speed
object.y += object.ay
end
function update_enemies()
for enemy in all(enemies) do
for fireball in all(fireballs) do
if (collide_rect(to_rect(enemy,7,7),to_rect(fireball,7,7))) then
del(fireballs,fireball)
del(enemies,enemy)
return
end
end
move_enemy(enemy,7,7)
end
end
function update_scores()
if player.currScore.lifetime > time() then
player.currScore.lifetime -= 1
player.currScore.y -= 1
end
end
function player_enemy_collision()
for monster in all(enemies) do
if( (collide_rect(to_rect(monster,7,7),to_rect(player,7,7))) and (global.tick > player.nextinvc) ) then
player.status = "hit"
end
end
end
function check_stomp()
for enemy in all(enemies) do
if (collide_rect (to_rect (player.x,player.y,8,8), to_rect (enemy.x, enemy.y, 8, 8))) and (player.ay > 0) then
local score = 0
if enemy.speed < 0 then
create_animation(enemy,enemy.hitspr,2,4,false,false,10)
else
create_animation(enemy,enemy.hitspr,2,4,true,false,10)
end
del(enemies,enemy)
player.ay = -player.jumpForce
if player.isStomping then
player.ay-= 2
player.isStomping = false
end
player.stompCount += 1
score = player.stompCount * 200
player.score += score
if player.currScore.lifetime > time () then
score = player.currScore.val + score
player.currScore.lifetime = time() + 5
end
player.currScore = {
x = player.x+4,
y = player.y-8,
val = score,
lifetime = time() + 5
}
end
end
end
function update_enemy_projectiles()
end
function update_pickup()
for pickup in all(pickups) do
if (pickup.deleteTime == nil) then
if collide_rect(to_rect(player.x, player.y, 8, 8), to_rect(pickup.x, pickup.y, 8,8 )) then
local score = 0
-- coin
if pickup.tpe == 0 then
player.coins += 1
pickup.animSpeed = pickup.animSpeed*2
pickup.deleteTime = time() + 1
score = 200
player.score += score
sfx(2)
end
if pickup.tpe == 1 then
player.powerUp = 2
pickup.animSpeed = pickup.animSpeed*2
pickup.deleteTime = time() + 0.1
score = 400
player.score += score
end
if pickup.tpe == 2 then
player.powerUp = 3
pickup.animSpeed = pickup.animSpeed*2
pickup.deleteTime = time() + 0.1
score = 400
player.score += score
end
if pickup.tpe == 99 then
pickup.deleteTime = time() + 0.1
score = 2000
player.score += score
global.levelEndReached = true
global.transition = true
end
printh("added score")
if player.currScore.lifetime > time () then
score = player.currScore.val + score
end
player.currScore = {
x = player.x+4,
y = player.y,
val = score,
lifetime = time() + 5
}
end
elseif (pickup.deleteTime > time()) then
pickup.y -= 0.5
else
del(pickups, pickup)
end
end
end
-- 0: menu, 1: gameplay, 2: endscreen, [3: help, 4: settings]
function _draw()
if not (global.transition) then
if global.state == 0 then
draw_menu()
elseif global.state == 1 then
draw_game()
elseif global.state == 2 then
draw_end_screen()
end
else
draw_transition(global.trans.x,global.trans.y)
end
end
function draw_menu()
cls()
map()
title = "dINO wIP pROJECT"
control = "press x to play"
print(title,64-(#title*2),20,9)
if (time()%1 > 0.5) then
print(control,64-(#control*2),40,6)
end
end
function draw_game()
local xPos = player.x
local yPos = player.y
cls()
rectfill(-70,0,1200,300,12)
map()
rectfill(crect.x1,crect.y1,crect.x2,crect.y2, 6)
draw_particles()
draw_enemies()
if player.isStomping or (player.stompStun > time()) then
animate(player,76,1,10,player.isFlipped,true)
else
if (player.ax == 0) then
animate(player,66,4,10,player.isFlipped,true)
else
animate(player,64,2,13,player.isFlipped,true)
end
end
print(player.status, xPos, yPos-8, 8)
--draw_enemy_projectile()
draw_global_animations()
-- camera setup
local target_pos = {
x = player.x-60,
y = 0
}
local camera_treshold = 16
local position_minimum = {
x = 0,
y = 0
}
local position_maximum = {
x = 64*8-64,
y = 64+182
}
-- calculate out of buffer corrigations
if (cam.x + camera_treshold) < target_pos.x then
cam.x += min(target_pos.x - (cam.x + camera_treshold), 4)
end
if (cam.x - camera_treshold) > target_pos.x then
cam.x += min(target_pos.x - (cam.x - camera_treshold), 4)
end
if (cam.y + camera_treshold) < target_pos.y then
cam.y += min(target_pos.y - (cam.y + camera_treshold), 4)
end
if (cam.y - camera_treshold) > target_pos.y then
cam.y += min(target_pos.y - (cam.y - camera_treshold), 4)
end
if cam.x < position_minimum.x then
cam.x = position_minimum.x
end
if cam.x > position_maximum.x then
cam.x = position_maximum.x
end
if cam.y < position_minimum.y then