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 /* kokomonds is a fork of JewelToy.
24 * repository: http://github.com/exterlulz/kokomonds
29 #import "ScoreBubble.h"
33 #import "OpenGLSprite.h"
36 NSMutableDictionary *stringAttributes;
38 @implementation ScoreBubble
40 + (ScoreBubble *)scoreWithValue:(int)val at:(NSPoint)location duration:(int)count {
41 return [[[[self class] alloc] initWithValue:val at:location duration:count] autorelease];
44 - (id)initWithValue:(int)val at:(NSPoint)location duration:(int)count
46 NSString *str= [NSString stringWithFormat:@"%d", val];
51 if (!stringAttributes) {
52 stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
53 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
54 [stringAttributes retain];
56 strsize= [str sizeWithAttributes:stringAttributes];
60 screenLocation = location;
61 screenLocation.x -= strsize.width / 2;
62 screenLocation.y -= strsize.height / 2;
63 animationCount = count;
64 image = [[NSImage alloc] initWithSize:strsize];
66 [stringAttributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
67 [str drawAtPoint:NSMakePoint(2,0) withAttributes:stringAttributes];
68 [stringAttributes setObject:[NSColor yellowColor] forKey:NSForegroundColorAttributeName];
69 [str drawAtPoint:NSMakePoint(1,1) withAttributes:stringAttributes];
74 sprite = [[OpenGLSprite alloc] initWithImage:image
75 cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height)
85 // TODO: _image = nil; everywhere
94 float alpha= (float)animationCount/20;
98 [image compositeToPoint:screenLocation operation:NSCompositeSourceOver fraction:alpha];
103 float alpha= (float)animationCount/20;
107 [sprite blitToX:screenLocation.x
109 Z:SCOREBUBBLE_SPRITE_Z
115 if (animationCount>0) {
120 return animationCount;
123 -(int)animationCount {
124 return animationCount;
127 -(void)setAnimationCount:(int)count {
128 animationCount = count;
139 -(NSPoint)screenLocation {
140 return screenLocation;