-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.c
97 lines (90 loc) · 2.91 KB
/
runner.c
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
// Copyright 2024-2025 Viacheslav Chimishuk <[email protected]>
//
// This file is part of loderunner-ng.
//
// loderunner-ng 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.
//
// loderunner-ng 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 loderunner-ng. If not, see <http://www.gnu.org/licenses/>.
#include "animation.h"
#include "exit.h"
#include "runner.h"
#include "texture.h"
#include "xmalloc.h"
struct runner *runner_init(void)
{
struct runner *r = xmalloc(sizeof(struct runner));
r->sx = 0;
r->sy = 0;
r->lefta = animation_init(ANIMATION_RUNNER_LEFT);
r->righta = animation_init(ANIMATION_RUNNER_RIGHT);
r->updowna = animation_init(ANIMATION_RUNNER_UPDOWN);
r->climblefta = animation_init(ANIMATION_RUNNER_CLIMB_LEFT);
r->climbrighta = animation_init(ANIMATION_RUNNER_CLIMB_RIGHT);
r->diglefta = animation_init(ANIMATION_RUNNER_DIG_LEFT);
r->digrighta = animation_init(ANIMATION_RUNNER_DIG_RIGHT);
r->falllefta = animation_init(ANIMATION_RUNNER_FALL_LEFT);
r->fallrighta = animation_init(ANIMATION_RUNNER_FALL_RIGHT);
r->holelefta = animation_init(ANIMATION_RUNNER_HOLE_LEFT);
r->holerighta = animation_init(ANIMATION_RUNNER_HOLE_RIGHT);
runner_reset(r);
return r;
}
void runner_destroy(struct runner *r)
{
animation_destroy(r->lefta);
animation_destroy(r->righta);
animation_destroy(r->updowna);
animation_destroy(r->climblefta);
animation_destroy(r->climbrighta);
animation_destroy(r->diglefta);
animation_destroy(r->digrighta);
animation_destroy(r->falllefta);
animation_destroy(r->fallrighta);
animation_destroy(r->holelefta);
animation_destroy(r->holerighta);
free(r);
}
void runner_reset(struct runner *r)
{
r->x = r->sx;
r->y = r->sy;
r->tx = 0;
r->ty = 0;
r->cura = r->righta;
r->state = RSTATE_RIGHT;
r->ngold = 0;
}
struct animation *runner_state_animation(struct runner *r, enum runner_state s)
{
switch (s) {
case RSTATE_DIG_LEFT:
return r->diglefta;
case RSTATE_CLIMB_LEFT:
return r->climblefta;
case RSTATE_CLIMB_RIGHT:
return r->climbrighta;
case RSTATE_DIG_RIGHT:
return r->digrighta;
case RSTATE_FALL_LEFT:
return r->falllefta;
case RSTATE_FALL_RIGHT:
return r->fallrighta;
case RSTATE_LEFT:
return r->lefta;
case RSTATE_RIGHT:
return r->righta;
case RSTATE_UPDOWN:
return r->updowna;
default:
die("illegal state");
}
}