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 _animationCount;
36 + (ScoreBubble *)scoreWithValue:(int)val At:(NSPoint)loc Duration:(int)count
38 // FIXME: possible bug, is it [self alloc] or [[self class] alloc]???
39 ScoreBubble *scoreBubble = [[self alloc] initWithValue:val At:loc Duration:count];
40 return [scoreBubble autorelease];
41 // !!!: remove: return [[[self alloc] initWithValue:val At:loc Duration:count] autorelease];
44 -(id)initWithValue:(int)val At:(NSPoint)loc Duration:(int)count
46 NSString *str= [NSString stringWithFormat:@"%d", val];
50 if (!stringAttributes) {
51 stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
52 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
53 [stringAttributes retain];
55 strsize= [str sizeWithAttributes:stringAttributes];
60 screenLocation.x-=strsize.width/2;
61 screenLocation.y-=strsize.height/2;
62 _animationCount= count;
63 image= [[NSImage alloc] initWithSize:strsize];
65 [stringAttributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
66 [str drawAtPoint:NSMakePoint(2,0) withAttributes:stringAttributes];
67 [stringAttributes setObject:[NSColor yellowColor] forKey:NSForegroundColorAttributeName];
68 [str drawAtPoint:NSMakePoint(1,1) withAttributes:stringAttributes];
73 sprite = [[OpenGLSprite alloc] initWithImage:image
74 cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height)
91 float alpha= (float)_animationCount/20;
95 [image compositeToPoint:screenLocation operation:NSCompositeSourceOver fraction:alpha];
100 float alpha= (float)_animationCount/20;
104 [sprite blitToX:screenLocation.x
106 Z:SCOREBUBBLE_SPRITE_Z
112 if (_animationCount>0) {
116 return _animationCount;
129 -(NSPoint)screenLocation
131 return screenLocation;