Skip to content

Commit fafea64

Browse files
CypherPoetCypherPoet
authored andcommitted
Complete Day 56: Project 14: Whack-a-Penguin, Part Two
1 parent 7f112b3 commit fafea64

File tree

8 files changed

+97
-0
lines changed

8 files changed

+97
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ Feedback and suggestions are highly appreciated. I'll be opening up [issues](htt
7171
- [Day 53: _Project 13: Instafilter_, Part Two](/day-053)
7272
- [Day 54: _Project 13: Instafilter_, Part Three](/day-054)
7373
- [Day 55: _Project 14: Whack-a-Penguin_, Part One](/day-055)
74+
- [Day 56: _Project 14: Whack-a-Penguin_, Part Two](/day-056)

day-056/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Day 56: _Project 14: Whack-a-Penguin_, Part Two
2+
3+
_Follow along at https://www.hackingwithswift.com/100/56_.
4+
5+
6+
7+
## 📒 Field Notes
8+
9+
> This day covers the second and final part of `Project 14: Whack-a-Penguin` in _[Hacking with Swift](https://www.hackingwithswift.com/read/14)_.
10+
>
11+
> I previously created projects alongside _Hacking with Swift_ in a [separate repository](https://github.com/CypherPoet/book--hacking-with-swift), and you can find Project 14 [here](https://github.com/CypherPoet/book--hacking-with-swift/tree/master/14-whack-a-penguin/Whack%20a%20Penguin). Even better, though, I copied it over to Day 55's folder so I could extend it for _100 Days of Swift_.
12+
>
13+
> With that in mind, Day 56 focuses on several specific topics:
14+
>
15+
> - SKAction sequences
16+
> - Wrapping up and extending the project with a set of challenges
17+
18+
19+
### SKAction Sequences
20+
21+
I alluded to it in [Day 55] when I was highlighting the way I created an `SKAction` _group_ for hiding a penguin in a slot...
22+
23+
24+
```swift
25+
extension WhackSlot {
26+
27+
var showAction: SKAction {
28+
return SKAction.moveBy(x: 0, y: 80, duration: 0.05)
29+
}
30+
31+
var hideActions: SKAction {
32+
return SKAction.group([
33+
SKAction.moveBy(x: 0, y: -80, duration: 0.05),
34+
SKAction.scale(to: 0.08, duration: 0.025),
35+
SKAction.run { [weak self] in
36+
self?.isShowingPenguin = false
37+
},
38+
])
39+
}
40+
}
41+
```
42+
43+
... but `SKAction` _sequences_ allow us to take that composability even further. With `SKAction.sequence`, we can declare SKActions to be run **one after another**, and since an `SKAction.group` is, itself, an `SKAction`, we can run sequences with groups without skipping a beat:
44+
45+
```swift
46+
func whack() {
47+
guard isShowingPenguin && !isWhacked else { return }
48+
49+
isWhacked = true
50+
51+
let delay = SKAction.wait(forDuration: 0.25)
52+
53+
penguinNode.run(SKAction.sequence([delay, hideActions]))
54+
}
55+
```
56+
57+
58+
## 🥅 Challenges
59+
60+
61+
### Challenge 1
62+
63+
> Record your own voice saying "Game over!" and have it play when the game ends.
64+
65+
- 🔗 [Commit](https://github.com/CypherPoet/100-days-of-swift/commit/69b6338a9403475f1e149c018c4ff309cb3736e9)
66+
67+
68+
### Challenge 2
69+
70+
> When showing “Game Over” add an SKLabelNode showing the user's final score.
71+
72+
- 🔗 [Commit](https://github.com/CypherPoet/100-days-of-swift/commit/1aaf99543ae43583ed7fe77bbed884cefee0b721)
73+
74+
75+
### Challenge 3
76+
77+
> Use SKEmitterNode to create a smoke-like effect when penguins are hit, and a separate mud-like effect when they go into or come out of a hole.
78+
79+
- 🔗 [Commit](https://github.com/CypherPoet/100-days-of-swift/commit/7f112b367b6e95e8ba795f1fbc710a2354a6ccfa)
80+
81+
82+
83+
## 📸 Screenshots
84+
85+
<div style="text-align: center;">
86+
<img src="./screenshot-1-landscape.png" width="968px;"/>
87+
<img src="./screenshot-2.png" width="968px;"/>
88+
<img src="./screenshot-3.png" width="968px;"/>
89+
<img src="./screenshot-4.png" width="968px;"/>
90+
</div>
91+
92+
93+
## 🔗 Additional/Related Links
94+
95+
- [Apple Docs: SKEmitterNode](https://developer.apple.com/documentation/spritekit/skemitternode)
96+
- [Apple Docs: Optimizing Emitter Node Performance](https://developer.apple.com/documentation/spritekit/skemitternode/optimizing_emitter_node_performance)

day-056/recording-1.mov

12.6 MB
Binary file not shown.

day-056/recording-1.mp4

12.6 MB
Binary file not shown.

day-056/screenshot-1-landscape.png

1.52 MB
Loading

day-056/screenshot-2.png

3.12 MB
Loading

day-056/screenshot-3.png

3.14 MB
Loading

day-056/screenshot-4.png

3.07 MB
Loading

0 commit comments

Comments
 (0)