├── README.md ├── Snakee.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ ├── 1012826.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── viviennecheng.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── 1012826.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ ├── Snakee.xcscheme │ │ └── xcschememanagement.plist │ └── viviennecheng.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── Snakee.xcscheme │ ├── Snakee1.xcscheme │ └── xcschememanagement.plist └── Snakee ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json ├── apple.imageset │ ├── Contents.json │ └── apple.png ├── body.imageset │ ├── Contents.json │ └── body.png ├── pause-2.imageset │ ├── Contents.json │ └── pause-2.png ├── pause.imageset │ ├── Contents.json │ └── pause-3.png ├── play-button-3.imageset │ ├── Contents.json │ └── play-button-3.png ├── settings.imageset │ ├── Contents.json │ └── settings.png ├── snakebody.imageset │ ├── Contents.json │ └── oie_transparent-2.png ├── snakehead.imageset │ ├── Contents.json │ └── oie_transparent.png └── snakehead1.imageset │ ├── Contents.json │ └── snakehead1.png ├── Base.lproj └── LaunchScreen.storyboard ├── GameScene.sks ├── GameScene.swift ├── GameViewController.swift ├── Grid.swift ├── Info.plist ├── Main.storyboard ├── ViewController2.swift └── pauseSceneViewController.swift /README.md: -------------------------------------------------------------------------------- 1 | # SwiftSnake 2 | A Snake clone written in Swift 3 | 4 | Controlled by swipes 5 | 6 | ![alt text](http://i.imgur.com/HCzGCtn.png"Screenshot") 7 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 15F135DA1D49A5AE0055FE77 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F135D91D49A5AE0055FE77 /* AppDelegate.swift */; }; 11 | 15F135DC1D49A5AE0055FE77 /* GameScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 15F135DB1D49A5AE0055FE77 /* GameScene.sks */; }; 12 | 15F135DE1D49A5AE0055FE77 /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F135DD1D49A5AE0055FE77 /* GameScene.swift */; }; 13 | 15F135E01D49A5AE0055FE77 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F135DF1D49A5AE0055FE77 /* GameViewController.swift */; }; 14 | 15F135E81D49A5AF0055FE77 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 15F135E61D49A5AF0055FE77 /* LaunchScreen.storyboard */; }; 15 | 15F135F21D49A6BF0055FE77 /* Grid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F135F11D49A6BF0055FE77 /* Grid.swift */; }; 16 | 69752D3C1D6345EB001370D3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 69752D3B1D6345EB001370D3 /* Assets.xcassets */; }; 17 | 69CFFA0A1D66BAAC00BE3598 /* pauseSceneViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69CFFA091D66BAAC00BE3598 /* pauseSceneViewController.swift */; }; 18 | 69CFFA0C1D66BE6D00BE3598 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 69CFFA0B1D66BE6D00BE3598 /* Main.storyboard */; }; 19 | 69CFFA0E1D66D34E00BE3598 /* ViewController2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69CFFA0D1D66D34E00BE3598 /* ViewController2.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 15F135D61D49A5AE0055FE77 /* Snakee.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Snakee.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 15F135D91D49A5AE0055FE77 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 25 | 15F135DB1D49A5AE0055FE77 /* GameScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = GameScene.sks; sourceTree = ""; }; 26 | 15F135DD1D49A5AE0055FE77 /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = ""; }; 27 | 15F135DF1D49A5AE0055FE77 /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; 28 | 15F135E71D49A5AF0055FE77 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 15F135E91D49A5AF0055FE77 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 15F135F11D49A6BF0055FE77 /* Grid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Grid.swift; sourceTree = ""; }; 31 | 69752D3B1D6345EB001370D3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | 69CFFA091D66BAAC00BE3598 /* pauseSceneViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = pauseSceneViewController.swift; sourceTree = ""; }; 33 | 69CFFA0B1D66BE6D00BE3598 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 34 | 69CFFA0D1D66D34E00BE3598 /* ViewController2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController2.swift; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 15F135D31D49A5AE0055FE77 /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 15F135CD1D49A5AE0055FE77 = { 49 | isa = PBXGroup; 50 | children = ( 51 | 15F135D81D49A5AE0055FE77 /* Snakee */, 52 | 15F135D71D49A5AE0055FE77 /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 15F135D71D49A5AE0055FE77 /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 15F135D61D49A5AE0055FE77 /* Snakee.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 15F135D81D49A5AE0055FE77 /* Snakee */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 69CFFA0B1D66BE6D00BE3598 /* Main.storyboard */, 68 | 69752D3B1D6345EB001370D3 /* Assets.xcassets */, 69 | 15F135D91D49A5AE0055FE77 /* AppDelegate.swift */, 70 | 15F135DB1D49A5AE0055FE77 /* GameScene.sks */, 71 | 15F135DD1D49A5AE0055FE77 /* GameScene.swift */, 72 | 15F135DF1D49A5AE0055FE77 /* GameViewController.swift */, 73 | 15F135E61D49A5AF0055FE77 /* LaunchScreen.storyboard */, 74 | 15F135E91D49A5AF0055FE77 /* Info.plist */, 75 | 15F135F11D49A6BF0055FE77 /* Grid.swift */, 76 | 69CFFA091D66BAAC00BE3598 /* pauseSceneViewController.swift */, 77 | 69CFFA0D1D66D34E00BE3598 /* ViewController2.swift */, 78 | ); 79 | path = Snakee; 80 | sourceTree = ""; 81 | }; 82 | /* End PBXGroup section */ 83 | 84 | /* Begin PBXNativeTarget section */ 85 | 15F135D51D49A5AE0055FE77 /* Snakee */ = { 86 | isa = PBXNativeTarget; 87 | buildConfigurationList = 15F135EC1D49A5AF0055FE77 /* Build configuration list for PBXNativeTarget "Snakee" */; 88 | buildPhases = ( 89 | 15F135D21D49A5AE0055FE77 /* Sources */, 90 | 15F135D31D49A5AE0055FE77 /* Frameworks */, 91 | 15F135D41D49A5AE0055FE77 /* Resources */, 92 | ); 93 | buildRules = ( 94 | ); 95 | dependencies = ( 96 | ); 97 | name = Snakee; 98 | productName = Snakee; 99 | productReference = 15F135D61D49A5AE0055FE77 /* Snakee.app */; 100 | productType = "com.apple.product-type.application"; 101 | }; 102 | /* End PBXNativeTarget section */ 103 | 104 | /* Begin PBXProject section */ 105 | 15F135CE1D49A5AE0055FE77 /* Project object */ = { 106 | isa = PBXProject; 107 | attributes = { 108 | LastSwiftUpdateCheck = 0720; 109 | LastUpgradeCheck = 0720; 110 | ORGANIZATIONNAME = "Caleb Cheng"; 111 | TargetAttributes = { 112 | 15F135D51D49A5AE0055FE77 = { 113 | CreatedOnToolsVersion = 7.2; 114 | DevelopmentTeam = P4NGY5379C; 115 | }; 116 | }; 117 | }; 118 | buildConfigurationList = 15F135D11D49A5AE0055FE77 /* Build configuration list for PBXProject "Snakee" */; 119 | compatibilityVersion = "Xcode 3.2"; 120 | developmentRegion = English; 121 | hasScannedForEncodings = 0; 122 | knownRegions = ( 123 | en, 124 | Base, 125 | ); 126 | mainGroup = 15F135CD1D49A5AE0055FE77; 127 | productRefGroup = 15F135D71D49A5AE0055FE77 /* Products */; 128 | projectDirPath = ""; 129 | projectRoot = ""; 130 | targets = ( 131 | 15F135D51D49A5AE0055FE77 /* Snakee */, 132 | ); 133 | }; 134 | /* End PBXProject section */ 135 | 136 | /* Begin PBXResourcesBuildPhase section */ 137 | 15F135D41D49A5AE0055FE77 /* Resources */ = { 138 | isa = PBXResourcesBuildPhase; 139 | buildActionMask = 2147483647; 140 | files = ( 141 | 15F135DC1D49A5AE0055FE77 /* GameScene.sks in Resources */, 142 | 15F135E81D49A5AF0055FE77 /* LaunchScreen.storyboard in Resources */, 143 | 69752D3C1D6345EB001370D3 /* Assets.xcassets in Resources */, 144 | 69CFFA0C1D66BE6D00BE3598 /* Main.storyboard in Resources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXResourcesBuildPhase section */ 149 | 150 | /* Begin PBXSourcesBuildPhase section */ 151 | 15F135D21D49A5AE0055FE77 /* Sources */ = { 152 | isa = PBXSourcesBuildPhase; 153 | buildActionMask = 2147483647; 154 | files = ( 155 | 69CFFA0A1D66BAAC00BE3598 /* pauseSceneViewController.swift in Sources */, 156 | 15F135DE1D49A5AE0055FE77 /* GameScene.swift in Sources */, 157 | 15F135E01D49A5AE0055FE77 /* GameViewController.swift in Sources */, 158 | 15F135F21D49A6BF0055FE77 /* Grid.swift in Sources */, 159 | 15F135DA1D49A5AE0055FE77 /* AppDelegate.swift in Sources */, 160 | 69CFFA0E1D66D34E00BE3598 /* ViewController2.swift in Sources */, 161 | ); 162 | runOnlyForDeploymentPostprocessing = 0; 163 | }; 164 | /* End PBXSourcesBuildPhase section */ 165 | 166 | /* Begin PBXVariantGroup section */ 167 | 15F135E61D49A5AF0055FE77 /* LaunchScreen.storyboard */ = { 168 | isa = PBXVariantGroup; 169 | children = ( 170 | 15F135E71D49A5AF0055FE77 /* Base */, 171 | ); 172 | name = LaunchScreen.storyboard; 173 | sourceTree = ""; 174 | }; 175 | /* End PBXVariantGroup section */ 176 | 177 | /* Begin XCBuildConfiguration section */ 178 | 15F135EA1D49A5AF0055FE77 /* Debug */ = { 179 | isa = XCBuildConfiguration; 180 | buildSettings = { 181 | ALWAYS_SEARCH_USER_PATHS = NO; 182 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 183 | CLANG_CXX_LIBRARY = "libc++"; 184 | CLANG_ENABLE_MODULES = YES; 185 | CLANG_ENABLE_OBJC_ARC = YES; 186 | CLANG_WARN_BOOL_CONVERSION = YES; 187 | CLANG_WARN_CONSTANT_CONVERSION = YES; 188 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 189 | CLANG_WARN_EMPTY_BODY = YES; 190 | CLANG_WARN_ENUM_CONVERSION = YES; 191 | CLANG_WARN_INT_CONVERSION = YES; 192 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 193 | CLANG_WARN_UNREACHABLE_CODE = YES; 194 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 195 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 196 | COPY_PHASE_STRIP = NO; 197 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 198 | ENABLE_STRICT_OBJC_MSGSEND = YES; 199 | ENABLE_TESTABILITY = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu99; 201 | GCC_DYNAMIC_NO_PIC = NO; 202 | GCC_NO_COMMON_BLOCKS = YES; 203 | GCC_OPTIMIZATION_LEVEL = 0; 204 | GCC_PREPROCESSOR_DEFINITIONS = ( 205 | "DEBUG=1", 206 | "$(inherited)", 207 | ); 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 215 | MTL_ENABLE_DEBUG_INFO = YES; 216 | ONLY_ACTIVE_ARCH = YES; 217 | SDKROOT = iphoneos; 218 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 219 | TARGETED_DEVICE_FAMILY = "1,2"; 220 | }; 221 | name = Debug; 222 | }; 223 | 15F135EB1D49A5AF0055FE77 /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_MODULES = YES; 230 | CLANG_ENABLE_OBJC_ARC = YES; 231 | CLANG_WARN_BOOL_CONVERSION = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 234 | CLANG_WARN_EMPTY_BODY = YES; 235 | CLANG_WARN_ENUM_CONVERSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 241 | COPY_PHASE_STRIP = NO; 242 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 243 | ENABLE_NS_ASSERTIONS = NO; 244 | ENABLE_STRICT_OBJC_MSGSEND = YES; 245 | GCC_C_LANGUAGE_STANDARD = gnu99; 246 | GCC_NO_COMMON_BLOCKS = YES; 247 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 248 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 249 | GCC_WARN_UNDECLARED_SELECTOR = YES; 250 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 251 | GCC_WARN_UNUSED_FUNCTION = YES; 252 | GCC_WARN_UNUSED_VARIABLE = YES; 253 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 254 | MTL_ENABLE_DEBUG_INFO = NO; 255 | SDKROOT = iphoneos; 256 | TARGETED_DEVICE_FAMILY = "1,2"; 257 | VALIDATE_PRODUCT = YES; 258 | }; 259 | name = Release; 260 | }; 261 | 15F135ED1D49A5AF0055FE77 /* Debug */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 265 | INFOPLIST_FILE = Snakee/Info.plist; 266 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 267 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 268 | PRODUCT_BUNDLE_IDENTIFIER = com.xyz.Snakee1; 269 | PRODUCT_NAME = "$(TARGET_NAME)"; 270 | }; 271 | name = Debug; 272 | }; 273 | 15F135EE1D49A5AF0055FE77 /* Release */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | INFOPLIST_FILE = Snakee/Info.plist; 278 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 279 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 280 | PRODUCT_BUNDLE_IDENTIFIER = com.xyz.Snakee1; 281 | PRODUCT_NAME = "$(TARGET_NAME)"; 282 | }; 283 | name = Release; 284 | }; 285 | /* End XCBuildConfiguration section */ 286 | 287 | /* Begin XCConfigurationList section */ 288 | 15F135D11D49A5AE0055FE77 /* Build configuration list for PBXProject "Snakee" */ = { 289 | isa = XCConfigurationList; 290 | buildConfigurations = ( 291 | 15F135EA1D49A5AF0055FE77 /* Debug */, 292 | 15F135EB1D49A5AF0055FE77 /* Release */, 293 | ); 294 | defaultConfigurationIsVisible = 0; 295 | defaultConfigurationName = Release; 296 | }; 297 | 15F135EC1D49A5AF0055FE77 /* Build configuration list for PBXNativeTarget "Snakee" */ = { 298 | isa = XCConfigurationList; 299 | buildConfigurations = ( 300 | 15F135ED1D49A5AF0055FE77 /* Debug */, 301 | 15F135EE1D49A5AF0055FE77 /* Release */, 302 | ); 303 | defaultConfigurationIsVisible = 0; 304 | defaultConfigurationName = Release; 305 | }; 306 | /* End XCConfigurationList section */ 307 | }; 308 | rootObject = 15F135CE1D49A5AE0055FE77 /* Project object */; 309 | } 310 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/project.xcworkspace/xcuserdata/1012826.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee.xcodeproj/project.xcworkspace/xcuserdata/1012826.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Snakee.xcodeproj/project.xcworkspace/xcuserdata/viviennecheng.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee.xcodeproj/project.xcworkspace/xcuserdata/viviennecheng.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Snakee.xcodeproj/xcuserdata/1012826.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/xcuserdata/1012826.xcuserdatad/xcschemes/Snakee.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/xcuserdata/1012826.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Snakee.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 15F135D51D49A5AE0055FE77 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/xcuserdata/viviennecheng.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/xcuserdata/viviennecheng.xcuserdatad/xcschemes/Snakee.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/xcuserdata/viviennecheng.xcuserdatad/xcschemes/Snakee1.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Snakee.xcodeproj/xcuserdata/viviennecheng.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Snakee.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | Snakee1.xcscheme 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 15F135D51D49A5AE0055FE77 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Snakee/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Snakee 4 | // 5 | // Created by Caleb Cheng on 28/07/2016. 6 | // Copyright © 2016 Caleb Cheng. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/apple.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "apple.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/apple.imageset/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/apple.imageset/apple.png -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/body.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "body.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/body.imageset/body.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/body.imageset/body.png -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/pause-2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "pause-2.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/pause-2.imageset/pause-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/pause-2.imageset/pause-2.png -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/pause.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "pause-3.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/pause.imageset/pause-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/pause.imageset/pause-3.png -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/play-button-3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "play-button-3.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/play-button-3.imageset/play-button-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/play-button-3.imageset/play-button-3.png -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/settings.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "settings.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/settings.imageset/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/settings.imageset/settings.png -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/snakebody.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "oie_transparent-2.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/snakebody.imageset/oie_transparent-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/snakebody.imageset/oie_transparent-2.png -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/snakehead.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "oie_transparent.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/snakehead.imageset/oie_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/snakehead.imageset/oie_transparent.png -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/snakehead1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "snakehead1.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Snakee/Assets.xcassets/snakehead1.imageset/snakehead1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/Assets.xcassets/snakehead1.imageset/snakehead1.png -------------------------------------------------------------------------------- /Snakee/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Snakee/GameScene.sks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/caleb0/SwiftSnake/d414f2f438ff547e449b5f2af76562c8bc02f4c1/Snakee/GameScene.sks -------------------------------------------------------------------------------- /Snakee/GameScene.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GameScene.swift 3 | // Snakee 4 | // 5 | // Created by Caleb Cheng on 28/07/2016. 6 | // Copyright (c) 2016 Caleb Cheng. All rights reserved. 7 | // 8 | 9 | //make 10 | 11 | import SpriteKit 12 | 13 | class Body: SKSpriteNode { 14 | var row:Int = 0 15 | var col:Int = 0 16 | var nextMove: String = "" 17 | var curMove: String = "" 18 | var nextPos: CGPoint = CGPoint(x: 0, y: 0) 19 | var jumped: Bool = false 20 | 21 | func getRow() -> Int { // idek why these are functions 22 | return row 23 | } 24 | 25 | func getCol() -> Int { 26 | return col 27 | } 28 | 29 | convenience init(imageNamed: String) 30 | { 31 | let color = UIColor() 32 | let texture = SKTexture(imageNamed: imageNamed) 33 | let size = CGSizeMake(24.0, 24.0) 34 | self.init(texture: texture, color: color, size: size) 35 | } 36 | } 37 | 38 | 39 | class Fruit: SKSpriteNode { 40 | 41 | var row: Int = 0 42 | var col: Int = 0 43 | 44 | convenience init(imageNamed: String){ 45 | let color = UIColor() 46 | let texture = SKTexture(imageNamed: imageNamed) 47 | let size = CGSizeMake(16, 16) 48 | self.init(texture: texture, color: color, size: size) 49 | } 50 | } 51 | 52 | 53 | class GameScene: SKScene { 54 | let viewWidth:CGFloat = UIScreen.mainScreen().bounds.width 55 | let viewHeight:CGFloat = UIScreen.mainScreen().bounds.height 56 | let gridCols = 16 57 | let gridRows = 10 58 | 59 | var gameOver = UILabel() 60 | var snakeHead = Body(imageNamed:"snakehead") // our snake head 61 | var grid:Grid = Grid(blockSize:0, rows:1, cols:1, renderGrid: shouldRenderGrid) // empty init of grid 62 | var apple: Fruit = Fruit(imageNamed: "apple") 63 | var mySnake: [Body] = [] // our snake is defined as an array of bodies 64 | 65 | var pauseButton: SKSpriteNode = SKSpriteNode(imageNamed: "pause") 66 | 67 | override func didMoveToView(view: SKView) { 68 | scaleMode = .ResizeFill 69 | view.backgroundColor = UIColor.blackColor() 70 | 71 | let blockSize = viewWidth / 28 72 | grid = Grid(blockSize:blockSize, rows:gridRows, cols:gridCols, renderGrid: shouldRenderGrid) 73 | grid.addChild(apple) 74 | grid.position = CGPointMake (CGRectGetMidX(view.frame),CGRectGetMidY(view.frame)) 75 | addChild(grid) 76 | 77 | gameOver.text = "GAME OVER" 78 | gameOver.textColor = UIColor.whiteColor() 79 | gameOver.frame = CGRect(x: viewWidth / 2 - 50, y: 20, width: 100, height: 30) 80 | gameOver.textAlignment = NSTextAlignment.Center 81 | gameOver.alpha = 0 82 | self.view!.addSubview(gameOver) 83 | 84 | 85 | // initis for snakehead 86 | snakeHead.position = grid.gridPosition(3, col: 5) 87 | snakeHead.row = 3 88 | snakeHead.col = 5 89 | grid.addChild(snakeHead) 90 | 91 | // set the first move for snakeHead 92 | snakeHead.nextMove = "right" 93 | mySnake.append(snakeHead) 94 | 95 | let directions: [UISwipeGestureRecognizerDirection] = [.Right, .Left, .Up, .Down] 96 | 97 | for direction in directions { 98 | let gesture = UISwipeGestureRecognizer(target: self, action: Selector("respondToSwipeGesture:")) 99 | gesture.direction = direction 100 | view.addGestureRecognizer(gesture) 101 | } 102 | 103 | let snakeBody = Body(imageNamed: "snakebody") 104 | snakeBody.row = snakeHead.row - 1 105 | snakeBody.col = snakeHead.col 106 | snakeBody.position = grid.gridPosition(snakeBody.row, col: snakeBody.col) 107 | snakeBody.nextPos = grid.gridPosition(snakeBody.row + 1, col: snakeBody.col) 108 | grid.addChild(snakeBody) 109 | 110 | mySnake.append(snakeBody) 111 | generateFruit() 112 | // our "tick" 113 | 114 | } 115 | 116 | override func touchesBegan(touches: Set, withEvent event: UIEvent?) { 117 | /* Called when a touch begins */ 118 | 119 | } 120 | 121 | override func update(currentTime: CFTimeInterval) { 122 | /* Called before each frame is rendered */ 123 | 124 | } 125 | 126 | 127 | func respondToSwipeGesture(gesture: UIGestureRecognizer) { 128 | 129 | if let swipeGesture = gesture as? UISwipeGestureRecognizer { 130 | switch swipeGesture.direction { 131 | case UISwipeGestureRecognizerDirection.Right: 132 | if snakeHead.curMove != "left"{ 133 | snakeHead.nextMove = "right" 134 | } 135 | case UISwipeGestureRecognizerDirection.Down: 136 | if snakeHead.curMove != "up" { 137 | snakeHead.nextMove = "down" 138 | } 139 | case UISwipeGestureRecognizerDirection.Left: 140 | if snakeHead.curMove != "right" { 141 | snakeHead.nextMove = "left" 142 | } 143 | case UISwipeGestureRecognizerDirection.Up: 144 | if snakeHead.curMove != "down" { 145 | snakeHead.nextMove = "up" 146 | } 147 | default: 148 | break // should never get here. 149 | } 150 | } 151 | } 152 | 153 | func generateFruit(){ 154 | let row = Int(arc4random_uniform(UInt32(gridRows-1)) + 1) 155 | let col = Int(arc4random_uniform(UInt32(gridCols-1)) + 1) 156 | apple.position = grid.gridPosition(row, col: col) 157 | apple.row = row 158 | apple.col = col 159 | } 160 | 161 | func appendBody(){ 162 | let lastBody = mySnake.last 163 | let newBody = Body(imageNamed: "snakebody") 164 | newBody.position = lastBody!.position 165 | newBody.row = lastBody!.row 166 | newBody.col = lastBody!.col 167 | newBody.nextPos = grid.gridPosition(newBody.row, col: newBody.col) 168 | mySnake.append(newBody) 169 | grid.addChild(newBody) 170 | 171 | } 172 | 173 | func ripSnake() { 174 | self.view?.paused = true 175 | UIView.animateWithDuration(2) { () -> Void in 176 | self.gameOver.alpha = 1 177 | } 178 | 179 | } 180 | 181 | 182 | func tick() { 183 | 184 | switch(snakeHead.nextMove){ 185 | case "right": 186 | snakeHead.col += 1 187 | snakeHead.curMove = "right" 188 | snakeHead.runAction(SKAction.rotateToAngle(CGFloat(M_PI * 1.5), duration: 0.1, shortestUnitArc: true)) 189 | break 190 | case "down": 191 | snakeHead.row += 1 192 | snakeHead.curMove = "down" 193 | snakeHead.runAction(SKAction.rotateToAngle(CGFloat(M_PI), duration: 0.1, shortestUnitArc: true)) 194 | break 195 | case "left": 196 | snakeHead.col -= 1 197 | snakeHead.curMove = "left" 198 | snakeHead.runAction(SKAction.rotateToAngle(CGFloat(M_PI/2.0), duration: 0.1, shortestUnitArc: true)) 199 | break 200 | case "up": 201 | snakeHead.row -= 1 202 | snakeHead.curMove = "up" 203 | snakeHead.runAction(SKAction.rotateToAngle(CGFloat(0), duration: 0.1, shortestUnitArc: true)) 204 | break 205 | default: 206 | break 207 | } 208 | 209 | 210 | snakeHead.jumped = false 211 | 212 | if snakeHead.col == gridCols{ 213 | snakeHead.col = 0 214 | snakeHead.jumped = true 215 | 216 | } else if snakeHead.col < 0{ 217 | snakeHead.col = gridCols - 1 218 | snakeHead.jumped = true 219 | } 220 | if snakeHead.row == gridRows{ 221 | snakeHead.row = 0 222 | snakeHead.jumped = true 223 | 224 | } else if snakeHead.row < 0{ 225 | snakeHead.row = gridRows - 1 226 | snakeHead.jumped = true 227 | } 228 | 229 | if snakeHead.row == apple.row && snakeHead.col == apple.col{ 230 | generateFruit() 231 | appendBody() 232 | } 233 | 234 | let moveDuration: Double = snakeHead.jumped ? 0 : 0.1 235 | 236 | snakeHead.nextPos = grid.gridPosition(snakeHead.getRow(), col: snakeHead.getCol()) // update the pos 237 | snakeHead.runAction(SKAction.moveTo(snakeHead.nextPos, duration: moveDuration)) 238 | 239 | for i in (1...mySnake.count-1).reverse(){ // start from the tail 240 | 241 | let snakeToFollow = mySnake[i-1] 242 | let snakeToMove = mySnake[i] 243 | let moveDuration: Double = snakeToMove.jumped ? 0 : 0.1 244 | 245 | snakeToMove.runAction(SKAction.moveTo(snakeToMove.nextPos, duration: moveDuration)) 246 | if snakeHead.row == snakeToMove.row && snakeHead.col == snakeToMove.col{ 247 | ripSnake() 248 | } 249 | snakeToMove.nextPos = grid.gridPosition(snakeToFollow.row, col: snakeToFollow.col) 250 | snakeToMove.row = snakeToFollow.row 251 | snakeToMove.col = snakeToFollow.col 252 | snakeToMove.jumped = snakeToFollow.jumped 253 | } 254 | 255 | 256 | 257 | } 258 | 259 | } 260 | 261 | -------------------------------------------------------------------------------- /Snakee/GameViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GameViewController.swift 3 | // Snakee 4 | // 5 | // Created by Caleb Cheng on 28/07/2016. 6 | // Copyright (c) 2016 Caleb Cheng. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SpriteKit 11 | 12 | 13 | class GameViewController: UIViewController { 14 | @IBOutlet weak var pauseButton: UIButton! 15 | var flip = true 16 | var myTimer = NSTimer() 17 | let scene = GameScene(fileNamed: "GameScene") 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | myTimer = NSTimer.scheduledTimerWithTimeInterval(0.3, target: scene!, selector: "tick", userInfo: nil, repeats: true) 21 | 22 | if (scene != nil) { 23 | // Configure the view. 24 | let skView = self.view as! SKView 25 | skView.showsFPS = true 26 | skView.showsNodeCount = true 27 | 28 | /* Sprite Kit applies additional optimizations to improve rendering performance */ 29 | skView.ignoresSiblingOrder = true 30 | 31 | /* Set the scale mode to scale to fit the window */ 32 | scene!.scaleMode = .AspectFill 33 | 34 | skView.presentScene(scene) 35 | } 36 | } 37 | 38 | @IBAction func onButtonPress(sender: UIButton) { 39 | if flip{ 40 | pauseButton.setImage(UIImage(named: "play-button-3"), forState: .Normal) 41 | scene!.view?.paused = true 42 | myTimer.invalidate() 43 | 44 | } else { 45 | pauseButton.setImage(UIImage(named: "pause-2"), forState: .Normal) 46 | scene!.view?.paused = false 47 | myTimer = NSTimer.scheduledTimerWithTimeInterval(0.3, target: scene!, selector: "tick", userInfo: nil, repeats: true) 48 | } 49 | 50 | flip = !flip 51 | 52 | } 53 | override func shouldAutorotate() -> Bool { 54 | return true 55 | } 56 | 57 | override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 58 | if UIDevice.currentDevice().userInterfaceIdiom == .Phone { 59 | return .AllButUpsideDown 60 | } else { 61 | return .All 62 | } 63 | } 64 | 65 | override func didReceiveMemoryWarning() { 66 | super.didReceiveMemoryWarning() 67 | // Release any cached data, images, etc that aren't in use. 68 | } 69 | 70 | override func prefersStatusBarHidden() -> Bool { 71 | return true 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Snakee/Grid.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Grid.swift 3 | // Snakee 4 | // 5 | // Created by Caleb Cheng on 28/07/2016. 6 | // Copyright © 2016 Caleb Cheng. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | import SpriteKit 12 | 13 | 14 | // my grid class is beast 15 | 16 | 17 | class Grid:SKSpriteNode { 18 | var rows:Int! 19 | var cols:Int! 20 | var blockSize:CGFloat! 21 | 22 | convenience init(blockSize:CGFloat,rows:Int,cols:Int, renderGrid: Bool) { 23 | let texture = Grid.gridTexture(blockSize,rows: rows, cols:cols, renderGrid: renderGrid) 24 | self.init(texture: texture, color:SKColor.clearColor(), size: texture.size()) 25 | self.blockSize = blockSize 26 | self.rows = rows 27 | self.cols = cols 28 | } 29 | 30 | override init(texture: SKTexture!, color: SKColor, size: CGSize) { 31 | super.init(texture: texture, color: color, size: size) 32 | } 33 | 34 | required init?(coder aDecoder: NSCoder) { 35 | fatalError("init(coder:) has not been implemented") 36 | } 37 | 38 | class func gridTexture(blockSize:CGFloat,rows:Int,cols:Int, renderGrid: Bool) -> SKTexture { 39 | // Add 1 to the height and width to ensure the borders are within the sprite 40 | let size = CGSize(width: CGFloat(cols)*blockSize+1.0, height: CGFloat(rows)*blockSize+1.0) 41 | UIGraphicsBeginImageContext(size) 42 | 43 | let context = UIGraphicsGetCurrentContext() 44 | let bezierPath = UIBezierPath() 45 | let offset:CGFloat = 0.5 46 | if renderGrid { 47 | // Draw vertical lines 48 | for i in 0...cols { 49 | let x = CGFloat(i)*blockSize + offset 50 | bezierPath.moveToPoint(CGPoint(x: x, y: 0)) 51 | bezierPath.addLineToPoint(CGPoint(x: x, y: size.height)) 52 | } 53 | // Draw horizontal lines 54 | for i in 0...rows { 55 | let y = CGFloat(i)*blockSize + offset 56 | bezierPath.moveToPoint(CGPoint(x: 0, y: y)) 57 | bezierPath.addLineToPoint(CGPoint(x: size.width, y: y)) 58 | } 59 | 60 | } else { 61 | bezierPath.moveToPoint(CGPoint(x:0, y: 0)) 62 | bezierPath.addLineToPoint(CGPoint(x: 0, y: size.height)) 63 | 64 | bezierPath.moveToPoint(CGPoint(x: CGFloat(cols) * blockSize + offset, y: 0)) 65 | bezierPath.addLineToPoint(CGPoint(x: size.width, y: size.height)) 66 | 67 | bezierPath.moveToPoint(CGPoint(x:0, y: 0)) 68 | bezierPath.addLineToPoint(CGPoint(x: size.width, y: 0)) 69 | 70 | bezierPath.moveToPoint(CGPoint(x: 0, y: CGFloat(rows)*blockSize + offset)) 71 | bezierPath.addLineToPoint(CGPoint(x: size.width, y: size.height)) 72 | } 73 | 74 | SKColor.greenColor().setStroke() 75 | bezierPath.lineWidth = 1.0 76 | bezierPath.stroke() 77 | CGContextAddPath(context, bezierPath.CGPath) 78 | let image = UIGraphicsGetImageFromCurrentImageContext() 79 | UIGraphicsEndImageContext() 80 | 81 | return SKTexture(image: image) 82 | } 83 | 84 | 85 | 86 | 87 | 88 | func gridPosition(row:Int, col:Int) -> CGPoint { 89 | let offset = blockSize / 2.0 90 | let x = CGFloat(col) * blockSize - (blockSize * CGFloat(cols)) / 2.0 + offset 91 | let y = CGFloat(rows - row - 1) * blockSize - (blockSize * CGFloat(rows)) / 2.0 + offset 92 | return CGPoint(x:x, y:y) 93 | } 94 | 95 | func isEmpty(row:Int, col:Int) -> Bool { 96 | return false 97 | } 98 | } -------------------------------------------------------------------------------- /Snakee/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIStatusBarHidden 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationLandscapeLeft 38 | UIInterfaceOrientationLandscapeRight 39 | 40 | UISupportedInterfaceOrientations~ipad 41 | 42 | UIInterfaceOrientationLandscapeLeft 43 | UIInterfaceOrientationLandscapeRight 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Snakee/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 29 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /Snakee/ViewController2.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController2.swift 3 | // Snakee 4 | // 5 | // Created by Vivienne Cheng on 19/08/2016. 6 | // Copyright © 2016 Caleb Cheng. All rights reserved. 7 | // 8 | 9 | 10 | import UIKit 11 | 12 | var shouldRenderGrid = false 13 | 14 | class ViewController2: UIViewController { 15 | 16 | @IBOutlet weak var renderGrid: UISwitch! 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | 20 | // Do any additional setup after loading the view. 21 | } 22 | 23 | override func didReceiveMemoryWarning() { 24 | super.didReceiveMemoryWarning() 25 | // Dispose of any resources that can be recreated. 26 | } 27 | 28 | @IBAction func renderFlipped(sender: UISwitch) { 29 | if renderGrid.on{ 30 | shouldRenderGrid = true 31 | } else { 32 | shouldRenderGrid = false 33 | } 34 | } 35 | 36 | /* 37 | // MARK: - Navigation 38 | 39 | // In a storyboard-based application, you will often want to do a little preparation before navigation 40 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 41 | // Get the new view controller using segue.destinationViewController. 42 | // Pass the selected object to the new view controller. 43 | } 44 | */ 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Snakee/pauseSceneViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // pauseSceneViewController.swift 3 | // Snakee 4 | // 5 | // Created by Vivienne Cheng on 19/08/2016. 6 | // Copyright © 2016 Caleb Cheng. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class pauseSceneViewController: UIViewController { 12 | var snakeHeads = ["snakehead", "snakehead1"] 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 24 | return snakeHeads.count 25 | } 26 | 27 | func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! { 28 | return snakeHeads[row] 29 | } 30 | 31 | func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { 32 | return 1 33 | } 34 | 35 | /* 36 | // MARK: - Navigation 37 | 38 | // In a storyboard-based application, you will often want to do a little preparation before navigation 39 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 40 | // Get the new view controller using segue.destinationViewController. 41 | // Pass the selected object to the new view controller. 42 | } 43 | */ 44 | 45 | } 46 | --------------------------------------------------------------------------------