forked from Pakz001/MonkeyXExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2D Mining Game Full.monkey
More file actions
1041 lines (1002 loc) · 28.3 KB
/
2D Mining Game Full.monkey
File metadata and controls
1041 lines (1002 loc) · 28.3 KB
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
' version 7-12-2015.
' Template.
' Scrolling platformer with RPG features.
' Based on the scrolling platformer with vines
' template on my Monkey-X blog.
'
' The mapwidth variables can be set to large(200+) or
' small(100*100) maps. There will be multiple mines
' placed and populated if there is enough space for them
' on the map. (This version runs fast enough on low
' end laptops with maps up to 320*240 - there currently
' is no LOD implemented.)
'
' Game :
' Travel down/explore the mine.
' Has mining eggs feature. Hunting for meat.
' Monsters lay eggs. Only one monster hatches from a egg
' if there are no other monsters nearby.
' Monsters/breeders do not attack.
' You can pick up the eggs. Kill the monsters for meat.
' You can place an egg on the ground and a monster could be
' hatched.
' Eggs can also spawn Deathwings and they attack/hurt you.
' You have health and if zero restarts the game.
' p - Place egg on the ground.
' t - Pick up egg from the ground.
' Space - Attack with spear.
' curs left/right/up - move and jump.
'
' Thinking of adding automated machine gun nests that you
' can place/move around and they kill the flying monsters.
'
' Mood of the game at the moment is :
' Monsters live in an old abandoned mining area. You can
' mine meat/eggs to make a profit. Monsters
' have been seen flying nearby mines attacking people.
'
'
Import mojo
Global gamestate:String="select"
Global mapwidth:Int=100
Global mapheight:Int=100
Const tilewidth:Int=32
Const tileheight:Int=32
Global mapx:Int=0
Global mapy:Int=0
Global mapsx:Int=0
Global mapsy:Int=0
Global maxdeathwings:Int=10
Class menuselect
Field go:Bool=False
Field m:maptest
Field index:Int = 0
Method New()
End Method
Method update()
If KeyHit(KEY_LEFT) Then index -= 1
If KeyHit(KEY_RIGHT) Then index += 1
If KeyHit(KEY_ENTER) Then go=True
If index < 0 Then index = 0
If index > 2 Then index = 2
Select index
Case 0
mapwidth = 100
mapheight = 100
maxdeathwings = 10
Case 1
mapwidth = 150
mapheight = 150
maxdeathwings = 20
Case 2
mapwidth = 200
mapheight = 200
maxdeathwings = 40
End Select
End Method
Method draw()
Local w:Int,h:Int
Local x:Int,y:Int
SetColor 255,255,255
DrawText "Cursor keys to select - Enter = start",0,0
PushMatrix()
Scale 3,3
DrawText "Select Difficulty",320/3,280/3,.5,.5
Local mystring:String
Select index
Case 0
mystring="Easy"
Case 1
mystring="Normal"
Case 2
mystring="Difficult"
End Select
DrawText mystring,320/3,320/3,.5,.5
PopMatrix()
Seed = 1
x = 0+50
y = 50
w = 100
h = 100
m = New maptest(w,h,640,480)
drawmap(x,y,1,1)
If index = 0
SetColor 255,255,255
mydrawrect x,y,w,h
mydrawrect x+1,y+1,w-2,h-2
End If
Seed = 1
x = 150+50
y = 50
w = 150
h = 150
m = New maptest(w,h,640,480)
drawmap(x,y,1,1)
If index = 1
SetColor 255,255,255
mydrawrect x,y,w,h
mydrawrect x+1,y+1,w-2,h-2
End If
Seed = 1
x = 320+50
y = 50
w = 200
h = 200
m = New maptest(w,h,640,480)
If index = 2
SetColor 255,255,255
mydrawrect x,y,w,h
mydrawrect x+1,y+1,w-2,h-2
End If
drawmap(x,y,1,1)
End Method
Method drawmap(x1:Int,y1:Int,tw:Int,th:Int)
For Local y=0 Until m.h
For Local x=0 Until m.w
If m.map[x][y] = 1
SetColor 255,255,255
DrawRect (x*tw)+x1,(y*th)+y1,tw,th
End If
If m.map[x][y] = 3
SetColor 200,200,10
DrawOval (x*tw)+x1,(y*th)+y1,tw,th
End If
Next
Next
End Method
Method mydrawrect(x:Int,y:Int,w:Int,h:Int)
SetColor 255,255,255
DrawLine x,y,x+w,y
DrawLine x,y,x,y+h
DrawLine x,y+h,x+w,y+h
DrawLine x+w,y,x+w,y+h
End Method
End Class
Class maptest
Field sw:Int,sh:Int
Field tw:Int,th:Int
Field w:Int,h:Int
Field map:Int[][]
Method New(w:Int,h:Int,sw:Int,sh:Int)
Self.sw = sw
Self.sh = sh
Self.w = w
Self.h = h
tw = sw/w
th = sh/h
map = New Int[w][]
For Local i=0 Until w
map[i] = New Int[h]
Next
drawmaprect(0,0,w-1,15)
For Local i=0 Until h
map[1][i] = 0
map[w-2][i] = 0
Next
Local x:Int=32
While x<w-48
makemine(x,15,Rnd(4,h/15))
x+=Rnd(48,64)
Wend
End Method
Method makemine(x:Int,y:Int,depth:Int)
For Local mydepth=0 Until depth
Local d1:Int=Rnd(8,16)'depth
tunneldown(x,y,d1)
y+=d1
Local d2:Int=Rnd(1,4)'direction
If d2=1 Then sidetunnel(x,y,"left")
If d2=2 Then sidetunnel(x,y,"right")
If d2=3 Then
sidetunnel(x,y,"left")
sidetunnel(x,y,"right")
End If
Next
For Local y1=0 Until y
map[x][y1] = 2
Next
End Method
Method sidetunnel(x:Int,y:Int,d:String)
If d="left"
Local width:Int=Rnd(5,10)
drawmaprect(x-width+2,y,width,3)
Local roomw:Int=Rnd(5,15)
drawmaprect(x-width+2-roomw,y-1,roomw,5)
For Local x1=0 Until roomw/3
map[(x-width+2-roomw)+x1][y+4] = 3
eggs.AddLast( New egg((x-width+2-roomw)+x1,y+4) )
Next
' a.AddLast( New agent( ((x-width+2-roomw))*tilewidth,
' (y+4)*tileheight) )
End If
If d="right"
Local width:Int=Rnd(5,10)
drawmaprect(x-1,y,width,3)
Local roomw:Int=Rnd(5,15)
drawmaprect(x+width,y-1,roomw,5)
For Local x1=roomw Until roomw/1.5 Step -1
map[(x+width)+x1][y+4] = 3
eggs.AddLast( New egg((x+width)+x1,y+4) )
Next
' a.AddLast( New agent( (x+width+2)*tilewidth,
' (y+4)*tileheight ))
End If
End Method
Method tunneldown(x:Int,y:Int,d:Int)
drawmaprect(x-2,y,4,d)
End Method
Method drawmaprect(x:Int,y:Int,w:Int,h:Int)
For Local y1=y To y+h
For Local x1=x To x+w
map[x1][y1] = 1
Next
Next
End Method
Method draw()
For Local y=0 Until h
For Local x=0 Until w
If map[x][y] = 1
SetColor 255,255,255
DrawRect x*tw,y*th,tw,th
End If
If map[x][y] = 3
SetColor 200,200,10
DrawOval x*tw,y*th,tw,th
End If
Next
Next
End Method
End Class
Class spear
Field x:Float,y:Float
Field w:Int=20
Field h:Int=4
Field d:String
Field incx:Float
Field active:Bool
Method New(x:Int,y:Int,d:String)
Self.x = x
Self.y = y
Self.d = d
incx = 3
active = True
End Method
Method update()
If active = False Then Return
w+=incx
incx-=0.5
If incx > 0
killcreature
End If
If incx < -3 Then active = False
End Method
Method killcreature()
For Local i:=Eachin dw
If d="left"
If rectsoverlap( i.x,i.y,32,32,
x-32,y,32,32)
i.remove = True
myinven.meat+=1
End If
Else
If rectsoverlap( i.x,i.y,32,32,
x+32,y,32,32)
i.remove = True
myinven.meat+=1
End If
End If
Next
For Local i:=Eachin a
If d="left"
If rectsoverlap( i.x,i.y,32,32,
x-32,y,32,32)
i.remove = True
myinven.meat+=1
End If
Else
If rectsoverlap( i.x,i.y,32,32,
x+32,y,32,32)
i.remove = True
myinven.meat+=1
End If
End If
Next
For Local i:=Eachin a
If i.remove=True
a.Remove i
End If
Next
End Method
Method draw()
If active = True
SetColor 200,100,0
If d = "right"
DrawRect x+32,y+8,w,h
Else
DrawRect x-w,y+8,w,h
End If
End If
End Method
End Class
Class player
Field x:Float=0
Field y:Float=0
Field w:Int=32
Field h:Int=32
Field incy:Float=0
Field isjumping:Bool = False
Field facing:Int '0 = left , 1 = right
Field jumpofvine:Bool=False
Field jumpofvinetimeout:Int
Field health:Int=10
Method update()
Local ox:Int=x
Local oy:Int=y
If pvc(0,0) = False Or jumpofvine = True Then regularmode
If pvc(0,0) = True
If jumpofvine = False
vinemode
End If
End If
If KeyHit(KEY_SPACE)
Local md:String
If facing = 0 Then
md="left"
Else
md="right"
End If
myspear = New spear(p.x,p.y,md)
End If
If KeyHit(KEY_T)
Local offx:Int
If p.facing=0 Then
offx=0
Else
offx=32
End If
Local cx = (p.x+offx)/tilewidth+mapx
Local cy = (p.y)/tileheight+mapy
If mymaptest.map[cx][cy] = 3
mymaptest.map[cx][cy] = 1
myinven.eggs+=1
For Local i:=Eachin eggs
If i.x = cx And
i.y = cy
i.remove = True
End If
Next
For Local i:=Eachin eggs
If i.remove=True
eggs.Remove i
End If
Next
End If
End If
If KeyHit(KEY_P)
If myinven.eggs > 0
Local cx = (p.x)/tilewidth+mapx
Local cy = (p.y)/tileheight+mapy
If mymaptest.map[cx][cy] = 1
mymaptest.map[cx][cy] = 3
eggs.AddLast(New egg(cx,cy))
End If
End If
myinven.eggs-=1
End If
End Method
Method movea(x1:Int,y1:Int)
For Local i:=Eachin a
i.x+=x1
i.y+=y1
Next
For Local i:=Eachin dw
i.x+=x1
i.y+=y1
Next
End Method
Method vinemode()
isjumping = False
incy=0
If KeyDown(KEY_J)
jumpofvine = True
jumpofvinetimeout = Millisecs() + 1000
isjumping = True
incy=-4
End If
If KeyDown(KEY_UP)
For Local i=0 Until 4
If pvc(0,0) = True And ptc(0,-1) = False
y-=1
End If
Next
End If
If KeyDown(KEY_DOWN)
For Local i=0 Until 4
If pvc(0,0) = True And ptc(0,1) = False
y+=1
End If
Next
End If
If KeyDown(KEY_LEFT)
For Local i=0 Until 4
If pvc(0,0) = True And ptc(-1,0) = False
x-=1
facing=0
End If
Next
End If
If KeyDown(KEY_RIGHT)
For Local i=0 Until 4
If pvc(0,0) = True And ptc(1,0) = False
x+=1
facing = 1
End If
Next
End If
End Method
Method regularmode()
If jumpofvine = True
If Millisecs() > jumpofvinetimeout Then jumpofvine=False
End If
'Left and Right movement
If KeyDown(KEY_RIGHT)
For Local i=0 Until 4 ' move with 4 pixels at a time
If ptc(1,0) = False
x+=1
facing = 1
End If
Next
End If
If KeyDown(KEY_LEFT)
For Local i=0 Until 4
If ptc(-1,0) = False
x-=1
facing = 0
End If
Next
End If
'player gravity part
'if in the air and not in jump
If isjumping = False
If ptc(0,1) = False
isjumping=True
incy=0
End If
End If
' jump
If KeyDown(KEY_UP)
If isjumping = False
isjumping = True
incy=-4
End If
End If
' if we are in a jump/falling down
If isjumping=True
If incy>=0 'if we are going down
If incy<4 Then incy+=.1
For Local i=0 Until(incy)
If ptc(0,1) = False
y+=1
Else
isjumping = False
End If
Next
End If
If incy<0 'if we are going up
incy+=.1
For Local i=0 Until Abs(incy)
If ptc(0,-1) = False
y-=1
Else
incy=0
End If
Next
End If
End If
End Method
Method draw()
SetColor 255,255,0
DrawRect x,y,w,h
End Method
End Class
Class deathwing
Field x:Int,y:Int
Field w:Int,h:Int
Field state:String
Field remove:Bool=False
Field lasthurt:Int=Millisecs()
Method New(x:Int,y:Int)
Self.x = x
Self.y = y
w = 32
h = 32
state = "flyup"
End Method
Method update()
hurtplayer
Local x1:Int = ((Self.x-mapsx+16)/tilewidth)+mapx
Local y1:Int = ((Self.y)/tileheight)+mapy
Local x1r:Int = (((Self.x+1)-mapsx+16)/tilewidth)+mapx
Local x1l:Int = (((Self.x-1)-mapsx+16)/tilewidth)+mapx
Local y1u:Int = (((Self.y-1))/tileheight)+mapy
Local y1d:Int = (((Self.y+1))/tileheight)+mapy
canattack
Select state
Case "attack"
If p.x < x And mymaptest.map[x1l][y1] = 1 Then x-=1
If p.y < y And mymaptest.map[x1][y1u] = 1 Then y-=1
If p.x > x And mymaptest.map[x1r][y1] = 1 Then x+=1
If p.y > y And mymaptest.map[x1][y1d] = 1 Then y+=1
Case "flyup"
' if high enough
If y1<12 Then
If Rnd(10)<5
state="flyleft"
Else
state="flyright"
End If
End If
'if can fly up
If mymaptest.map[x1][y1-2] = 1
y-=1
Else
If Rnd(10)<5
state="flyleft"
Else
state="flyright"
End If
End If
Case "flyleft"
If mymaptest.map[x1][y1] = 1
x-=1
Else
state="flyright"
End If
If Rnd(150)<5
If canflyup(x1+2,y1) = True
state="flyup"
End If
Elseif Rnd(150)>140
If canflydown(x1+2,y1) = True
state="flydown"
End If
End If
Case "flyright"
If mymaptest.map[x1+2][y1] = 1
x+=1
Else
state="flyleft"
End If
If Rnd(150)<5 Then
If canflyup(x1,y1) = True
state="flyup"
End If
Elseif Rnd(150)>140
If canflydown(x1,y1) = True
state="flydown"
End If
End If
Case "flydown"
If mymaptest.map[x1][y1+1] = 1
y+=1
Else
state="flyup"
End If
End Select
End Method
Method hurtplayer()
If lasthurt<Millisecs()
lasthurt = Millisecs()+600
If rectsoverlap(p.x,p.y,32,32,x,y,32,32)
p.health-=1
End If
End If
End Method
Method canattack()
If state="attack"
If distance(p.x,p.y,x,y) > 128
If Rnd(10)<5 Then
state="flyright"
Else
state="flyleft"
End If
End If
End If
If rectsoverlap(p.x-48,p.y-48,96,96,x-48,y-48,96,96)
state="attack"
End If
End Method
Method canflydown:Bool(x1:Int,y1:Int)
For Local y2=y1 To y1+5
If mymaptest.map[x1][y2] <> 1 Then
Return False
End If
Next
Return True
End Method
Method canflyup:Bool(x1:Int,y1:Int)
If y1<14 Then Return False
For Local y2=y1 To y1-5 Step -1
If mymaptest.map[x1][y2] <> 1 Then
Return False
End If
Next
Return True
End Method
Method draw()
SetColor 0,250,20
DrawOval x,y,w,h
SetColor 255,255,255
End Method
End Class
Class agent
Field x:Int,y:Int
Field w:Int,h:Int
Field state:String
Field remove:Bool=False
Method New(x:Int,y:Int)
Self.x = x
Self.y = y
w = 32
h = 32
state="right"
End Method
Method update()
Local x1:Int = ((Self.x-mapsx+16)/tilewidth)+mapx
Local y1:Int = ((Self.y)/tileheight)+mapy
Select state
Case "right"
If mymaptest.map[x1+2][y1] = 0 Or
mymaptest.map[x1+2][y1+1] = 1 Then
state="left"
Else
x+=1
End If
Case "left"
If mymaptest.map[x1][y1] = 0 Or
mymaptest.map[x1][y1+1] = 1 Then
state="right"
Else
x-=1
End If
End Select
If Rnd(1500)<2
Local placeegg:Bool=True
For Local i:=Eachin eggs
If i.x = x1 And i.y = y1
placeegg=False
End If
Next
If placeegg = True
If mymaptest.map[x1][y1] = 1
mymaptest.map[x1][y1] = 3
eggs.AddLast(New egg(x1,y1) )
End If
End If
End If
End Method
Method draw()
SetColor 255,0,0
DrawRect x,y,w,h
SetColor 255,255,255
End Method
End Class
Class egg
Field x:Int,y:Int
Field hatch:Bool=False
Field remove:Bool=False
Method New(x:Int,y:Int)
Self.x = x
Self.y = y
End Method
End Class
Class inventory
Field eggs:Int=0
Field meat:Int=0
Method New()
End Method
Method draw()
SetColor 0,0,0
DrawRect 0,DeviceHeight()-64,
DeviceWidth(),64
SetColor 255,255,255
DrawText "Eggs :"+eggs,10,DeviceHeight()-40
DrawText "Meat :"+meat,10,DeviceHeight()-20
DrawText "Health :"+p.health,100,DeviceHeight()-40
DrawText "This game template might be updated if I get inspired",DeviceWidth()/3,DeviceHeight()-60
DrawText "or if there are lots of hits on it. So check this",DeviceWidth()/3,DeviceHeight()-40
DrawText "link in the future.",DeviceWidth()/3,DeviceHeight()-20
End Method
End Class
' -----------------------------------------------------------------------------------------------
Global mymenuselect:menuselect = New menuselect
Global myinven:inventory = New inventory
Global mymaptest:maptest
Global p:player
Global a:List<agent> = New List<agent>
Global dw:List<deathwing> = New List<deathwing>
Global eggs:List<egg> = New List<egg>
Global myspear:spear = New spear
Class MyGame Extends App
Method OnCreate()
SetUpdateRate(60)
' restartgame
End Method
Method OnUpdate()
Select gamestate
Case "select"
mymenuselect.update
If mymenuselect.go = True
mymenuselect.go = False
gamestate = "play"
Seed = Millisecs()
restartgame
End If
Case "play"
If p.health < 0 Or KeyHit(KEY_ESCAPE)
'banana
gamestate = "select"
'restartgame
End If
p.update
alignmap
For Local i:=Eachin a
i.update
Next
For Local i:=Eachin dw
i.update
If i.remove = True
dw.Remove i
End If
Next
egghatch()
myspear.update
End Select
End Method
Method OnRender()
Cls 0,0,0
Select gamestate
Case "select"
mymenuselect.draw
Case "play"
drawmap
For Local i:=Eachin a
i.draw
Next
For Local i:=Eachin dw
i.draw
Next
myspear.draw
p.draw
SetColor 0,0,0
DrawRect 0,0,DeviceWidth(),50
SetColor 255,255,255
myinven.draw
DrawText "Use Cursor left/right to move, cursor up to jump. Travel down the mine and mine eggs/meat.",0,0
DrawText "Space to attack. t to take egg. p to place egg. Monsters spawn from eggs.",0,16
DrawText "Monsters lay eggs. M - Show map.",0,32
If KeyDown(KEY_M) Then
Cls 0,0,0
mymaptest.draw
End If
End Select
End Method
End Class
Function Main()
New MyGame()
End Function
Function egghatch()
'hatch deathwing
For Local z=0 Until 2
Local ax:Int=Rnd(mapwidth)
Local ay:Int=Rnd(mapheight)
If mymaptest.map[ax][ay] = 3
If countdeathwings()<maxdeathwings
dw.AddLast( New deathwing( (ax*tilewidth)-
(mapx*tilewidth),
(ay*tileheight)-
(mapy*tileheight)+
(mapsy) ) )
For Local i:=Eachin eggs
If i.x = ax
If i.y = ay
i.remove = True
End If
End If
Next
mymaptest.map[ax][ay] = 1
For Local i:=Eachin eggs
If i.remove = True
eggs.Remove i
End If
Next
Exit
End If
End If
Next
'hatch breeder
For Local z=0 Until mapwidth/2
Local ax:Int=Rnd(mapwidth)
Local ay:Int=Rnd(mapheight)
If mymaptest.map[ax][ay] = 3
For Local i:=Eachin eggs
If i.x = ax And i.y = ay
i.hatch = True
For Local ii:=Eachin a
Local x1:Int = ((ii.x-mapsx+16)/tilewidth)+mapx
Local y1:Int = ((ii.y)/tileheight)+mapy
If distance(i.x,i.y,x1,y1) < 15
i.hatch = False
End If
Next
End If
Next
End If
Next
For Local i:=Eachin eggs
If i.hatch = True
mymaptest.map[i.x][i.y] = 1
If Rnd(10) > 3 'hatch monster
a.AddLast( New agent( (i.x*tilewidth)-
(mapx*tilewidth),
(i.y*tileheight)-
(mapy*tileheight)+
(mapsy) ) )
End If
i.remove = True
For Local ii:=Eachin eggs
If i<>ii
If distance(i.x,i.y,ii.x,ii.y) < 10
ii.hatch=False
End If
End If
Next
End If
Next
For Local i:=Eachin eggs
If i.remove = True Then
eggs.Remove i
End If
Next
End Function
Function countdeathwings:Int()
Local cnt:Int=0
For Local i:=Eachin dw
cnt+=1
Next
Return cnt
End Function
Function alignmap:Bool()
For Local i=0 Until 4
If p.x > DeviceWidth / 2
If mapx+20 < mapwidth-1
mapsx-=1
If mapsx < 0 Then
mapsx = 31
mapx += 1
Endif
p.x-=1
p.movea(-1,0)
End If
End If
Next
For Local i=0 Until 4
If p.x < DeviceWidth / 2
If mapx > 0
mapsx+=1
If mapsx > 31 Then
mapsx = 0
mapx -= 1
Endif
p.x+=1
p.movea(1,0)
End If
End If
Next
' scrolling down
For Local i=0 Until 16
If p.y > DeviceHeight / 2
If mapy+14 < mapheight-1
mapsy-=1
If mapsy < 0 Then
mapsy = 31
mapy += 1
Endif
p.y-=1
p.movea(0,-1)
End If
End If
Next
' scrolling up
For Local i=0 Until 16
If p.y < DeviceHeight / 2
If mapy > 0
mapsy+=1
If mapsy > 31 Then
mapsy = 0
mapy -= 1
Endif
p.y+=1
p.movea(0,1)
End If
End If
Next
End Function
'player collide with solid blocks true/false
Function ptc:Bool(offsetx:Int=0,offsety:Int=0)
Local cx = (p.x+offsetx)/tilewidth+mapx
Local cy = (p.y+offsety)/tileheight+mapy
For Local y2=cy-1 Until cy+4
For Local x2=cx-1 Until cx+4
If x2>=0 And x2<mapwidth And y2>=0 And y2<mapheight
If mymaptest.map[x2][y2] = 0
Local x3 = (x2-mapx)*tilewidth-32+mapsx
Local y3 = (y2-mapy)*tileheight+mapsy
If rectsoverlap(p.x+offsetx,p.y+offsety,p.w,p.h,x3,y3,tilewidth,tileheight) = True
Return True
End If
End If
End If
Next
Next
Return False
End Function
'player collide with vines blocks true/false
Function pvc:Bool(offsetx:Int=0,offsety:Int=0)
Local cx = (p.x+offsetx)/tilewidth+mapx
Local cy = (p.y+offsety)/tileheight+mapy
For Local y2=cy-1 Until cy+4
For Local x2=cx-1 Until cx+4
If x2>=0 And x2<mapwidth And y2>=0 And y2<mapheight
If mymaptest.map[x2][y2] = 2
Local x3 = (x2-mapx)*tilewidth-32+mapsx
Local y3 = (y2-mapy)*tileheight+mapsy
If rectsoverlap(p.x+offsetx,p.y+offsety,p.w,p.h,x3,y3,tilewidth,tileheight) = True
Return True
End If
End If
End If
Next
Next
Return False
End Function
Function drawmap:Void()
For Local y=0 To 14
For Local x=0 To 20
Local x1 = ((x*tilewidth)+mapsx)-tilewidth