-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathobject.c
More file actions
102 lines (94 loc) · 2.28 KB
/
object.c
File metadata and controls
102 lines (94 loc) · 2.28 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* BreakHack - A dungeone crawler RPG
* Copyright (C) 2025 Linus Probert <linus.probert@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "object.h"
#include "gui.h"
#include "util.h"
#include "mixer.h"
#include "random.h"
#include "texturecache.h"
Object *
object_create(void)
{
Object *o = ec_malloc(sizeof(Object));
o->sprite = sprite_create();
o->blocking = false;
o->damage = 0;
o->timeout = -1;
o->dead = false;
return o;
}
Object *
object_create_fire()
{
Object *o = object_create();
Texture *t0 = texturecache_add("Objects/Effect0.png");
Texture *t1 = texturecache_add("Objects/Effect1.png");
sprite_set_texture(o->sprite, t0, 0);
sprite_set_texture(o->sprite, t1, 1);
o->sprite->dim = GAME_DIMENSION;
o->sprite->clip = CLIP16(16, 21*16);
o->damage = 3;
o->timeout = 5;
return o;
}
Object *
object_create_green_gas()
{
Object *o = object_create();
Texture *t0 = texturecache_add("Objects/Effect0.png");
Texture *t1 = texturecache_add("Objects/Effect1.png");
sprite_set_texture(o->sprite, t0, 0);
sprite_set_texture(o->sprite, t1, 1);
o->sprite->dim = GAME_DIMENSION;
o->sprite->clip = CLIP16(32, 24*16);
o->damage = 3;
o->timeout = 3;
return o;
}
void
object_render(Object *o, Camera *cam)
{
sprite_render(o->sprite, cam);
}
void
object_step(Object *o)
{
if (o->timeout < 0)
return;
o->timeout--;
if (o->timeout <= 0)
o->dead = true;
}
void
object_damage(Object *o, Player *p)
{
if (!o->damage)
return;
if (player_has_potion_effect(p, POTION_FROST)) {
gui_log("Your frost skin protects you from damage");
return;
}
p->stats.hp -= o->damage;
player_hit(p, o->damage);
}
void
object_destroy(Object *o)
{
sprite_destroy(o->sprite);
free(o);
}