Home » Archimedes archive » Acorn User » AU 1996-Xmas.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 1996-Xmas.adf » Features
Filename: Arcade/!Popcorn/c/NewProto
Read OK:
File size: 04F2 bytes
Load address: 0000
Exec address: 0000
File contents
#include <stdlib.h>

#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)
    return(NULL);

  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 50  |.h>..#include "P|
00000020  6f 70 63 6f 72 6e 3a 68  2e 50 6f 70 63 6f 72 6e  |opcorn:h.Popcorn|
00000030  22 0a 0a 73 74 72 75 63  74 20 67 61 6d 65 5f 6f  |"..struct game_o|
00000040  62 6a 65 63 74 20 2a 50  6f 70 63 6f 72 6e 5f 4e  |bject *Popcorn_N|
00000050  65 77 50 72 6f 74 6f 74  79 70 65 28 73 74 72 75  |ewPrototype(stru|
00000060  63 74 20 6f 62 6a 65 63  74 5f 74 61 62 6c 65 20  |ct object_table |
00000070  2a 74 61 62 6c 65 2c 0a  20 20 20 20 20 20 20 09  |*table,.       .|
00000080  09 20 20 20 09 09 09 20  20 69 6e 74 09 20 09 20  |.   ...  int. . |
00000090  20 20 20 20 20 70 72 6f  74 6f 74 79 70 65 5f 69  |     prototype_i|
000000a0  64 2c 0a 20 20 20 20 20  20 20 09 09 20 20 20 09  |d,.       ..   .|
000000b0  09 09 20 20 69 6e 74 09  09 20 20 20 20 20 20 78  |..  int..      x|
000000c0  2c 0a 20 20 20 20 20 20  20 09 09 20 20 20 09 09  |,.       ..   ..|
000000d0  09 20 20 69 6e 74 09 09  20 20 20 20 20 20 79 29  |.  int..      y)|
000000e0  0a 7b 0a 20 20 69 6e 74  20 20 20 20 20 20 20 20  |.{.  int        |
000000f0  20 20 20 20 20 20 20 20  20 20 63 20 3d 20 30 3b  |          c = 0;|
00000100  0a 20 20 73 74 72 75 63  74 20 67 61 6d 65 5f 6f  |.  struct game_o|
00000110  62 6a 65 63 74 20 20 20  2a 6f 62 6a 3b 0a 0a 20  |bject   *obj;.. |
00000120  20 77 68 69 6c 65 20 28  20 70 72 6f 74 6f 74 79  | while ( prototy|
00000130  70 65 5b 63 5d 2d 3e 69  64 20 21 3d 20 70 72 6f  |pe[c]->id != pro|
00000140  74 6f 74 79 70 65 5f 69  64 20 26 26 20 63 20 21  |totype_id && c !|
00000150  3d 20 70 72 6f 74 6f 74  79 70 65 5f 66 72 65 65  |= prototype_free|
00000160  20 29 0a 20 20 20 20 63  2b 2b 3b 20 2f 2a 20 46  | ).    c++; /* F|
00000170  69 6e 64 20 70 72 6f 74  6f 74 79 70 65 20 2a 2f  |ind prototype */|
00000180  0a 0a 20 20 69 66 20 28  63 20 3d 3d 20 70 72 6f  |..  if (c == pro|
00000190  74 6f 74 79 70 65 5f 66  72 65 65 29 0a 20 20 20  |totype_free).   |
000001a0  20 72 65 74 75 72 6e 28  4e 55 4c 4c 29 3b 0a 0a  | return(NULL);..|
000001b0  20 20 6f 62 6a 20 3d 20  50 6f 70 63 6f 72 6e 5f  |  obj = Popcorn_|
000001c0  4e 65 77 4f 62 6a 65 63  74 28 74 61 62 6c 65 29  |NewObject(table)|
000001d0  3b 0a 20 20 69 66 20 28  6f 62 6a 20 3d 3d 20 4e  |;.  if (obj == N|
000001e0  55 4c 4c 29 0a 20 20 20  20 72 65 74 75 72 6e 28  |ULL).    return(|
000001f0  4e 55 4c 4c 29 3b 20 2f  2a 20 43 68 65 63 6b 20  |NULL); /* Check |
00000200  77 65 27 76 65 20 67 6f  74 20 73 70 61 63 65 20  |we've got space |
00000210  69 6e 20 74 68 65 20 74  61 62 6c 65 20 2a 2f 0a  |in the table */.|
00000220  0a 2f 2a 20 46 69 6c 6c  20 6f 62 6a 65 63 74 27  |./* Fill object'|
00000230  73 20 69 6e 66 6f 72 6d  61 74 69 6f 6e 20 2a 2f  |s information */|
00000240  0a 0a 20 20 6f 62 6a 2d  3e 6f 62 6a 65 63 74 5f  |..  obj->object_|
00000250  69 64 20 3d 20 70 72 6f  74 6f 74 79 70 65 5f 69  |id = prototype_i|
00000260  64 3b 20 6f 62 6a 2d 3e  78 20 3d 20 78 3b 20 6f  |d; obj->x = x; o|
00000270  62 6a 2d 3e 79 20 3d 20  79 3b 0a 20 20 6f 62 6a  |bj->y = y;.  obj|
00000280  2d 3e 66 6c 61 67 73 20  3d 20 70 72 6f 74 6f 74  |->flags = protot|
00000290  79 70 65 5b 63 5d 2d 3e  66 6c 61 67 73 3b 20 6f  |ype[c]->flags; o|
000002a0  62 6a 2d 3e 68 61 6e 64  6c 65 72 20 3d 20 70 72  |bj->handler = pr|
000002b0  6f 74 6f 74 79 70 65 5b  63 5d 2d 3e 68 61 6e 64  |ototype[c]->hand|
000002c0  6c 65 72 3b 0a 20 20 6f  62 6a 2d 3e 66 72 61 6d  |ler;.  obj->fram|
000002d0  65 20 3d 20 6f 62 6a 2d  3e 74 69 6d 65 72 2e 76  |e = obj->timer.v|
000002e0  61 6c 75 65 20 3d 20 6f  62 6a 2d 3e 74 69 6d 65  |alue = obj->time|
000002f0  72 2e 64 65 63 72 65 6d  65 6e 74 20 3d 20 6f 62  |r.decrement = ob|
00000300  6a 2d 3e 78 76 20 3d 20  6f 62 6a 2d 3e 79 76 20  |j->xv = obj->yv |
00000310  3d 20 30 3b 0a 20 20 6f  62 6a 2d 3e 75 73 65 72  |= 0;.  obj->user|
00000320  5f 64 61 74 61 20 3d 20  4e 55 4c 4c 3b 0a 0a 20  |_data = NULL;.. |
00000330  20 6f 62 6a 2d 3e 73 69  7a 65 2e 78 20 3d 20 70  | obj->size.x = p|
00000340  72 6f 74 6f 74 79 70 65  5b 63 5d 2d 3e 61 6e 69  |rototype[c]->ani|
00000350  6d 61 74 69 6f 6e 2e 66  72 61 6d 65 5b 30 5d 2e  |mation.frame[0].|
00000360  73 69 7a 65 5f 78 3b 0a  20 20 6f 62 6a 2d 3e 73  |size_x;.  obj->s|
00000370  69 7a 65 2e 79 20 3d 20  70 72 6f 74 6f 74 79 70  |ize.y = prototyp|
00000380  65 5b 63 5d 2d 3e 61 6e  69 6d 61 74 69 6f 6e 2e  |e[c]->animation.|
00000390  66 72 61 6d 65 5b 30 5d  2e 73 69 7a 65 5f 79 3b  |frame[0].size_y;|
000003a0  0a 20 20 6f 62 6a 2d 3e  70 6c 6f 74 5f 6f 66 66  |.  obj->plot_off|
000003b0  73 65 74 2e 78 20 3d 20  70 72 6f 74 6f 74 79 70  |set.x = prototyp|
000003c0  65 5b 63 5d 2d 3e 61 6e  69 6d 61 74 69 6f 6e 2e  |e[c]->animation.|
000003d0  66 72 61 6d 65 5b 30 5d  2e 63 65 6e 74 72 65 5f  |frame[0].centre_|
000003e0  78 3b 0a 20 20 6f 62 6a  2d 3e 70 6c 6f 74 5f 6f  |x;.  obj->plot_o|
000003f0  66 66 73 65 74 2e 79 20  3d 20 70 72 6f 74 6f 74  |ffset.y = protot|
00000400  79 70 65 5b 63 5d 2d 3e  61 6e 69 6d 61 74 69 6f  |ype[c]->animatio|
00000410  6e 2e 66 72 61 6d 65 5b  30 5d 2e 63 65 6e 74 72  |n.frame[0].centr|
00000420  65 5f 79 3b 0a 0a 20 20  69 66 20 28 70 72 6f 74  |e_y;..  if (prot|
00000430  6f 74 79 70 65 5b 63 5d  2d 3e 61 6e 69 6d 61 74  |otype[c]->animat|
00000440  69 6f 6e 2e 66 72 61 6d  65 73 20 3d 3d 20 31 29  |ion.frames == 1)|
00000450  0a 20 20 20 20 6f 62 6a  2d 3e 70 6c 6f 74 5f 69  |.    obj->plot_i|
00000460  64 2e 73 70 72 69 74 65  5f 61 6e 63 68 6f 72 20  |d.sprite_anchor |
00000470  3d 20 70 72 6f 74 6f 74  79 70 65 5b 63 5d 2d 3e  |= prototype[c]->|
00000480  61 6e 69 6d 61 74 69 6f  6e 2e 66 72 61 6d 65 5b  |animation.frame[|
00000490  30 5d 2e 73 70 72 69 74  65 5f 61 6e 63 68 6f 72  |0].sprite_anchor|
000004a0  3b 0a 20 20 65 6c 73 65  0a 20 20 20 20 6f 62 6a  |;.  else.    obj|
000004b0  2d 3e 70 6c 6f 74 5f 69  64 2e 61 6e 69 6d 61 74  |->plot_id.animat|
000004c0  69 6f 6e 20 3d 20 26 70  72 6f 74 6f 74 79 70 65  |ion = &prototype|
000004d0  5b 63 5d 2d 3e 61 6e 69  6d 61 74 69 6f 6e 3b 0a  |[c]->animation;.|
000004e0  0a 20 20 72 65 74 75 72  6e 28 6f 62 6a 29 3b 0a  |.  return(obj);.|
000004f0  7d 0a                                             |}.|
000004f2