-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.agc
576 lines (365 loc) · 14 KB
/
main.agc
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
// Project: Careca's Hero
// Created: 2021-06-03
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Careca's Hero" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetDefaultWrapU(1)
backdropf=LoadImage("Background final 1023x758.png")
backspritef=CreateSprite(backdropf)
SetSpritePosition(backspritef,0,0)
SetSpriteVisible(backspritef,0)
//Incluir os arquivos
#include "Moviment.agc"
#include "Loader.agc"
//Inserir os shapes
gosub load_moviment
gosub loade_images
gosub Load_sound
gosub Load_menu
gosub Load_titles
score=0
do
xcroll#=xcroll#+.0006
SetSpriteUVOffset(backspritem,xcroll#,0)
if GetPointerPressed()=1
if GetTextHitTest(1,GetPointerX(),GetPointerY()) //Clicar no botão Play Game
PlaySound(5)
PlayMusic(1,1)
//Deixa os botões invisíveis
SetTextVisible(1,0) //Botão Start Game
SetTextVisible(3,0) //Botão Exit
//Deixa o botão "Score" visível
SetTextVisible(4,1)
//Deixa as árvores visível
SetSpriteVisible(26,1)
SetSpriteVisible(27,1)
//Deixa o inimigo visível
SetSpriteVisible(24,1)
SetSpriteVisible(31,1)
//Deixa a logo e o background do menu invisíveis
SetSpriteVisible(logosprite,0)
SetSpriteVisible(backspritem,0)
SetSpriteVisible(backsprite,1)
SetSpritePosition(2,CarecaX,CarecaY)
//Define o score = 0 ao iniciar o game
SetTextString(4,"Score: "+str(score))
//Ativa a música e define o seu volume
PlayMusic(1,1)
SetMusicSystemVolume(35)
//Adiciona e anima o personagem jogável
AddSpriteAnimationFrame(2,LoadImage("Careca-parado.png"))
AddSpriteAnimationFrame(2,LoadImage("Careca-andando1.png"))
AddSpriteAnimationFrame(2,LoadImage("Careca-andando2.png"))
PlaySprite(2,7,1,1,3)
//Deixa o Careca e o background visíveis
SetSpriteVisible(2,1)
SetSpriteVisible(21,1)
EnemyX=1200
EnemyY=680
EnemyVX=-900
EnemyVY=690
BossX=1200
BossY=380
endif
endif
if GetSpriteCollision(2,24)=1
StopMusic()
//Deixa os botões invisíveis
SetTextVisible(1,1) //Botão Start Game
SetTextVisible(3,1) //Botão Exit
//Deixa o botão "Score" visível
SetTextVisible(4,0)
//Deixa as árvores invisível
SetSpriteVisible(26,0)
SetSpriteVisible(27,0)
SetSpriteVisible(28,0)
SetSpriteVisible(29,0)
//Deixa o inimigo invisível
SetSpriteVisible(24,0)
SetSpriteVisible(31,0)
//Deixa o chão invisível
SetSpriteVisible(21,0)
SetSpriteVisible(30,0)
SetSpriteVisible(2,0)
//Deixa a logo e o background do menu visível
SetSpriteVisible(logosprite,1)
SetSpriteVisible(backspritem,1)
SetSpriteVisible(backsprite,0)
SetSpriteVisible(backdropf,0)
EnemyX=0
EnemyY=0
EnemyVX=0
EnemyVY=0
score=0
endif
if GetSpriteCollision(2,31)=1
StopMusic()
//Deixa os botões invisíveis
SetTextVisible(1,1) //Botão Start Game
SetTextVisible(3,1) //Botão Exit
//Deixa o botão "Score" visível
SetTextVisible(4,0)
//Deixa as árvores invisível
SetSpriteVisible(26,0)
SetSpriteVisible(27,0)
SetSpriteVisible(28,0)
SetSpriteVisible(29,0)
//Deixa o inimigo invisível
SetSpriteVisible(24,0)
SetSpriteVisible(31,0)
//Deixa o chão invisível
SetSpriteVisible(21,0)
SetSpriteVisible(30,0)
SetSpriteVisible(2,0)
//Deixa a logo e o background do menu visível
SetSpriteVisible(logosprite,1)
SetSpriteVisible(backspritem,1)
SetSpriteVisible(backsprite,0)
SetSpriteVisible(backdropf,0)
EnemyX=0
EnemyY=0
EnemyVX=0
EnemyVY=0
score=0
endif
if GetPointerPressed()=1
if GetTextHitTest(3,GetPointerX(),GetPointerY()) //Clicar no botão Exit
PlaySound(5)
end //Finaliza o jogo
endif
endif
if GetRawKeyState(39) //Pressionar a setinha da direita
//Move o personagem para a direita
SetSpriteFlip(2,0,0) //Define um flip mantendo o personagem para direita
CarecaX=CarecaX+Speed//Move somando a sua posição com o speed
SetSpritePosition(2,CarecaX,CarecaY)
CarecaRight=1 //Deixa a variável CarecaRight como true
CarecaLeft=0
elseif GetRawKeyState(37) //Pressionar a setinha para esquerda
//Move o personagem para a direita
SetSpriteFlip(2,180,0) //Define um flip de 180 mantendo o personagem para esquerda
CarecaX=CarecaX-Speed //Move subtraindo a sua posição com o speed
SetSpritePosition(2,CarecaX,CarecaY)
CarecaRight=0
CarecaLeft=1 //Deixa a variável CarecaLeft como true
else
if (GetSpritePlaying(2)=1) //Ao se mover, a animação de andar será iniciada
PlaySprite(2,10,1,1,3)
endif
endif
if GetRawkeyState(90) and CarecaRight=1 //Pressionar a tecla 'Z' e CarecaRight for true
//Animação de socar
SetSpritePosition(20,CarecaX,CarecaY) //Define a posição do sprite de soco
SetSpriteVisible(20,1) //Deixa a animação de soco visível
SetSpriteFlip(20,0,0) //Define um flip mantendo o personagem dando um soco para direita
SetSpriteVisible(2,0) //Deixa a animação de andar invisível
//Se a variável shooting for 0 entre nesse se
if shooting=0
shooting=1 //Define a variável shooting como 1
//Faça até 4 vezes o bullet
for b=0 to 3
//Se as bullets forem 0 entre nesse se
if all_bullets[b].Active=0
all_bullets[b].Active=1 //Ativa as bullets
all_bullets[b].BulletX=CarecaX+30 //Define sua posição em X
all_bullets[b].Bullety=Carecay+10 //Define sua posição em Y
PlaySound(2)
SetSpriteVisible(3+b,1) //Torna as sprites da bullet visíveis
exit
endif
next b
endif
else
//Torna a animação de soco invisível e a animação de andar visível
SetSpriteVisible(20,0)
SetSpriteVisible(2,1)
//Define a variável shooting como 0 novamente
shooting=0
endif //Termina todo o se
//Faça 4 vezes o bullet
for b = 0 to 3
//Se as bullets forem 1 entre nesse se
if all_bullets[b].Active=1
all_bullets[b].BulletX=all_bullets[b].BulletX+5 //Define a velocidade da bullet em linha reta
if all_bullets[b].BulletX>1500 then all_bullets[b].Active=0 //A bullet irá até a posição demarcada
endif
next b
//Faça 4 vezes o bullet
for b = 0 to 3
//Se as bullets forem 1 entre nesse se
if all_bullets[b].Active=1
if GetSpriteCollision(24,3+b)=1 //Define uma colisão entre a bullet e o inimigo
score=score+1 //Ao acertar um inimigo na direita, soma-se no score
SetTextString(4,"Score: "+str(score)) //Mostra o score e a quantidade exata de inimigos mortos
PlaySound(4) //Som do inimigo sendo atingido
all_bullets[b].Active=0 //Desativa a bala ao colidir com o inimigo
SetSpriteVisible(3+b,0) //Torna a sprite da bullet invisível ao colidir com o inimigo
EnemyX=1200 //Reseta a posição do inimigo, fazendo ele "renascer"
endif
endif
next b
//Faça 4 vezes o bullet
for b=0 to 3
SetSpritePosition(3+b, all_bullets[b].BulletX,all_bullets[b].BulletY) //Fica defindo a posição do sprite da bullet, fazendo-a se mover
next b
if GetRawKeyState(90) and CarecaLeft = 1 //Pressionar a tecla 'Z' e CarecaLeft for true
//Animação de socar
SetSpritePosition(20,CarecaX,CarecaY) //Define a posição do sprite de soco
SetSpriteVisible(20,1) //Deixa a animação de soco visível
SetSpriteFlip(20,180,0) //Define um flip de 180 mantendo o personagem dando um soco para esquerda
SetSpriteVisible(2,0) //Deixa a animação de andar invisível
//Se a variável shooting2 for 0 entre nesse se
if shooting2=0
shooting2=1 //Define a variável shooting2 como 1
//Faça 4 vezes o bullet
for b2 = 0 to 3
//Se as bullets forem 0 entre nesse se
if all_bullets2[b2].ActiveLeft=0
all_bullets2[b2].ActiveLeft=1 //Ativa as bullets
all_bullets2[b2].BulletLeft_X=CarecaX -30 //Define a posição em X
all_bullets2[b2].BulletLeft_Y=CarecaY +15 //Define a posição em Y
PlaySound(2) //Som da bullet
SetSpriteVisible(7+b2,1) //Torna as sprites da bullet visíveis
exit
endif
next b2
endif
else
shooting2=0 ////Define a variável shooting2 como 0 novamente
endif
//Faça 4 vezes o bullet
for b2=0 to 3
//Se as bullets forem 1 entra nesse se
if all_bullets2[b2].ActiveLeft=1
all_bullets2[b2].BulletLeft_X=all_bullets2[b2].BulletLeft_X-6 //Define a velocidade da bullet na esquerda
if all_bullets2[b2].BulletLeft_X<-100 then all_bullets2[b2].ActiveLeft=0 //A bullet irá até a posição demarcada para a esquerda
endif
next b2
//Faça 4 vezes o bullet
for b2 = 0 to 3
//Se as bullets forem 1 entra nesse se
if all_bullets2[b2].ActiveLeft=1
if GetSpriteCollision(24,7+b2)=1 //Define uma colisão entre a bullet e o inimigo na esquerda
score=score+1 //Ao acertar um inimigo na esquerda, soma-se no score
SetTextString(4,"Score: "+str(score)) //Mostra o score e a quantidade exata de inimigos mortos
PlaySound(4) //Som do inimigo sendo atingido
all_bullets2[b2].ActiveLeft=0 //Desativa a bala ao colidir com o inimigo
SetSpriteVisible(3+b,0) //Torna a sprite da bullet invisível ao colidir com o inimigo
EnemyX=1200 //Reseta a posição do inimigo na esquerda, fazendo ele "renascer"
endif
endif
next b2
//Faça 4 vezes o bullet
for b2=0 to 3
SetSpritePosition(7+b2,all_bullets2[b2].BulletLeft_X,all_bullets2[b2].BulletLeft_Y) //Fica defindo a posição do sprite da bullet, fazendo-a se mover para a esquerda
next b2
SetSpritePosition(24,EnemyX,EnemyY) //Define a posição do inimigo
if EnemyX<CarecaX //Se a posição do inimigo for menor que o Careca, entra nesse se
SetSpriteFlip(24,180,0) //Define um flip de 180 mantendo o inimigo para a esquerda
EnemyX=EnemyX+SpeedEnemyAz //Define a posição do inimigo, fazendo-o "seguir" o Careca
endif
if EnemyX>CarecaX //Se a posição do inimigo for maior que o Careca, entra nesse se
SetSpriteFlip(24,0,0) //Define um flip mantendo o inimigo para a direita
EnemyX = EnemyX-SpeedEnemyAz //Define a posição do inimigo, fazendo-o "seguir" o Careca
endif
SetSpritePosition(31,EnemyVX,EnemyVY)
if EnemyVX<CarecaX //Se a posição do inimigo for menor que o Careca, entra nesse se
SetSpriteFlip(31,180,0) //Define um flip de 180 mantendo o inimigo para a esquerda
EnemyVX=EnemyVX+SpeedEnemyVer //Define a posição do inimigo, fazendo-o "seguir" o Careca
endif
if EnemyVX>CarecaX //Se a posição do inimigo for maior que o Careca, entra nesse se
SetSpriteFlip(31,0,0) //Define um flip mantendo o inimigo para a direita
EnemyVX = EnemyVX-SpeedEnemyVer //Define a posição do inimigo, fazendo-o "seguir" o Careca
endif
//Chão
SetSpritePosition(21,FloorX,FloorY) //Define a posição do chão
SetSpritePosition(30,FloorX,FloorY) //Define a posição do chãoF
SetSpritePosition(26,TreeX,TreeY) //Define a posição da árvore direita
SetSpritePosition(27,950,TreeY) //Define a posição da árvore esquerda
SetSpritePosition(28,TreeX,TreeY) //Define a posição da árvore direita
SetSpritePosition(29,950,TreeY) //Define a posição da árvore esquerda
if GetSpriteCollision(2,21) = 1 or Jump = 1 //Define uma colisão entre o careca, ou caso a variável Jump for true
Fall=0 //Define a variável Fall como false, fazendo o personagem ir para o ar
else
Fall=1 //Define a variável Fall como true, fazendo o personagem ficar no chão
endif
if Fall=0 //Se a variável Fall for false, entra nesse se
CarecaY=CarecaY+0 //Define a posição em Y
elseif Fall=1 //Se a variável Fall for true, entra nesse se
CarecaX=CarecaX+0 //Define a posição em X
endif
if GetRawKeyPressed(32) //Pressionar o botão "espaço"
Jump=1 //Define a variável Jump=1
PlaySound(3)
endif
if Jump=1 //Se a variável Jump for true
//A sprite de pulo é executada
SetSpritePosition(23,CarecaX,CarecaY)
SetSpriteVisible(23,1)
SetSpriteVisible(2,0)
SetSpriteFlip(23,0,0)
SetSpritePosition(2,CarecaX,CarecaY)
Fall=0
JumpTimer=JumpTimer+2.7 //Define até onde o pulo irá
Movement=6 //Define a velocidade do pulo
if JumpTimer<80
CarecaY=CarecaY-Movement
elseif JumpTimer>83
CarecaY=CarecaY+Movement
SetSpritePosition(25,CarecaX,CarecaY)
SetSpriteFlip(25,0,0)
SetSpriteVisible(25,1)
SetSpriteVisible(23,0)
endif
if GetSpriteCollision(2,21)=1 and JumpTimer >80
Movement=0
Fall=0
JumpTimer=0
Jump=0
SetSpriteVisible(23,0)
SetSpriteVisible(25,0)
endif
endif
if Jump=1 and CarecaLeft=1
SetSpritePosition(23,CarecaX,CarecaY)
SetSpriteVisible(23,1)
SetSpriteVisible(2,0)
SetSpriteFlip(23,180,0)
if JumpTimer<80
elseif JumpTimer>83 and CarecaLeft=1
SetSpritePosition(25,CarecaX,CarecaY)
SetSpriteFlip(25,180,0)
SetSpriteVisible(25,1)
SetSpriteVisible(23,0)
endif
endif
if GetSpriteCollision(26,2)
CarecaX=70
CarecaY=675
endif
if GetSpriteCollision(27,2)
CarecaX=70
CarecaY=675
endif
if score=30
SetSpriteVisible(backsprite,0) //Desativa o background normal
SetSpriteVisible(backspritef,1) //Ativa o background final
SetSpriteVisible(30,1) //Ativa o Floor final
SetSpriteVisible(26,0)
SetSpriteVisible(27,0)
SetSpriteVisible(28,1)
SetSpriteVisible(29,1)
SpeedEnemyAz=2.3
SpeedEnemyVer=1.6
endif
sync()
loop