5 // Created by Mike Wessler on Sat Jun 15 2002.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ----====----====----====----====----====----====----====----====----====---- */
23 #import "ScoreBubble.h"
25 #import "OpenGLSprite.h"
27 NSMutableDictionary *stringAttributes;
29 // Open GL Z value for scorebubbles
30 #define SCOREBUBBLE_SPRITE_Z -0.30
32 @implementation ScoreBubble
34 @synthesize value = _value;
35 @synthesize screenLocation = _screenLocation;
36 @synthesize animationCount = _animationCount;
37 @synthesize image = _image;
39 + (ScoreBubble *)scoreWithValue:(int)value at:(NSPoint)location duration:(int)count
41 // FIXME: possible bug, is it [self alloc] or [[self class] alloc]???
42 ScoreBubble *scoreBubble = [[self alloc] initWithValue:value
45 return [scoreBubble autorelease];
48 -(id)initWithValue:(int)value at:(NSPoint)location duration:(int)count
50 NSString *str= [NSString stringWithFormat:@"%d", value];
54 if (!stringAttributes) {
55 stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
56 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
57 [stringAttributes retain];
59 strsize= [str sizeWithAttributes:stringAttributes];
63 _screenLocation = location;
64 _screenLocation.x -= strsize.width / 2;
65 _screenLocation.y -= strsize.height / 2;
66 _animationCount= count;
67 _image = [[NSImage alloc] initWithSize:strsize];
69 [stringAttributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
70 [str drawAtPoint:NSMakePoint(2,0) withAttributes:stringAttributes];
71 [stringAttributes setObject:[NSColor yellowColor] forKey:NSForegroundColorAttributeName];
72 [str drawAtPoint:NSMakePoint(1,1) withAttributes:stringAttributes];
76 NSSize imageSize = _image.size;
77 sprite = [[OpenGLSprite alloc] initWithImage:_image
78 cropRectangle:NSMakeRect(0, 0, imageSize.width, imageSize.height)
95 float alpha = (float)_animationCount/20;
100 [_image compositeToPoint:_screenLocation
101 operation:NSCompositeSourceOver
107 float alpha= (float)_animationCount/20;
111 [sprite blitToX:_screenLocation.x
113 Z:SCOREBUBBLE_SPRITE_Z
119 if (_animationCount > 0) {
124 return _animationCount;