Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Kolo13
    @Kolo13
    //
    //  GameScene.swift
    //  SkaterBrad
    //
    //  Created by Kevin Pham on 10/27/14.
    //  Copyright (c) 2014 Mother Functions. All rights reserved.
    //
    
    import SpriteKit
    
    class GameScene: SKScene {
    
        // Jump Properties
        var currentTime = 0.0
        var previousTime = 0.0
        var deltaTime = 0.0
        var jumpNumber = 0
        var jumpTime = 0.0
        var jumpMode = false
    
        var hero = SKSpriteNode()
    
        let bar = SKSpriteNode(imageNamed: "bar")
        let obst2 = SKSpriteNode(imageNamed: "sprite2")
        let hydrant = SKSpriteNode(imageNamed: "hydrant")
        let square1 = SKSpriteNode(color: SKColor.blackColor(), size: CGSize(width: 500.0, height: 200.0))
        var hydrantBaseline = CGFloat(0)
    
        // Node Categories
        let heroCategory = 0x1 << 1
        let groundCategory = 0x1 << 2
    
    
        var groundSpeed = 2
    
    
        override func didMoveToView(view: SKView) {
    
            //obstacles
            self.bar.anchorPoint = CGPointMake(0, 0.5)
            self.bar.position = CGPointMake(CGRectGetMinX(self.frame),
              CGRectGetMinY(self.frame) + (self.bar.size.height / 2))
    
            self.obst2.anchorPoint = CGPointMake(1.0, 1.0)
            self.obst2.position = CGPointMake((CGRectGetMaxX(self.frame) * 0.75),
              CGRectGetMaxY(self.frame))
    
            self.square1.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: 500.0, height: 200.0))
    
    
            self.hydrantBaseline = self.bar.position.y + (self.bar.size.height) + (self.hydrant.size.height/8)
            self.hydrant.position = CGPointMake((self.hydrant.size.width)/2,
              self.hydrantBaseline + self.bar.size.height)
    
            self.square1.position = CGPointMake(CGRectGetMinX(self.frame),
              CGRectGetMinY(self.frame) + (self.square1.size.height / 2.0))
            self.square1.zPosition = 0
            self.square1.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(self.frame.size.width, bar.size.height))
            self.square1.physicsBody?.dynamic = false
    
            self.obst2.size = CGSize(width: 20.0, height: 350.0)
    
          //self.addChild(self.bar)
          //self.addChild(self.hydrant)
          //self.addChild(self.square1)
            self.addChild(self.obst2)
            // Swipe Recognizer Setup
            var swipeRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeAction:")
            swipeRecognizer.direction = UISwipeGestureRecognizerDirection.Up
            self.view?.addGestureRecognizer(swipeRecognizer)
    
            // Physics - setting gravity to game world
            self.physicsWorld.gravity = CGVectorMake(0.0, -9.8)
    
            // Hero
            var bradTexture = SKTexture(imageNamed: "hero.jpg") // Change 90x90 image
            bradTexture.filteringMode = SKTextureFilteringMode.Nearest
    
            hero = SKSpriteNode(texture: bradTexture)
            hero.setScale(0.5)
            hero.position = CGPoint(x: self.frame.size.width * 0.35, y: self.frame.size.height * 0.5) // Change y to ground level
    
            // Determine physics body around Hero
            hero.physicsBody = SKPhysicsBody(circleOfRadius: hero.size.height / 2)
            //hero.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize) // look at later
            hero.physicsBody?.dynamic = true
            hero.physicsBody?.allowsRotation = false
            hero.physicsBody?.categoryBitMask = UInt32(self.heroCategory)
    
            self.addChild(hero)
    
            // Ground
            var groundTexture = SKTexture(imageNamed: "") // Add 336x112 image
    
            var sprite = SKSpriteNode(texture: groundTexture)
            sprite.setScale(2.0)
            sprite.position = CGPointMake(self.size.width / 2, sprite.size.height / 2)
    
            self.addChild(sprite)
    
            var ground = SKNode()
    
            ground.position = CGPointMake(0, groundTexture.size().height)
            ground.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(self.frame.size.width, groundTexture.size().height * 2))
            ground.physicsBody?.dynamic = false
            ground.physicsBody?.categoryBitMask = UInt32(self.groundCategory)
    
    //        var ground = SKShapeNode(rec