-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpriteNode.swift
53 lines (43 loc) · 1.32 KB
/
SpriteNode.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// SpriteNode.swift
// ShootingGallery
//
// Created by Julian Moorhouse on 13/08/2019.
// Copyright © 2019 Mindwarp Consultancy Ltd. All rights reserved.
//
import Foundation
import SpriteKit
class SpriteNode: SKNode {
var scoreAmount = 0
var row = 0
var sprite: SKSpriteNode!
func configure(row: Int, yPos: Int, xPos: Int, slide: Int, zPosition: CGFloat) {
let spriteNum: Int = Int.random(in: 0...3)
self.row = row
sprite = SKSpriteNode(imageNamed: "target\(spriteNum)")
sprite.position = CGPoint(x: xPos, y: yPos)
sprite.name = "good"
sprite.zPosition = zPosition
if !(Int.random(in: 0...10) % 5 == 0) {
sprite.color = .lightGray
sprite.colorBlendFactor = 1
sprite.name = "bad"
}
switch row {
case 0:
sprite.setScale(1.0)
scoreAmount = 10
case 1:
sprite.setScale(0.8)
scoreAmount = 20
case 2:
sprite.setScale(0.6)
scoreAmount = 30
default:
break
}
addChild(sprite)
sprite.physicsBody = SKPhysicsBody(texture: sprite.texture!, size: sprite.size)
sprite.physicsBody?.velocity = CGVector(dx: slide, dy: 0)
}
}