aboutsummaryrefslogtreecommitdiff
path: root/fx.c
blob: 8e0e41fd27944061427345682564a8a402b4df60 (plain) (blame)
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
#include "components.h"
#include "fx.h"
#include "world.h"

static int new_fx(
	World* world,
	int x,
	int y,
	Animation_ID anim,
	Asset_ID bitmap
) {
	Entity e;
	CPosition* pos;
	CSprite* sprite;
	CAnimated* animated;

	e = new_entity(world);
	add_components(
		world,
		e,
		ctype_sprite |
		ctype_position |
		ctype_animated |
		ctype_destroy_on_anim_done
	);

	pos = &world->positions[e];
	sprite = &world->sprites[e];
	animated = &world->animateds[e];

	pos->x = x;
	pos->y = y;

	sprite->id = bitmap;
	sprite->rect = make_rect(0, 0, 16, 16);

	animated->id = anim;
	animated->frame = 0;
	animated->timer = 0;

	return e;
}

int new_enemy_bullet_explosion(
	World* world,
	int x,
	int y
) {
	return new_fx(
		world,
		x,
		y,
		animation_enemy_bullet_explode,
		asset_id_bullet
	);
}

int new_player_bullet_explosion(
	World* world,
	int x,
	int y
) {
	return new_fx(
		world,
		x,
		y,
		animation_player_bullet_explode,
		asset_id_bullet
	);
}

int new_heart_break(
	struct World* world,
	int x,
	int y
) {
	return new_fx(
		world,
		x,
		y,
		animation_heart_break,
		asset_id_usr
	);
}