[7f9531]: split.c  Maximize  Restore  History

Download this file

90 lines (77 with data), 2.4 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
/* Asteroids3D - a first person game of blowing up asteroids
* Copyright (C) 2000 Stuart Mark Pomerantz <smp [at] psc edu>
*
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Stuart Pomerantz
* 3935 Stonecliffe drive
* Monroeville, PA 15146
*/
#include <stdio.h>
#include "asteroids3D.h"
#include "vecops.h"
static void gen_rand_asteroid_at_pos(const Vector *, Asteroid *, int);
/* generate new asteroids at position pos smaller then type */
void add_new_asteroids(const Vector *ppos, int type) {
Node *current = NULL;
int num_new_rocks ;
int i;
/* decide how many new rocks to generate. Wieghted to be 2 or 3 */
i = gen_rand_int(0, 9) ; /* FIXME after gen_rand_int is fixed */
switch(i) {
case 3:
case 4:
case 5:
case 6:
num_new_rocks = 3 ;
break ;
case 7:
case 8:
num_new_rocks = 4 ;
break ;
case 9:
num_new_rocks = 5 ;
break ;
default:
num_new_rocks = 2 ;
break;
}
current = al_tail ;
for( i = 0 ; i < num_new_rocks ; i++ ) {
if( current->next == NULL )
current->next = add_node() ;
current = current->next ;
gen_rand_asteroid_at_pos(ppos, &current->rock, type);
}
al_tail = current ;
return ;
}
static void gen_rand_asteroid_at_pos(const Vector *ppos, Asteroid *a,
int type)
{
double k;
a->type = gen_rand_int(0,type-1) ;
a->mass = MIN_AST_MASS + AST_MASS_K*a->type ; /* based on type */
a->radius = 0.5*(float)(a->type+1) ; /* based on type */
a->pos = *ppos;
k = gen_rand_float( 0, MAX_APD ) ;
gen_rand_vec( &a->velocity ) ;
vec_smul(&a->velocity, &a->velocity, k);
a->rot = 0 ;
a->rot_delta = gen_rand_int(-MAX_ARD, MAX_ARD) ;
gen_rand_vec( &a->rot_axis ) ;
return ;
}