From ff252154089a200a66dfbb7ad514cda277b39e7b Mon Sep 17 00:00:00 2001 From: exterlulz Date: Fri, 20 Aug 2010 19:46:58 +0200 Subject: [PATCH] set Gem._animationCounter as property --- src/Game.m | 23 ++++++++++++----------- src/Gem.h | 9 +++------ src/Gem.m | 54 ++++++++++++++++++++++++------------------------------ 3 files changed, 39 insertions(+), 47 deletions(-) diff --git a/src/Game.m b/src/Game.m index dde807a..32bd64e 100644 --- a/src/Game.m +++ b/src/Game.m @@ -183,7 +183,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int gemtype = [board[x][y] gemType]; tx = x; ty = y; cx = x; cy = y; bonus = 0; - if ([board[x][y] state] == GEMSTATE_FADING) result = YES; + if (board[x][y]._state == GEMSTATE_FADING) result = YES; while ((tx > 0)&&([board[tx-1][y] gemType]==gemtype)) tx = tx-1; while ((cx < 7)&&([board[cx+1][y] gemType]==gemtype)) cx = cx+1; if ((cx-tx) >= 2) @@ -197,7 +197,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. linebonus+= scorePerGem; [board[i][y] fade]; for (j=7; j>y; j--) { - if ([board[i][j] state]!= GEMSTATE_FADING) { + if (board[i][j]._state != GEMSTATE_FADING) { [board[i][j] shiver]; // MW prepare to fall } } @@ -223,7 +223,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. [board[x][i] fade]; } for (j=7; j>cy; j--) { - if ([board[x][j] state]!= GEMSTATE_FADING) { + if (board[x][j]._state != GEMSTATE_FADING) { [board[x][j] shiver]; // MW prepare to fall } } @@ -264,7 +264,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. int gemtype = [board[x][y] gemType]; tx = x; ty = y; cx = x; cy = y; - if ([board[x][y] state] == GEMSTATE_FADING) return YES; + if (board[x][y]._state == GEMSTATE_FADING) return YES; while ((tx > 0)&&([board[tx-1][y] gemType]==gemtype)) tx = tx-1; while ((cx < 7)&&([board[cx+1][y] gemType]==gemtype)) cx = cx+1; @@ -314,7 +314,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) - if ([board[i][j] state]!=GEMSTATE_FADING) + if (board[i][j]._state != GEMSTATE_FADING) result = result | [self testForThreeAt:i:j]; // CASCADE BONUS check for reset if (!result) cascade = 1; @@ -351,10 +351,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) { - if ([board[i][j] state] == GEMSTATE_FADING) + if (board[i][j]._state == GEMSTATE_FADING) { [board[i][j] erupt]; - [board[i][j] setAnimationCounter:1]; + // !!!: remove: [board[i][j] setAnimationCounter:1]; + board[i][j]._animationCounter = 1; } else [board[i][j] erupt]; @@ -411,7 +412,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // let non-faded gems fall into place for (j = 0; j < 8; j++) { - if ([board[i][j] state] != GEMSTATE_FADING) + if (board[i][j]._state != GEMSTATE_FADING) { column[y] = board[i][j]; if ([board[i][j] positionOnScreen].y > y*48) @@ -424,7 +425,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // transfer faded gems to top of column for (j = 0; j < 8; j++) { - if ([board[i][j] state] == GEMSTATE_FADING) + if (board[i][j]._state == GEMSTATE_FADING) { // randomly reassign int r = (rand() % 7); @@ -459,7 +460,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // let non-faded gems fall into place for (j = 0; j < 8; j++) { - if ([board[i][j] state] != GEMSTATE_FADING) + if (board[i][j]._state != GEMSTATE_FADING) { column[y] = board[i][j]; if ([board[i][j] positionOnScreen].y > y*48) @@ -472,7 +473,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // transfer faded gems to top of column for (j = 0; j < 8; j++) { - if ([board[i][j] state] == GEMSTATE_FADING) + if (board[i][j]._state == GEMSTATE_FADING) { // randomly reassign int r = (rand() % 7); diff --git a/src/Gem.h b/src/Gem.h index 99559eb..d553976 100644 --- a/src/Gem.h +++ b/src/Gem.h @@ -60,15 +60,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // MW int waitForFall; - // int _state; - int animationCounter; + int _animationCounter; double vx, vy; NSPoint positionOnScreen, positionOnBoard; } @property int _state; +@property int _animationCounter; - (id)init; - (void)dealloc; @@ -81,9 +81,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - (void) fall; - (void) shake; - (void) erupt; + // MW... - (void) shiver; -// - (int) gemType; - (void) setGemType:(int) d; @@ -96,9 +96,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - (void) setSprite:(OpenGLSprite *) value; - (void) drawSprite; -- (int) animationCounter; -- (void) setAnimationCounter:(int) value; - - (NSPoint) positionOnScreen; - (void) setPositionOnScreen:(int) valx :(int) valy; - (void) setVelocity:(int) valx :(int) valy :(int) steps; diff --git a/src/Gem.m b/src/Gem.m index 8493e18..8b26227 100644 --- a/src/Gem.m +++ b/src/Gem.m @@ -24,11 +24,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Open GL #import "OpenGLSprite.h" -// @implementation Gem @synthesize _state; +@synthesize _animationCounter; - (id)init { @@ -72,12 +72,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. if (_state == GEMSTATE_RESTING) { [self setPositionOnScreen:positionOnBoard.x*48:positionOnBoard.y*48]; - animationCounter = 0; + _animationCounter = 0; } if (_state == GEMSTATE_FADING) { [self setPositionOnScreen:positionOnBoard.x*48:positionOnBoard.y*48]; - if (animationCounter > 0) animationCounter--; + if (_animationCounter > 0) + _animationCounter--; } // MW... if (_state== GEMSTATE_SHIVERING) { @@ -87,17 +88,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // if (_state == GEMSTATE_FALLING) { - if (animationCounter (positionOnBoard.y*48)) { positionOnScreen.y += vy; positionOnScreen.x = positionOnBoard.x*48; vy -= GRAVITY; - animationCounter++; + _animationCounter++; } else { @@ -110,14 +111,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. { positionOnScreen.x = positionOnBoard.x*48+(rand()%5)-2; positionOnScreen.y = positionOnBoard.y*48+(rand()%5)-2; - if (animationCounter > 1) animationCounter--; + if (_animationCounter > 1) _animationCounter--; else _state = GEMSTATE_RESTING; } if (_state == GEMSTATE_ERUPTING) { if (positionOnScreen.y > -48) { - if (animationCounter < GEM_ERUPT_DELAY) + if (_animationCounter < GEM_ERUPT_DELAY) { positionOnScreen.x = positionOnBoard.x*48+(rand()%5)-2; positionOnScreen.y = positionOnBoard.y*48+(rand()%5)-2; @@ -128,32 +129,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. positionOnScreen.x += vx; vy -= GRAVITY; } - animationCounter++; + _animationCounter++; } else { - animationCounter = 0; + _animationCounter = 0; } } if (_state == GEMSTATE_MOVING) { - if (animationCounter > 0) + if (_animationCounter > 0) { positionOnScreen.y += vy; positionOnScreen.x += vx; - animationCounter--; + _animationCounter--; } else _state = GEMSTATE_RESTING; } - return animationCounter; + return _animationCounter; } - (void) fade { [sploink play]; _state = GEMSTATE_FADING; - animationCounter = FADE_STEPS; + _animationCounter = FADE_STEPS; } + - (void) fall { _state = GEMSTATE_FALLING; @@ -162,20 +164,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // vx = 0; vy = 0; - animationCounter = 1; + _animationCounter = 1; } // MW... - (void) shiver { _state= GEMSTATE_SHIVERING; - animationCounter= 0; + _animationCounter = 0; } - (void) shake { _state = GEMSTATE_SHAKING; - animationCounter = 25; + _animationCounter = 25; } - (void) erupt @@ -183,7 +185,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. [self setVelocity:(rand()%5)-2:(rand()%7)-2:1]; _state = GEMSTATE_ERUPTING; - animationCounter = GEM_ERUPT_DELAY; + _animationCounter = GEM_ERUPT_DELAY; } - (int) gemType @@ -206,7 +208,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - (void) drawImage { if (_state == GEMSTATE_FADING) - [[self image] compositeToPoint:[self positionOnScreen] operation:NSCompositeSourceOver fraction:(animationCounter / FADE_STEPS)]; + [[self image] compositeToPoint:[self positionOnScreen] operation:NSCompositeSourceOver fraction:(_animationCounter / FADE_STEPS)]; else [[self image] compositeToPoint:[self positionOnScreen] operation:NSCompositeSourceOver]; } @@ -225,7 +227,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. [[self sprite] blitToX:positionOnScreen.x Y:positionOnScreen.y Z:GEM_SPRITE_Z - Alpha:(animationCounter / FADE_STEPS)]; + Alpha:(_animationCounter / FADE_STEPS)]; else [[self sprite] blitToX:positionOnScreen.x Y:positionOnScreen.y @@ -233,15 +235,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Alpha:1.0]; } -- (int) animationCounter -{ - return animationCounter; -} -- (void) setAnimationCounter:(int) value -{ - animationCounter = value; -} - - (NSPoint) positionOnScreen { return positionOnScreen; @@ -255,7 +248,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. { vx = valx; vy = valy; - animationCounter = steps; + + _animationCounter = steps; _state = GEMSTATE_MOVING; } -- 2.11.4.GIT