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"
27 #import "OpenGLSprite.h"
30 NSMutableDictionary *stringAttributes;
32 @implementation ScoreBubble
34 +(ScoreBubble *)scoreWithValue:(int)val At:(NSPoint)loc Duration:(int)count
36 return [[[[self class] alloc] initWithValue:val At:loc Duration:count] autorelease];
39 -(id)initWithValue:(int)val At:(NSPoint)loc Duration:(int)count
41 NSString *str= [NSString stringWithFormat:@"%d", val];
45 if (!stringAttributes) {
46 stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
47 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
48 [stringAttributes retain];
50 strsize= [str sizeWithAttributes:stringAttributes];
55 screenLocation.x-=strsize.width/2;
56 screenLocation.y-=strsize.height/2;
57 animationCount= count;
58 image= [[NSImage alloc] initWithSize:strsize];
60 [stringAttributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
61 [str drawAtPoint:NSMakePoint(2,0) withAttributes:stringAttributes];
62 [stringAttributes setObject:[NSColor yellowColor] forKey:NSForegroundColorAttributeName];
63 [str drawAtPoint:NSMakePoint(1,1) withAttributes:stringAttributes];
68 sprite = [[OpenGLSprite alloc] initWithImage:image
69 cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height)
86 float alpha= (float)animationCount/20;
90 [image compositeToPoint:screenLocation operation:NSCompositeSourceOver fraction:alpha];
95 float alpha= (float)animationCount/20;
99 [sprite blitToX:screenLocation.x
101 Z:SCOREBUBBLE_SPRITE_Z
107 if (animationCount>0) {
111 return animationCount;
116 return animationCount;
118 -(void)setAnimationCount:(int)count
120 animationCount= count;
133 -(NSPoint)screenLocation
135 return screenLocation;