Home » Archimedes archive » Acorn User » AU 1997-01 B.adf » Features » Arcade/!Popcorn/c/NewProto
Arcade/!Popcorn/c/NewProto
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1997-01 B.adf » Features |
Filename: | Arcade/!Popcorn/c/NewProto |
Read OK: | ✔ |
File size: | 0540 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
#include <stdlib.h> #include "DeskLib:h.Error" #include "Popcorn:h.Popcorn" struct game_object *Popcorn_NewPrototype(struct object_table *table, int prototype_id, int x, int y) { int c = 0; struct game_object *obj; while ( prototype[c]->id != prototype_id && c != prototype_free ) c++; /* Find prototype */ if (c == prototype_free) Error_ReportFatal(0, "Prototype %08X not found", prototype_id); obj = Popcorn_NewObject(table); if (obj == NULL) return(NULL); /* Check we've got space in the table */ /* Fill object's information */ obj->object_id = prototype_id; obj->x = x; obj->y = y; obj->flags = prototype[c]->flags; obj->handler = prototype[c]->handler; obj->frame = obj->timer.value = obj->timer.decrement = obj->xv = obj->yv = 0; obj->user_data = NULL; obj->size.x = prototype[c]->animation.frame[0].size_x; obj->size.y = prototype[c]->animation.frame[0].size_y; obj->plot_offset.x = prototype[c]->animation.frame[0].centre_x; obj->plot_offset.y = prototype[c]->animation.frame[0].centre_y; if (prototype[c]->animation.frames == 1) obj->plot_id.sprite_anchor = prototype[c]->animation.frame[0].sprite_anchor; else obj->plot_id.animation = &prototype[c]->animation; return(obj); }
00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 6c 69 62 |#include <stdlib| 00000010 2e 68 3e 0a 0a 23 69 6e 63 6c 75 64 65 20 22 44 |.h>..#include "D| 00000020 65 73 6b 4c 69 62 3a 68 2e 45 72 72 6f 72 22 0a |eskLib:h.Error".| 00000030 0a 23 69 6e 63 6c 75 64 65 20 22 50 6f 70 63 6f |.#include "Popco| 00000040 72 6e 3a 68 2e 50 6f 70 63 6f 72 6e 22 0a 0a 73 |rn:h.Popcorn"..s| 00000050 74 72 75 63 74 20 67 61 6d 65 5f 6f 62 6a 65 63 |truct game_objec| 00000060 74 20 2a 50 6f 70 63 6f 72 6e 5f 4e 65 77 50 72 |t *Popcorn_NewPr| 00000070 6f 74 6f 74 79 70 65 28 73 74 72 75 63 74 20 6f |ototype(struct o| 00000080 62 6a 65 63 74 5f 74 61 62 6c 65 20 2a 74 61 62 |bject_table *tab| 00000090 6c 65 2c 0a 20 20 20 20 20 20 20 09 09 20 20 20 |le,. .. | 000000a0 09 09 09 20 20 69 6e 74 09 20 09 20 20 20 20 20 |... int. . | 000000b0 20 70 72 6f 74 6f 74 79 70 65 5f 69 64 2c 0a 20 | prototype_id,. | 000000c0 20 20 20 20 20 20 09 09 20 20 20 09 09 09 20 20 | .. ... | 000000d0 69 6e 74 09 09 20 20 20 20 20 20 78 2c 0a 20 20 |int.. x,. | 000000e0 20 20 20 20 20 09 09 20 20 20 09 09 09 20 20 69 | .. ... i| 000000f0 6e 74 09 09 20 20 20 20 20 20 79 29 0a 7b 0a 20 |nt.. y).{. | 00000100 20 69 6e 74 20 20 20 20 20 20 20 20 20 20 20 20 | int | 00000110 20 20 20 20 20 20 63 20 3d 20 30 3b 0a 20 20 73 | c = 0;. s| 00000120 74 72 75 63 74 20 67 61 6d 65 5f 6f 62 6a 65 63 |truct game_objec| 00000130 74 20 20 20 2a 6f 62 6a 3b 0a 0a 20 20 77 68 69 |t *obj;.. whi| 00000140 6c 65 20 28 20 70 72 6f 74 6f 74 79 70 65 5b 63 |le ( prototype[c| 00000150 5d 2d 3e 69 64 20 21 3d 20 70 72 6f 74 6f 74 79 |]->id != prototy| 00000160 70 65 5f 69 64 20 26 26 20 63 20 21 3d 20 70 72 |pe_id && c != pr| 00000170 6f 74 6f 74 79 70 65 5f 66 72 65 65 20 29 0a 20 |ototype_free ). | 00000180 20 20 20 63 2b 2b 3b 20 2f 2a 20 46 69 6e 64 20 | c++; /* Find | 00000190 70 72 6f 74 6f 74 79 70 65 20 2a 2f 0a 0a 20 20 |prototype */.. | 000001a0 69 66 20 28 63 20 3d 3d 20 70 72 6f 74 6f 74 79 |if (c == prototy| 000001b0 70 65 5f 66 72 65 65 29 0a 20 20 20 20 45 72 72 |pe_free). Err| 000001c0 6f 72 5f 52 65 70 6f 72 74 46 61 74 61 6c 28 30 |or_ReportFatal(0| 000001d0 2c 20 22 50 72 6f 74 6f 74 79 70 65 20 25 30 38 |, "Prototype %08| 000001e0 58 20 6e 6f 74 20 66 6f 75 6e 64 22 2c 20 70 72 |X not found", pr| 000001f0 6f 74 6f 74 79 70 65 5f 69 64 29 3b 0a 0a 20 20 |ototype_id);.. | 00000200 6f 62 6a 20 3d 20 50 6f 70 63 6f 72 6e 5f 4e 65 |obj = Popcorn_Ne| 00000210 77 4f 62 6a 65 63 74 28 74 61 62 6c 65 29 3b 0a |wObject(table);.| 00000220 20 20 69 66 20 28 6f 62 6a 20 3d 3d 20 4e 55 4c | if (obj == NUL| 00000230 4c 29 0a 20 20 20 20 72 65 74 75 72 6e 28 4e 55 |L). return(NU| 00000240 4c 4c 29 3b 20 2f 2a 20 43 68 65 63 6b 20 77 65 |LL); /* Check we| 00000250 27 76 65 20 67 6f 74 20 73 70 61 63 65 20 69 6e |'ve got space in| 00000260 20 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 0a 2f | the table */../| 00000270 2a 20 46 69 6c 6c 20 6f 62 6a 65 63 74 27 73 20 |* Fill object's | 00000280 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a 0a |information */..| 00000290 20 20 6f 62 6a 2d 3e 6f 62 6a 65 63 74 5f 69 64 | obj->object_id| 000002a0 20 3d 20 70 72 6f 74 6f 74 79 70 65 5f 69 64 3b | = prototype_id;| 000002b0 20 6f 62 6a 2d 3e 78 20 3d 20 78 3b 20 6f 62 6a | obj->x = x; obj| 000002c0 2d 3e 79 20 3d 20 79 3b 0a 20 20 6f 62 6a 2d 3e |->y = y;. obj->| 000002d0 66 6c 61 67 73 20 3d 20 70 72 6f 74 6f 74 79 70 |flags = prototyp| 000002e0 65 5b 63 5d 2d 3e 66 6c 61 67 73 3b 20 6f 62 6a |e[c]->flags; obj| 000002f0 2d 3e 68 61 6e 64 6c 65 72 20 3d 20 70 72 6f 74 |->handler = prot| 00000300 6f 74 79 70 65 5b 63 5d 2d 3e 68 61 6e 64 6c 65 |otype[c]->handle| 00000310 72 3b 0a 20 20 6f 62 6a 2d 3e 66 72 61 6d 65 20 |r;. obj->frame | 00000320 3d 20 6f 62 6a 2d 3e 74 69 6d 65 72 2e 76 61 6c |= obj->timer.val| 00000330 75 65 20 3d 20 6f 62 6a 2d 3e 74 69 6d 65 72 2e |ue = obj->timer.| 00000340 64 65 63 72 65 6d 65 6e 74 20 3d 20 6f 62 6a 2d |decrement = obj-| 00000350 3e 78 76 20 3d 20 6f 62 6a 2d 3e 79 76 20 3d 20 |>xv = obj->yv = | 00000360 30 3b 0a 20 20 6f 62 6a 2d 3e 75 73 65 72 5f 64 |0;. obj->user_d| 00000370 61 74 61 20 3d 20 4e 55 4c 4c 3b 0a 0a 20 20 6f |ata = NULL;.. o| 00000380 62 6a 2d 3e 73 69 7a 65 2e 78 20 3d 20 70 72 6f |bj->size.x = pro| 00000390 74 6f 74 79 70 65 5b 63 5d 2d 3e 61 6e 69 6d 61 |totype[c]->anima| 000003a0 74 69 6f 6e 2e 66 72 61 6d 65 5b 30 5d 2e 73 69 |tion.frame[0].si| 000003b0 7a 65 5f 78 3b 0a 20 20 6f 62 6a 2d 3e 73 69 7a |ze_x;. obj->siz| 000003c0 65 2e 79 20 3d 20 70 72 6f 74 6f 74 79 70 65 5b |e.y = prototype[| 000003d0 63 5d 2d 3e 61 6e 69 6d 61 74 69 6f 6e 2e 66 72 |c]->animation.fr| 000003e0 61 6d 65 5b 30 5d 2e 73 69 7a 65 5f 79 3b 0a 20 |ame[0].size_y;. | 000003f0 20 6f 62 6a 2d 3e 70 6c 6f 74 5f 6f 66 66 73 65 | obj->plot_offse| 00000400 74 2e 78 20 3d 20 70 72 6f 74 6f 74 79 70 65 5b |t.x = prototype[| 00000410 63 5d 2d 3e 61 6e 69 6d 61 74 69 6f 6e 2e 66 72 |c]->animation.fr| 00000420 61 6d 65 5b 30 5d 2e 63 65 6e 74 72 65 5f 78 3b |ame[0].centre_x;| 00000430 0a 20 20 6f 62 6a 2d 3e 70 6c 6f 74 5f 6f 66 66 |. obj->plot_off| 00000440 73 65 74 2e 79 20 3d 20 70 72 6f 74 6f 74 79 70 |set.y = prototyp| 00000450 65 5b 63 5d 2d 3e 61 6e 69 6d 61 74 69 6f 6e 2e |e[c]->animation.| 00000460 66 72 61 6d 65 5b 30 5d 2e 63 65 6e 74 72 65 5f |frame[0].centre_| 00000470 79 3b 0a 0a 20 20 69 66 20 28 70 72 6f 74 6f 74 |y;.. if (protot| 00000480 79 70 65 5b 63 5d 2d 3e 61 6e 69 6d 61 74 69 6f |ype[c]->animatio| 00000490 6e 2e 66 72 61 6d 65 73 20 3d 3d 20 31 29 0a 20 |n.frames == 1). | 000004a0 20 20 20 6f 62 6a 2d 3e 70 6c 6f 74 5f 69 64 2e | obj->plot_id.| 000004b0 73 70 72 69 74 65 5f 61 6e 63 68 6f 72 20 3d 20 |sprite_anchor = | 000004c0 70 72 6f 74 6f 74 79 70 65 5b 63 5d 2d 3e 61 6e |prototype[c]->an| 000004d0 69 6d 61 74 69 6f 6e 2e 66 72 61 6d 65 5b 30 5d |imation.frame[0]| 000004e0 2e 73 70 72 69 74 65 5f 61 6e 63 68 6f 72 3b 0a |.sprite_anchor;.| 000004f0 20 20 65 6c 73 65 0a 20 20 20 20 6f 62 6a 2d 3e | else. obj->| 00000500 70 6c 6f 74 5f 69 64 2e 61 6e 69 6d 61 74 69 6f |plot_id.animatio| 00000510 6e 20 3d 20 26 70 72 6f 74 6f 74 79 70 65 5b 63 |n = &prototype[c| 00000520 5d 2d 3e 61 6e 69 6d 61 74 69 6f 6e 3b 0a 0a 20 |]->animation;.. | 00000530 20 72 65 74 75 72 6e 28 6f 62 6a 29 3b 0a 7d 0a | return(obj);.}.| 00000540