-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreation.lua
More file actions
1765 lines (1695 loc) · 61.2 KB
/
creation.lua
File metadata and controls
1765 lines (1695 loc) · 61.2 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
local numtap=0--gestion de la demande de creation de d'un batiment
local animconst = require ( "constructanim" )
local batiment = require( "batiment" )
local ancienxvalide=nil
local ancienyvalide=nil
local bugmulticlic=0
--nbatiment1exist=nil
local compteuropt=0
local cliccreabouton=false
if not functionload then
function removenbatbt()--supression de bouton pour la creation d'un batiment
if groupebattemp~=nil then
-- group[2048]:remove(groupebattemp)
-- groupebattemp:removeSelf()
display.remove(groupebattemp)
groupebattemp=nil
end
if grcreabatcer~=nil then
display.remove(grcreabatcer)
-- grcreabatcer:removeSelf()
grcreabatcer=nil
cercle=nil
end
-- print("remove bouton\n\n\n\n")
-- if valider~=nil then
-- group[2048]:remove( valider )
-- valider:removeSelf()
-- valider=nil
-- supprimer:removeEventListener( "tap", supprimer )
-- group[2048]:remove( supprimer )
-- supprimer:removeSelf()
-- supprimer=nil
-- group[2048]:remove(interdit)
-- interdit:removeSelf( )
-- interdit=nil
-- grcreabatcer:removeSelf()
-- grcreabatcer=nil
-- for i, v in ipairs(cercle) do
-- cercle[i]=nil
-- end
-- cercle=nil
-- group[2048].remove(conttext)
-- conttext:removeSelf()
-- conttext=nil
-- group[2048]:remove(conttextOr)
-- conttextOr:removeSelf()
-- conttextOr=nil
-- end
end
function removenbat(faite)--supression du batiment temporaire
if enconst~=0 then
print("removenbat")
-- nbatiment:removeEventListener( "touch", nbatiment )
-- nbatiment:removeEventListener( "tap", nbatiment )
-- group[2048]:remove(nbatiment)
display.remove(nbatiment.image)
-- nbatiment:removeSelf()
-- local function timertemp(event)
-- nbatiment=nil
-- end
-- local timertemp1=timer.performWithDelay(50,timertemp)
enconst=0
removenbatbt()
if tuto==2 and not faite then
if tutoaction==1 or tutoaction==2 then
print("sup bat tuto")
actiondefaite()
end
end
end
end
-- function removebattemp()
-- group[2048]:remove(groupebattemp)
-- groupebattemp:removeSelf()
-- groupebattemp=nil
-- end
end
local creadisp=function(obj)
construireinf.isVisible=false
construirearch.isVisible=false
construirearch.x=construirearch.x1
construirearch.y=construirearch.y1
construireinf.x=construireinf.x1
construireinf.y=construireinf.y1
construirearch.xScale=construirearch.scale
construirearch.yScale=construirearch.scale
construireinf.xScale=construireinf.scale
construireinf.yScale=construireinf.scale
construirearchTexte.x=construirearchTexte.x1
construirearchTexte.y=construirearchTexte.y1
construireinfTexte.x=construireinfTexte.x1
construireinfTexte.y=construireinfTexte.y1
construirearchOr.x=construirearchOr.x1
construirearchOr.y=construirearchOr.y1
construireinfOr.x=construireinfOr.x1
construireinfOr.y=construireinfOr.y1
construirearchTexte.xScale=construirearchTexte.scale
construirearchTexte.yScale=construirearchTexte.scale
construireinfTexte.xScale=construireinfTexte.scale
construireinfTexte.yScale=construireinfTexte.scale
construirearchOr.xScale=construirearchOr.scale
construirearchOr.yScale=construirearchOr.scale
construireinfOr.xScale=construireinfOr.scale
construireinfOr.yScale=construireinfOr.scale
construireinfTexte.isVisible=false
construirearchTexte.isVisible=false
construireinfOr.isVisible=false
construirearchOr.isVisible=false
end
if not functionload then
function removecrea(partiel)--pas utiliser
numtapba=0
-- animation ici avec listener
print("effacer crea 51")
transition.to(construireinf,{time=250,transition=easing.inCirc, y=construire.y,xScale=construireinf.scale*0.5,yScale=construireinf.scale*0.5, x=construire.x, onComplete=creadisp})
transition.to(construirearch,{time=250,transition=easing.inCirc,xScale=construirearch.scale*0.5,yScale=construirearch.scale*0.5, y=construire.y, x=construire.x})
transition.to(construireinfTexte,{time=250,transition=easing.inCirc,xScale=construirearchTexte.scale*0.5,yScale=construirearchTexte.scale*0.5, y=construire.y, x=construire.x})
transition.to(construireinfOr,{time=250,transition=easing.inCirc,xScale=construirearchOr.scale*0.5,yScale=construirearchOr.scale*0.5, y=construire.y, x=construire.x})
transition.to(construirearchTexte,{time=250,transition=easing.inCirc,xScale=construirearchTexte.scale*0.5,yScale=construirearchTexte.scale*0.5, y=construire.y, x=construire.x})
transition.to(construirearchOr,{time=250,transition=easing.inCirc,xScale=construirearchOr.scale*0.5,yScale=construirearchOr.scale*0.5, y=construire.y, x=construire.x})
-- construireinfTexte.isVisible=false
-- construirearchTexte.isVisible=false
-- construireinfOr.isVisible=false
-- construirearchOr.isVisible=false
--construireinf.isVisible=false
--construirearch.isVisible=false
numtapb=0
if partiel==true then
removenbat()
end
if tuto==2 then
if tutoaction==1 then
print("removecrea l55")
actiondefaite()
end
end
end
end
local function autorisefunction(testinbatiment)
local autorise=0
if testinbatiment==nil then
autorise=1
end
if autorise==0 then
if testinbatiment.y==nil then
autorise=1
end
end
if autorise==0 then
if testinbatiment.y+30<mayminuspos2+30 or testinbatiment.y+30>maypos2 or testinbatiment.x<maxminuspos2+30 or testinbatiment.x>maxpos2-30 then
autorise=1
end
end
if autorise==0 and not modezombie and not modepanique then
local i=1
if not goh then
while i<=cheminnb+1 do
--for i=1,cheminnb+1,1 do
local coef=1
if chemin[i].mechant~=nil and not modepanique then
if chemin[i].mechant>1 then
coef=chemin[i].mechant*0.9
end
end
-- if not modepanique and cheminlargeur~=nil then
-- coef=coef*cheminlargeur
-- end
if 1500*coef*cheminlargeur>((testinbatiment.x-chemin[i].x)*(testinbatiment.x-chemin[i].x)+(testinbatiment.y+30-chemin[i].y)*(testinbatiment.y+30-chemin[i].y)) then
autorise=1
i=cheminnb+2
end
i=i+1
end
else
while i<=cheminnb+1 do
local rayonauto=1500
if chemin[i].rayon~=nil then
rayonauto=chemin[i].rayon
end
if rayonauto>((testinbatiment.x-chemin[i].x)*(testinbatiment.x-chemin[i].x)+(testinbatiment.y+30-chemin[i].y)*(testinbatiment.y+30-chemin[i].y)) then
autorise=1
i=cheminnb+2
end
i=i+1
end
end
end
if autorise==0 then
local i=1
while i<=obstaclenb do
--for i=1,obstaclenb,1 do--wandrille le 11 correspond au nb de point de collision (obstacle)------------------------------------------------------------------------------------------------------------
if 3000>((testinbatiment.x-obstacle[i].x)*(testinbatiment.x-obstacle[i].x)+(testinbatiment.y+30-obstacle[i].y)*(testinbatiment.y+30-obstacle[i].y))then
autorise=1
i=obstaclenb+1
end
i=i+1
end
end
if autorise==0 then
local i=1
while i<=obstacle1nb do
--for i=1,obstacle1nb,1 do--wandrille le 1 correspond au nb de point de collison(obstacle1)----------------------------------------------------------------------------------------------------------------
if 20000>((testinbatiment.x-obstacle1[i].x)*(testinbatiment.x-obstacle1[i].x)+(testinbatiment.y+30-obstacle1[i].y)*(testinbatiment.y+30-obstacle1[i].y))then
autorise=1
i=obstacle1nb+1
end
i=i+1
end
end
if autorise==0 then
if obstacle0nb>=1 then
local i=1
while i<=obstacle0nb do
local rayon=500
if obstacle0[i].rayon~=nil then
rayon=obstacle0[i].rayon
end
if rayon>((testinbatiment.x-obstacle0[i].x)*(testinbatiment.x-obstacle0[i].x)+(testinbatiment.y+30-obstacle0[i].y)*(testinbatiment.y+30-obstacle0[i].y))then
autorise=1
i=obstacle0nb+1
end
i=i+1
end
end
end
-- if autorise==0 then
-- local i=1
-- while i<=#obstacleim do
-- --for i=1,#obstacleim,1 do
-- if 500>((testinbatiment.x-obstacleim[i].x)^2+(testinbatiment.y+30-obstacleim[i].y)^2)then
-- autorise=1
-- i=#obstacleim+1
-- end
-- i=i+1
-- end
-- end
if autorise==0 then
if nbbatiment>0 then
local i=1
while i<=nbbatiment do
if ibatiment[i]~=nil then
--for i=1,nbbatiment do//for remplacer par while
if ibatiment[i].x1~=nil and ibatiment[i].y1~=nil and ibatiment[i].sup1==0 then
if 10000>((testinbatiment.x-ibatiment[i].x1)*(testinbatiment.x-ibatiment[i].x1)+(1.25*(testinbatiment.y-ibatiment[i].y1))*(1.25*(testinbatiment.y-ibatiment[i].y1))) then
autorise=1
i=nbbatiment+1
end
end
end
i=i+1
end
end
end
return autorise
end
local function testinterdit(testinbatiment,deb,batconfli)--verifiaction si on a le droit de positionner le batiment
if testinbatiment~=nil then
--print("1testinbatiment.x= "..testinbatiment.x)
autorise=autorisefunction(testinbatiment)
-- if batconfli~=0 then
-- --print("batconfli!=0")
-- cercle[batconfli]:setFillColor(0.8,0.2,0.2,0.2 )
-- cercle[batconfli]:setStrokeColor( 1, 0.2, 0.2,0.5 )
batconfli=0
-- end
if nbbatiment>0 and grcreabatcer~=nil then
for i=1,nbbatiment do
if ibatiment[i]~=nil then
if ibatiment[i].x1==nil or ibatiment[i].sup1~=0 then
--print("coucou")
if cercle[i+2]~=nil then
grcreabatcer:remove(cercle[i+2])
cercle[i+2]:removeSelf()
cercle[i+2]=nil
end
else
if cercle[i+2]==nil then
cercle[i+2]=display.newCircle(grcreabatcer,ibatiment[i].x1+ibatiment[i].xbase,ibatiment[i].y1+ibatiment[i].ybase,50)
cercle[i+2]:setFillColor(0.8,0.2,0.2,0.2 )
cercle[i+2].strokeWidth = 2
cercle[i+2]:setStrokeColor( 1, 0.2, 0.2,0.5 )
cercle[i+2].yScale=0.8
end
if 10000>((testinbatiment.x-ibatiment[i].x1)*(testinbatiment.x-ibatiment[i].x1)+(1.25*(testinbatiment.y-ibatiment[i].y1))*(1.25*(testinbatiment.y-ibatiment[i].y1))) then
autorise=1
batconfli=i+2
cercle[i+2]:setFillColor(1,0.2,0.2,0.5 )
cercle[i+2]:setStrokeColor( 1, 0.2, 0.2,0.8 )
else
cercle[i+2]:setFillColor(0.8,0.2,0.2,0.2 )
cercle[i+2]:setStrokeColor( 1, 0.2, 0.2,0.5 )
end
end
end
end
end
if autorise==1 then
--print("autorise==1")
if ancienxvalide~=nil then
--print("ancienxvalide~=nil")
compteuropt=compteuropt+1
if compteuropt>2 then
compteuropt=0
local distancemin=(testinbatiment.x-ancienxvalide)*(testinbatiment.x-ancienxvalide)+(testinbatiment.y-ancienyvalide)*(testinbatiment.y-ancienyvalide)
if distancemin>1000 then
local limitex1carre=ancienxvalide
local limitex2carre=testinbatiment.x
local limitey1carre=ancienyvalide
local limitey2carre=testinbatiment.y
local minx=limitex1carre
local maxx=limitex2carre
if minx>maxx then
maxx=limitex1carre
minx=limitex2carre
end
maxx=maxx+60
minx=minx-60
local miny=limitey1carre
local maxy=limitey2carre
if miny>maxy then
miny=limitey2carre
maxy=limitey1carre
end
maxy=maxy+60
miny=miny-60
local testposbat={}
testposbat.x=minx -- ancienxvalide
testposbat.y=miny -- ancienyvalide
local varrandx=mathfloor((maxx-minx)*0.2)
--print("maxx "..maxx.." minx "..minx.." result "..varrandx)
if varrandx<10 then
varrandx=10
end
local varrandy=mathfloor((maxy-miny)*0.2)
--print("maxy "..maxy.." miny "..miny.." result "..varrandy)
if varrandy<10 then
varrandy=10
end
-- print("nb operation "..(((maxx-minx)/varrandx)*((maxy-miny)/varrandy)))
-- if ((maxx-minx)/varrandx)*((maxy-miny)/varrandy)<20 then
-- print("precision ajouter")
-- while ((maxx-minx)/varrandx)*((maxy-miny)/varrandy)<20 do
-- varrandx=varrandx*0.9
-- varrandy=varrandy*0.9
-- end
-- end
while testposbat.x<maxx do --i*xdirec<limitex2carre*(xdirec) do
while testposbat.y<maxy do --j*ydirec<limitey2carre*(ydirec) do
local distancemintest=(testinbatiment.x-testposbat.x)*(testinbatiment.x-testposbat.x)+(testinbatiment.y-testposbat.y)*(testinbatiment.y-testposbat.y)
if distancemin>distancemintest then
local autorise1=autorisefunction(testposbat)
if autorise1==0 then
distancemin=distancemintest
ancienxvalide=testposbat.x
ancienyvalide=testposbat.y
end
end
testposbat.y=testposbat.y+varrandy
end
testposbat.y=miny
testposbat.x=testposbat.x+varrandx
end
end
end
if groupebattemp~=nil then
groupebattemp.nbatiment1.isVisible=true
groupebattemp.nbatiment1.x=testinbatiment.x+batimentinit[testinbatiment.typebatiment][0][1].x
groupebattemp.nbatiment1.y=testinbatiment.y+batimentinit[testinbatiment.typebatiment][0][1].y
end
testinbatiment.y=ancienyvalide
testinbatiment.x=ancienxvalide
testinbatiment.image.x=testinbatiment.x+batimentinit[testinbatiment.typebatiment][0][1].x
testinbatiment.image.y=testinbatiment.y+batimentinit[testinbatiment.typebatiment][0][1].y
if tuto==2 then
if tutoaction==2 then
if fleche.type then
background:remove(fleche)
fleche:removeSelf()
fleche=display.newImage(imbouton.swipe,1)
background:insert(fleche)
fleche.group=1
fleche.type=false
end
fleche.xScale=0.5
fleche.yScale=0.5
fleche.x=testinbatiment.x+fleche.width*fleche.xScale*0.5 --nbatiment.x-fleche.width*0.6*fleche.xScale
fleche.y=testinbatiment.y+fleche.height*fleche.yScale*0.5 --nbatiment.y-fleche.height*0.6*fleche.yScale
end
end
-- if groupebattemp~=nil then
-- groupebattemp.interdit.x=groupebattemp.nbatiment1.x
-- groupebattemp.interdit.y=groupebattemp.nbatiment1.y
-- groupebattemp.interdit.isVisible=true
-- end
autorise=0
else
local trouverpos=false
local dirchx=1
local dirchy=0
local direct=-1
local largeur=1
local largfai=0
local largfin=0
local testcoor={}
testcoor.x=testinbatiment.x
testcoor.y=testinbatiment.y
while not trouverpos and largeur<5 do
largfai=0
largfin=largfin+1
if largfin>=2 then
largfin=0
largeur=largeur+1
end
direct=direct+1
if direct>=4 then
direct=0
end
if direct==0 then
dirchx=1
dirchy=0
elseif direct==1 then
dirchx=0
dirchy=1
elseif direct==2 then
dirchx=-1
dirchy=0
elseif direct==3 then
dirchx=0
dirchy=-1
end
while largfai<=largeur and not trouverpos do
largfai=largfai+1
testcoor.x=testcoor.x+7*dirchx*largfai
testcoor.y=testcoor.y+7*dirchy*largfai
local autorise1=autorisefunction(testcoor)
if autorise1==0 then
trouverpos=true
end
--local lecercle=display.newCircle(group[2048],testcoor.x,testcoor.y,7)
end
end
if trouverpos then
if groupebattemp~=nil then
--print("trouverpos")
groupebattemp.nbatiment1.isVisible=false --true
--nbatiment1.x=testcoor.y --testinbatiment.x
--nbatiment1.y=testcoor.x --testinbatiment.y
-- groupebattemp.interdit.x=testinbatiment.x
-- groupebattemp.interdit.y=testinbatiment.y
groupebattemp.conttext.x=testinbatiment.x
groupebattemp.conttextOr.x=groupebattemp.conttext.x+25*apparence
groupebattemp.conttext.y=testinbatiment.y-30-10*apparence
groupebattemp.conttextOr.y=groupebattemp.conttext.y
end
testinbatiment.y=testcoor.y
--print("3testinbatiment.x= "..testinbatiment.x)
testinbatiment.x=testcoor.x
--print("4testinbatiment.x= "..testinbatiment.x)
testinbatiment.image.x=testinbatiment.x+batimentinit[testinbatiment.typebatiment][0][1].x
testinbatiment.image.y=testinbatiment.y+batimentinit[testinbatiment.typebatiment][0][1].y
ancienxvalide=testcoor.x
ancienyvalide=testcoor.y
if tuto==2 then
if tutoaction==2 then
if fleche.type then
background:remove(fleche)
fleche:removeSelf()
fleche=display.newImage(imbouton.swipe,1)
background:insert(fleche)
fleche.group=1
fleche.type=false
end
fleche.xScale=0.5
fleche.yScale=0.5
fleche.x=testinbatiment.x+fleche.width*fleche.xScale*0.5 --nbatiment.x-fleche.width*0.6*fleche.xScale
fleche.y=testinbatiment.y+fleche.height*fleche.yScale*0.5 --nbatiment.y-fleche.height*0.6*fleche.yScale
end
end
-- interdit.x=nbatiment1.x
-- interdit.y=nbatiment1.y
--groupebattemp.interdit.isVisible=true
autorise=0
end
end
if ancienxvalide==nil then
groupebattemp.nbatiment1.isVisible=false
-- groupebattemp.interdit.x=testinbatiment.x
-- groupebattemp.interdit.y=testinbatiment.y
-- groupebattemp.interdit.isVisible=true
if tuto==2 then
if tutoaction==2 then
if not fleche.type then
fleche.xScale=0.5
fleche.yScale=0.5
fleche.x=testinbatiment.x+fleche.width*fleche.xScale*0.5 --nbatiment.x-fleche.width*0.6*fleche.xScale
fleche.y=testinbatiment.y+fleche.height*fleche.yScale*0.5 --nbatiment.y-fleche.height*0.6*fleche.yScale
end
end
end
end
else
--print("autorise~=1")
if groupebattemp~=nil then
groupebattemp.nbatiment1.isVisible=false
--groupebattemp.interdit.isVisible=false
end
ancienxvalide=testinbatiment.x
ancienyvalide=testinbatiment.y
if tuto==2 then
if tutoaction==2 then
if not fleche.type then
background:remove(fleche)
fleche:removeSelf()
fleche=display.newImage(imbouton.fleche,1)
background:insert(fleche)
fleche.group=1
fleche.xScale=1.2
fleche.yScale=1.2
fleche.type=true
print("remplace fleche")
end
fleche.xScale=1.2
fleche.yScale=1.2
fleche.x=nbatiment.x-fleche.width*0.6*fleche.xScale
fleche.y=nbatiment.y-fleche.height*0.6*fleche.yScale
transition.from(fleche,{time=200,transition=easing.inCirc,xScale=fleche.xScale*0.9,yScale=fleche.yScale*0.9})
end
end
end
if groupebattemp~=nil then
groupebattemp.supprimer.x=testinbatiment.x
groupebattemp.supprimer.y=testinbatiment.y+30+30*apparence
groupebattemp.valider.x=testinbatiment.x
groupebattemp.valider.y=testinbatiment.y+10
groupebattemp.valider.isVisible = false
groupebattemp.supprimer.isVisible=false
end
-- interdit.x=testinbatiment.x
-- interdit.y=testinbatiment.y
-- interdit.isVisible=false
if cercle~=nil then
if cercle[1]~=nil then
cercle[1].x=testinbatiment.x
cercle[1].y=testinbatiment.y+30
end
end
cercleporte.x=testinbatiment.x
cercleporte.y=testinbatiment.y+30
if(autorise==1)then
cercle[1]:setFillColor(1,0.2,0.2,0.7 )
cercle[1]:setStrokeColor( 1, 0.2, 0.2,1 )
if deb==1 then
groupebattemp.supprimer.isVisible=true
end
--interdit.isVisible=true
else
if cercle~=nil then
if cercle[1]~=nil then
cercle[1]:setFillColor(0.8,0.2,0.2,0.4 )
cercle[1]:setStrokeColor( 0, 0.5, 0,0.8 )
end
end
if deb==1 then
if groupebattemp~=nil then
--groupebattemp.interdit.isVisible=false
groupebattemp.supprimer.isVisible=true
--groupebattemp.valider.alpha=1--0.5
groupebattemp.valider.isVisible=true
groupebattemp.conttext.isVisible=true
groupebattemp.conttextOr.isVisible=true
end
end
end
--print("2testinbatiment.x= "..testinbatiment.x)
return batconfli
end
end
local function nouv(typebatiment)--nuveau batiment temporel créé
--local batiment = require( "batiment" )
--if cliccreabouton==false then
-- tuto ici
-- if coroutine.running()~=nil then
-- print("coroutine creation: "..coroutine.running())
-- else
-- print("coroutine creation: nil")
-- end
cliccreabouton=true
local function listenercliccreabouton(event)
cliccreabouton=false
print("remove listener")
end
local timercliccreabouton=timer.performWithDelay( 500, listenercliccreabouton )
local batconfli=0
numtap=0
local function nbatimenttap()--demande de construction du batiment(endroit chossi)
if(autorise==0 and numtapb==0 and clicpouvoir1==0 and clicpouvoir2==0 and clicpouvoir3==0 and geneclic==0)then
numtap=numtap+1
-- if(numtap==1)then
-- valider.alpha = 1
-- --text5 = display.newText( "1", 180, 10, native.systemFontBold, 12 )
-- end
if(numtap==1)then
--corriger pb lorsque on clique en meme temps sur le bouton construire azerty
-- print("numtapb")
-- print(numtapb)
removenbatbt()
if argent-(-(prix[typebatiment][0][1])*3)<=0 then
argent=argent-(-3*prix[typebatiment][0][1])
--print(argent)
vartune()
--tune.text=-argent/3 --.." d'or"
--if -argent/3>-1 and -argent/3<1 then
-- print("mise a 0 abs")
--tune.text=1
-- tune.text=0
--end
nbatiment.type1=typebatiment
constructionanim(nbatiment,1)
if 1500>((nbatiment.x-genepoint.x)^2+(nbatiment.y-genepoint.y)^2) then
local function testautorisation(self)
local autorise=1
if self.y+30<mayminuspos2+30 or self.y+30>maypos2-30 or self.x<maxminuspos2+30 or self.x>maxpos2-30 then
autorise=2
end
if autorise==1 then
if modezombie or modepanique then
autorise=0
else
local i=1
if not goh then
while i<=cheminnb+1 do
--for i=1, cheminnb+1,1 do
if 2000>((self.x-chemin[i].x)^2+(self.y+30-chemin[i].y)^2)then
autorise=0
end
i=i+1
end
else
while i<=cheminnb+1 do
local coef=1
if chemin[i].mechant~=nil and not modepanique then
if chemin[i].mechant>1 then
coef=chemin[i].mechant*chemin[i].mechant
end
end
if 400*coef*cheminlargeur>((self.x-chemin[i].x)*(self.x-chemin[i].x)+(self.y-chemin[i].y)*(self.y-chemin[i].y))then
autorise=0
end
i=i+1
end
end
end
end
if autorise==2 then
autorise=1
end
if autorise==0 then
local i=1
while i<=nbbatiment do
if ibatiment[i]~=nil then
if ibatiment[i].x~=nil and ibatiment[i].sup1==0 then
--for i=1,nbbatiment do//for remplacer par while
if 1500>((self.x-ibatiment[i].x1)^2+((self.y-ibatiment[i].y1))^2) then
autorise=1
i=nbbatiment+1
end
end
end
i=i+1
end
if 1500>((self.x-nbatiment.x)^2+((self.y-nbatiment.y))^2) then
autorise=1
end
end
return autorise
end
local testposbat={}
testposbat.x=genepoint.x
testposbat.y=genepoint.y
local i=1
local xy=0
local plusmoins=1
local cpt=0
local autorise=1
while autorise==1 do
if xy==0 then
testposbat.x=testposbat.x+plusmoins*30
else
testposbat.y=testposbat.y+plusmoins*30
end
cpt=cpt+1
if cpt==i then
cpt=0
if xy==0 then
xy=1
else
xy=0
plusmoins=-plusmoins
i=i+1
end
end
--print("test autorise "..testposbat.x.." "..testposbat.y)
--local pointteset=display.newCircle(group[2048],testposbat.x,testposbat.y, 2 )
autorise=testautorisation(testposbat)
end
-- local k=1
-- while k<=nbsoldat do
-- if isoldat[k].gene==1 then
-- if isoldat[k].encombat==1 then
-- isoldat[k].vivant=false
-- isoldat[k].endeplacement=1
-- end
-- k=nbsoldat+1
-- end
-- end
genepoint.x=testposbat.x
genepoint.y=testposbat.y
end
else
pasassezfric()
-- tune.xScale=tune.xScale*7
-- tune.yScale=tune.yScale*7
-- tune:setFillColor( 1, 0, 0 )
-- local k=0
-- local pair=0
-- local function listener( event )
-- k=k+1
-- if pair==1 then
-- print(pair)
-- tune.xScale=tune.xScale*7
-- tune.yScale=tune.yScale*7
-- --pair=0
-- end
-- if pair==0 then
-- print(pair)
-- tune.xScale=tune.xScale/7
-- tune.yScale=tune.yScale/7
-- pair=1
-- else
-- pair=0
-- end
-- if k<10 then
-- print(k)
-- timer.performWithDelay( 500, listener )
-- else
-- tune.xScale=tune.xScale/7
-- tune.yScale=tune.yScale/7
-- tune:setFillColor( 1, 1, 1 )
-- end
-- end
-- timer.performWithDelay( 500, listener )
removenbat()
-- group[2048]:remove(nbatiment)
-- nbatiment:removeSelf()
-- nbatiment=nil
end
numtap=0
enconst=0
end
end
end
local var=0
function nbatiment.image:touch( event )--placement du batiment
local result = true
--print()
local phase = event.phase
local previousTouches = self.previousTouches
local numTotalTouches = 1
if ( previousTouches ) then
-- add in total from previousTouches, subtract one if event is already in the array
numTotalTouches = numTotalTouches + self.numPreviousTouches
if previousTouches[event.id] then
numTotalTouches = numTotalTouches - 1
end
end
if "began" == phase then
retinf.nbaction=retinf.nbaction+1
if ( not self.isFocus ) then
display.getCurrentStage():setFocus( self )
self.isFocus = true
self.myX = event.x/taille-nbatiment.x-- event.x/(taille^0.55)-self.x------------------------------------a modifier ici ou plus bas
self.myY = event.y/taille-nbatiment.y----------------probleme du a taille qui vaut 1 par defaut alors qu'il devrait valoir (?)
previousTouches = {}
self.previousTouches = previousTouches
self.numPreviousTouches = 0
elseif ( not self.distance ) then
local dx,dy
end
if not previousTouches[event.id] then
self.numPreviousTouches = self.numPreviousTouches + 1
end
previousTouches[event.id] = event
xori=nbatiment.x
yori=nbatiment.y
var=0
elseif self.isFocus then
if "moved" == phase then
if ( self.distance ) then
local dx,dy
else
--self.myx coordonnée de depart
--var=var+(event.x*event.x)+(event.y*event.y)
nbatiment.x = event.x/taille - self.myX
nbatiment.y = event.y/taille - self.myY
nbatiment.image.x=nbatiment.x+batimentinit[nbatiment.typebatiment][0][1].x
nbatiment.image.y=nbatiment.y+batimentinit[nbatiment.typebatiment][0][1].y
var=var+(nbatiment.x-xori)*(nbatiment.x-xori)+(nbatiment.y-yori)*(nbatiment.y-yori)
-- supprimer.x=self.x
-- supprimer.y=self.y+30+30*apparence
-- valider.x=self.x
-- valider.y=self.y+10
-- valider.isVisible = false
-- supprimer.isVisible=false
-- interdit.x=self.x
-- interdit.y=self.y
-- interdit.isVisible=false
-- cercle[1].x=self.x
-- cercle[1].y=self.y+30
batconfli=testinterdit(nbatiment,0,batconfli)
if groupebattemp~=nil then
groupebattemp.conttext.x=groupebattemp.valider.x
groupebattemp.conttext.y=nbatiment.y-30-10*apparence
groupebattemp.conttextOr.x=groupebattemp.conttext.x+25*apparence
groupebattemp.conttextOr.y=groupebattemp.conttext.y
groupebattemp.conttext.isVisible=false
groupebattemp.conttextOr.isVisible=false
end
--numtap=0
end
if not previousTouches[event.id] then
self.numPreviousTouches = self.numPreviousTouches + 1
end
previousTouches[event.id] = event
elseif "ended" == phase or "cancelled" == phase then
blabla=testinterdit(nbatiment,1,0)
groupebattemp.nbatiment1.isVisible=false
-- if nbatiment1exist~=nil then
-- nbatiment1.isVisible=false
-- end
if previousTouches[event.id] then
self.numPreviousTouches = self.numPreviousTouches - 1
previousTouches[event.id] = nil
end
if ( #previousTouches > 0 ) then
-- must be at least 2 touches remaining to pinch/zoom
self.distance = nil
else
-- previousTouches is empty so no more fingers are touching the screen
-- Allow touch events to be sent normally to the objects they "hit"
display.getCurrentStage():setFocus( nil )
if(autorise==0)then
groupebattemp.supprimer.isVisible=true
--groupebattemp.valider.alpha=1--0.5
groupebattemp.valider.isVisible=true
groupebattemp.conttext.isVisible=true
groupebattemp.conttextOr.isVisible=true
end
self.isFocus = false
self.distance = nil
self.xScaleOriginal = nil
self.yScaleOriginal = nil
-- reset array
self.previousTouches = nil
self.numPreviousTouches = nil
--print(self.x.." "..self.myX.."my"..self.y.." "..self.myY)
--print(event.x.." "..self.x)
--print("var"..var)
--if newvar~=nil then
-- newvar.text="var: "..var
if var<80 then --if ((self.x-self.myX)^2+(self.y-self.myY)^2)<10000 then
clicsurqqcfunc()
local function timerdemerde(event)
if(fenaff==false and clicpause==0 and pv1clic==0 and pv2clic==0 and pv3clic==0 and clicconstruire==0 and clicinfanterie==0 and clicarcher==0 and clicpouvoir1==0 and clicpouvoir2==0 and clicpouvoir3==0 and pv1clicactiver==0 and pv2clicactiver==0 )then --
if nbatiment.x==nil then
nbatiment.x=xori
if nbatiment.x==nil then
nbatiment.x=(-background.x+contentcenterx)/taille
end
end
if nbatiment.y==nil then
nbatiment.y=yori
if nbatiment.y==nil then
nbatiment.y=(-background.y+contentcentery)/taille
end
end
if creationtime==0 then
creationtime=1
--print("et hop ca c'est fait")
local function listenercreation(event)
creationtime=0
--print()
end
local timer1creation=timer.performWithDelay( 100, listenercreation )
nbatimenttap()
end
nbatiment.x=xori--à corriger si genere bug
nbatiment.y=yori--
nbatiment.image.x=nbatiment.x+batimentinit[nbatiment.typebatiment][0][1].x
nbatiment.image.y=nbatiment.y+batimentinit[nbatiment.typebatiment][0][1].y
end
end
local timerdemerde=timer.performWithDelay( 10, timerdemerde )
else
numtap=0
end
end
--if event.x
end
end
return result
end
-- register table listener
function nbatiment.image:tap( event )--action lorsqu'on clique sur un le batiment ou le bouton confirmer
clicsurqqcfunc()
local function timerdemerde(event)
if(fenaff==false and clicpause==0 and pv1clic==0 and pv2clic==0 and pv3clic==0 and clicconstruire==0 and clicinfanterie==0 and clicarcher==0 and clicpouvoir1==0 and clicpouvoir2==0 and clicpouvoir3==0 and pv1clicactiver==0 and pv2clicactiver==0 )then --
if creationtime==0 then
creationtime=1
clicsurval=true
--print("et hop ca c'est fait")
local function listenercreation(event)
creationtime=0
clicsurval=false
--print()
end
local timer1creation=timer.performWithDelay( 100, listenercreation )
nbatimenttap()
end
else
removenbat()
end
end
local timerdemerde=timer.performWithDelay( 10, timerdemerde )
end
function groupebattempsupprimer( event )--clic sur annuler la demande de creationd'un batiment
clicsurqqcfunc()
if numtapb==0 and clicpouvoir1==0 and clicpouvoir2==0 and clicpouvoir3==0 and geneclic==0 then
removenbat()
end
end
--function valider:tap( event)
--end
-- function valider:tap(event)--clic sur valider la construction du batiment
-- clicsurqqcfunc()
-- local function timerdemerde(event)
-- if(fenaff==false and clicpause==0 and pv1clic==0 and pv2clic==0 and pv3clic==0 and clicconstruire==0 and clicinfanterie==0 and clicarcher==0 and clicpouvoir1==0 and clicpouvoir2==0 and clicpouvoir3==0 and pv1clicactiver==0 and pv2clicactiver==0 )then --
-- if creationtime==0 then
-- creationtime=1
-- clicsurval=true
-- --print("et hop ca c'est fait")
-- local function listenercreation(event)
-- creationtime=0
-- clicsurval=false
-- --print()
-- end
-- local timer1creation=timer.performWithDelay( 100, listenercreation )
-- nbatimenttap()
-- end
-- else
-- removenbat()