Skip to content

Commit

Permalink
Refactored game animations. Improved game examples
Browse files Browse the repository at this point in the history
  • Loading branch information
syrel committed Nov 9, 2017
1 parent f988c7b commit ec7db6a
Show file tree
Hide file tree
Showing 34 changed files with 175 additions and 138 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
announcement - handling
onDisappear
| disappearAnimation enlargeAnimation scalingAnimation parallelAnimation sequentialAnimation |
| vanish enlarge minimize disappear |

enlargeAnimation := BlScaleAnimation new
target: self;
"when two cards match we want them to enlarge a bit in order to get player's attention"
enlarge := BlTransformAnimation scale: 1.15 @ 1.15.
enlarge
absolute;
easing: BlEasing bounceOut;
scaleTo: 0.2@0.2;
duration: 500.
duration: 0.5 seconds;
target: self.

disappearAnimation := BlOpacityAnimation new
target: self;
"vanish animation manipulates opacity to make element transparent"
vanish := BlOpacityAnimation new
opacity: 0;
duration: 400.
duration: 0.35 seconds;
target: self.

scalingAnimation := BlScaleAnimation new
target: self;
"minimization animation changes card's scale to a tiny value"
minimize := BlTransformAnimation scale: 0.01 @ 0.01.
minimize
absolute;
easing: BlEasing linear;
scaleTo: (0.9@0.9) negated;
duration: 400.
parallelAnimation := BlParallelAnimation new
addAll: { disappearAnimation . scalingAnimation }.
duration: 0.35 seconds;
target: self.

"disappearing animation makes card transparent and minimizes until it becomes invisible"
disappear := BlParallelAnimation with: { vanish . minimize }.

sequentialAnimation := BlSequentialAnimation new
onFinishedDo: [ self mouseTransparent: true ];
addAll: { enlargeAnimation. parallelAnimation }.

sequentialAnimation start
"final animation consists of two sequential animations: enlarge and disappear"
(BlSequentialAnimation with: { enlarge. disappear })
"in order to preserve grid layout we don't actually remove cards from the window,
we make them transparent (vanish animation) and forbid them from handling mouse events"
onFinishedDo: [ self wantsMouse: false ];
start
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
announcement - handling
onFlippedBack
BlScaleAnimation new
target: self;
| animation |

animation := BlTransformAnimation scale: 1@1.
animation
absolute;
easing: BlEasing bounceOut;
scaleTo: 0.001@0.001;
duration: 350;
start
duration: 0.35 seconds.

animation startOn: self
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
announcement - handling
onFlippedFace
BlScaleAnimation new
target: self;
| animation |

animation := BlTransformAnimation scale: 0.85 @ 0.85.
animation
absolute;
easing: BlQuinticInterpolator default;
scaleTo: (0.15@0.15) negated;
duration: 300;
start
duration: 0.3 seconds.

animation startOn: self
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
actions
resetStep
|lastCard|
| lastCard |

lastCard := self chosenCards last.

self chosenCards
allButLastDo: [ :aCard | aCard flip ];
removeAll;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
testing
shouldCompleteStep
^ self chosenCards size = self matchesCount and: [
self chosenCardMatch ]
"Return true if current step should be completed, false otherwise.
According to game rules step is done when all chosen cards match
and their amount corresponds to a specific number (#matchesCount)"
<return: #Boolean>

^ self chosenCards size = self matchesCount
and: [ self chosenCardMatch ]
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
announcement - handling
onDisappear
| disappearAnimation enlargeAnimation scalingAnimation parallelAnimation sequentialAnimation |
| vanish enlarge minimize disappear |

enlargeAnimation := BlScaleAnimation new
target: self;
"when two cards match we want them to enlarge a bit in order to get player's attention"
enlarge := BlTransformAnimation scale: 1.15 @ 1.15.
enlarge
absolute;
easing: BlEasing bounceOut;
scaleTo: 0.2@0.2;
duration: 500.
duration: 0.5 seconds;
target: self.

disappearAnimation := BlOpacityAnimation new
target: self;
"vanish animation manipulates opacity to make element transparent"
vanish := BlOpacityAnimation new
opacity: 0;
duration: 400.

scalingAnimation := BlScaleAnimation new
target: self;
duration: 0.35 seconds;
target: self.

"minimization animation changes card's scale to a tiny value"
minimize := BlTransformAnimation scale: 0.01 @ 0.01.
minimize
absolute;
easing: BlEasing linear;
scaleTo: (0.9@0.9) negated;
duration: 400.
parallelAnimation := BlParallelAnimation new
addAll: { disappearAnimation . scalingAnimation }.
duration: 0.35 seconds;
target: self.

"disappearing animation makes card transparent and minimizes until it becomes invisible"
disappear := BlParallelAnimation with: { vanish . minimize }.

sequentialAnimation := BlSequentialAnimation new
onFinishedDo: [ self mouseTransparent: true ];
addAll: { enlargeAnimation. parallelAnimation }.

sequentialAnimation start
"final animation consists of two sequential animations: enlarge and disappear"
(BlSequentialAnimation with: { enlarge. disappear })
"in order to preserve grid layout we don't actually remove cards from the window,
we make them transparent (vanish animation) and forbid them from handling mouse events"
onFinishedDo: [ self wantsMouse: false ];
start
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
announcement - handling
onFlippedBack
BlScaleAnimation new
target: self;
| animation |

animation := BlTransformAnimation scale: 1@1.
animation
absolute;
easing: BlEasing bounceOut;
scaleTo: 0.001@0.001;
duration: 350;
start
duration: 0.35 seconds.

animation startOn: self
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
announcement - handling
onFlippedFace
BlScaleAnimation new
target: self;
| animation |

animation := BlTransformAnimation scale: 0.85 @ 0.85.
animation
absolute;
easing: BlQuinticInterpolator default;
scaleTo: (0.15@0.15) negated;
duration: 300;
start
duration: 0.3 seconds.

animation startOn: self
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I contain examples of how to create card and grid elements
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
as yet unclassified
instance creation
basicGrid
<gtExample>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
as yet unclassified
accessing
card
<gtExample>

^ MgCardElement new

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing
gameElementWithModel
<gtExample>

^ self basicGrid memoryGame: MgModelExamples new gameModelWithCards

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "",
"commentStamp" : "AliakseiSyrel 11/9/2017 12:46",
"super" : "Object",
"category" : "Bloc-MemoryGame-Examples",
"classinstvars" : [ ],
Expand Down
1 change: 1 addition & 0 deletions src/Bloc-MemoryGame.package/MgExamples.class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I contain runnable games initalized with different card types
8 changes: 0 additions & 8 deletions src/Bloc-MemoryGame.package/MgExamples.class/class/example.st

This file was deleted.

19 changes: 8 additions & 11 deletions src/Bloc-MemoryGame.package/MgExamples.class/class/open.st
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
instance creation
examples
open
<example>
| space game gameElement |
space := BlSpace new.
space extent: 420@420.

"I create and start a game with Number cards"
<script: 'self open'>
| game gameElement |

game := MgGameModel new.
"game initializeForSymbols: '为从公家里地个时'."
game initializeForSymbols: '💰🏡🎅🍪🍕🚀😸🙈'.
game initializeForSymbols: '12345678'.

gameElement := MgGameElement new.
gameElement memoryGame: game.

space root addChild: gameElement.
space show

self openInWindow: gameElement
14 changes: 14 additions & 0 deletions src/Bloc-MemoryGame.package/MgExamples.class/class/openEmoji.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
examples
openEmoji
"I create and start a game with Emoji cards.
(only works on OSX with Moz2D rendering backend)"
<script: 'self openEmoji'>
| game gameElement |

game := MgGameModel new.
game initializeForSymbols: '💰🏡🎅🍪🍕🚀😸🙈'.

gameElement := MgGameElement new.
gameElement memoryGame: game.

self openInWindow: gameElement
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
examples
openHieroglyphs
"I create and start a game with Hieroglyph cards.
(only works on OSX with Moz2D rendering backend)"
<script: 'self openHieroglyphs'>
| game gameElement |

game := MgGameModel new.
game initializeForSymbols: '为从公家里地个时'.

gameElement := MgGameElement new.
gameElement memoryGame: game.

self openInWindow: gameElement
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
opening
openInWindow: anElement
"Open a given game element in a window"
| aSpace |
aSpace := BlSpace new
extent: 420@420;
title: 'Memory Game'.

aSpace root
addChild: anElement;
yourself.

aSpace show
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "",
"commentStamp" : "AliakseiSyrel 11/9/2017 12:54",
"super" : "Object",
"category" : "Bloc-MemoryGame-Examples",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I contain examples of how to instantiate and initialize a game model with cards and query card count or grid size

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
examples
instance creation
basicCard
<gtExample>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
examples
instance creation
basicGame
<gtExample>

Expand Down

This file was deleted.

Loading

0 comments on commit ec7db6a

Please sign in to comment.