Extract default test map, add map protocol to game scene
This commit is contained in:
parent
df58c822a1
commit
ffc4c05a46
@ -7,9 +7,13 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SpriteKit
|
||||
|
||||
protocol MapProtocoll {
|
||||
|
||||
var size: CGSize! {get set}
|
||||
|
||||
func create()
|
||||
func adjacent(base: Base) -> Array<Base>
|
||||
|
||||
}
|
||||
|
@ -7,13 +7,78 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SpriteKit
|
||||
|
||||
class TwoPlayerDefaultTestMap: MapProtocoll {
|
||||
|
||||
var entityManager: EntityManager!
|
||||
var size: CGSize!
|
||||
var adjacencyList: Dictionary<Base, Array<Base>>!
|
||||
|
||||
init(scene: SKScene, entityManager: EntityManager) {
|
||||
self.entityManager = entityManager;
|
||||
self.size = scene.size
|
||||
}
|
||||
|
||||
func adjacent(base: Base) -> Array<Base> {
|
||||
return Array()
|
||||
return adjacencyList[base]!
|
||||
}
|
||||
|
||||
func create() {
|
||||
createNodes()
|
||||
createNeighbourMapping()
|
||||
}
|
||||
|
||||
func createNodes() {
|
||||
for i in 0...7 {
|
||||
let base: Base
|
||||
var position = CGPoint(x: 0, y: 0)
|
||||
switch i {
|
||||
case 0...2:
|
||||
let width = self.size.width * 0.25
|
||||
|
||||
if i == 0 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.25)
|
||||
}
|
||||
if i == 1 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.5)
|
||||
}
|
||||
if i == 2 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.75)
|
||||
}
|
||||
|
||||
case 3...4:
|
||||
let width = self.size.width * 0.5
|
||||
|
||||
if i == 3 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.333)
|
||||
}
|
||||
if i == 4 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.666)
|
||||
}
|
||||
|
||||
case 5...7:
|
||||
let width = self.size.width * 0.75
|
||||
|
||||
if i == 5 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.25)
|
||||
}
|
||||
if i == 6 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.5)
|
||||
}
|
||||
if i == 7 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.75)
|
||||
}
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
base = Base(textureName: "Base", team: nil, position: position)
|
||||
entityManager.add(base)
|
||||
}
|
||||
}
|
||||
|
||||
func createNeighbourMapping() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import GameplayKit
|
||||
class GameScene: SKScene{
|
||||
|
||||
var entityManager: EntityManager!
|
||||
var map: MapProtocoll!
|
||||
|
||||
override func sceneDidLoad() {
|
||||
entityManager = EntityManager(scene: self)
|
||||
@ -42,60 +43,10 @@ class GameScene: SKScene{
|
||||
|
||||
// TODO: Issue #24 create Map generation Service
|
||||
func initMap() {
|
||||
|
||||
createVirginBases()
|
||||
self.map = TwoPlayerDefaultTestMap(scene: self, entityManager: self.entityManager)
|
||||
self.map.create()
|
||||
}
|
||||
|
||||
func createVirginBases() {
|
||||
for i in 0...7 {
|
||||
let base:Base
|
||||
var position = CGPoint(x: 0, y: 0)
|
||||
switch i {
|
||||
case 0...2:
|
||||
let width = self.size.width * 0.25
|
||||
|
||||
if i == 0 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.25)
|
||||
}
|
||||
if i == 1 {
|
||||
position = CGPoint(x: width, y: self.size.height * 0.5)
|
||||
}
|
||||
if i == 2{
|
||||
position = CGPoint(x: width, y: self.size.height * 0.75)
|
||||
}
|
||||
|
||||
case 3...4:
|
||||
let width = self.size.width * 0.5
|
||||
|
||||
if i == 3{
|
||||
position = CGPoint(x: width, y: self.size.height * 0.333)
|
||||
}
|
||||
if i == 4{
|
||||
position = CGPoint(x: width, y: self.size.height * 0.666)
|
||||
}
|
||||
|
||||
case 5...7:
|
||||
let width = self.size.width * 0.75
|
||||
|
||||
if i == 5{
|
||||
position = CGPoint(x: width, y: self.size.height * 0.25)
|
||||
}
|
||||
if i == 6{
|
||||
position = CGPoint(x: width, y: self.size.height * 0.5)
|
||||
}
|
||||
if i == 7{
|
||||
position = CGPoint(x: width, y: self.size.height * 0.75)
|
||||
}
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
base = Base(textureName: "Base", team: nil, position: position)
|
||||
entityManager.add(base)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
guard let touch = touches.first else {
|
||||
|
Loading…
Reference in New Issue
Block a user