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 _screenLocation;
36 @synthesize _animationCount;
38 + (ScoreBubble *)scoreWithValue:(int)value at:(NSPoint)location duration:(int)count
40 // FIXME: possible bug, is it [self alloc] or [[self class] alloc]???
41 ScoreBubble *scoreBubble = [[self alloc] initWithValue:value
44 return [scoreBubble autorelease];
47 -(id)initWithValue:(int)value at:(NSPoint)location duration:(int)count
49 NSString *str= [NSString stringWithFormat:@"%d", value];
53 if (!stringAttributes) {
54 stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
55 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
56 [stringAttributes retain];
58 strsize= [str sizeWithAttributes:stringAttributes];
62 _screenLocation = location;
63 _screenLocation.x -= strsize.width / 2;
64 _screenLocation.y -= strsize.height / 2;
65 _animationCount= count;
66 image= [[NSImage alloc] initWithSize:strsize];
68 [stringAttributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
69 [str drawAtPoint:NSMakePoint(2,0) withAttributes:stringAttributes];
70 [stringAttributes setObject:[NSColor yellowColor] forKey:NSForegroundColorAttributeName];
71 [str drawAtPoint:NSMakePoint(1,1) withAttributes:stringAttributes];
76 sprite = [[OpenGLSprite alloc] initWithImage:image
77 cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height)
94 float alpha = (float)_animationCount/20;
99 [image compositeToPoint:_screenLocation
100 operation:NSCompositeSourceOver
106 float alpha= (float)_animationCount/20;
110 [sprite blitToX:_screenLocation.x
112 Z:SCOREBUBBLE_SPRITE_Z
118 if (_animationCount > 0) {
123 return _animationCount;