Skip to content

Commit

Permalink
added ground
Browse files Browse the repository at this point in the history
  • Loading branch information
PP100893 committed Jul 19, 2015
1 parent fd886a0 commit 90b0dd3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Xmaze/Xmaze/GameData.plist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<key>ShowPhysics</key>
<false/>
<key>ParallaxOffset</key>
<string>{ 0.7, 0.8 }</string>
<string>{ 0.7, 0.7 }</string>
<key>Gravity</key>
<string>{ 0.0, 0.0 }</string>
</dict>
Expand Down
53 changes: 50 additions & 3 deletions Xmaze/Xmaze/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
var heroIsDead:Bool = false
var starsAcquired:Int = 0
var starsTotal:Int = 0
var starsLabel:SKLabelNode?
var starsLeft:Int = 0
var enemyCount:Int = 0
var enemyDictionnary:[String : CGPoint] = [:]

Expand All @@ -43,10 +45,10 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
var bgImage:String?
var enemyLogic:Double?
var gameLabel:SKLabelNode?

var parallaxBG:SKSpriteNode?
var parallaxOffset:CGPoint = CGPointZero
var starsLabel:SKLabelNode?
var starsLeft:Int = 0


override func didMoveToView(view: SKView) {

Expand Down Expand Up @@ -184,6 +186,14 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
/* background */


if(bgImage != nil) {

createBackground(bgImage!)

}



//MARK: TOMORROW


Expand Down Expand Up @@ -614,6 +624,35 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{

let cameraPositionInScene:CGPoint = self.convertPoint(node.position, fromNode: mazeWorld!)
mazeWorld!.position = CGPoint(x: mazeWorld!.position.x - cameraPositionInScene.x, y: mazeWorld!.position.y - cameraPositionInScene.y)

/* handle parallax */

if (parallaxOffset.x != 0) {

if ( Int(cameraPositionInScene.x) < 0 ) {

parallaxBG!.position = CGPoint(x: parallaxBG!.position.x + parallaxOffset.x, y: parallaxBG!.position.y)

} else if ( Int(cameraPositionInScene.x) > 0 ) {

parallaxBG!.position = CGPoint(x: parallaxBG!.position.x - parallaxOffset.x, y: parallaxBG!.position.y)
}

}

if (parallaxOffset.y != 0) {

if ( Int(cameraPositionInScene.y) < 0 ) {

parallaxBG!.position = CGPoint(x: parallaxBG!.position.x, y: parallaxBG!.position.y + parallaxOffset.y)

} else if ( Int(cameraPositionInScene.y) > 0 ) {

parallaxBG!.position = CGPoint(x: parallaxBG!.position.x, y: parallaxBG!.position.y - parallaxOffset.y)
}

}

}

//MARK: ENEMY STUFF
Expand Down Expand Up @@ -832,6 +871,14 @@ class GameScene: SKScene, SKPhysicsContactDelegate, NSXMLParserDelegate{
}

}



func createBackground(image:String) {

parallaxBG = SKSpriteNode(imageNamed: image)
mazeWorld!.addChild(parallaxBG!)
parallaxBG!.position = CGPoint(x: parallaxBG!.size.width / 2, y: -parallaxBG!.size.height / 2)
parallaxBG!.alpha = 0.5
}

}
21 changes: 21 additions & 0 deletions Xmaze/Xmaze/Images.xcassets/star_field.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "star_filed.png"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 90b0dd3

Please sign in to comment.