Skip to content

Commit

Permalink
completed chapter 2.11. setup plist of enemy and hero (speed,logic, l…
Browse files Browse the repository at this point in the history
…evel...)
  • Loading branch information
PP100893 committed Jul 16, 2015
1 parent a015b83 commit 8554b18
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Xmaze/Xmaze.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
F811212E1B507075002D9380 /* Boundary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F811212D1B507075002D9380 /* Boundary.swift */; };
F847A8F51B544680004D5156 /* Enemy.swift in Sources */ = {isa = PBXBuildFile; fileRef = F847A8F41B544680004D5156 /* Enemy.swift */; };
F84B0CC91B5439ED00FEB9F3 /* moving.atlas in Resources */ = {isa = PBXBuildFile; fileRef = F84B0CC81B5439ED00FEB9F3 /* moving.atlas */; };
F85F51171B58591500B7F578 /* GameScene2.sks in Resources */ = {isa = PBXBuildFile; fileRef = F85F51161B58591500B7F578 /* GameScene2.sks */; };
F870DF791B5463D40006BBFF /* Maze.tmx in Resources */ = {isa = PBXBuildFile; fileRef = F870DF781B5463D40006BBFF /* Maze.tmx */; };
F89043CA1B5717D700ACF657 /* GameData.plist in Resources */ = {isa = PBXBuildFile; fileRef = F89043C91B5717D700ACF657 /* GameData.plist */; };
F89043CC1B572D5800ACF657 /* GameData.swift in Sources */ = {isa = PBXBuildFile; fileRef = F89043CB1B572D5800ACF657 /* GameData.swift */; };
Expand Down Expand Up @@ -52,6 +53,7 @@
F811212D1B507075002D9380 /* Boundary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Boundary.swift; sourceTree = "<group>"; };
F847A8F41B544680004D5156 /* Enemy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enemy.swift; sourceTree = "<group>"; };
F84B0CC81B5439ED00FEB9F3 /* moving.atlas */ = {isa = PBXFileReference; lastKnownFileType = folder.skatlas; path = moving.atlas; sourceTree = "<group>"; };
F85F51161B58591500B7F578 /* GameScene2.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = GameScene2.sks; sourceTree = "<group>"; };
F870DF781B5463D40006BBFF /* Maze.tmx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Maze.tmx; sourceTree = "<group>"; };
F89043C91B5717D700ACF657 /* GameData.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = GameData.plist; sourceTree = "<group>"; };
F89043CB1B572D5800ACF657 /* GameData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameData.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -101,6 +103,7 @@
F89FC9BE1B51F5860033BEFA /* Star.swift */,
F81121071B506FD0002D9380 /* AppDelegate.swift */,
F81121091B506FD0002D9380 /* GameScene.sks */,
F85F51161B58591500B7F578 /* GameScene2.sks */,
F811212B1B507056002D9380 /* hero.swift */,
F89043C91B5717D700ACF657 /* GameData.plist */,
F811212D1B507075002D9380 /* Boundary.swift */,
Expand Down Expand Up @@ -237,6 +240,7 @@
F89043CA1B5717D700ACF657 /* GameData.plist in Resources */,
F811210A1B506FD0002D9380 /* GameScene.sks in Resources */,
F81121111B506FD0002D9380 /* Main.storyboard in Resources */,
F85F51171B58591500B7F578 /* GameScene2.sks in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
75 changes: 74 additions & 1 deletion Xmaze/Xmaze/GameData.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,80 @@
<key>ParallaxOffset</key>
<string>{ 0.7, 0.7 }</string>
<key>Gravity</key>
<string>{ 0.0, -1 }</string>
<string>{ 0.0, 0.0 }</string>
</dict>
<key>LevelSettings</key>
<array>
<dict>
<key>TMXFile</key>
<string>Maze</string>
<key>NextSKSFile</key>
<string>GameScene2</string>
<key>Speed</key>
<integer>5</integer>
<key>EnemySpeed</key>
<integer>4</integer>
<key>EnemyLogic</key>
<integer>5</integer>
<key>Background</key>
<string>star_field</string>
</dict>
<dict>
<key>TMXFile</key>
<string>Maze</string>
<key>NextSKSFile</key>
<string>GameScene2</string>
<key>Speed</key>
<integer>4</integer>
<key>EnemySpeed</key>
<integer>4</integer>
<key>EnemyLogic</key>
<integer>3</integer>
<key>BackGround</key>
<string>star_field</string>
</dict>
<dict>
<key>TMXFile</key>
<string>Maze</string>
<key>NextSKSFile</key>
<string>GameScene2</string>
<key>Speed</key>
<integer>4</integer>
<key>EnemySpeed</key>
<integer>4</integer>
<key>EnemyLogic</key>
<integer>3</integer>
<key>BackGround</key>
<string>star_field</string>
</dict>
<dict>
<key>TMXFile</key>
<string>Maze</string>
<key>NextSKSFile</key>
<string>GameScene2</string>
<key>Speed</key>
<integer>4</integer>
<key>EnemySpeed</key>
<integer>4</integer>
<key>EnemyLogic</key>
<integer>3</integer>
<key>BackGround</key>
<string>star_field</string>
</dict>
<dict>
<key>TMXFile</key>
<string>Maze</string>
<key>NextSKSFile</key>
<string>GameScene2</string>
<key>Speed</key>
<integer>4</integer>
<key>EnemySpeed</key>
<integer>4</integer>
<key>EnemyLogic</key>
<integer>3</integer>
<key>BackGround</key>
<string>star_field</string>
</dict>
</array>
</dict>
</plist>
80 changes: 68 additions & 12 deletions Xmaze/Xmaze/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum BodyType:UInt32 {
class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{

var currentSpeed:Float = 5
var enemySpeed:Float = 4
var heroLocation:CGPoint = CGPointZero
var mazeWorld:SKNode?
var hero:Hero?
Expand All @@ -36,6 +37,12 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
var enemyCount:Int = 0
var enemyDictionnary:[String : CGPoint] = [:]

var currentTMXFile:String?
var nextSKSFile:String?

var bgImage:String?
var enemyLogic:Double = 5

override func didMoveToView(view: SKView) {


Expand All @@ -46,8 +53,58 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
let dict = NSDictionary(contentsOfFile: path!)!
let heroDict:AnyObject = dict.objectForKey("HeroSettings")!
let gameDict:AnyObject = dict.objectForKey("GameSettings")!
let levelArray:AnyObject = dict.objectForKey("LevelSettings")!


if let levelNSArray:NSArray = levelArray as? NSArray {


println(levelNSArray)

var levelDict:AnyObject = levelNSArray[currentLevel]

if let tmxFile = levelDict.valueForKey("TMXFile") as? String {


currentTMXFile = tmxFile
println("specified a TMX file for this level")

}
if let sksFile = levelDict.valueForKey("NextSKSFile") as? String {

nextSKSFile = sksFile
println("specified a next SKS file if this level is passed")

}
if let speed = levelDict.valueForKey("Speed") as? Float {

currentSpeed = speed
println(currentSpeed)

}

if let espeed = levelDict.valueForKey("EnemySpeed") as? Float {

enemySpeed = espeed
println(enemySpeed)

}


if let elogic = levelDict.valueForKey("EnemyLogic") as? Double {

enemyLogic = elogic
println(enemyLogic)

}

if (levelDict.valueForKey("Background") != nil) {

bgImage = levelDict.valueForKey("Background") as? String

}
}

/* initial properties */

self.backgroundColor = SKColor.blackColor()
Expand All @@ -59,7 +116,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{

if ( gameDict.valueForKey("Gravity") as? String != nil) {

println("has gravity from property list")
//println("has gravity from property list")
let newGravity:CGPoint = CGPointFromString(gameDict.valueForKey("Gravity") as? String)
physicsWorld.gravity = CGVector(dx: newGravity.x, dy: newGravity.y)

Expand All @@ -72,10 +129,8 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{

physicsWorld.contactDelegate = self
self.anchorPoint = CGPoint(x: 0.5, y: 0.5)


let TMX:Bool = gameDict["UseTMXFiles"] as AnyObject? as! Bool? != false
useTMXFiles = TMX

useTMXFiles = (gameDict.valueForKey("UseTMXFile") as? Bool)!

if(useTMXFiles == true) {

Expand Down Expand Up @@ -145,7 +200,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{

} else {

parseTMXFileWithName("Maze")
parseTMXFileWithName(currentTMXFile!)
}


Expand All @@ -169,7 +224,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
self.mazeWorld!.addChild(newEnemy)
newEnemy.position = enemy.position
newEnemy.name = enemy.name!

newEnemy.enemySpeed = self.enemySpeed

self.enemyDictionnary.updateValue(newEnemy.position, forKey: newEnemy.name!)

Expand All @@ -192,7 +247,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{

if let boundary = node as? SKSpriteNode{

println("found boundary")
//println("found boundary")
let rect:CGRect = CGRect(origin: boundary.position, size: boundary.size)
let newBoundary:Boundary = Boundary(fromSKSwithRect: rect, isEdge:false)
self.mazeWorld!.addChild(newBoundary)
Expand All @@ -214,7 +269,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{

if let edge = node as? SKSpriteNode{

println("found boundary")
//println("found boundary")
let rect:CGRect = CGRect(origin: edge.position, size: edge.size)
let newEdge:Boundary = Boundary(fromSKSwithRect: rect, isEdge:true)
self.mazeWorld!.addChild(newEdge)
Expand Down Expand Up @@ -243,7 +298,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
newStar.position = star.position

self.starsTotal++
println(self.starsTotal)
//println(self.starsTotal)

star.removeFromParent()

Expand Down Expand Up @@ -390,7 +445,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{

if (starsAcquired == starsTotal) {

println("got all the stars")
//println("got all the stars")
}

default:
Expand Down Expand Up @@ -503,6 +558,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
mazeWorld!.addChild(newEnemy)

newEnemy.name = theName
newEnemy.enemySpeed = enemySpeed

let location:CGPoint = newEnemy.position

Expand Down Expand Up @@ -540,7 +596,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{



let enemyAction:SKAction = SKAction.waitForDuration(5)
let enemyAction:SKAction = SKAction.waitForDuration(enemyLogic)

self.runAction(enemyAction, completion: {

Expand Down
Binary file added Xmaze/Xmaze/GameScene2.sks
Binary file not shown.
5 changes: 1 addition & 4 deletions Xmaze/Xmaze/hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Hero:SKNode {
init (theDict:[String: AnyObject]){

super.init()
println(theDict)
//println(theDict)

let image:String = theDict["HeroImage"] as AnyObject? as! String

Expand All @@ -81,9 +81,6 @@ class Hero:SKNode {

}




let largerSize:CGSize = CGSize(width: objectSprite!.size.width * 1.15, height: objectSprite!.size.height * 1.15)


Expand Down

0 comments on commit 8554b18

Please sign in to comment.