Allow item images to be random.

This commit is contained in:
Steve 2016-06-05 08:35:59 +01:00
parent 0f97a08d25
commit 95e9d4d9a0
4 changed files with 19 additions and 24 deletions

View File

@ -56,9 +56,8 @@
],
"items" : [
{
"name" : "package",
"number" : 50,
"type" : "smallCrate",
"type" : "RANDOM",
"x" : 25,
"y" : 25,
"scatter" : 5000,

View File

@ -33,9 +33,8 @@
},
"items" : [
{
"name" : "package",
"number" : 8,
"type" : "smallCrate",
"type" : "RANDOM",
"x" : 25,
"y" : 25,
"scatter" : 5000,

View File

@ -32,7 +32,6 @@
},
"items" : [
{
"name" : "package",
"number" : 100,
"type" : "RANDOM",
"x" : 25,

View File

@ -63,11 +63,24 @@ void loadItemDefs(void)
Entity *spawnItem(char *name)
{
Entity *item, *def;
Entity *e, *def, *item;
item = spawnEntity();
def = getItemDef(name);
if (strcmp(name, "RANDOM"))
{
def = getItemDef(name);
}
else
{
for (e = defHead.next ; e != NULL ; e = e->next)
{
if (!def || rand() % 2)
{
def = e;
}
}
}
memcpy(item, def, sizeof(Entity));
@ -80,24 +93,9 @@ Entity *spawnItem(char *name)
void addRandomItem(int x, int y)
{
Entity *e, *def, *item;
def = item = e = NULL;
for (e = defHead.next ; e != NULL ; e = e->next)
{
if (!def || rand() % 2)
{
def = e;
}
}
item = spawnEntity();
memcpy(item, def, sizeof(Entity));
item->next = NULL;
Entity *item;
item = spawnItem("RANDOM");
item->x = x;
item->y = y;
item->speed = 1;