Top Related Projects
swift implementation of flappy bird. More at fullstackedu.com
EKAlgorithms contains some well known CS algorithms & data structures.
Algorithms and data structures in Swift, with explanations!
Swift Language Weather is an iOS weather app developed in Swift 4.
Quick Overview
FlappySwift is an open-source implementation of the popular Flappy Bird game, written entirely in Swift for iOS. It serves as a learning resource for Swift developers and demonstrates how to create a simple yet engaging game using Apple's SpriteKit framework.
Pros
- Excellent learning resource for Swift and SpriteKit
- Clean, well-organized codebase
- Fully functional game implementation
- Easy to understand and modify
Cons
- Limited features compared to more complex game projects
- Not actively maintained (last update was several years ago)
- May require updates to work with the latest Swift and iOS versions
- Lacks advanced game development concepts
Code Examples
- Setting up the game scene:
override func didMove(to view: SKView) {
canRestart = false
// Setup physics
self.physicsWorld.gravity = CGVector( dx: 0.0, dy: -5.0 )
self.physicsWorld.contactDelegate = self
// Setup background color
self.backgroundColor = SKColor(red: 81.0/255.0, green: 192.0/255.0, blue: 201.0/255.0, alpha: 1.0)
// Setup ground
var groundTexture = SKTexture(imageNamed: "land")
groundTexture.filteringMode = .nearest
// ... (more setup code)
}
- Handling touch events:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if moving.speed > 0 {
for _ in touches {
bird.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
bird.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 30))
}
} else if canRestart {
self.resetScene()
}
}
- Updating the game state:
override func update(_ currentTime: TimeInterval) {
// Calculate slope (rotation) of bird
let value = bird.physicsBody!.velocity.dy * ( bird.physicsBody!.velocity.dy < 0 ? 0.003 : 0.001 )
bird.zRotation = min( max(-1, value), 0.5 )
// Check if bird has collided with ground
if bird.position.y < -310 {
bird.position = CGPoint(x: bird.position.x, y: -310)
bird.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
bird.physicsBody?.collisionBitMask = worldCategory | pipeCategory
bird.speed = 0
}
}
Getting Started
To run FlappySwift:
- Clone the repository:
git clone https://github.com/newlinedotco/FlappySwift.git
- Open the Xcode project file (
FlappySwift.xcodeproj
). - Select a simulator or connect an iOS device.
- Build and run the project (Cmd + R).
Note: You may need to update the project settings and Swift syntax to match your current Xcode and iOS versions.
Competitor Comparisons
swift implementation of flappy bird. More at fullstackedu.com
Pros of FlappySwift
- Implements a classic game in Swift, providing a learning resource for iOS developers
- Uses SpriteKit for efficient 2D game rendering
- Demonstrates basic physics and collision detection in a mobile game context
Cons of FlappySwift
- Limited features compared to more advanced game implementations
- May not showcase best practices for larger-scale iOS app development
- Lacks extensive documentation or comments in the code
Code Comparison
FlappySwift:
func didBegin(_ contact: SKPhysicsContact) {
if moving.speed > 0 {
if ( contact.bodyA.categoryBitMask & scoreCategory ) == scoreCategory || ( contact.bodyB.categoryBitMask & scoreCategory ) == scoreCategory {
score += 1
scoreLabelNode.text = String(score)
scoreLabelNode.runAction(SKAction.sequence([SKAction.scale(to: 1.5, duration:TimeInterval(0.1)), SKAction.scale(to: 1.0, duration:TimeInterval(0.1))]))
} else {
moving.speed = 0
bird.physicsBody?.collisionBitMask = worldCategory
bird.run( SKAction.rotate(byAngle: CGFloat(Double.pi) * CGFloat(bird.position.y) * 0.01, duration:1), completion:{self.bird.speed = 0 })
self.removeAction(forKey: "flash")
self.run(SKAction.sequence([SKAction.repeat(SKAction.animate(with: textureSequence, timePerFrame: 0.01), count:3), SKAction.run({
self.bird.speed = 1
self.bird.physicsBody?.isDynamic = false
self.bird.physicsBody?.collisionBitMask = 0
self.bird.physicsBody?.velocity = CGVector( dx: 0, dy: 0 )
})]), withKey: "flash")
}
}
}
This code snippet demonstrates the collision detection and scoring mechanism in FlappySwift, showcasing the use of SpriteKit physics and actions.
EKAlgorithms contains some well known CS algorithms & data structures.
Pros of EKAlgorithms
- Comprehensive collection of algorithms and data structures
- Well-organized codebase with clear categorization
- Includes unit tests for most implementations
Cons of EKAlgorithms
- Less focused on a specific application or game development
- May be more complex for beginners to understand and use
- Lacks visual elements or interactive components
Code Comparison
EKAlgorithms (Binary Search implementation):
+ (NSInteger)binarySearchForValue:(NSInteger)value inSortedArray:(NSArray *)array {
NSInteger low = 0;
NSInteger high = [array count] - 1;
while (low <= high) {
NSInteger mid = (low + high) / 2;
if ([[array objectAtIndex:mid] integerValue] > value) {
high = mid - 1;
} else if ([[array objectAtIndex:mid] integerValue] < value) {
low = mid + 1;
} else {
return mid;
}
}
return -1;
}
FlappySwift (Game loop implementation):
override func update(currentTime: CFTimeInterval) {
if lastUpdateTime > 0 {
dt = currentTime - lastUpdateTime
} else {
dt = 0
}
lastUpdateTime = currentTime
bird.update(dt)
// check if bird touched the ground
if bird.position.y < bird.size.height/2 {
bird.position.y = bird.size.height/2
bird.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
}
}
Algorithms and data structures in Swift, with explanations!
Pros of swift-algorithm-club
- Comprehensive collection of algorithms and data structures implemented in Swift
- Well-documented code with explanations and complexity analysis
- Active community with regular contributions and updates
Cons of swift-algorithm-club
- Larger codebase, potentially overwhelming for beginners
- Focused on algorithms rather than game development
- May require more time to understand and implement in practical projects
Code Comparison
swift-algorithm-club (Binary Search implementation):
func binarySearch<T: Comparable>(_ a: [T], key: T) -> Int? {
var lowerBound = 0
var upperBound = a.count
while lowerBound < upperBound {
let midIndex = lowerBound + (upperBound - lowerBound) / 2
if a[midIndex] == key {
return midIndex
} else if a[midIndex] < key {
lowerBound = midIndex + 1
} else {
upperBound = midIndex
}
}
return nil
}
FlappySwift (Game loop implementation):
override func update(currentTime: CFTimeInterval) {
if lastUpdateTime > 0 {
delta = currentTime - lastUpdateTime
} else {
delta = 0
}
lastUpdateTime = currentTime
bird.update(delta)
}
The code comparison shows that swift-algorithm-club focuses on implementing algorithms, while FlappySwift is geared towards game development with specific game mechanics.
Swift Language Weather is an iOS weather app developed in Swift 4.
Pros of SwiftLanguageWeather
- More comprehensive and practical application, providing real-world weather information
- Demonstrates integration with external APIs and data handling
- Showcases more advanced Swift features and UI design patterns
Cons of SwiftLanguageWeather
- More complex codebase, potentially harder for beginners to understand
- Requires API keys and internet connectivity to function properly
- Less focused on game development concepts compared to FlappySwift
Code Comparison
SwiftLanguageWeather:
struct WeatherData: Codable {
let location: Location
let current: Current
let forecast: Forecast
}
class WeatherService {
func fetchWeather(for city: String) async throws -> WeatherData {
// API call implementation
}
}
FlappySwift:
class GameScene: SKScene, SKPhysicsContactDelegate {
var bird: SKSpriteNode!
var skyColor: SKColor!
var pipeTextureUp: SKTexture!
var pipeTextureDown: SKTexture!
var movePipesAndRemove: SKAction!
}
The code snippets highlight the different focus areas of each project. SwiftLanguageWeather deals with structured data and API interactions, while FlappySwift concentrates on game mechanics and sprite handling.
SwiftLanguageWeather offers a more diverse learning experience for iOS development, covering data modeling, networking, and UI design. FlappySwift, on the other hand, provides a simpler, game-oriented approach that may be more appealing to beginners or those interested in game development.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
FlappySwift
An implementation of Flappy Bird in Swift for iOS 8.
Notes
We're launching a course Game Programming with Swift
If you are interested in early access to the course, head to fullstackedu.com and enter in your email in the signup box at the bottom of the page to be notified of updates on the course itself.
Authors
- Nate Murray - @eigenjoy
- Ari Lerner - @auser
- Based on code by Matthias Gall
Top Related Projects
swift implementation of flappy bird. More at fullstackedu.com
EKAlgorithms contains some well known CS algorithms & data structures.
Algorithms and data structures in Swift, with explanations!
Swift Language Weather is an iOS weather app developed in Swift 4.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot