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
35 @synthesize _animationCount;
37 + (ScoreBubble *)scoreWithValue:(int)value at:(NSPoint)location duration:(int)count
39 // FIXME: possible bug, is it [self alloc] or [[self class] alloc]???
40 ScoreBubble *scoreBubble = [[self alloc] initWithValue:value
43 return [scoreBubble autorelease];
46 -(id)initWithValue:(int)value At:(NSPoint)loc Duration:(int)count
48 NSString *str= [NSString stringWithFormat:@"%d", value];
52 if (!stringAttributes) {
53 stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
54 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
55 [stringAttributes retain];
57 strsize= [str sizeWithAttributes:stringAttributes];
62 screenLocation.x-=strsize.width/2;
63 screenLocation.y-=strsize.height/2;
64 _animationCount= count;
65 image= [[NSImage alloc] initWithSize:strsize];
67 [stringAttributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
68 [str drawAtPoint:NSMakePoint(2,0) withAttributes:stringAttributes];
69 [stringAttributes setObject:[NSColor yellowColor] forKey:NSForegroundColorAttributeName];
70 [str drawAtPoint:NSMakePoint(1,1) withAttributes:stringAttributes];
75 sprite = [[OpenGLSprite alloc] initWithImage:image
76 cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height)
93 float alpha= (float)_animationCount/20;
97 [image compositeToPoint:screenLocation operation:NSCompositeSourceOver fraction:alpha];
102 float alpha= (float)_animationCount/20;
106 [sprite blitToX:screenLocation.x
108 Z:SCOREBUBBLE_SPRITE_Z
114 if (_animationCount > 0) {
119 return _animationCount;
127 -(NSPoint)screenLocation
129 return screenLocation;