Skip to content

Commit

Permalink
Merge pull request #5 from cdmx/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
vicegax authored Jul 2, 2017
2 parents 47cb33c + c6f6446 commit e533cc1
Show file tree
Hide file tree
Showing 278 changed files with 8,425 additions and 4,221 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# MiniMancera
MiniMancera
![](logo.png)

![iOS](https://img.shields.io/badge/iOS-9.0%2B-orange.svg)
![Swift](https://img.shields.io/badge/Swift-3.1-orange.svg)
![Devices](https://img.shields.io/badge/Devices-Universal-orange.svg)
![Arch](https://img.shields.io/badge/Arc-CMV-orange.svg)
![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=plastic)
[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&style=plastic)](https://twitter.com/MiniManceraApp)

[<img src="https://cloud.githubusercontent.com/assets/219689/5575342/963e0ee8-9013-11e4-8091-7ece67d64729.png" height="32" alt="AppStore"/>](https://itunes.apple.com/mx/app/minimancera/id1247193502?l=en)



## Description
MiniMancera Adventures on CDMX

## Features


■ SpriteKit

■ GameKit

■ StoreKit

■ CoreGraphics animations

■ CMV (Controller-Manager-View)

■ English and Spanish localization
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,072 changes: 894 additions & 178 deletions miniMancera.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

172 changes: 68 additions & 104 deletions miniMancera/Controller/Abstract/ControllerGame.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import UIKit
import SpriteKit

class ControllerGame<T:MGameProtocol>:UIViewController
class ControllerGame<T:MGame>:UIViewController, SKSceneDelegate, SKPhysicsContactDelegate
{
let model:T
let playSounds:Bool
private(set) weak var dataOption:DOption?
private(set) var lastUpdateTime:TimeInterval?
private(set) var elapsedTime:TimeInterval

init(dataOption:DOption)
required init(dataOption:DOption)
{
self.dataOption = dataOption
model = T()

if let playSounds:Bool = MSession.sharedInstance.settings?.sounds
{
self.playSounds = playSounds
}
else
{
playSounds = true
}

elapsedTime = 0

super.init(nibName:nil, bundle:nil)
}

Expand All @@ -35,7 +49,7 @@ class ControllerGame<T:MGameProtocol>:UIViewController

override func loadView()
{
let view:SKView = SKView(frame:UIScreen.main.bounds)
let view:ViewGame = ViewGame(controller:self)
self.view = view
}

Expand All @@ -46,89 +60,48 @@ class ControllerGame<T:MGameProtocol>:UIViewController
extendedLayoutIncludesOpaqueBars = false
automaticallyAdjustsScrollViewInsets = false

let size:CGSize = view.bounds.size

guard

let scene:SKScene = model.sceneWithSize(controller:self, size:size),
let view:SKView = self.view as? SKView

else
{
return
}

scene.scaleMode = SKSceneScaleMode.resizeFill
view.showsFPS = false
view.showsNodeCount = false
view.ignoresSiblingOrder = true
view.presentScene(scene)

NotificationCenter.default.addObserver(
self,
selector:#selector(notifiedEnterBackground(sender:)),
name:Notification.enterBackground,
object:nil)
}

//MARK: notified

func notifiedEnterBackground(sender notification:Notification)
override func viewDidAppear(_ animated:Bool)
{
}

//MARK: private

private func asyncShowMenu()
{
let alert:UIAlertController = UIAlertController(
title:nil,
message:nil,
preferredStyle:UIAlertControllerStyle.actionSheet)

let actionResume:UIAlertAction = UIAlertAction(
title:
String.localized(key:"ControllerGame_menuResume"),
style:
UIAlertActionStyle.cancel)
{ [weak self] (action:UIAlertAction) in

self?.resume()
}
super.viewDidAppear(animated)

let actionExit:UIAlertAction = UIAlertAction(
title:
String.localized(key:"ControllerGame_menuExit"),
style:
UIAlertActionStyle.destructive)
{ [weak self] (action:UIAlertAction) in

self?.exitGame()
}
guard

alert.addAction(actionResume)
alert.addAction(actionExit)
let parent:ControllerParent = self.parent as? ControllerParent,
let view:ViewParent = parent.view as? ViewParent

if let popover:UIPopoverPresentationController = alert.popoverPresentationController
else
{
popover.sourceView = view
popover.sourceRect = CGRect.zero
popover.permittedArrowDirections = UIPopoverArrowDirection.up
return
}

present(alert, animated:true, completion:nil)
view.panRecognizer.isEnabled = false
}

//MARK: notified

func notifiedEnterBackground(sender notification:Notification)
{
stopTimer()
}

//MARK: public

func postScore()
func didMove()
{
let gameScore:Int = model.score
postScoreWithScore(score:gameScore)
model.didMove()
}

func postScoreWithScore(score:Int)
func postScore()
{
let score:Int = model.score

guard

let dataOption:DOption = self.dataOption
Expand All @@ -153,58 +126,49 @@ class ControllerGame<T:MGameProtocol>:UIViewController
parent.gameScore(score:score, gameId:gameId)
}

func pause()
func stopTimer()
{
guard

let view:SKView = self.view as? SKView

else
{
return
}

view.isPaused = true
lastUpdateTime = nil
}

func resume()
func restartTimer()
{
guard
elapsedTime = 0
lastUpdateTime = nil
}

//MARK: scene delegate

func update(_ currentTime:TimeInterval, for scene:SKScene)
{
if let lastUpdateTime:TimeInterval = self.lastUpdateTime
{
let deltaTime:TimeInterval = currentTime - lastUpdateTime
elapsedTime += deltaTime

let view:SKView = self.view as? SKView
guard

let strategy:MGameStrategyMain<T> = model.gameStrategy(modelType:model),
let scene:ViewGameScene<T> = scene as? ViewGameScene<T>

else
{
return
else
{
return
}

strategy.update(elapsedTime:elapsedTime, scene:scene)
}

view.isPaused = false
lastUpdateTime = currentTime
}

func showMenu()
//MARK: contact delegate

func didBegin(_ contact:SKPhysicsContact)
{
pause()

DispatchQueue.main.async
{ [weak self] in

self?.asyncShowMenu()
}
}

func exitGame()
func didEnd(_ contact:SKPhysicsContact)
{
postScore()

guard

let parent:UIViewController = UIApplication.shared.keyWindow?.rootViewController

else
{
return
}

parent.dismiss(animated:true, completion:nil)
}
}
Loading

0 comments on commit e533cc1

Please sign in to comment.