change method parameters
[exterlulz-kokogems.git] / src / ScoreBubble.m
blob6e282b3fa77d99ff3593ff638ba122ee2dcb4f9b
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 _value;
35 @synthesize _animationCount;
37 + (ScoreBubble *)scoreWithValue:(int)value at:(NSPoint)location duration:(int)count
39   // FIXME: possible bug, is it [self alloc] or [[self class] alloc]???
40   ScoreBubble *scoreBubble = [[self alloc] initWithValue:value
41                                                       At:location
42                                                 Duration:count];
43   return [scoreBubble autorelease];
46 -(id)initWithValue:(int)value At:(NSPoint)loc Duration:(int)count
48     NSString *str= [NSString stringWithFormat:@"%d", value];
49     NSSize strsize;
50   self = [super init];
51     if (self != nil) {
52         if (!stringAttributes) {
53             stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
54                 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
55             [stringAttributes retain];
56         }
57         strsize= [str sizeWithAttributes:stringAttributes];
58         strsize.width+= 3;
59         strsize.height+=1;
60         _value= value;
61         screenLocation= loc;
62         screenLocation.x-=strsize.width/2;
63         screenLocation.y-=strsize.height/2;
64         _animationCount= count;
65         image= [[NSImage alloc] initWithSize:strsize];
66         [image lockFocus];
67         [stringAttributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];        
68         [str drawAtPoint:NSMakePoint(2,0) withAttributes:stringAttributes];
69         [stringAttributes setObject:[NSColor yellowColor] forKey:NSForegroundColorAttributeName];       
70         [str drawAtPoint:NSMakePoint(1,1) withAttributes:stringAttributes];
71         [image unlockFocus];
73         // Open GL
74         //
75         sprite = [[OpenGLSprite alloc] initWithImage:image
76                                        cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height)
77                                                 size:[image size]];
78         //
79     }
80     return self;
83 - (void)dealloc
85   [image release];
86   [sprite release];
87   
88   [super dealloc];
91 -(void)drawImage
93     float alpha= (float)_animationCount/20;
94     if (alpha>1) {
95         alpha= 1;
96     }
97     [image compositeToPoint:screenLocation operation:NSCompositeSourceOver fraction:alpha];
100 -(void)drawSprite
102     float alpha= (float)_animationCount/20;
103     if (alpha>1) {
104         alpha= 1;
105     }
106     [sprite blitToX:screenLocation.x
107                   Y:screenLocation.y
108                   Z:SCOREBUBBLE_SPRITE_Z
109               Alpha:alpha];
112 -(int)animate
114   if (_animationCount > 0) {
115     screenLocation.y++;
116     _animationCount--;
117   }
118   
119   return _animationCount;
122 -(NSImage *)image
124     return image;
127 -(NSPoint)screenLocation
129     return screenLocation;
132 @end