Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOSparkEntity.m
Go to the documentation of this file.
1/*
2
3OOSparkEntity.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
26#import "OOSparkEntity.h"
27#import "Universe.h"
28#import "PlayerEntity.h"
29#import "OOColor.h"
30
31
32@interface OOSparkEntity (Private)
33
34- (void) performUpdate:(OOTimeDelta)delta_t;
35
36@end
37
38
39@implementation OOSparkEntity
40
41- (id) initWithPosition:(HPVector)pos
42 velocity:(Vector)vel
43 duration:(OOTimeDelta)duration
44 size:(float)size
45 color:(OOColor *)color
46{
47 if ((self = [super initWithDiameter:size]))
48 {
49 [self setPosition:pos];
50 [self setVelocity:vel];
51 _duration = _timeRemaining = duration;
52 [self setCollisionRadius:2.0];
53
54 [color getRed:&_baseRGBA[0] green:&_baseRGBA[1] blue:&_baseRGBA[2] alpha:&_baseRGBA[3]];
55 [self performUpdate:0]; // Handle colour mixing and such.
56 }
57
58 return self;
59}
60
61
62- (void) update:(OOTimeDelta)delta_t
63{
64 [super update:delta_t];
65 [self performUpdate:delta_t];
66}
67
68
69- (void) performUpdate:(OOTimeDelta)delta_t
70{
71 _timeRemaining -= delta_t;
72
73 float mix = OOClamp_0_1_f(_timeRemaining / _duration);
74
75 // Fade towards red while fading out.
76 _colorComponents[0] = mix * _baseRGBA[0] + (1.0f - mix);
77 _colorComponents[1] = mix * _baseRGBA[1];
78 _colorComponents[2] = mix * _baseRGBA[2];
79 _colorComponents[3] = mix * _baseRGBA[3];
80
81 // Disappear when gone.
82 if (mix == 0) [UNIVERSE removeEntity:self];
83}
84
85@end
double OOTimeDelta
Definition OOTypes.h:224
void setVelocity:(Vector vel)
Definition Entity.m:757
void setCollisionRadius:(GLfloat amount)
Definition Entity.m:917
void setPosition:(HPVector posn)
Definition Entity.m:647
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:368
void performUpdate:(OOTimeDelta delta_t)
voidpf void uLong size
Definition ioapi.h:134