Line data Source code
1 0 : /* 2 : 3 : OOSparkEntity.m 4 : 5 : 6 : Oolite 7 : Copyright (C) 2004-2013 Giles C Williams and contributors 8 : 9 : This program is free software; you can redistribute it and/or 10 : modify it under the terms of the GNU General Public License 11 : as published by the Free Software Foundation; either version 2 12 : of the License, or (at your option) any later version. 13 : 14 : This program is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU General Public License for more details. 18 : 19 : You should have received a copy of the GNU General Public License 20 : along with this program; if not, write to the Free Software 21 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 : MA 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 0 : - (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 0 : - (void) update:(OOTimeDelta)delta_t 63 : { 64 : [super update:delta_t]; 65 : [self performUpdate:delta_t]; 66 : } 67 : 68 : 69 0 : - (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