summaryrefslogtreecommitdiff
path: root/src/game/decos.cpp
blob: bbb1ceea13948c3ba6e6668b3a22b29fde7e2ff0 (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
This file is part of Minitrem.

Minitrem 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 2 of the License, or
(at your option) any later version.

Minitrem 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 Minitrem.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "game.hpp"

namespace game {

static const struct {
	render::animated_texture_t *texture;
	v2f_t mins, maxs;
	world::cflags_t cflags;
	v2f_t render_mins, render_maxs;
	double fps;
} decos[ ] = {
	{
		&assets::deco.stone,
		{-0.4f, +0.1f}, {+0.4f, +0.4f}, CF_SOLID,
		{-0.4f, -0.4f}, {+0.4f, +0.4f}, 0.0
	},
	{
		&assets::deco.stone_cracked,
		{-0.4f, +0.1f}, {+0.4f, +0.4f}, CF_SOLID,
		{-0.4f, -0.4f}, {+0.4f, +0.4f}, 0.0
	},
	{
		&assets::deco.stone,
		{-0.2f, +0.1f}, {+0.2f, +0.2f}, 0,
		{-0.2f, -0.2f}, {+0.2f, +0.2f}, 0.0
	},
	{
		&assets::deco.eyething,
		{-0.4f, -0.4f}, {+0.4f, +0.4f}, CF_SOLID,
		{-0.4f, -1.2f}, {+0.4f, +0.4f}, 0.3
	},
	{
		&assets::deco.eyething_dead,
		{-0.4f, -0.4f}, {+0.4f, +0.4f}, 0,
		{-0.4f, -1.2f}, {+0.4f, +0.4f}, 0.3
	},
	{
		&assets::deco.spike,
		{-0.4f, -0.4f}, {+0.4f, +0.4f}, CF_SOLID,
		{-0.4f, -1.2f}, {+0.4f, +0.4f}, 0.0
	},
	{
		&assets::deco.spike_broken,
		{-0.4f, -0.4f}, {+0.4f, +0.4f}, 0,
		{-0.4f, -1.2f}, {+0.4f, +0.4f}, 0.0
	},
	{
		&assets::deco.spike_small,
		{-0.2f, +0.1f}, {+0.2f, +0.2f}, 0,
		{-0.2f, -0.6f}, {+0.2f, +0.2f}, 0.0
	},
	{
		&assets::deco.wart,
		{-0.2f, +0.1f}, {+0.2f, +0.2f}, 0,
		{-0.2f, -0.2f}, {+0.2f, +0.2f}, 0.0
	}
};

deco_t::deco_t(game::state_t *game_, deco_type_t type_) : game::entity_t(game_, ET_DECO)
{
	type = type_;

	size[0] = decos[type].mins;
	size[1] = decos[type].maxs;
	render_size[0] = decos[type].render_mins;
	render_size[1] = decos[type].render_maxs;
	cmodel.cflags = decos[type].cflags;
}

void deco_t::render_to(render::state_t *render)
{
	render->render(game->now * decos[type].fps + phase_shift,
	               decos[type].texture, render_bounds, sf::Color::White);
}

void deco_t::damage(int points, unit_t *attacker)
{
	switch (type) {
	case DECO_STONE:
		type = DECO_STONE_CRACKED;
		break;

	case DECO_EYETHING:
		type = DECO_EYETHING_DEAD;
		break;

	case DECO_SPIKE:
		type = DECO_SPIKE_BROKEN;
		break;

	default:
		break;
	}

	cmodel.cflags = decos[type].cflags;
}

} // namespace game