1 /* ----====----====----====----====----====----====----====----====----====----
4 JewelToy is a simple game played against the clock.
5 Copyright (C) 2001 Giles Williams
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 ----====----====----====----====----====----====----====----====----====---- */
22 /* kokomonds is a fork of JewelToy.
23 * repository: http://github.com/exterlulz/kokomonds
31 #import "OpenGLSprite.h"
39 [self setSoundsTink:[NSSound soundNamed:@"tink"] Sploink:[NSSound soundNamed:@"sploink"]];
51 + (Gem *) gemWithNumber:(int) d andImage:(NSImage *)img
53 Gem *result = [[[Gem alloc] init] autorelease];
54 [result setGemType:d];
55 [result setImage:img];
56 [result setSoundsTink:[NSSound soundNamed:@"tink"] Sploink:[NSSound soundNamed:@"sploink"]];
60 + (Gem *) gemWithNumber:(int) d andSprite:(OpenGLSprite *)aSprite
62 Gem *result = [[[Gem alloc] init] autorelease];
63 [result setGemType:d];
64 [result setSprite:aSprite];
65 [result setSoundsTink:[NSSound soundNamed:@"tink"] Sploink:[NSSound soundNamed:@"sploink"]];
71 if (state == GEMSTATE_RESTING)
73 [self setPositionOnScreen:positionOnBoard.x*48:positionOnBoard.y*48];
76 if (state == GEMSTATE_FADING)
78 [self setPositionOnScreen:positionOnBoard.x*48:positionOnBoard.y*48];
79 if (animationCounter > 0) animationCounter--;
82 if (state== GEMSTATE_SHIVERING) {
83 positionOnScreen.x= positionOnBoard.x*48+(rand()%3)-1;
84 positionOnScreen.y= positionOnBoard.y*48;
87 if (state == GEMSTATE_FALLING)
89 if (animationCounter<waitForFall) {
90 positionOnScreen.x= positionOnBoard.x*48;
91 //positionOnScreen.y= positionOnBoard.y*48;
94 else if (positionOnScreen.y > (positionOnBoard.y*48))
96 positionOnScreen.y += vy;
97 positionOnScreen.x = positionOnBoard.x*48;
104 positionOnScreen.y = positionOnBoard.y * 48;
105 state = GEMSTATE_RESTING;
108 if (state == GEMSTATE_SHAKING)
110 positionOnScreen.x = positionOnBoard.x*48+(rand()%5)-2;
111 positionOnScreen.y = positionOnBoard.y*48+(rand()%5)-2;
112 if (animationCounter > 1) animationCounter--;
113 else state = GEMSTATE_RESTING;
115 if (state == GEMSTATE_ERUPTING)
117 if (positionOnScreen.y > -48)
119 if (animationCounter < GEM_ERUPT_DELAY)
121 positionOnScreen.x = positionOnBoard.x*48+(rand()%5)-2;
122 positionOnScreen.y = positionOnBoard.y*48+(rand()%5)-2;
126 positionOnScreen.y += vy;
127 positionOnScreen.x += vx;
134 animationCounter = 0;
137 if (state == GEMSTATE_MOVING)
139 if (animationCounter > 0)
141 positionOnScreen.y += vy;
142 positionOnScreen.x += vx;
145 else state = GEMSTATE_RESTING;
147 return animationCounter;
153 state = GEMSTATE_FADING;
154 animationCounter = FADE_STEPS;
158 state = GEMSTATE_FALLING;
160 waitForFall= rand()%6;
164 animationCounter = 1;
169 state= GEMSTATE_SHIVERING;
175 state = GEMSTATE_SHAKING;
176 animationCounter = 25;
180 [self setVelocity:(rand()%5)-2:(rand()%7)-2:1];
181 state = GEMSTATE_ERUPTING;
182 animationCounter = GEM_ERUPT_DELAY;
189 - (void) setGemType:(int) d
198 - (void) setImage:(NSImage *) value
204 if (state == GEMSTATE_FADING)
205 [[self image] compositeToPoint:[self positionOnScreen] operation:NSCompositeSourceOver fraction:(animationCounter / FADE_STEPS)];
207 [[self image] compositeToPoint:[self positionOnScreen] operation:NSCompositeSourceOver];
210 - (OpenGLSprite *) sprite
214 - (void) setSprite:(OpenGLSprite *) value
220 if (state == GEMSTATE_FADING)
221 [[self sprite] blitToX:positionOnScreen.x
224 Alpha:(animationCounter / FADE_STEPS)];
226 [[self sprite] blitToX:positionOnScreen.x
236 - (void) setState:(int) value
241 - (int) animationCounter
243 return animationCounter;
245 - (void) setAnimationCounter:(int) value
247 animationCounter = value;
250 - (NSPoint) positionOnScreen
252 return positionOnScreen;
254 - (void) setPositionOnScreen:(int) valx :(int) valy
256 positionOnScreen.x = valx;
257 positionOnScreen.y = valy;
259 - (void) setVelocity:(int) valx :(int) valy :(int) steps
263 animationCounter = steps;
264 state = GEMSTATE_MOVING;
267 - (NSPoint) positionOnBoard
269 return positionOnBoard;
271 - (void) setPositionOnBoard:(int) valx :(int) valy
273 positionOnBoard.x = valx;
274 positionOnBoard.y = valy;
277 - (void) setSoundsTink:(NSSound *) tinkSound Sploink:(NSSound *) sploinkSound
280 sploink = sploinkSound;