Consistent drawing order of items based on significance
So e.g. a Life will never be obscured behind a Point
This commit is contained in:
parent
2f5629befa
commit
67128fad8f
2 changed files with 23 additions and 11 deletions
18
src/item.c
18
src/item.c
|
@ -9,8 +9,19 @@
|
|||
#include "global.h"
|
||||
#include "list.h"
|
||||
|
||||
Item *create_item(complex pos, complex v, Type type) {
|
||||
Item *i = create_element((void **)&global.items, sizeof(Item));
|
||||
Item *create_item(complex pos, complex v, ItemType type) {
|
||||
Item *e, **d, **dest = &global.items;
|
||||
|
||||
for(e = *dest; e && e->next; e = e->next)
|
||||
if(e->prev && type < e->type)
|
||||
break;
|
||||
|
||||
if(e == NULL)
|
||||
d = dest;
|
||||
else
|
||||
d = &e;
|
||||
|
||||
Item *i = create_element((void **)d, sizeof(Item));
|
||||
i->pos = pos;
|
||||
i->pos0 = pos;
|
||||
i->v = v;
|
||||
|
@ -21,7 +32,6 @@ Item *create_item(complex pos, complex v, Type type) {
|
|||
return i;
|
||||
}
|
||||
|
||||
|
||||
void delete_item(Item *item) {
|
||||
delete_element((void **)&global.items, item);
|
||||
}
|
||||
|
@ -129,7 +139,7 @@ int collision_item(Item *i) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void spawn_item(complex pos, Type type) {
|
||||
void spawn_item(complex pos, ItemType type) {
|
||||
tsrand_fill(2);
|
||||
create_item(pos, 5*cexp(I*tsrand_a(0)/afrand(1)*M_PI*2), type);
|
||||
}
|
||||
|
|
16
src/item.h
16
src/item.h
|
@ -14,12 +14,14 @@
|
|||
typedef struct Item Item;
|
||||
|
||||
typedef enum {
|
||||
Power,
|
||||
Point,
|
||||
// from least important to most important
|
||||
// this affects the draw order
|
||||
BPoint,
|
||||
Point,
|
||||
Power,
|
||||
Bomb,
|
||||
Life,
|
||||
Bomb
|
||||
} Type;
|
||||
} ItemType;
|
||||
|
||||
struct Item{
|
||||
Item *next;
|
||||
|
@ -30,12 +32,12 @@ struct Item{
|
|||
complex pos0;
|
||||
|
||||
int auto_collect;
|
||||
Type type;
|
||||
ItemType type;
|
||||
|
||||
complex v;
|
||||
};
|
||||
|
||||
Item *create_item(complex pos, complex v, Type type);
|
||||
Item *create_item(complex pos, complex v, ItemType type);
|
||||
void delete_item(Item *item);
|
||||
void draw_items(void);
|
||||
void delete_items(void);
|
||||
|
@ -43,7 +45,7 @@ void delete_items(void);
|
|||
int collision_item(Item *p);
|
||||
void process_items(void);
|
||||
|
||||
void spawn_item(complex pos, Type type);
|
||||
void spawn_item(complex pos, ItemType type);
|
||||
void spawn_items(complex pos, int point, int power, int bomb, int life);
|
||||
|
||||
void items_preload(void);
|
||||
|
|
Loading…
Reference in a new issue