forked from pharo-graphics/Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored game animations. Improved game examples
- Loading branch information
Showing
34 changed files
with
175 additions
and
138 deletions.
There are no files selected for viewing
46 changes: 26 additions & 20 deletions
46
src/Bloc-MemoryGame-Demo.package/MgdCardElement.class/instance/onDisappear.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 8 additions & 5 deletions
13
src/Bloc-MemoryGame-Demo.package/MgdCardElement.class/instance/onFlippedBack.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 8 additions & 5 deletions
13
src/Bloc-MemoryGame-Demo.package/MgdCardElement.class/instance/onFlippedFace.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
4 changes: 3 additions & 1 deletion
4
src/Bloc-MemoryGame-Demo.package/MgdGameModel.class/instance/resetStep.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
src/Bloc-MemoryGame-Demo.package/MgdGameModel.class/instance/shouldCompleteStep.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] |
48 changes: 27 additions & 21 deletions
48
src/Bloc-MemoryGame.package/MgCardElement.class/instance/onDisappear.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 8 additions & 5 deletions
13
src/Bloc-MemoryGame.package/MgCardElement.class/instance/onFlippedBack.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 8 additions & 5 deletions
13
src/Bloc-MemoryGame.package/MgCardElement.class/instance/onFlippedFace.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I contain examples of how to create card and grid elements |
2 changes: 1 addition & 1 deletion
2
src/Bloc-MemoryGame.package/MgElementExamples.class/instance/basicGrid.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
as yet unclassified | ||
instance creation | ||
basicGrid | ||
<gtExample> | ||
|
||
|
3 changes: 2 additions & 1 deletion
3
src/Bloc-MemoryGame.package/MgElementExamples.class/instance/card.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
as yet unclassified | ||
accessing | ||
card | ||
<gtExample> | ||
|
||
^ MgCardElement new |
3 changes: 0 additions & 3 deletions
3
src/Bloc-MemoryGame.package/MgElementExamples.class/instance/gameElementWith..st
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/Bloc-MemoryGame.package/MgElementExamples.class/instance/gameElementWithModel.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
accessing | ||
gameElementWithModel | ||
<gtExample> | ||
|
||
^ self basicGrid memoryGame: MgModelExamples new gameModelWithCards |
7 changes: 0 additions & 7 deletions
7
src/Bloc-MemoryGame.package/MgElementExamples.class/instance/grid.for..st
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/Bloc-MemoryGame.package/MgElementExamples.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
8
src/Bloc-MemoryGame.package/MgExamples.class/class/example.st
This file was deleted.
Oops, something went wrong.
19 changes: 8 additions & 11 deletions
19
src/Bloc-MemoryGame.package/MgExamples.class/class/open.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
src/Bloc-MemoryGame.package/MgExamples.class/class/openEmoji.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
src/Bloc-MemoryGame.package/MgExamples.class/class/openHieroglyphs.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 13 additions & 0 deletions
13
src/Bloc-MemoryGame.package/MgExamples.class/class/openInWindow..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
7 changes: 0 additions & 7 deletions
7
src/Bloc-MemoryGame.package/MgModelExamples.class/instance/addCard.to..st
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/Bloc-MemoryGame.package/MgModelExamples.class/instance/basicCard.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
examples | ||
instance creation | ||
basicCard | ||
<gtExample> | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/Bloc-MemoryGame.package/MgModelExamples.class/instance/basicGame.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
examples | ||
instance creation | ||
basicGame | ||
<gtExample> | ||
|
||
|
6 changes: 0 additions & 6 deletions
6
src/Bloc-MemoryGame.package/MgModelExamples.class/instance/cardsCount..st
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.