Skip to content

Commit 33f20b7

Browse files
caroltausrebeccamelloGabrielenamie
authored
Feat/achievements (#63)
* Teste para achievement de 25 pontos * ACHIEVEMENT FUNCIONANDO!!! * Achievements de pontuação * Lógica dos achievements * fix bundle and swiftlint * arrumando launchscreen * fix sticker Co-authored-by: Rebecca Mello <rebecca.mello@me.com> Co-authored-by: Gabriele Namie <gabrielenamie@hotmail.com>
1 parent 8c06196 commit 33f20b7

File tree

16 files changed

+160
-78
lines changed

16 files changed

+160
-78
lines changed

FlyGame/Catch Fly Stickers/Info.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>CFBundleDisplayName</key>
6-
<string>Catch Fly Stickers</string>
75
<key>NSExtension</key>
86
<dict>
97
<key>NSExtensionPointIdentifier</key>

FlyGame/Catch Fly Stickers/Stickers.xcassets/Sticker Pack.stickerpack/Contents.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
},
4646
{
4747
"filename" : "logo.sticker"
48-
},
49-
{
50-
"filename" : "vó.sticker"
5148
}
5249
]
5350
}

FlyGame/FlyGame Shared/Assets/Assets.xcassets/launchscreen.imageset/Contents.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
{
22
"images" : [
33
{
4-
"filename" : "iPad Pro 12.9_ - 1.png",
5-
"idiom" : "universal",
4+
"filename" : "cenario.png",
5+
"idiom" : "iphone",
66
"scale" : "1x"
77
},
88
{
9-
"filename" : "iPad Pro 12.9_ - 2.png",
10-
"idiom" : "universal",
9+
"filename" : "cenario2.png",
10+
"idiom" : "iphone",
1111
"scale" : "2x"
1212
},
1313
{
14-
"filename" : "iPad Pro 12.9_ - 3.png",
15-
"idiom" : "universal",
14+
"filename" : "cenario3.png",
15+
"idiom" : "iphone",
1616
"scale" : "3x"
17+
},
18+
{
19+
"filename" : "iPad Pro 12.9_ - 1.png",
20+
"idiom" : "ipad",
21+
"scale" : "1x"
22+
},
23+
{
24+
"filename" : "iPad Pro 12.9_ - 2.png",
25+
"idiom" : "ipad",
26+
"scale" : "2x"
1727
}
1828
],
1929
"info" : {
2.43 KB
Loading
7.65 KB
Loading
15.7 KB
Loading
Binary file not shown.

FlyGame/FlyGame Shared/Controllers/GameSceneController.swift

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import GameplayKit
99
import SpriteKit
10+
import GameKit
1011

1112
func randomizer(min: Int, max: Int) -> Int {
1213
let randomizer = GKRandomDistribution(lowestValue: min, highestValue: max)
@@ -41,6 +42,8 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
4142
var pausedTime: TimeInterval = 0
4243
var buttonsPause = UITapGestureRecognizer()
4344
var buttonTvOS = UITapGestureRecognizer()
45+
let grandmaTexture = SKTexture(imageNamed: "vovo")
46+
var coinsInRun: Int = 0
4447

4548
private func calculateScore(currentTime: TimeInterval) {
4649
if timeScore == 0 {
@@ -49,6 +52,10 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
4952
let deltaTime = (currentTime - timeScore)
5053
if deltaTime >= 1 {
5154
score += 1
55+
if score == 80 && coinsInRun == 0 {
56+
GameCenterService.shared.showAchievements(achievementID: "noCoinsInRunID")
57+
}
58+
5259
gameDelegate?.drawScore(score: score)
5360
timeScore = currentTime
5461
}
@@ -89,13 +96,13 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
8996
}
9097

9198
func passedObstacles(node: SKNode) -> Bool {
92-
if let sprite = node as? SKSpriteNode {
93-
return sprite.position.x < (-1 * (sprite.size.width/2 + 20))
94-
} else {
95-
return false
96-
}
99+
if let sprite = node as? SKSpriteNode {
100+
return sprite.position.x < (-1 * (sprite.size.width/2 + 20))
101+
} else {
102+
return false
103+
}
97104
}
98-
105+
99106
func setSwipeGesture() -> [UISwipeGestureRecognizer] {
100107
let swipeUp: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
101108
swipeUp.direction = .up
@@ -114,13 +121,18 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
114121
if gameDelegate?.pausedStatus() == false {
115122
gameDelegate?.movePlayer(direction: direction)
116123
}
124+
}
125+
126+
#if os(tvOS)
127+
func addTargetToTapGestureRecognizer() -> UITapGestureRecognizer {
128+
buttonsPause.addTarget(self, action: #selector(clicked))
117129

118-
defaults.set(true, forKey: "playerFirstTime")
130+
return buttonsPause
119131
}
120132

121-
#if os(tvOS)
122-
func addTargetToTapGestureRecognizer() -> UITapGestureRecognizer {
123-
buttonsPause.addTarget(self, action: #selector(clicked))
133+
@objc func clicked() {
134+
if gameDelegate?.getResumeButton().isFocused == true {
135+
gameDelegate?.resumeGame()
124136

125137
return buttonsPause
126138
}
@@ -142,33 +154,34 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
142154
gameDelegate?.musicAction()
143155
}
144156
}
145-
#endif
157+
}
158+
#endif
146159

147160
func calculateObstacleMovement(allObstacles: [SKNode]) {
148161
for obstacle in allObstacles {
149162
if gameDelegate?.pausedStatus() == true {
150163
obstacle.position.x -= 0
151164
}
152165
else {
153-
#if os(iOS)
154-
let moveObstAction = SKAction.moveTo(x: (-100000), duration: duration*100)
155-
#elseif os(tvOS)
156-
let moveObstAction = SKAction.moveTo(x: (-100000), duration: durationTV*100)
157-
#endif
166+
#if os(iOS)
167+
let moveObstAction = SKAction.moveTo(x: (-100000), duration: duration*100)
168+
#elseif os(tvOS)
169+
let moveObstAction = SKAction.moveTo(x: (-100000), duration: durationTV*100)
170+
#endif
158171

159172
obstacle.run(moveObstAction)
160173
}
161174
}
162175
}
163176

164-
#if os(tvOS)
165-
func addTargetToPauseActionToTV() -> UITapGestureRecognizer {
166-
self.buttonTvOS.addTarget(self, action: #selector(self.tvOSAction))
167-
self.buttonTvOS.allowedPressTypes = [NSNumber(value: UIPress.PressType.playPause.rawValue)]
168-
169-
return buttonTvOS
170-
}
171-
#endif
177+
#if os(tvOS)
178+
func addTargetToPauseActionToTV() -> UITapGestureRecognizer {
179+
self.buttonTvOS.addTarget(self, action: #selector(self.tvOSAction))
180+
self.buttonTvOS.allowedPressTypes = [NSNumber(value: UIPress.PressType.playPause.rawValue)]
181+
182+
return buttonTvOS
183+
}
184+
#endif
172185

173186
// MARK: - Função de clicar no botão com tvRemote
174187
@objc private func tvOSAction() {
@@ -237,7 +250,7 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
237250
}
238251
}
239252
}
240-
253+
241254
func chooseObstacle() -> [Obstacle] {
242255
/*
243256
1. decidir peso
@@ -328,28 +341,25 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
328341
lastCoinTimeCreated = currentTime
329342
}
330343
let pastTime = (currentTime - lastCoinTimeCreated)
331-
#if os(iOS)
344+
#if os(iOS)
332345
if pastTime >= coinDelayIOS {
333346
gameDelegate?.createCoin()
334347
lastCoinTimeCreated = currentTime
335348
if coinDelayIOS > 1.5 { // limite minimo do delay
336349
coinDelayIOS -= 0.05 // cada vez que o update é chamado diminui o delay
337350
}
338351
}
339-
#elseif os (tvOS)
352+
#elseif os (tvOS)
340353
if pastTime >= coinDelayTV {
341354
gameDelegate?.createCoin()
342355
lastCoinTimeCreated = currentTime
343356
if coinDelayTV > 4 { // limite minimo do delay
344357
coinDelayTV -= 0.085 // cada vez que o update é chamado diminui o delay
345358
}
346359
}
347-
#endif
348-
}
349-
// MARK: Primera vez do player no jogo
350-
func firstTime() {
351-
defaults.set(false, forKey: "playerFirstTime")
360+
#endif
352361
}
362+
353363
// MARK: TearDown
354364
func tearDown() {
355365
timeCounter = 0
@@ -358,7 +368,7 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
358368
score = 0
359369
}
360370

361-
func contact(contact: SKPhysicsContact, nodeA: SKNode, nodeB: SKNode) {
371+
func contact(contact: SKPhysicsContact, nodeA: SKSpriteNode, nodeB: SKSpriteNode) {
362372
if contact.bodyB.node?.name == "Fly" || contact.bodyA.node?.name == "Fly" {
363373
collisionBetween(player: nodeA, enemy: nodeB)
364374
}
@@ -384,11 +394,26 @@ class GameSceneController: NSObject, SKPhysicsContactDelegate {
384394
}
385395
}
386396

387-
func collisionBetween(player: SKNode, enemy: SKNode) {
397+
func collisionBetween(player: SKSpriteNode, enemy: SKSpriteNode) {
388398
if player.name == "Coin" || enemy.name == "Coin" {
389399
AudioService.shared.soundManager(with: .coin, soundAction: .play)
390400
increaseScore(player: player, enemy: enemy)
401+
coinsInRun += 1
402+
print(coinsInRun)
403+
if coinsInRun == 5 {
404+
GameCenterService.shared.showAchievements(achievementID: "firstCoinsInRunID")
405+
}
406+
if coinsInRun == 12 {
407+
GameCenterService.shared.showAchievements(achievementID: "secondCoinsInRunID")
408+
}
391409
} else {
410+
guard let playerTexture = player.texture else {return}
411+
guard let enemyTexture = enemy.texture else {return}
412+
413+
if playerTexture.description == grandmaTexture.description || enemyTexture.description == grandmaTexture.description {
414+
GameCenterService.shared.showAchievements(achievementID: "crashedGrandmaID")
415+
}
416+
392417
gameDelegate?.goToGameOverScene()
393418
}
394419
}

FlyGame/FlyGame Shared/Controllers/MenuSceneController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class MenuSceneController {
8383
let scene = GameScene.newGameScene()
8484
scene.gameLogic.isGameStarted = true
8585
menuDelegate?.presentScene(scene: scene)
86-
8786
}
8887
}
8988
}

FlyGame/FlyGame Shared/Controllers/MenuViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MenuViewController: UIViewController {
2828
func gameCenterVerification() {
2929
// Fazendo a autenticação com o Game Center
3030
GameCenterService.shared.autenticateUser {vct, score, error in
31-
if let error = error {
31+
if error != nil {
3232
return
3333
}
3434
if let vct = vct {

0 commit comments

Comments
 (0)