/
engine.h
1869 lines (1651 loc) · 46.5 KB
/
engine.h
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
// Motor.h
#ifndef PLAYER_MIN_KILLABLE
#define PLAYER_MIN_KILLABLE 0
#endif
#ifndef PLAYER_MIN_KILLABLE_SP
#define PLAYER_MIN_KILLABLE_SP 0
#endif
#ifdef ANDROID_TCP_IP
extern char __LIB__ *strstr(char *, char *);
extern void __LIB__ *memset(void *, unsigned char, uint);
int sockfd, connfd, polled, rc;
struct sockaddr_in my_addr;
char rxdata[128];
struct pollfd p; /* the poll information structure */
int sent_ack_first_time=-1;
int selected_android = 0;
int configured_android = 0;
int client_is_joystick = 0;
int simulate_key_d = 0;
unsigned char read_vjoystick_tcpip (int initialize);
int init_tcpip () {
char keypressed = 0;
unsigned char x=0;
sent_ack_first_time=-1;
while(sent_ack_first_time == -1){
if (create_socket()==-1){
return -1;
}
read_vjoystick_tcpip (1);
if (sent_ack_first_time == -1){
sockclose(sockfd);
}
}
return 1;
}
int create_socket () {
/* Create the socket */
/* The first argument, AF_INET is the family. The Spectranet only
supports AF_INET at present. SOCK_STREAM in this context is
for a TCP connection. */
sockfd=socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0)
{
//printf("Could not open the socket - rc=%d\n", sockfd);
sp_Border (RED);
return -1;
}
/* Now set up the sockaddr_in structure. */
/* Zero it out so that any fields we don't set are set to
NULL (the structure also contains the local address to bind to).
We will listne to port 8081. */
memset(&my_addr, 0, sizeof(my_addr)); /* zero out all fields */
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(8081); /* Port 8081 */
if(bind(sockfd, &my_addr, sizeof(my_addr)) < 0)
{
sp_Border (RED);
sockclose(sockfd);
return -1;
}
/* The socket should now listen. The Spectranet hardware in
its present form doesn't support changing the backlog, but
the second argument to listen should still be a sensible value */
if(listen(sockfd, 1) < 0)
{
//printf("listen failed.\n");
sp_Border (RED);
sockclose(sockfd);
return -1;
}
return 0;
}
unsigned char read_vjoystick_tcpip (int initialize) {
char *retV;
struct sockaddr_in* tmpsck = NULL;
socklen_t * tmplen = NULL;
unsigned char accumulated_actions=255;
unsigned char no_action=255;
int i;
int j;
char res = 1;
if (initialize==1){
for (i = 0; i < 20 && res; i ++) {
for (j = 0; j < 250; j ++) { res = 1; }
}
}
/* pollall() fills a pollfd struct when something happens.
It returns the socket descriptor on which that something
happened */
polled=pollall(&p);
/* Was the socket descriptor the listening socket? */
if(polled == sockfd)
{
/* Yes. So accept the incoming connection. */
//printf("Accepting a new connection...\n");
connfd=accept(sockfd, tmpsck, tmplen);
polled=pollall(&p);
client_is_joystick=0;
}
/* if any other socket descriptor returned status, then
something happened on a communication socket */
else if(polled > 0)
{
/* Did the other end hang up on us? */
if(p.revents & POLLHUP)
{
//printf("Remote host disconnected\n");
/* ...so close our end too and free the fd */
sockclose(polled);
/* Close the listening socket and exit while. */
//sockclose(sockfd);
return no_action;
}
/* No, the other end didn't hang up */
else
{
/* Some data is ready to collect */
rc=recv(polled, rxdata, sizeof(rxdata)-1, 0);
if(rc < 0)
{
//printf("recv failed!\n");
sockclose(polled);
/* Close the listening socket and exit while. */
sockclose(sockfd);
return no_action;
}
/* Ensure there's a null on the end */
*(rxdata+rc)=0;
retV=strstr(rxdata, "START");
if(retV != NULL) {
client_is_joystick=1;
}
retV=strstr(rxdata, "UP");
if(retV != NULL) {
//00000001
accumulated_actions = accumulated_actions & ~sp_UP;
}
retV=strstr(rxdata, "DOWN");
if(retV != NULL) {
//00000010
//accumulated_actions = accumulated_actions & ~sp_DOWN;
}
retV=strstr(rxdata, "LEFT");
if(retV != NULL) {
//00000100
accumulated_actions = accumulated_actions & ~sp_LEFT;
}
retV=strstr(rxdata, "RIGHT");
if(retV != NULL) {
//00001000
accumulated_actions = accumulated_actions & ~sp_RIGHT;
}
retV=strstr(rxdata, "BUTTON1");
if(retV != NULL) {
//10000000
accumulated_actions = accumulated_actions & ~sp_FIRE;
}
retV=strstr(rxdata, "BUTTON2");
if(retV != NULL) {
//10000000
if (simulate_key_d==0){
simulate_key_d=1;
}else{
simulate_key_d=simulate_key_d+1;
}
//accumulated_actions = accumulated_actions & ~sp_FIRE;
}else{
simulate_key_d=0;
}
retV=strstr(rxdata, "BUTTON3");
if(retV != NULL) {
//10000000
accumulated_actions = accumulated_actions & ~sp_FIRE;
}
if (client_is_joystick==0){
// We do not want this connection!
/* ...so close our end too and free the fd */
sockclose(polled);
/* Close the listening socket and exit while. */
sockclose(sockfd);
//sp_Border (BLUE);
return no_action;
}
/* Send ID to client. This will verify that I am the correct IP */
if (sent_ack_first_time==-1){
rc=send(polled, "TCPIPJOYSTICKSPECTRUM\r\n", 25, 0);
if(rc < 0)
{
sockclose(polled);
sockclose(sockfd);
return no_action;
}else{
sent_ack_first_time=1;
return sp_FIRE;
}
}
return accumulated_actions;
}
}
return no_action;
}
#endif
#ifndef ANDROID_TCP_IP
void print_panel_msg(char* pant_msgA, char* pant_msgB){
print_str (12, 21, colorM1, pant_msgA);
print_str (12, 22, colorM2, pant_msgB);
}
// Draws a "known world" map at the bottom-left part of the screen
void draw_map(void){
asm_int_B[0] = asm_int_dir[n_pant];
asm_int_F[0] = 0;
if (n_pant==12 || n_pant==14 || n_pant==24){
asm_int_F[0] = 32;
}else if (n_pant==17 || n_pant==29){
asm_int_F[0] = 2;
}
if (n_pant%2==0){
asm_int_mask1[0]=48;
}else{
asm_int_mask1[0]=3;
}
asm_int_C[0] = asm_int_mask2[n_pant];
asm_int_D[0] = asm_int_mask3[n_pant];
asm_int_E[0] = 0;
if (n_pant%12>5){
asm_int_E[0] = 4;
}
#asm
ld de, 20480
ld a, (_asm_int_B)
ld e, a
ld hl, (_asm_int_F)
call looper
call looper
ld a, (_asm_int_E)
loopmap: inc d
dec a
jp nz, loopmap
ld hl, (_asm_int_mask1)
call looper
ld hl, (_asm_int_C)
call looper
ld hl, (_asm_int_D)
ld a, l
jp z, endoptag
call looper
call looper
jp endoptag
looper: LD a, (de)
or a, l
LD (de), a
inc d
ret
endoptag: inc a
#endasm
}
#endif
#ifdef PLAYER_MOGGY_STYLE
// right: 0 + frame
// left: 2 + frame
// up: 4 + frame
// down: 6 + frame
unsigned char *player_frames [] = {
sprite_1_a, sprite_2_a, sprite_3_a, sprite_4_a,
sprite_5_a, sprite_6_a, sprite_7_a, sprite_8_a
};
#else
#ifdef PLAYER_BOOTEE
// vy = 0: 0 + facing
// vy < 0: 1 + facing
// vy > 0: 2 + facing
unsigned char *player_frames [] = {
sprite_5_a, sprite_6_a, sprite_7_a, sprite_8_a,
sprite_1_a, sprite_2_a, sprite_3_a, sprite_4_a
};
#else
#ifdef PLAYER_ALTERNATE_ANIMATION
// Alternate animation:
// 0 1 2 + facing = walk, 0 = stand, 3 = jump/fall
unsigned char *player_frames [] = {
sprite_5_a, sprite_6_a, sprite_7_a, sprite_8_a,
sprite_1_a, sprite_2_a, sprite_3_a, sprite_4_a
};
#else
// Normal animation:
// 0 1 2 3 + facing: walk, 1 = stand. 8 + facing = jump/fall
unsigned char *player_frames [] = {
sprite_5_a, sprite_6_a, sprite_7_a, sprite_6_a,
sprite_1_a, sprite_2_a, sprite_3_a, sprite_2_a,
sprite_8_a, sprite_4_a
};
#endif
#endif
#endif
unsigned char *enem_frames [] = {
sprite_9_a, sprite_10_a, sprite_11_a, sprite_12_a,
sprite_13_a, sprite_14_a, sprite_15_a, sprite_16_a
};
// Funciones:
#ifdef COMPRESSED_LEVELS
void prepare_level (unsigned char level) {
unpack ((unsigned int) levelset [level].leveldata_c, MAP_DATA);
unpack ((unsigned int) levelset [level].tileset_c, (unsigned int) (tileset));
unpack ((unsigned int) levelset [level].spriteset_c, (unsigned int) (sprite_1_a - 16));
n_pant = levelset [level].ini_pant;
player.x = levelset [level].ini_x << 10;
player.y = levelset [level].ini_y << 10;
n_bolts = *((unsigned char *) (NBOLTS_PEEK));
}
#endif
void init_player () {
// Inicializa player con los valores iniciales
// (de ahí lo de inicializar).
player.x = PLAYER_INI_X << 10;
player.y = PLAYER_INI_Y << 10;
player.vy = 0;
player.vx = 0;
player.cont_salto = 1;
player.saltando = 0;
player.frame = 0;
player.subframe = 0;
player.facing = 1;
player.estado = EST_NORMAL;
player.ct_estado = 0;
player.life = PLAYER_LIFE;
player.objs = 0;
player.keys = 0;
player.killed = 0;
pant_final = SCR_FIN;
}
unsigned char collide (unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2) {
// Colisión segura y guarra.
unsigned char l1x, l1y, l2x, l2y;
#ifdef SMALL_COLLISION
l1x = (x1 > 8) ? x1 - 8 : 0;
l2x = x1 + 8;
l1y = (y1 > 8) ? y1 - 8 : 0;
l2y = y1 + 8;
#else
l1x = (x1 > 13) ? x1 - 13 : 0;
l2x = x1 + 13;
l1y = (y1 > 12) ? y1 - 12 : 0;
l2y = y1 + 12;
#endif
return (x2 >= l1x && x2 <= l2x && y2 >= l1y && y2 <= l2y);
}
#ifndef ANDROID_TCP_IP
unsigned char rand (void) {
unsigned char res;
#asm
.rand16
ld hl, _seed
ld a, (hl)
ld e, a
inc hl
ld a, (hl)
ld d, a
;; Ahora DE = [SEED]
ld a, d
ld h, e
ld l, 253
or a
sbc hl, de
sbc a, 0
sbc hl, de
ld d, 0
sbc a, d
ld e, a
sbc hl, de
jr nc, nextrand
inc hl
.nextrand
ld d, h
ld e, l
ld hl, _seed
ld a, e
ld (hl), a
inc hl
ld a, d
ld (hl), a
;; Ahora [SEED] = HL
ld hl, _asm_int
ld a, e
ld (hl), a
inc hl
ld a, d
ld (hl), a
;; Ahora [ASM_INT] = HL
#endasm
res = asm_int [0];
return res;
}
#endif
unsigned int abs (int n) {
if (n < 0)
return (unsigned int) (-n);
else
return (unsigned int) n;
}
void step (void) {
#ifndef ANDROID_TCP_IP
#asm
ld a, 16
out (254), a
nop
nop
nop
nop
nop
nop
nop
nop
nop
xor 16
out (254), a
#endasm
#endif
}
/*
void cortina (void) {
#asm
;; Antes que nada vamos a limpiar el PAPER de toda la pantalla
;; para que no queden artefactos feos
ld de, 22528 ; Apuntamos con DE a la zona de atributos
ld b, 3 ; Procesamos 3 tercios
.clearb1
push bc
ld b, 255 ; Procesamos los 256 atributos de cada tercio
.clearb2
ld a, (de) ; Nos traemos un atributo
and 199 ; Le hacemos la máscara 11000111 y dejamos PAPER a 0
ld (de), a ; Y lo volvemos a poner
inc de ; Siguiente atributo
djnz clearb2
pop bc
djnz clearb1
;; Y ahora el código original que escribí para UWOL:
ld a, 8
.repitatodo
ld c, a ; Salvamos el contador de "repitatodo" en 'c'
ld hl, 16384
ld a, 12
.bucle
ld b, a ; Salvamos el contador de "bucle" en 'b'
ld a, 255
.bucle1
sla (hl)
inc hl
dec a
jr nz, bucle1
ld a, 255
.bucle2
srl (hl)
inc hl
dec a
jr nz, bucle2
ld a, b ; Restituimos el contador de "bucle" a 'a'
dec a
jr nz, bucle
ld a, c ; Restituimos el contador de "repitatodo" a 'a'
dec a
jr nz, repitatodo
#endasm
}
*/
// Game
char espera_activa (int espera) {
char res = 1;
int i;
int j;
for (i = 0; i < espera && res; i ++) {
for (j = 0; j < 250; j ++) {
res = 1;
}
//if (sp_GetKey ()) res = 0;
}
return res;
}
void game_ending (void) {
print_str (6, 8, 79, " ");
print_str (6, 9, 79, " YOU WIN!!!!!! ");
print_str (6, 10, 79, " THE LEPRICANTS ");
print_str (6, 11, 79, " WILL NOT BE BACK!! ");
print_str (6, 12, 79, " ");
sp_UpdateNow ();
peta_el_beeper (0);
espera_activa(200);
}
void game_over (void) {
print_str (6, 9, 79, " ");
print_str (6, 10, 79, " GAME OVER.WHEH! ");
print_str (6, 11, 79, " ");
sp_UpdateNow ();
peta_el_beeper (6);
espera_activa(200);
}
signed int addsign (signed int n, signed int value) {
return (n == 0 ? 0 : (n < 0 ? -value : value));
}
unsigned char ctileoff (char n) {
return (n > 0 ? 1 : 0);
}
// Engine globals (for speed) & size!
unsigned char gpx, gpy, gpd, gpc, gpt;
unsigned char gpxx, gpyy, gpcx, gpcy;
unsigned char possee, hit_v, hit_h, hit, wall;
unsigned char gpen_x, gpen_y, gpen_cx, gpen_cy, gpen_xx, gpen_yy, gpaux;
unsigned char tocado, active;
unsigned char gpit, gpjt;
unsigned char enoffsmasi;
unsigned char *map_pointer;
#ifndef COMPRESSED_LEVELS
#ifndef DEACTIVATE_KEYS
void init_cerrojos (void) {
// Activa todos los cerrojos
for (gpit = 0; gpit < MAX_CERROJOS; gpit ++)
cerrojos [gpit].st = 1;
}
#endif
#endif
#ifdef PLAYER_CAN_FIRE
void init_bullets (void) {
// Inicializa las balas
for (gpit = 0; gpit < MAX_BULLETS; gpit ++)
bullets [gpit].estado = 0;
}
#endif
#if defined(PLAYER_KILLS_ENEMIES) || defined (PLAYER_CAN_FIRE)
void init_malotes (void) {
for (gpit = 0; gpit < MAP_W * MAP_H * 3; gpit ++) {
malotes [gpit].t = malotes [gpit].t & 15;
};
// force reinitizalizarion of Clive
//malotes [33]={112, 80, 112, 80, 144, 80, 2, 0, 2};
malotes [33].x=112;
malotes [33].y=80;
malotes [33].mx=2;
malotes [33].my=0;
//malotes [34]={144, 80, 144, 80, 128, 112, -2, 2, 2};
malotes [34].x=144;
malotes [34].y=80;
malotes [34].mx=-2;
malotes [34].my=2;
//malotes [35]={128, 112, 128, 112, 112, 80, -2, -2, 2};
malotes [35].x=128;
malotes [35].y=112;
malotes [35].mx=-2;
malotes [35].my=-2;
//malotes [45]={96, 48, 96, 48, 96, 64, 0, 1, 3};
malotes [45].y=48;
malotes [45].my=1;
//malotes [46]={128, 48, 128, 48, 128, 64, 0, 1, 3};
malotes [46].y=48;
malotes [46].my=1;
//malotes [47]={112, 64, 112, 64, 112, 80, 0, 1, 2};
malotes [47].y=64;
malotes [47].my=1;
//malotes [105]={96, 64, 96, 64, 96, 80, 0, 2, 2};
malotes [105].y=64;
malotes [105].my=2;
//malotes [106]={80, 48, 80, 48, 80, 64, 0, 2, 3};
malotes [106].y=48;
malotes [106].my=2;
//malotes [107]={112, 48, 112, 48, 112, 64, 0, 2, 3};
malotes [107].y=48;
malotes [107].my=2;
}
#endif
#ifndef COMPRESSED_LEVELS
void init_hotspots (void) {
unsigned char gpit;
for (gpit = 0; gpit < MAP_W * MAP_H; gpit ++)
hotspots [gpit].act = 1;
}
#endif
#if defined(PLAYER_PUSH_BOXES) || !defined(DEACTIVATE_KEYS)
void process_tile (unsigned char x0, unsigned char y0, signed char x1, signed char y1) {
#ifndef DEACTIVATE_KEYS
if (qtile (x0, y0) == 15 && player.keys) {
map_attr [15 * y0 + x0] = 0;
map_buff [15 * y0 + x0] = 0;
#ifdef COMPRESSED_LEVELS
for (gpit = 0; gpit < n_bolts; gpit ++) {
#else
for (gpit = 0; gpit < MAX_CERROJOS; gpit ++) {
#endif
if (cerrojos [gpit].x == x0 && cerrojos [gpit].y == y0 && cerrojos [gpit].np == n_pant) {
cerrojos [gpit].st = 0;
break;
}
}
draw_coloured_tile (VIEWPORT_X + x0 + x0, VIEWPORT_Y + y0 + y0, 0);
player.keys --;
peta_el_beeper (8);
}
#endif
}
#endif
unsigned char move (int first_time) {
#ifdef ANDROID_TCP_IP
if (selected_android==1){
gpit = read_vjoystick_tcpip (0);
if (gpit==255){
gpit = (joyfunc) (&keys); // Leemos del teclado
}
}else{
gpit = (joyfunc) (&keys); // Leemos del teclado
}
#else
gpit = (joyfunc) (&keys); // Leemos del teclado
#endif
if (first_time==1){
gpit=~sp_LEFT;
}
/* Por partes. Primero el movimiento vertical. La ecuación de movimien-
to viene a ser, en cada ciclo:
1.- vy = vy + g
2.- y = y + vy
O sea la velocidad afectada por la gravedad.
Para no colarnos con los nmeros, ponemos limitadores:
*/
#ifndef PLAYER_MOGGY_STYLE
// Si el tipo de movimiento no es MOGGY_STYLE, entonces nos afecta la gravedad.
if (player.vy < PLAYER_MAX_VY_CAYENDO)
player.vy += PLAYER_G;
else
player.vy = PLAYER_MAX_VY_CAYENDO;
#ifdef PLAYER_CUMULATIVE_JUMP
if (!player.saltando)
#endif
if (player.gotten) player.vy = 0;
#else
// Si lo es, entonces el movimiento vertical se comporta exactamente igual que
// el horizontal.
if ( ! ((gpit & sp_UP) == 0 || (gpit & sp_DOWN) == 0)) {
player.facing_v = 0xff;
if (player.vy > 0) {
player.vy -= PLAYER_RX;
if (player.vy < 0)
player.vy = 0;
} else if (player.vy < 0) {
player.vy += PLAYER_RX;
if (player.vy > 0)
player.vy = 0;
}
}
if ((gpit & sp_UP) == 0) {
player.facing_v = FACING_UP;
if (player.vy > -PLAYER_MAX_VX) {
player.vy -= PLAYER_AX;
}
}
if ((gpit & sp_DOWN) == 0) {
player.facing_v = FACING_DOWN;
if (player.vy < PLAYER_MAX_VX) {
player.vy += PLAYER_AX;
}
}
#endif
player.y += player.vy;
// Safe
if (player.y < 0)
player.y = 0;
if (player.y > 9216)
player.y = 9216;
/* El problema es que no es tan fácil... Hay que ver si no nos chocamos.
Si esto pasa, hay que "recular" hasta el borde del obstáculo.
Por eso miramos el signo de vy, para que los cálculos sean más sencillos.
De paso vamos a precalcular un par de cosas para que esto vaya más rápido.
*/
gpx = player.x >> 6; // dividimos entre 64 para pixels, y luego entre 16 para tiles.
gpy = player.y >> 6;
gpxx = gpx >> 4;
gpyy = gpy >> 4;
// Ya
possee = 0;
hit_v = 0;
#ifdef BOUNDING_BOX_8_BOTTOM
if (player.vy < 0) { // estamos ascendiendo
if ((gpy & 15) < 8) {
if ( ((gpx & 15) < 12 && attr (gpxx, gpyy) > 7) || ((gpx & 15) > 4 && attr (gpxx + 1, gpyy) > 7)) {
#ifdef PLAYER_BOUNCE_WITH_WALLS
player.vy = -(player.vy / 2);
#else
player.vy = 0;
#endif
player.y = ((gpyy + 1) << 10) - 512;
wall = WTOP;
} else if ( ((gpx & 15) < 12 && attr (gpxx, gpyy) == 1) || ((gpx & 15) > 4 && attr (gpxx + 1, gpyy) == 1)) {
hit_v = 1;
}
}
} else if (player.vy > 0 && (gpy & 15) < 8) { // estamos descendiendo
if (player.y < 9216) {
if ( ((gpx & 15) < 12 && attr (gpxx, gpyy + 1) > 3) || ((gpx & 15) > 4 && attr (gpxx + 1, gpyy + 1) > 3)) {
#if defined(PLAYER_BOUNCE_WITH_WALLS) && defined(PLAYER_MOGGY_STYLE)
player.vy = -(player.vy / 2);
#else
#ifdef PLAYER_CUMULATIVE_JUMP
if (!player.saltando)
#endif
player.vy = 0;
#endif
player.y = gpyy << 10;
wall = WBOTTOM;
possee = 1;
} else if ( ((gpx & 15) < 12 && attr (gpxx, gpyy + 1) == 1) || ((gpx & 15) > 4 && attr (gpxx + 1, gpyy + 1) == 1)) {
hit_v = 1;
}
}
}
#else
#ifdef BOUNDING_BOX_8_CENTERED
if (player.vy < 0) {
if ((gpy & 15) < 12) {
if ( ((gpx & 15) < 12 && attr (gpxx, gpyy) > 7) || ((gpx & 15) > 4 && attr (gpxx + 1, gpyy) > 7)) {
#ifdef PLAYER_BOUNCE_WITH_WALLS
player.vy = -(player.vy / 2);
#else
player.vy = 0;
#endif
player.y = ((gpyy + 1) << 10) - 256;
wall = WTOP;
} else if ( ((gpx & 15) < 12 && attr (gpxx, gpyy) == 1) || ((gpx & 15) > 4 && attr (gpxx + 1, gpyy) == 1)) {
hit_v = 1;
}
}
} else if (player.vy > 0 && (gpy & 15) >= 4) {
if (player.y < 9216) {
if ( ((gpx & 15) < 12 && attr (gpxx, gpyy + 1) > 3) || ((gpx & 15) > 4 && attr (gpxx + 1, gpyy + 1) > 3)) {
#if defined(PLAYER_BOUNCE_WITH_WALLS) && defined(PLAYER_MOGGY_STYLE)
player.vy = -(player.vy / 2);
#else
#ifdef PLAYER_CUMULATIVE_JUMP
if (!player.saltando)
#endif
player.vy = 0;
#endif
player.y = (gpyy << 10) + 256;
wall = WBOTTOM;
possee = 1;
} else if ( ((gpx & 15) < 12 && attr (gpxx, gpyy + 1) == 1) || ((gpx & 15) > 4 && attr (gpxx + 1, gpyy + 1) == 1)) {
hit_v = 1;
}
}
}
#else
if (player.vy < 0) {
if (attr (gpxx, gpyy) > 7 || ((gpx & 15) && attr (gpxx + 1, gpyy) > 7)) {
#ifdef PLAYER_BOUNCE_WITH_WALLS
player.vy = -(player.vy / 2);
#else
player.vy = 0;
#endif
player.y = (gpyy + 1) << 10;
wall = WTOP;
} else if (attr (gpxx, gpyy) == 1 || ((gpx & 15) && attr (gpxx + 1, gpyy) == 1)) {
hit_v = 1;
}
} else if (player.vy > 0 && (gpy & 15) < 8) {
if (player.y < 9216) {
if (attr (gpxx, gpyy + 1) > 3 || ((gpx & 15) && attr (gpxx + 1, gpyy + 1) > 3))
{
#if defined(PLAYER_BOUNCE_WITH_WALLS) && defined(PLAYER_MOGGY_STYLE)
player.vy = -(player.vy / 2);
#else
#ifdef PLAYER_CUMULATIVE_JUMP
if (!player.saltando)
#endif
player.vy = 0;
#endif
player.y = gpyy << 10;
possee = 1;
wall = WBOTTOM;
} else if (attr (gpxx, gpyy + 1) == 1 || ((gpx & 15) && attr (gpxx + 1, gpyy + 1) == 1)) {
hit_v = 1;
}
}
}
#endif
#endif
/* Salto: El salto se reduce a dar un valor negativo a vy. Esta es la forma más
sencilla. Sin embargo, para más control, usamos el tipo de salto "mario bros".
Para ello, en cada pulsación dejaremos decrementar vy hasta un mínimo, y de-
tectando que no se vuelva a pulsar cuando estemos en el aire. Juego de banderas ;)
*/
#ifdef PLAYER_HAS_JUMP
#ifdef PLAYER_CUMULATIVE_JUMP
if (((gpit & sp_FIRE) == 0) && (possee || player.gotten)) {
player.vy = -player.vy - PLAYER_VY_INICIAL_SALTO;
if (player.vy < -PLAYER_MAX_VY_SALTANDO) player.vy = -PLAYER_MAX_VY_SALTANDO;
#else
if (((gpit & sp_FIRE) == 0) && player.saltando == 0 && (possee || player.gotten)) {
#endif
player.saltando = 1;
player.cont_salto = 0;
peta_el_beeper (3);
}
#ifndef PLAYER_CUMULATIVE_JUMP
if ( ((gpit & sp_FIRE) == 0) && player.saltando ) {
player.vy -= (PLAYER_VY_INICIAL_SALTO + PLAYER_INCR_SALTO - (player.cont_salto>>1));
if (player.vy < -PLAYER_MAX_VY_SALTANDO) player.vy = -PLAYER_MAX_VY_SALTANDO;
player.cont_salto ++;
if (player.cont_salto == 8)
player.saltando = 0;
}
if ((gpit & sp_FIRE))
player.saltando = 0;
#endif
#endif
// ------ ok con el movimiento vertical.
/* Movimiento horizontal:
Mientras se pulse una tecla de dirección,
x = x + vx
vx = vx + ax
Si no se pulsa nada:
x = x + vx
vx = vx - rx
*/
if ( ! ((gpit & sp_LEFT) == 0 || (gpit & sp_RIGHT) == 0)) {
#ifdef PLAYER_MOGGY_STYLE
player.facing_h = 0xff;
#endif
if (player.vx > 0) {
player.vx -= PLAYER_RX;
if (player.vx < 0)
player.vx = 0;
} else if (player.vx < 0) {
player.vx += PLAYER_RX;
if (player.vx > 0)
player.vx = 0;
}
}
if ((gpit & sp_LEFT) == 0) {
if (player.vx > -PLAYER_MAX_VX) {
#ifndef PLAYER_MOGGY_STYLE
player.facing = 0;
#endif
player.vx -= PLAYER_AX;
}
}