Swift Game Programming for Absolute Beginners by Arjan Egges
Author:Arjan Egges
Language: eng
Format: epub, pdf
Publisher: Apress, Berkeley, CA
Maintaining a Score
Scores are often a very effective way to motivate players to continue playing. High scores work especially well in that regard because they introduce a competitive factor into the game: you want to be better than AAA or XYZ (many early arcade games allowed only three characters for each name in the high-score list, leading to very imaginative names). High scores are so motivating that third-party systems exist to incorporate them into games. These systems let users compare themselves against thousands of other players around the world. In the Painter game, you keep it simple and add the property score to the GameWorld class in which to store the current score:
var score = 0
The player starts with a score of zero. Each time a paint can falls outside the screen, the score is updated. If a can of the correct color falls out of the screen, 10 points are added to the score. If a can isn’t the right color, the player loses a life.
The score is a part of what is called the economy of a game. The game’s economy basically describes the different costs and merits in the game and how they interact. When you make your own game, it’s always useful to think about its economy. What do things cost, and what are the gains of executing different actions as a player? And are these two things in balance with each other?
You update the score in the PaintCan class, where you can check whether the can falls outside the screen. If so, you check whether it has the right color, and update the score and the number of player lives accordingly. Then you hide the PaintCan object so that it can fall again, like so:
let top = CGPoint(x: self.position.x, y: self.position.y + red.size.height/2)
if GameScene.world.isOutsideWorld(top) {
if color != targetColor {
GameScene.world.lives -= 1
} else {
GameScene.world.score += 10
collectPointsSound.play()
}
self.hidden = true
}
In this code, you can also see that whenever a can of the right color falls off the screen, you play a sound effect stored in the collectPointsSound property.
Download
Swift Game Programming for Absolute Beginners by Arjan Egges.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12563)
Hello! Python by Anthony Briggs(9911)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9794)
The Mikado Method by Ola Ellnestam Daniel Brolund(9775)
Dependency Injection in .NET by Mark Seemann(9335)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8292)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7758)
Grails in Action by Glen Smith Peter Ledbrook(7693)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7016)
Microservices with Go by Alexander Shuiskov(6783)
Practical Design Patterns for Java Developers by Miroslav Wengner(6696)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6636)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Angular Projects - Third Edition by Aristeidis Bampakos(6045)
The Art of Crafting User Stories by The Art of Crafting User Stories(5575)
NetSuite for Consultants - Second Edition by Peter Ries(5508)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5309)
Kotlin in Action by Dmitry Jemerov(5061)
