-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.c
107 lines (92 loc) · 2.72 KB
/
defs.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
98
99
100
101
102
103
104
105
106
107
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (C) 1995 Ronny Wester
Copyright (C) 2003 Jeremy Chin
Copyright (C) 2003-2007 Lucas Martin-King
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------
defs.c - definitions
Author: $Author: lmartinking $
Rev: $Revision: 250 $
URL: $HeadURL: svn://svn.icculus.org/cdogs-sdl/trunk/src/defs.c $
ID: $Id: defs.c 250 2007-07-06 16:38:43Z lmartinking $
*/
#include "defs.h"
int cmd2dir[16] = {
0, // Nothing
DIRECTION_LEFT, // CMD_LEFT
DIRECTION_RIGHT, // CMD_RIGHT
0, // CMD_LEFT + CMD_RIGHT
DIRECTION_UP, // CMD_UP
DIRECTION_UPLEFT, // CMD_UP + CMD_LEFT
DIRECTION_UPRIGHT, // CMD_UP + CMD_RIGHT
0, // CMD_UP + CMD_LEFT + CMD_RIGHT
DIRECTION_DOWN, // CMD_DOWN
DIRECTION_DOWNLEFT, // CMD_DOWN + CMD_LEFT
DIRECTION_DOWNRIGHT, // CMD_DOWN + CMD_RIGHT
0, // CMD_DOWN + CMD_LEFT + CMD_RIGHT
0, // CMD_UP + CMD_DOWN
0, // CMD_UP + CMD_DOWN + CMD_LEFT
0, // CMD_UP + CMD_DOWN + CMD_RIGHT
0 // CMD_UP + CMD_DOWN + CMD_LEFT + CMD_RIGHT
};
int dir2cmd[8] = {
CMD_UP,
CMD_UP + CMD_RIGHT,
CMD_RIGHT,
CMD_DOWN + CMD_RIGHT,
CMD_DOWN,
CMD_DOWN + CMD_LEFT,
CMD_LEFT,
CMD_UP + CMD_LEFT
};
int dir2angle[8] = {
192,
224,
0,
32,
64,
96,
128,
160
};
static int cSinus[65] = {
0, 6, 12, 18, 25, 31, 37, 43,
49, 56, 62, 68, 74, 80, 86, 92,
97, 103, 109, 115, 120, 126, 131, 136,
142, 147, 152, 157, 162, 167, 171, 176,
181, 185, 189, 193, 197, 201, 205, 209,
212, 216, 219, 222, 225, 228, 231, 234,
236, 238, 241, 243, 244, 246, 248, 249,
251, 252, 253, 254, 254, 255, 255, 255,
256
};
void GetVectorsForAngle(int angle, int *dx, int *dy)
{
if (angle <= 64) {
*dx = cSinus[64 - angle];
*dy = cSinus[angle];
} else if (angle <= 128) {
*dx = -cSinus[angle - 64];
*dy = cSinus[128 - angle];
} else if (angle <= 192) {
*dx = -cSinus[192 - angle];
*dy = -cSinus[angle - 128];
} else {
*dx = cSinus[angle - 192];
*dy = -cSinus[256 - angle];
}
*dy *= 3;
*dy /= 4;
}