Oolite
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 "OOColor.h"
28#import "PlayerEntity.h"
29#import "Universe.h"
30
31@interface OOSparkEntity (Private)
32
33- (void)performUpdate:(OOTimeDelta)delta_t;
34
35@end
36
37@implementation OOSparkEntity
38
39- (id)initWithPosition:(HPVector)pos
40 velocity:(Vector)vel
41 duration:(OOTimeDelta)duration
42 size:(float)size
43 color:(OOColor*)color
44{
45 if ((self = [super initWithDiameter:size])) {
46 [self setPosition:pos];
47 [self setVelocity:vel];
48 _duration = _timeRemaining = duration;
49 [self setCollisionRadius:2.0];
50
51 [color getRed:&_baseRGBA[0] green:&_baseRGBA[1] blue:&_baseRGBA[2] alpha:&_baseRGBA[3]];
52 [self performUpdate:0]; // Handle colour mixing and such.
53 }
54
55 return self;
56}
57
58- (void)update:(OOTimeDelta)delta_t
59{
60 [super update:delta_t];
61 [self performUpdate:delta_t];
62}
63
64- (void)performUpdate:(OOTimeDelta)delta_t
65{
66 _timeRemaining -= delta_t;
67
68 float mix = OOClamp_0_1_f(_timeRemaining / _duration);
69
70 // Fade towards red while fading out.
71 _colorComponents[0] = mix * _baseRGBA[0] + (1.0f - mix);
72 _colorComponents[1] = mix * _baseRGBA[1];
73 _colorComponents[2] = mix * _baseRGBA[2];
74 _colorComponents[3] = mix * _baseRGBA[3];
75
76 // Disappear when gone.
77 if (mix == 0)
78 [UNIVERSE removeEntity:self];
79}
80
81@end
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
double OOTimeDelta
Definition OOTypes.h:193
void setVelocity:(Vector vel)
Definition Entity.m:703
void update:(OOTimeDelta delta_t)
Definition Entity.m:850
void setCollisionRadius:(GLfloat amount)
Definition Entity.m:840
void setPosition:(HPVector posn)
Definition Entity.m:608
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:344
GLfloat _timeRemaining
GLfloat _duration
void performUpdate:(OOTimeDelta delta_t)
voidpf void uLong size
Definition ioapi.h:126