diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Messages.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Messages.swift new file mode 100644 index 0000000..e066b5a --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Messages.swift @@ -0,0 +1,9 @@ +// +// Messages.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 12/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/SnakeHead.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/SnakeHead.swift new file mode 100644 index 0000000..14f8e5a --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/SnakeHead.swift @@ -0,0 +1,9 @@ +// +// SnakeHead.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation diff --git a/lesson08/.DS_Store b/lesson08/.DS_Store new file mode 100644 index 0000000..9f990e4 Binary files /dev/null and b/lesson08/.DS_Store differ diff --git a/lesson08/8L_RaskinSergey_snake.xcodeproj/project.pbxproj b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.pbxproj new file mode 100644 index 0000000..f383e0a --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.pbxproj @@ -0,0 +1,367 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 915D02BB23A223ED0007F011 /* EdgeBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 915D02BA23A223ED0007F011 /* EdgeBody.swift */; }; + 91CDC15D23A130E20082565D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC15C23A130E20082565D /* AppDelegate.swift */; }; + 91CDC16323A130E20082565D /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC16223A130E20082565D /* GameScene.swift */; }; + 91CDC16523A130E20082565D /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC16423A130E20082565D /* GameViewController.swift */; }; + 91CDC16823A130E20082565D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91CDC16623A130E20082565D /* Main.storyboard */; }; + 91CDC16A23A130E30082565D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 91CDC16923A130E30082565D /* Assets.xcassets */; }; + 91CDC16D23A130E30082565D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91CDC16B23A130E30082565D /* LaunchScreen.storyboard */; }; + 91CDC17523A13A350082565D /* Apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17423A13A350082565D /* Apple.swift */; }; + 91CDC17723A13EFB0082565D /* SnakeBodyPart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17623A13EFB0082565D /* SnakeBodyPart.swift */; }; + 91CDC17923A140B10082565D /* SnakeHead.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17823A140B10082565D /* SnakeHead.swift */; }; + 91CDC17B23A141730082565D /* Snake.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17A23A141730082565D /* Snake.swift */; }; + 91CDC17F23A221040082565D /* GameMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17E23A221040082565D /* GameMessages.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 915D02BA23A223ED0007F011 /* EdgeBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EdgeBody.swift; sourceTree = ""; }; + 91CDC15923A130E20082565D /* 8L_RaskinSergey_snake.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 8L_RaskinSergey_snake.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 91CDC15C23A130E20082565D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 91CDC16223A130E20082565D /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = ""; }; + 91CDC16423A130E20082565D /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; + 91CDC16723A130E20082565D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 91CDC16923A130E30082565D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 91CDC16C23A130E30082565D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 91CDC16E23A130E30082565D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 91CDC17423A13A350082565D /* Apple.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Apple.swift; sourceTree = ""; }; + 91CDC17623A13EFB0082565D /* SnakeBodyPart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnakeBodyPart.swift; sourceTree = ""; }; + 91CDC17823A140B10082565D /* SnakeHead.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnakeHead.swift; sourceTree = ""; }; + 91CDC17A23A141730082565D /* Snake.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Snake.swift; sourceTree = ""; }; + 91CDC17E23A221040082565D /* GameMessages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameMessages.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 91CDC15623A130E20082565D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 91CDC15023A130E20082565D = { + isa = PBXGroup; + children = ( + 91CDC15B23A130E20082565D /* 8L_RaskinSergey_snake */, + 91CDC15A23A130E20082565D /* Products */, + ); + sourceTree = ""; + }; + 91CDC15A23A130E20082565D /* Products */ = { + isa = PBXGroup; + children = ( + 91CDC15923A130E20082565D /* 8L_RaskinSergey_snake.app */, + ); + name = Products; + sourceTree = ""; + }; + 91CDC15B23A130E20082565D /* 8L_RaskinSergey_snake */ = { + isa = PBXGroup; + children = ( + 91CDC17E23A221040082565D /* GameMessages.swift */, + 91CDC15C23A130E20082565D /* AppDelegate.swift */, + 91CDC16223A130E20082565D /* GameScene.swift */, + 91CDC16423A130E20082565D /* GameViewController.swift */, + 91CDC16623A130E20082565D /* Main.storyboard */, + 91CDC16923A130E30082565D /* Assets.xcassets */, + 91CDC16B23A130E30082565D /* LaunchScreen.storyboard */, + 91CDC16E23A130E30082565D /* Info.plist */, + 91CDC17423A13A350082565D /* Apple.swift */, + 91CDC17623A13EFB0082565D /* SnakeBodyPart.swift */, + 91CDC17823A140B10082565D /* SnakeHead.swift */, + 91CDC17A23A141730082565D /* Snake.swift */, + 915D02BA23A223ED0007F011 /* EdgeBody.swift */, + ); + path = 8L_RaskinSergey_snake; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 91CDC15823A130E20082565D /* 8L_RaskinSergey_snake */ = { + isa = PBXNativeTarget; + buildConfigurationList = 91CDC17123A130E30082565D /* Build configuration list for PBXNativeTarget "8L_RaskinSergey_snake" */; + buildPhases = ( + 91CDC15523A130E20082565D /* Sources */, + 91CDC15623A130E20082565D /* Frameworks */, + 91CDC15723A130E20082565D /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = 8L_RaskinSergey_snake; + productName = 8L_RaskinSergey_snake; + productReference = 91CDC15923A130E20082565D /* 8L_RaskinSergey_snake.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 91CDC15123A130E20082565D /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1130; + LastUpgradeCheck = 1130; + ORGANIZATIONNAME = "raskin-sa"; + TargetAttributes = { + 91CDC15823A130E20082565D = { + CreatedOnToolsVersion = 11.3; + }; + }; + }; + buildConfigurationList = 91CDC15423A130E20082565D /* Build configuration list for PBXProject "8L_RaskinSergey_snake" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 91CDC15023A130E20082565D; + productRefGroup = 91CDC15A23A130E20082565D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 91CDC15823A130E20082565D /* 8L_RaskinSergey_snake */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 91CDC15723A130E20082565D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91CDC16823A130E20082565D /* Main.storyboard in Resources */, + 91CDC16A23A130E30082565D /* Assets.xcassets in Resources */, + 91CDC16D23A130E30082565D /* LaunchScreen.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 91CDC15523A130E20082565D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91CDC17923A140B10082565D /* SnakeHead.swift in Sources */, + 91CDC17523A13A350082565D /* Apple.swift in Sources */, + 91CDC17F23A221040082565D /* GameMessages.swift in Sources */, + 91CDC16323A130E20082565D /* GameScene.swift in Sources */, + 91CDC16523A130E20082565D /* GameViewController.swift in Sources */, + 91CDC17723A13EFB0082565D /* SnakeBodyPart.swift in Sources */, + 91CDC17B23A141730082565D /* Snake.swift in Sources */, + 91CDC15D23A130E20082565D /* AppDelegate.swift in Sources */, + 915D02BB23A223ED0007F011 /* EdgeBody.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 91CDC16623A130E20082565D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 91CDC16723A130E20082565D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 91CDC16B23A130E30082565D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 91CDC16C23A130E30082565D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 91CDC16F23A130E30082565D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.2; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 91CDC17023A130E30082565D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.2; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 91CDC17223A130E30082565D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5C3KKHP5ML; + INFOPLIST_FILE = 8L_RaskinSergey_snake/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "home.-L-RaskinSergey-snake"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 91CDC17323A130E30082565D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5C3KKHP5ML; + INFOPLIST_FILE = 8L_RaskinSergey_snake/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "home.-L-RaskinSergey-snake"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 91CDC15423A130E20082565D /* Build configuration list for PBXProject "8L_RaskinSergey_snake" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91CDC16F23A130E30082565D /* Debug */, + 91CDC17023A130E30082565D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 91CDC17123A130E30082565D /* Build configuration list for PBXNativeTarget "8L_RaskinSergey_snake" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91CDC17223A130E30082565D /* Debug */, + 91CDC17323A130E30082565D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 91CDC15123A130E20082565D /* Project object */; +} diff --git a/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..72e3bfc --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/IDEFindNavigatorScopes.plist b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/IDEFindNavigatorScopes.plist new file mode 100644 index 0000000..5dd5da8 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/IDEFindNavigatorScopes.plist @@ -0,0 +1,5 @@ + + + + + diff --git a/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..e749e0d Binary files /dev/null and b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Expressions.xcexplist b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Expressions.xcexplist new file mode 100644 index 0000000..a0bfbf1 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + diff --git a/lesson08/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/lesson08/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..5941be1 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lesson08/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist b/lesson08/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..fcf4a07 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + 8L_RaskinSergey_snake.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/lesson08/8L_RaskinSergey_snake/.DS_Store b/lesson08/8L_RaskinSergey_snake/.DS_Store new file mode 100644 index 0000000..53e21e7 Binary files /dev/null and b/lesson08/8L_RaskinSergey_snake/.DS_Store differ diff --git a/lesson08/8L_RaskinSergey_snake/AppDelegate.swift b/lesson08/8L_RaskinSergey_snake/AppDelegate.swift new file mode 100644 index 0000000..6fad8c1 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/AppDelegate.swift @@ -0,0 +1,41 @@ +// +// AppDelegate.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + // 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. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // 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. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // 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. + } + + +} + diff --git a/lesson08/8L_RaskinSergey_snake/Apple.swift b/lesson08/8L_RaskinSergey_snake/Apple.swift new file mode 100644 index 0000000..275210d --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/Apple.swift @@ -0,0 +1,30 @@ +// +// Apple.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class Apple: SKShapeNode { + convenience init(position: CGPoint) { + self.init() + + path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 10, height:10 )).cgPath + + fillColor = UIColor.red + strokeColor = UIColor.red + lineWidth = 5 + + self.position = position + + // придаем яблоку параметры физического тела + self.physicsBody = SKPhysicsBody(circleOfRadius: 10.0, center: CGPoint(x:5, y:5)) + self.physicsBody?.categoryBitMask = CollisionCategory.Apple + } + +} + diff --git a/lesson08/8L_RaskinSergey_snake/Assets.xcassets/AppIcon.appiconset/Contents.json b/lesson08/8L_RaskinSergey_snake/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/lesson08/8L_RaskinSergey_snake/Assets.xcassets/Contents.json b/lesson08/8L_RaskinSergey_snake/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/lesson08/8L_RaskinSergey_snake/Base.lproj/LaunchScreen.storyboard b/lesson08/8L_RaskinSergey_snake/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lesson08/8L_RaskinSergey_snake/Base.lproj/Main.storyboard b/lesson08/8L_RaskinSergey_snake/Base.lproj/Main.storyboard new file mode 100644 index 0000000..2cc971a --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lesson08/8L_RaskinSergey_snake/EdgeBody.swift b/lesson08/8L_RaskinSergey_snake/EdgeBody.swift new file mode 100644 index 0000000..f3179d0 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/EdgeBody.swift @@ -0,0 +1,37 @@ +// +// EdgeBody.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 12/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class EdgeBody: SKShapeNode{ + + + init(atPoint point: CGPoint){ + super.init() + + // path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: diametr, height: diametr)).cgPath + path = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 100, height: 100)).cgPath + + fillColor = UIColor.green + strokeColor = UIColor.green + + lineWidth = 5 + self.position = point + +// self.physicsBody = SKPhysicsBody(circleOfRadius: CGFloat(diametr-4), center: CGPoint(x: 5, y: 5)) + self.physicsBody = SKPhysicsBody(edgeLoopFrom: (path!)) + self.physicsBody?.isDynamic = true + self.physicsBody?.categoryBitMask = CollisionCategory.EdgeBody + self.physicsBody?.contactTestBitMask = CollisionCategory.SnakeHead | CollisionCategory.Apple + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/lesson08/8L_RaskinSergey_snake/GameMessages.swift b/lesson08/8L_RaskinSergey_snake/GameMessages.swift new file mode 100644 index 0000000..bb6e2ef --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/GameMessages.swift @@ -0,0 +1,28 @@ +// +// Messages.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 12/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import UIKit +import Foundation + +class GameMessage :UIViewController { + + convenience init (titleText: String, messageText:String) { + + self.init() + + // Создаем контроллер + let alert = UIAlertController(title: titleText, message: messageText, preferredStyle: .alert) + // Создаем кнопку для UIAlertController + let action = UIAlertAction(title: "OK", style: .cancel, handler: nil) + // Добавляем кнопку на UIAlertController + alert.addAction(action) + // Показываем UIAlertController + present(alert, animated: true, completion: nil) + } //convenience init + +} diff --git a/lesson08/8L_RaskinSergey_snake/GameScene.swift b/lesson08/8L_RaskinSergey_snake/GameScene.swift new file mode 100644 index 0000000..8ccfe55 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/GameScene.swift @@ -0,0 +1,263 @@ +// +// GameScene.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import SpriteKit +import GameplayKit + +struct CollisionCategory{ + static let Snake: UInt32 = 0x1 << 0 + static let SnakeHead:UInt32 = 0x1 << 1 + static let Apple:UInt32 = 0x1 << 2 + static let EdgeBody:UInt32 = 0x1 << 3 +} + +class GameScene: SKScene { + + var snake:Snake? + + //private var label : SKLabelNode? + private var spinnyNode : SKShapeNode? + private var isEndGame: Bool = false + + let shiftForButton:CGFloat = 45 + //края игры + private var xStartPosition:CGFloat = 0.0 + private var yStartPosition:CGFloat = 0.0 + private var gameRectWidth:CGFloat = 0.0 + private var gameRectHeight:CGFloat = 0.0 + private var gameRect:CGRect = CGRect(x: 0, y: 0, width: 0, height: 0) + //текстовое поле в центре экрана + var risedTextNode = SKLabelNode(fontNamed: "Chalkduster") + var risedScoreNode = SKLabelNode(fontNamed: "Chalkduster") + + + //счет игры + var score:Int = 0 + + var apple : SKShapeNode? + + override func didMove(to view: SKView) { + // первое появление сцены на экране + backgroundColor = SKColor.black + + self.physicsWorld.gravity = CGVector(dx: 0, dy: 0) + self.physicsWorld.contactDelegate = self + self.physicsBody = SKPhysicsBody(edgeLoopFrom: frame) + self.physicsBody?.allowsRotation = false + + view.showsPhysics = true +////////// +////////// кнопка поворачивает змейку против часовой стрелки +///////// + let leftCounterClockwiseButton = SKShapeNode() + //форма кнопки - круглая + leftCounterClockwiseButton.path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 45, height: 45)).cgPath + //координаты размещения нашей кнопки + leftCounterClockwiseButton.position = CGPoint(x: view.scene!.frame.minX+30, y: view.scene!.frame.minY+30) // 30 - отступ от нижнего левого угла экрана + //цвет кнопки + leftCounterClockwiseButton.fillColor = UIColor.gray + //цвет рамки + leftCounterClockwiseButton.strokeColor = UIColor.gray + //ширина + leftCounterClockwiseButton.lineWidth = 10 + //имя кнопки + leftCounterClockwiseButton.name = "leftCounterClockwiseButton" + //добавляем на экран + self.addChild(leftCounterClockwiseButton) + +////////// +//////////  кнопка поворачивает змейку по часовой стрелки +///////// + let clockWiseButton = SKShapeNode() + //форма кнопки - круглая + clockWiseButton.path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 45, height: 45)).cgPath + //координаты размещения нашей кнопки + clockWiseButton.position = CGPoint(x: view.scene!.frame.maxX-80, y: view.scene!.frame.minY+30) // 30 - отступ от нижнего левого угла экрана + //цвет кнопки + clockWiseButton.fillColor = UIColor.gray + //цвет рамки + clockWiseButton.strokeColor = UIColor.gray + //ширина + clockWiseButton.lineWidth = 10 + //имя кнопки + clockWiseButton.name = "clockWiseButton" + self.addChild(clockWiseButton) + + //края сцены c учетом кнопок + xStartPosition = view.scene!.frame.minX + yStartPosition = view.scene!.frame.minY+shiftForButton + gameRectWidth = view.scene!.frame.maxX - xStartPosition + gameRectHeight = view.scene!.frame.maxY - yStartPosition - 100 + + gameRect = CGRect(x: xStartPosition, y: yStartPosition, width: gameRectWidth, height: gameRectHeight) + +////////// +//////// физический объект прямоугольник с краями игры, касание которого приводит к окончанию игры +/////// + let quad = SKShapeNode(rect: gameRect) + quad.position = CGPoint(x:xStartPosition, y: yStartPosition) // задаем позицию. + quad.lineWidth = 4 // задаем размер линий. + quad.strokeColor = UIColor.green // задаем цвет контура. + quad.fillColor = UIColor.black // задаем цвет внутренности. + + quad.physicsBody = SKPhysicsBody(edgeLoopFrom: gameRect) + quad.physicsBody?.categoryBitMask = CollisionCategory.EdgeBody //края экрана + quad.physicsBody?.collisionBitMask = CollisionCategory.Snake|CollisionCategory.SnakeHead + quad.name = "Quad" // задаем имя. + self.addChild(quad) // добавляем наш объект на нашу сцену. + +/////////////// + ////////// // текст сообщения о конце игры +//////////// + risedTextNode.position = CGPoint(x: view.scene!.frame.midX, y: view.scene!.frame.midY) // задаем позицию. + risedTextNode.fontSize = 18; // задаем размер шрифта. + risedTextNode.fontColor = UIColor.white // задаем цвет шрифта. + risedTextNode.color = UIColor.blue // задаем цвет (Нужен для сочетание с colorBlendFactor). + risedTextNode.colorBlendFactor = 0.5 // задаем colorBlendFactor (0.0 - 1.0) + risedTextNode.numberOfLines = 3 + risedTextNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center // задаем способ выравнивание текста. + risedTextNode.name = "First" // задаем имя спрайта + // !!! но на экран не выводим раньше времени, пока игра не закончилась + +/////////////// +////////// // //текст сообщения о счете игры +//////////// + risedScoreNode.position = CGPoint(x: view.scene!.frame.midX, y: view.scene!.frame.minY+30) // задаем позицию = между двумя кнопками + risedScoreNode.fontSize = 18; // задаем размер шрифта. + risedScoreNode.fontColor = UIColor.white // задаем цвет шрифта. + risedScoreNode.color = UIColor.blue // задаем цвет (Нужен для сочетание с colorBlendFactor). + risedScoreNode.colorBlendFactor = 0.5 // задаем colorBlendFactor (0.0 - 1.0) + risedScoreNode.text = "счет: \(score)" // задаем текст. + risedScoreNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center // задаем способ выравнивание текста. + risedScoreNode.name = "Score" // задаем имя спрайта + self.addChild(risedScoreNode) // добавляем наш спрайт на нашу сцену. + //инициализация змейки и яблока + startGame() + + }//func didMove + + func createApple(){ + var randX:UInt32 + randX = arc4random_uniform(UInt32(gameRect.maxX)) + if randX >= 410{randX = 409} //чтобы яблоко не попадало за пределы прямоугольника + var randY:UInt32 + randY = arc4random_uniform(UInt32(gameRect.maxY)) + if randY <= 100{randY = 101} //чтобы яблоко не попадало за пределы прямоугольника + + + apple = Apple(position: CGPoint(x: CGFloat(randX), y: CGFloat(randY))) + //apple = Apple(position: CGPoint(x: CGFloat(410), y: CGFloat(796))) + self.addChild(apple!) + + //отладочный принт + // print("randX = \(randX),randY = \(randY) gameRect.minX = \(gameRect.minX), gameRect.maxX= \(gameRect.maxX), gameRect.minY = \(gameRect.minY),gameRect.maxY = \(gameRect.maxY), gameRect.width = \(gameRect.width), gameRect.height = \(gameRect.height),xStartPosition = \(xStartPosition), yStartPosition = \(yStartPosition), shiftForButton = \(shiftForButton)") + } + +override func touchesBegan(_ touches: Set, with event: UIEvent?) { + + for touch in touches{ + let touchLocation = touch.location(in: self) + guard let touchesNode = self.atPoint(touchLocation) as? SKShapeNode, touchesNode.name == "leftCounterClockwiseButton" || touchesNode.name == "clockWiseButton" else{ + return + } + + touchesNode.fillColor = UIColor.green + + //если конец игры наступил, то левая кнопка - начинает игру заново + if touchesNode.name == "leftCounterClockwiseButton"{ + if isEndGame{ + isEndGame = false + startGame() + }else{ + snake!.moveCounterClockwise() + } + }else if touchesNode.name == "clockWiseButton"{ + snake!.moveClockwise() + } + } + }//func touchesBegan + + override func touchesEnded(_ touches: Set, with event: UIEvent?) { + //если касаемся кнопки - красим кнопку в зеленый цвет + for touch in touches{ + let touchLocation = touch.location(in: self) + guard let touchesNode = self.atPoint(touchLocation) as? SKShapeNode, touchesNode.name == "leftCounterClockwiseButton" || touchesNode.name == "clockWiseButton" else{ + return + } + touchesNode.fillColor = UIColor.gray + } + + }//func touchesEnded + + override func touchesCancelled(_ touches: Set, with event: UIEvent?) { + } + + override func update(_ currentTime: TimeInterval) { + // если не выставлен флаг конец игры, то змея двигается. Иначе - нет + if !isEndGame{ + snake!.move() + } + } + +//функция инициализирует элементы сцены и вначале и когда надо начать новую игру после поражения + func startGame(){ + risedTextNode.removeFromParent() + snake?.removeFromParent() + apple?.removeFromParent() + score = 0 + riseScoreMessage(iScore: score) + createApple() + // + snake = Snake(atPoint: CGPoint(x: (view?.scene!.frame.midX)!, y: (view?.scene!.frame.midY)!)) + + self.addChild(snake!) + }// func startGame + + func riseMessage(messageText:String) { + risedTextNode.text = messageText // задаем текст. + self.addChild(risedTextNode) // добавляем наш спрайт на нашу сцену. + }// func riseMessage + + func riseScoreMessage(iScore: Int) { + risedScoreNode.text = "счет: \(iScore)" // задаем текст. + }// func riseScoreMessage +}//class GameScene + + +extension GameScene: SKPhysicsContactDelegate { + func didBegin(_ contact: SKPhysicsContact) { + let bodyes = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask + let collisionObject = bodyes ^ CollisionCategory.SnakeHead + var appleNode: SKNode? + + appleNode = contact.bodyA.node is Apple ? contact.bodyA.node : contact.bodyB.node + + switch collisionObject { + case CollisionCategory.Apple: //голова столкнулась с яблоком + + snake?.addBodyPart() + + appleNode?.removeFromParent() + score += 1 + riseScoreMessage(iScore: score) + createApple() + + case CollisionCategory.EdgeBody: + isEndGame = true + appleNode?.removeFromParent() + //к сожалению, для многострочного текста надо вручную будет выставлять координаты каждой последующей строки + //решил код не перегружать, поэтому текст простой + riseMessage(messageText: "Конец игры! Нажмите левую кнопку") + + //передаем управление функции нажатия левой кнопки -> func touchesBegan + + default: break + + }//switch + }//func +}//extension diff --git a/lesson08/8L_RaskinSergey_snake/GameViewController.swift b/lesson08/8L_RaskinSergey_snake/GameViewController.swift new file mode 100644 index 0000000..af1d6cb --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/GameViewController.swift @@ -0,0 +1,50 @@ +// +// GameViewController.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import UIKit +import SpriteKit +import GameplayKit + +class GameViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + //создали сцену для игры + let scene = GameScene(size: view.bounds.size) + //создали экран + let skView = view as! SKView + + //показывать кол-во объектов + skView.showsNodeCount = true + skView.showsFPS = true + skView.ignoresSiblingOrder = true + //растянули на весь экран + scene.scaleMode = .resizeFill + //отправили сцену на экран + skView.presentScene(scene) + + + } + + override var shouldAutorotate: Bool { + return true + } + + override var supportedInterfaceOrientations: UIInterfaceOrientationMask { + if UIDevice.current.userInterfaceIdiom == .phone { + return .allButUpsideDown + } else { + return .all + } + } + + override var prefersStatusBarHidden: Bool { + return true + } +} diff --git a/lesson08/8L_RaskinSergey_snake/Info.plist b/lesson08/8L_RaskinSergey_snake/Info.plist new file mode 100644 index 0000000..870f784 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarHidden + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/lesson08/8L_RaskinSergey_snake/Snake.swift b/lesson08/8L_RaskinSergey_snake/Snake.swift new file mode 100644 index 0000000..dddea0d --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/Snake.swift @@ -0,0 +1,81 @@ +// +// Snake.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class Snake: SKShapeNode { + + let moveSpeed = 125 + var angle: CGFloat = 0.0 + + + var body = [SnakeBodyPart]() + + convenience init(atPoint point: CGPoint){ + self.init() + + let head = SnakeHead(atPoint: point) + + body.append(head) + addChild(head) + } + + func addBodyPart() { + let newBodyPart = SnakeBodyPart(atPoint: CGPoint(x: body[0].position.x, y: body[0].position.y)) + + body.append(newBodyPart) + + addChild(newBodyPart) + } + +// func removeBodyPart(){ +// body = [SnakeBodyPart]() +// +// } + + + func move(){ + guard !body.isEmpty else {return} + let head = body[0] + + moveHead(head) + + for index in (0.. 0 { + let prevBodyPart = body[index-1] + let curBodyPart = body[index] + + moveBodyPart(prevBodyPart,c: curBodyPart) + } + + } + + func moveHead(_ head: SnakeBodyPart){ + let dx = CGFloat(moveSpeed) * sin(angle) + let dy = CGFloat(moveSpeed) * cos(angle) + + let nextPosition = CGPoint(x: head.position.x + dx, y: head.position.y + dy) + let moveAction = SKAction.move(to: nextPosition, duration: 1.0) + + head.run(moveAction) + } + + func moveBodyPart(_ p: SnakeBodyPart, c: SnakeBodyPart){ + let moveAction = SKAction.move(to: CGPoint(x: p.position.x, y: p.position.y), duration: 0.1) + + c.run(moveAction) + } + + func moveClockwise(){ + angle += CGFloat(Double.pi/2) + } + + func moveCounterClockwise(){ + angle -= CGFloat(Double.pi/2) + } +} diff --git a/lesson08/8L_RaskinSergey_snake/SnakeBodyPart.swift b/lesson08/8L_RaskinSergey_snake/SnakeBodyPart.swift new file mode 100644 index 0000000..e7d8186 --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/SnakeBodyPart.swift @@ -0,0 +1,35 @@ +// +// SnakeBodyPart.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class SnakeBodyPart: SKShapeNode{ + let diametr = 10 + + init(atPoint point: CGPoint){ + super.init() + + path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: diametr, height: diametr)).cgPath + + fillColor = UIColor.green + strokeColor = UIColor.green + + lineWidth = 5 + self.position = point + + self.physicsBody = SKPhysicsBody(circleOfRadius: CGFloat(diametr-4), center: CGPoint(x: 5, y: 5)) + self.physicsBody?.isDynamic = true + self.physicsBody?.categoryBitMask = CollisionCategory.Snake + self.physicsBody?.contactTestBitMask = CollisionCategory.EdgeBody | CollisionCategory.Apple + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/lesson08/8L_RaskinSergey_snake/SnakeHead.swift b/lesson08/8L_RaskinSergey_snake/SnakeHead.swift new file mode 100644 index 0000000..2d37cee --- /dev/null +++ b/lesson08/8L_RaskinSergey_snake/SnakeHead.swift @@ -0,0 +1,24 @@ +// +// SnakeHead.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class SnakeHead: SnakeBodyPart { + override init(atPoint point: CGPoint) { + super.init(atPoint: point) + + self.physicsBody?.categoryBitMask = CollisionCategory.SnakeHead + + self.physicsBody?.contactTestBitMask = CollisionCategory.EdgeBody | CollisionCategory.Apple | CollisionCategory.Snake + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +}