Skip to content

Commit

Permalink
prevent static ecosystems (for real this time)
Browse files Browse the repository at this point in the history
  • Loading branch information
amiantos committed May 19, 2019
1 parent cf6bd35 commit 9763a16
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Life Saver/LifeScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class LifeScene: SKScene {
if nodeData.alive {
if livingNeighbors.count > 3 || livingNeighbors.count < 2 {
dyingNodes.append(nodeData)
} else if nodeData.timeInState > 20 {
dyingNodes.append(nodeData)
} else {
livingNodes.append(nodeData)
}
Expand All @@ -164,6 +166,7 @@ class LifeScene: SKScene {

livingNodes.forEach {
if !$0.alive {
$0.timeInState = 0
$0.node.removeAllActions()
$0.alive = true
let fadeAction = SKAction.fadeAlpha(to: 1, duration: updateTime)
Expand All @@ -172,16 +175,21 @@ class LifeScene: SKScene {
colorAction.timingMode = .easeInEaseOut
$0.node.run(fadeAction)
$0.node.run(colorAction)
} else {
$0.timeInState += 1
}
}

dyingNodes.forEach {
if $0.alive {
$0.timeInState = 0
$0.node.removeAllActions()
$0.alive = false
let fadeAction = SKAction.fadeAlpha(to: 0.2, duration: updateTime * 5)
fadeAction.timingMode = .easeInEaseOut
$0.node.run(fadeAction)
} else {
$0.timeInState += 1
}
}

Expand Down

0 comments on commit 9763a16

Please sign in to comment.