add koko_fantomes_80
[exterlulz-kokogems.git] / src / ScoreBubble.m
blob0769a805a99a114021162ae2d9368f6e8fb849c1
1 //
2 //  ScoreBubble.m
3 //  jeweltoy
4 //
5 //  Created by Mike Wessler on Sat Jun 15 2002.
6 //
7 /*
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];
47     NSSize strsize;
48   self = [super init];
49     if (self != nil) {
50         if (!stringAttributes) {
51             stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
52                 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
53             [stringAttributes retain];
54         }
55         strsize= [str sizeWithAttributes:stringAttributes];
56         strsize.width+= 3;
57         strsize.height+=1;
58         value= val;
59         screenLocation= loc;
60         screenLocation.x-=strsize.width/2;
61         screenLocation.y-=strsize.height/2;
62         _animationCount= count;
63         image= [[NSImage alloc] initWithSize:strsize];
64         [image lockFocus];
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];
69         [image unlockFocus];
71         // Open GL
72         //
73         sprite = [[OpenGLSprite alloc] initWithImage:image
74                                        cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height)
75                                                 size:[image size]];
76         //
77     }
78     return self;
81 - (void)dealloc
83   [image release];
84   [sprite release];
85   
86   [super dealloc];
89 -(void)drawImage
91     float alpha= (float)_animationCount/20;
92     if (alpha>1) {
93         alpha= 1;
94     }
95     [image compositeToPoint:screenLocation operation:NSCompositeSourceOver fraction:alpha];
98 -(void)drawSprite
100     float alpha= (float)_animationCount/20;
101     if (alpha>1) {
102         alpha= 1;
103     }
104     [sprite blitToX:screenLocation.x
105                   Y:screenLocation.y
106                   Z:SCOREBUBBLE_SPRITE_Z
107               Alpha:alpha];
110 -(int)animate
112     if (_animationCount>0) {
113         screenLocation.y++;
114         _animationCount--;
115     }
116     return _animationCount;
119 -(int)value
121     return value;
124 -(NSImage *)image
126     return image;
129 -(NSPoint)screenLocation
131     return screenLocation;
134 @end