firebase

Firebase入門 フリマアプリを作りながら、認証・Firestore・Cloud Functionsの使い方を学ぼう! - エンジニアHub|若手Webエンジニアのキャリアを考える!

  • firestore default rule ( not test mode)
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

Swift3 game development

SKAction

    override func didMove(to view: SKView) {
        self.anchorPoint = .zero
        let mySprite = SKSpriteNode(color: .blue, size:
            CGSize(width: 50, height: 50))
        mySprite.position = CGPoint(x: 150, y: 150)
        
        //let demoAction = SKAction.move(to: CGPoint(x: 300, y:150),duration:3)
        //let demoAction = SKAction.scale(to: 4, duration:5)
        let demoAction1 = SKAction.scale(to: 4, duration:5)
        let demoAction2 = SKAction.rotate(byAngle: 5, duration:5)
        //let actionGroup = SKAction.group([demoAction1, demoAction2])
        let actionSequence = SKAction.sequence([demoAction1, demoAction2])
        mySprite.run(actionSequence)
        
        self.addChild(mySprite)
  • bee-fly
        let bee = SKSpriteNode(imageNamed: "bee-fly")
        bee.size = CGSize(width:28,height:24)
        bee.position = CGPoint(x:250,y:250)
        
        self.addChild(bee)
  • bee never ending flight
    override func didMove(to view: SKView) {
        self.anchorPoint = .zero
        self.backgroundColor = UIColor(red: 0.4, green: 0.6, blue:0.95, alpha:1.0)
        
        let bee = SKSpriteNode()
        bee.position = CGPoint(x:250,y:250)
        bee.size = CGSize(width:28,height:24)
        self.addChild(bee)
        
        let beeAtlas = SKTextureAtlas(named:"Enemies")
        let beeFrames:[SKTexture] = [
            beeAtlas.textureNamed("bee"),
            beeAtlas.textureNamed("bee-fly")
        ]
        let flyAction = SKAction.animate(with:beeFrames,timePerFrame:0.14)
        let beeAction = SKAction.repeatForever(flyAction)
        bee.run(beeAction)
        let pathLeft = SKAction.moveBy(x:-200,y:-10,duration:2)
        let pathRight = SKAction.moveBy(x:200,y:10, duration:2)
        let flipTextureNegative = SKAction.scaleX(to:-1,duration:0)
        let flipTexturePositive = SKAction.scaleX(to:1, duration:0)
        let flightOfTheBee = SKAction.sequence([pathLeft,flipTextureNegative, pathRight, flipTexturePositive])
        let neverEndingFlight = SKAction.repeatForever(flightOfTheBee)
        bee.run(neverEndingFlight)
    }
  • bee2, bee3
import SpriteKit
import GameplayKit

class GameScene: SKScene {
    let cam = SKCameraNode()
    let ground = Ground()
    let bee = SKSpriteNode()

    override func didMove(to view: SKView) {
        self.anchorPoint = .zero
        self.backgroundColor = UIColor(red: 0.4, green: 0.6, blue:0.95, alpha:1.0)
        
        self.camera = cam
        self.addTheFlyingBee()
        let bee2 = Bee()
        bee2.position = CGPoint(x: 325, y:325)
        self.addChild(bee2)
        let bee3 = Bee()
        bee3.position = CGPoint(x:200, y:325)
        self.addChild(bee3)
        
        ground.position = CGPoint(x:-self.size.width*2, y:150)
        ground.size = CGSize(width:self.size.width*6, height:0)
        ground.createChildren()
        self.addChild(ground)
    }
    
    override func didSimulatePhysics() {
        self.camera!.position = bee.position
    }
    
    func addTheFlyingBee() {
        bee.position = CGPoint(x: 250, y:250)
        bee.size = CGSize(width: 28, height:24)
        self.addChild(bee)
        let beeAtlas = SKTextureAtlas(named:"Enemies")
        let beeFrames:[SKTexture] = [
            beeAtlas.textureNamed("bee"), beeAtlas.textureNamed("bee-fly")
        ]
        let flyAction = SKAction.animate(with: beeFrames, timePerFrame: 0.14)
        let beeAction = SKAction.repeatForever(flyAction)
        bee.run(beeAction)
        let pathLeft = SKAction.moveBy(x:-200,y:-10,duration:2)
         let pathRight = SKAction.moveBy(x:200,y:10, duration:2)
         let flipTextureNegative = SKAction.scaleX(to:-1,duration:0)
         let flipTexturePositive = SKAction.scaleX(to:1, duration:0)
         let flightOfTheBee = SKAction.sequence([pathLeft,flipTextureNegative, pathRight, flipTexturePositive])
         let neverEndingFlight = SKAction.repeatForever(flightOfTheBee)
         bee.run(neverEndingFlight)
    }
 }
  • didSimulatePhysics
   override func didSimulatePhysics() {
        var cameraYPos = screenCenterY
        cam.yScale = 1
        cam.xScale = 1
        if (player.position.y > screenCenterY) {
            cameraYPos = player.position.y
            let percentOfMaxHeight = (player.position.y - screenCenterY)
                / (player.maxHeight - screenCenterY)
            let newScale = 1 + percentOfMaxHeight
            cam.yScale = newScale
            cam.xScale = newScale
        }
        self.camera!.position = CGPoint(x:player.position.x, y:cameraYPos)
        
        playerProgress = player.position.x - initialPlayerPosition.x
        ground.checkForReposition(playerProgress:playerProgress)
        if player.position.x > nextEncounterSpawnPosition {
            encounterManager.placeNextEncounter(currentXPos:nextEncounterSpawnPosition)
            nextEncounterSpawnPosition += 1200
            //let starRoll = Int(arc4random_uniform(10))
            let starRoll = 0
            if starRoll == 0 {
                if abs(player.position.x - powerUpStar.position.x) > 1200 {
                    let randomYPos = 50 + CGFloat(arc4random_uniform(400))
                    powerUpStar.position = CGPoint(x:nextEncounterSpawnPosition, y:randomYPos)
                    powerUpStar.physicsBody?.angularVelocity = 0
                    powerUpStar.physicsBody?.velocity = CGVector(dx:0,dy:0)
                    
                }
            }
...
  • physicsbody
       bee2.physicsBody?.applyImpulse(CGVector(dx:-25,dy:0))
        bee2.physicsBody?.mass = 0.2
  • bat,madFly,bronzeCoin,goldCoin,star
        let bat = Bat()
        bat.position = CGPoint(x:400,y:200)
        self.addChild(bat)
        let blade = Blade()
        blade.position = CGPoint(x:300,y:76)
        self.addChild(blade)
        
        let madFly = MadFly()
        madFly.position = CGPoint(x:50,y:50)
        self.addChild(madFly)
        
        let bronzeCoin = Coin()
        bronzeCoin.position = CGPoint(x:-50,y:250)
        self.addChild(bronzeCoin)
        
        let goldCoin = Coin()
        goldCoin.position = CGPoint(x:25, y:250)
        goldCoin.turnToGold()
        self.addChild(goldCoin)
        
        let star = Star()
        star.position = CGPoint(x:250, y:250)
        self.addChild(star)

CoreMotion

class GameScene: SKScene {
    let cam = SKCameraNode()
    let ground = Ground()
    let player = Player()
    let motionManager = CMMotionManager()
    
    override func update(_ currentTime: TimeInterval){
        player.update()
        if let accleData = self.motionManager.accelerometerData {
            var forceAmount:CGFloat
            var movement = CGVector()
            switch UIApplication.shared.statusBarOrientation {
            case .landscapeLeft:
                forceAmount = 20000
            case .landscapeRight:
                forceAmount = -20000
            default:
                forceAmount = 0
            }
            if accleData.acceleration.y > 0.15 {
                movement.dx = forceAmount
            }
            else if accleData.acceleration.y < -0.15 {
                movement.dx = forceAmount
            }
            player.physicsBody?.applyForce(movement)
        }
    }
    
    override func didMove(to view: SKView) {
        self.anchorPoint = .zero
        self.backgroundColor = UIColor(red: 0.4, green: 0.6, blue:0.95, alpha:1.0)
        
        self.camera = cam
        
        let bee2 = Bee()
        bee2.position = CGPoint(x: 325, y:325)
        self.addChild(bee2)
        let bee3 = Bee()
        bee3.position = CGPoint(x:200, y:325)
        self.addChild(bee3)
        
        ground.position = CGPoint(x:-self.size.width*2, y:30)
        ground.size = CGSize(width:self.size.width*6, height:0)
        ground.createChildren()
        self.addChild(ground)
        
        player.position = CGPoint(x:150, y:250)
        self.addChild(player)
        //bee2.physicsBody?.applyImpulse(CGVector(dx:-25,dy:0))
        //bee2.physicsBody?.mass = 0.2
        
        self.motionManager.startAccelerometerUpdates()
        
    }
    
    override func didSimulatePhysics() {
        self.camera!.position = player.position
    }
 }

  • flyanimation
    init() {
        // Call the init function on the base class (SKSpriteNode)
        super.init(texture: nil, color: .clear, size: initialSize)
        
        createAnimations()
        // If we run an action with a key, "flapAnimation",
        // we can later reference that key to remove the action.
        self.run(flyAnimation, withKey: "flapAnimation")
        let bodyTexture = textureAtlas.textureNamed("pierre-flying-3")
        self.physicsBody = SKPhysicsBody(texture: bodyTexture, size:self.size)
        self.physicsBody?.linearDamping = 0.9
        self.physicsBody?.mass = 30
        self.physicsBody?.allowsRotation = false

GameViewController

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()

        if let view = self.view as! SKView? {
            // Load the SKScene from 'GameScene.sks'
            if let scene = GameScene(fileNamed: "GameScene") {
                // Set the scale mode to scale to fit the window
                scene.scaleMode = .aspectFill
                // Size our scene to fit the view exactly:
                scene.size = view.bounds.size
                // Show the new scene:
                view.presentScene(scene)
            }

            view.ignoresSiblingOrder = true
            view.showsFPS = true
            view.showsNodeCount = true
        }
    }
...

Crate

    func explode() {
        // Do not do anything if this crate already exploded:
        if exploded { return }
        exploded = true
        
        // Prevent additional contact:
        self.physicsBody?.categoryBitMask = 0
    }

extension, protocol @ swift

Swiftの「エクステンション」と「プロトコル」~ 機能と役割、Objective-Cとの違いを知る (1/4):CodeZine(コードジン)

エクステンション | Swift言語を学ぶ

【Swift】Protocolごとにextensionで切り分けて実装するワケ | DevelopersIO

【Swift】エクステンション(extension)を使うメリット - Swift・iOS

【Swift入門】プロトコル(protocol)を使ってみよう! | 侍エンジニア塾ブログ(Samurai Blog) - プログラミング入門者向けサイト

Swift では Protocol を積極的に使おう - Qiita

CloudFunction

Triggers

Cloud Functions の呼び出し  |  Cloud Functions のドキュメント  |  Google Cloud

Direct Triggers  |  Cloud Functions Documentation  |  Google Cloud
Google Cloud Firestore Triggers  |  Cloud Functions Documentation  |  Google Cloud
Google Analytics for Firebase Triggers  |  Cloud Functions Documentation  |  Google Cloud
Firebase Realtime Database Triggers  |  Cloud Functions Documentation  |  Google Cloud
Firebase Authentication Triggers  |  Cloud Functions Documentation  |  Google Cloud

bestpractices

Retrying Background Functions  |  Cloud Functions Documentation  |  Google Cloud
Optimizing Networking  |  Cloud Functions Documentation  |  Google Cloud
テストと CI/CD  |  Cloud Functions のドキュメント  |  Google Cloud
Tips & Tricks  |  Cloud Functions Documentation  |  Google Cloud

deploy

Deploying Cloud Functions  |  Cloud Functions Documentation  |  Google Cloud
Deploying from Source Control  |  Cloud Functions Documentation  |  Google Cloud

introduction

Console を使用したクイックスタート  |  Cloud Functions のドキュメント  |  Google Cloud
Cloud Functions を書く  |  Cloud Functions のドキュメント  |  Google Cloud
バックグラウンド関数  |  Cloud Functions のドキュメント  |  Google Cloud
HTTP 関数  |  Cloud Functions のドキュメント  |  Google Cloud

etc

Connecting to Cloud SQL  |  Cloud Functions Documentation  |  Google Cloud
Cloud Functions API  |  Cloud Functions  |  Google Cloud
All Community Tutorials  |  Google Cloud Platform Community  |  Google Cloud
search cloudfunction
search node.js
Google Cloud Functions と Firebase  |  Cloud Functions のドキュメント  |  Google Cloud
Firebase
Cloud Functions Execution Environment  |  Cloud Functions Documentation  |  Google Cloud
Release Notes  |  Cloud Functions Documentation  |  Google Cloud

CloudSpanner, Paxos

Cloud Spanner のハイレベルアーキテクチャ解説 – google-cloud-jp – Medium
Google Spanner のアーキテクチャを知る - Yuichi Murata's Engineering Blog
「Google Cloud Spanner」発表。地球規模の大規模分散環境で稼働するミッションクリティカルなリレーショナルDB。NoSQL並のスケーラビリティでSQL対応、トランザクション処理を実現 - Publickey
Henry Robinsonによる優しいPaxosの解説 - minghaiの日記
翻訳:Paxos Made Simple - minghaiの日記
Paxos

Spanner, TrueTime and the CAP Theorem – Google AI

積み残し事項

Life of Cloud Spanner Reads & Writes  |  Cloud Spanner Documentation  |  Google Cloud
Life of a Cloud Spanner Query  |  Cloud Spanner Documentation  |  Google Cloud
Optimizing Schema Design for Cloud Spanner  |  Cloud Spanner Documentation  |  Google Cloud

Release Notes  |  Cloud Spanner Documentation  |  Google Cloud

ホワイトペーパー系

Spanner: Becoming a SQL System – Google AI
Spanner, TrueTime and the CAP Theorem – Google AI
Spanner: Google's Globally-Distributed Database – Google AI

Kubernetes Engine クラスタを作成するだけでも結構大変だった件: gcloud container clusters create testcluster

Quickstart  |  Kubernetes Engine Documentation  |  Google Cloud

google cloud platform - 403 "Request had insufficient authentication scopes" during gcloud container cluster get-credentials - Stack Overflow
サービス アカウントを使用した Cloud Platform への認証  |  Kubernetes Engine のドキュメント  |  Google Cloud
GCE(Google Compute Engine)のVMインスタンスのアカウントスコープを後から変更する - Qiita
Stopping or Deleting an Instance  |  Compute Engine Documentation  |  Google Cloud
IAMと管理 - サービスアカウント
サービス アカウントの作成と管理  |  Cloud Identity and Access Management のドキュメント  |  Google Cloud
gcloud beta compute instances set-scopes  |  Cloud SDK  |  Google Cloud
Getting Started with Google Kubernetes Engine | Coursera

貧者の GKE / 無料枠だけでクラスタを作ろう - Qiita