revamped sprite blocks, added green block, upgraded random number handling

This commit is contained in:
Amy G. Bowersox 2020-05-27 13:54:16 -06:00
parent 3a15dae884
commit 26b5a015d2
19 changed files with 13 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -9,11 +9,9 @@
import Foundation
import SpriteKit
let NumberOfColors: UInt32 = 6
// Colors that may be applied to blocks (whcih controls the sprite image they use)
enum BlockColor: Int, CustomStringConvertible {
case Blue = 0, Orange, Purple, Red, Teal, Yellow
enum BlockColor: Int, CustomStringConvertible, CaseIterable {
case Blue = 0, Orange, Purple, Red, Teal, Yellow, Green
var spriteName: String {
switch self {
@ -29,6 +27,8 @@ enum BlockColor: Int, CustomStringConvertible {
return "teal"
case .Yellow:
return "yellow"
case .Green:
return "green"
}
}
@ -37,7 +37,7 @@ enum BlockColor: Int, CustomStringConvertible {
}
static func random() -> BlockColor {
return BlockColor(rawValue:Int(arc4random_uniform(NumberOfColors)))!
return BlockColor.allCases.shuffled().first!
}
}

View File

@ -170,13 +170,13 @@ class GameScene: SKScene {
// Animate the "removed" blocks "exploding"
for rowToRemove in linesToRemove {
for block in rowToRemove {
let randomRadius = CGFloat(UInt(arc4random_uniform(400) + 100))
let goLeft = arc4random_uniform(100) % 2 == 0
let randomRadius = CGFloat(Float.random(in: 100.0 ... 500.0))
let goLeft = Bool.random()
var point = pointForColumn(column: block.column, row: block.row)
point = CGPoint(x: point.x + (goLeft ? -randomRadius : randomRadius), y: point.y)
let randomDuration = TimeInterval(arc4random_uniform(2)) + 0.5
let randomDuration = TimeInterval(Float.random(in: 0.5 ... 2.5))
var startAngle = CGFloat(Double.pi)
var endAngle = startAngle * 2

View File

@ -9,10 +9,10 @@
import Foundation
import SpriteKit
let NumOrientations: UInt32 = 4
//let NumOrientations: UInt32 = 4
// Represents the orientation of a shape in increments of 90 degrees
enum Orientation: Int, CustomStringConvertible {
enum Orientation: Int, CustomStringConvertible, CaseIterable {
case Zero = 0, Ninety, OneEighty, TwoSeventy
var description: String {
@ -29,7 +29,7 @@ enum Orientation: Int, CustomStringConvertible {
}
static func random() -> Orientation {
return Orientation(rawValue:Int(arc4random_uniform(NumOrientations)))!
return Orientation.allCases.shuffled().first!
}
// Returns the orientation resulting from a rotation in either direction.
@ -45,7 +45,7 @@ enum Orientation: Int, CustomStringConvertible {
}
// The number of total shape varieties
let NumShapeTypes: UInt32 = 7
let NumShapeTypes = 7
// Shape indexes
let FirstBlockIdx: Int = 0
@ -192,7 +192,7 @@ class Shape: Hashable, CustomStringConvertible {
// Generates a random shape.
final class func random(startingColumn: Int, startingRow: Int) -> Shape {
switch Int(arc4random_uniform(NumShapeTypes)) {
switch Int.random(in: 0 ..< NumShapeTypes) {
case 0:
return SquareShape(column: startingColumn, row: startingRow)
case 1:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 B

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 381 B

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 226 B

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 226 B

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 B

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 B

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 B

After

Width:  |  Height:  |  Size: 7.5 KiB