add warnings to the project
[exterlulz-kokogems.git] / src / ScoreBubble.m
blobf3ba07b98046719cbc1ffdcc83f7466e97d6cc31
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 // Open GL
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];
42     NSSize strsize;
43   self = [super init];
44     if (self != nil) {
45         if (!stringAttributes) {
46             stringAttributes= [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"ArialNarrow-Bold" size:18],
47                 NSFontAttributeName, [NSColor blackColor], NSForegroundColorAttributeName, NULL];
48             [stringAttributes retain];
49         }
50         strsize= [str sizeWithAttributes:stringAttributes];
51         strsize.width+= 3;
52         strsize.height+=1;
53         value= val;
54         screenLocation= loc;
55         screenLocation.x-=strsize.width/2;
56         screenLocation.y-=strsize.height/2;
57         animationCount= count;
58         image= [[NSImage alloc] initWithSize:strsize];
59         [image lockFocus];
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];
64         [image unlockFocus];
66         // Open GL
67         //
68         sprite = [[OpenGLSprite alloc] initWithImage:image
69                                        cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height)
70                                                 size:[image size]];
71         //
72     }
73     return self;
76 - (void) dealloc
78     [image release];
79     [sprite release];
80     
81     [super dealloc];
84 -(void)drawImage
86     float alpha= (float)animationCount/20;
87     if (alpha>1) {
88         alpha= 1;
89     }
90     [image compositeToPoint:screenLocation operation:NSCompositeSourceOver fraction:alpha];
93 -(void)drawSprite
95     float alpha= (float)animationCount/20;
96     if (alpha>1) {
97         alpha= 1;
98     }
99     [sprite blitToX:screenLocation.x
100                   Y:screenLocation.y
101                   Z:SCOREBUBBLE_SPRITE_Z
102               Alpha:alpha];
105 -(int)animate
107     if (animationCount>0) {
108         screenLocation.y++;
109         animationCount--;
110     }
111     return animationCount;
114 -(int)animationCount
116     return animationCount;
118 -(void)setAnimationCount:(int)count
120     animationCount= count;
123 -(int)value
125     return value;
128 -(NSImage *)image
130     return image;
133 -(NSPoint)screenLocation
135     return screenLocation;
138 @end