diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f045b46c --- /dev/null +++ b/.gitignore @@ -0,0 +1,217 @@ +######################### +# .gitignore file for Xcode4 and Xcode5 Source projects +# +# Apple bugs, waiting for Apple to fix/respond: +# +# 15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation? +# +# Version 2.6 +# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects +# +# 2015 updates: +# - Fixed typo in "xccheckout" line - thanks to @lyck for pointing it out! +# - Fixed the .idea optional ignore. Thanks to @hashier for pointing this out +# - Finally added "xccheckout" to the ignore. Apple still refuses to answer support requests about this, but in practice it seems you should ignore it. +# - minor tweaks from Jona and Coeur (slightly more precise xc* filtering/names) +# 2014 updates: +# - appended non-standard items DISABLED by default (uncomment if you use those tools) +# - removed the edit that an SO.com moderator made without bothering to ask me +# - researched CocoaPods .lock more carefully, thanks to Gokhan Celiker +# 2013 updates: +# - fixed the broken "save personal Schemes" +# - added line-by-line explanations for EVERYTHING (some were missing) +# +# NB: if you are storing "built" products, this WILL NOT WORK, +# and you should use a different .gitignore (or none at all) +# This file is for SOURCE projects, where there are many extra +# files that we want to exclude +# +######################### + +##### +# OS X temporary files that should never be committed +# +# c.f. http://www.westwind.com/reference/os-x/invisibles.html + +.DS_Store + +# c.f. http://www.westwind.com/reference/os-x/invisibles.html + +.Trashes + +# c.f. http://www.westwind.com/reference/os-x/invisibles.html + +*.swp + +# +# *.lock - this is used and abused by many editors for many different things. +# For the main ones I use (e.g. Eclipse), it should be excluded +# from source-control, but YMMV. +# (lock files are usually local-only file-synchronization on the local FS that should NOT go in git) +# c.f. the "OPTIONAL" section at bottom though, for tool-specific variations! +# +# In particular, if you're using CocoaPods, you'll want to comment-out this line: +*.lock + + +# +# profile - REMOVED temporarily (on double-checking, I can't find it in OS X docs?) +#profile + + +#### +# Xcode temporary files that should never be committed +# +# NB: NIB/XIB files still exist even on Storyboard projects, so we want this... + +*~.nib + + +#### +# Xcode build files - +# +# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData" + +DerivedData/ + +# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build" + +build/ + + +##### +# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups) +# +# This is complicated: +# +# SOMETIMES you need to put this file in version control. +# Apple designed it poorly - if you use "custom executables", they are +# saved in this file. +# 99% of projects do NOT use those, so they do NOT want to version control this file. +# ..but if you're in the 1%, comment out the line "*.pbxuser" + +# .pbxuser: http://lists.apple.com/archives/xcode-users/2004/Jan/msg00193.html + +*.pbxuser + +# .mode1v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html + +*.mode1v3 + +# .mode2v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html + +*.mode2v3 + +# .perspectivev3: http://stackoverflow.com/questions/5223297/xcode-projects-what-is-a-perspectivev3-file + +*.perspectivev3 + +# NB: also, whitelist the default ones, some projects need to use these +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + + +#### +# Xcode 4 - semi-personal settings +# +# Apple Shared data that Apple put in the wrong folder +# c.f. http://stackoverflow.com/a/19260712/153422 +# FROM ANSWER: Apple says "don't ignore it" +# FROM COMMENTS: Apple is wrong; Apple code is too buggy to trust; there are no known negative side-effects to ignoring Apple's unofficial advice and instead doing the thing that actively fixes bugs in Xcode +# Up to you, but ... current advice: ignore it. +*.xccheckout + +# +# +# OPTION 1: --------------------------------- +# throw away ALL personal settings (including custom schemes! +# - unless they are "shared") +# As per build/ and DerivedData/, this ought to have a trailing slash +# +# NB: this is exclusive with OPTION 2 below +xcuserdata/ + +# OPTION 2: --------------------------------- +# get rid of ALL personal settings, but KEEP SOME OF THEM +# - NB: you must manually uncomment the bits you want to keep +# +# NB: this *requires* git v1.8.2 or above; you may need to upgrade to latest OS X, +# or manually install git over the top of the OS X version +# NB: this is exclusive with OPTION 1 above +# +#xcuserdata/**/* + +# (requires option 2 above): Personal Schemes +# +#!xcuserdata/**/xcschemes/* + +#### +# Xcode 4 workspaces - more detailed +# +# Workspaces are important! They are a core feature of Xcode - don't exclude them :) +# +# Workspace layout is quite spammy. For reference: +# +# /(root)/ +# /(project-name).xcodeproj/ +# project.pbxproj +# /project.xcworkspace/ +# contents.xcworkspacedata +# /xcuserdata/ +# /(your name)/xcuserdatad/ +# UserInterfaceState.xcuserstate +# /xcshareddata/ +# /xcschemes/ +# (shared scheme name).xcscheme +# /xcuserdata/ +# /(your name)/xcuserdatad/ +# (private scheme).xcscheme +# xcschememanagement.plist +# +# + +#### +# Xcode 4 - Deprecated classes +# +# Allegedly, if you manually "deprecate" your classes, they get moved here. +# +# We're using source-control, so this is a "feature" that we do not want! + +*.moved-aside + +#### +# OPTIONAL: Some well-known tools that people use side-by-side with Xcode / iOS development +# +# NB: I'd rather not include these here, but gitignore's design is weak and doesn't allow +# modular gitignore: you have to put EVERYTHING in one file. +# +# COCOAPODS: +# +# c.f. http://guides.cocoapods.org/using/using-cocoapods.html#what-is-a-podfilelock +# c.f. http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control +# +#!Podfile.lock +# +# RUBY: +# +# c.f. http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/ +# +#!Gemfile.lock +# +# IDEA: +# +# c.f. https://www.jetbrains.com/objc/help/managing-projects-under-version-control.html?search=workspace.xml +# +#.idea/workspace.xml +# +# TEXTMATE: +# +# -- UNVERIFIED: c.f. http://stackoverflow.com/a/50283/153422 +# +#tm_build_errors + +#### +# UNKNOWN: recommended by others, but I can't discover what these files are +# \ No newline at end of file diff --git a/star-dash/.swiftlint.yml b/star-dash/.swiftlint.yml new file mode 100644 index 00000000..5310eee9 --- /dev/null +++ b/star-dash/.swiftlint.yml @@ -0,0 +1,83 @@ +excluded: + - Pods + +opt_in_rules: + - anyobject_protocol + - array_init + - attributes + - closure_body_length + - closure_end_indentation + - closure_spacing + - collection_alignment + - conditional_returns_on_newline + - contains_over_filter_count + - contains_over_filter_is_empty + - contains_over_first_not_nil + - contains_over_range_nil_comparison + - empty_collection_literal + - empty_count + - empty_string + - empty_xctest_method + - expiring_todo + - explicit_init + - explicit_self + - fallthrough + - fatal_error_message + - file_name + - first_where + - flatmap_over_map_reduce + - function_default_parameter_at_end + - identical_operands + - implicit_return + - joined_default_parameter + - last_where + - legacy_multiple + - legacy_random + - lower_acl_than_parent + - modifier_order + - nimble_operator + - no_extension_access_modifier + - nslocalizedstring_key + - nslocalizedstring_require_bundle + - number_separator + - object_literal + - operator_usage_whitespace + - overridden_super_call + - override_in_extension + - pattern_matching_keywords + - private_action + - private_outlet + - prohibited_super_call + - quick_discouraged_call + - quick_discouraged_focused_test + - quick_discouraged_pending_test + - reduce_into + - redundant_nil_coalescing + - redundant_type_annotation + - required_enum_case + - single_test_class + - sorted_first_last + - static_operator + - strong_iboutlet + - switch_case_on_newline + - toggle_bool + - unavailable_function + - unneeded_parentheses_in_closure_argument + - unowned_variable_capture + - untyped_error_in_catch + - unused_declaration + - unused_import + - vertical_parameter_alignment_on_call + - xct_specific_matcher + - yoda_condition + +disabled_rules: + - attributes + - identifier_name + - multiple_closures_with_trailing_closure # for e.g. SwiftUI buttons + - todo + - type_name + +line_length: + warning: 120 + error: 150 diff --git a/star-dash/star-dash.xcodeproj/project.pbxproj b/star-dash/star-dash.xcodeproj/project.pbxproj index 1d0d7ac0..dabe59c5 100644 --- a/star-dash/star-dash.xcodeproj/project.pbxproj +++ b/star-dash/star-dash.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 142D9F8F2BA15FBB005FE9E0 /* .swiftlint.yml in Resources */ = {isa = PBXBuildFile; fileRef = 142D9F8E2BA15FBB005FE9E0 /* .swiftlint.yml */; }; 4E630EF62B9F7E070008F887 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF52B9F7E070008F887 /* AppDelegate.swift */; }; 4E630EF82B9F7E070008F887 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF72B9F7E070008F887 /* SceneDelegate.swift */; }; 4E630EFA2B9F7E070008F887 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF92B9F7E070008F887 /* ViewController.swift */; }; @@ -16,6 +17,20 @@ 4E630F0D2B9F7E090008F887 /* star_dashTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F0C2B9F7E090008F887 /* star_dashTests.swift */; }; 4E630F172B9F7E090008F887 /* star_dashUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F162B9F7E090008F887 /* star_dashUITests.swift */; }; 4E630F192B9F7E090008F887 /* star_dashUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F182B9F7E090008F887 /* star_dashUITestsLaunchTests.swift */; }; + 4E630F272B9F7E770008F887 /* Entity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F262B9F7E770008F887 /* Entity.swift */; }; + 4E630F2A2B9F7EF60008F887 /* PositionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F292B9F7EF60008F887 /* PositionComponent.swift */; }; + 4E630F2C2B9F7F460008F887 /* Component.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F2B2B9F7F460008F887 /* Component.swift */; }; + 4E630F2E2B9F81850008F887 /* HealthComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F2D2B9F81850008F887 /* HealthComponent.swift */; }; + 4E630F302B9F83DE0008F887 /* SpriteComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F2F2B9F83DE0008F887 /* SpriteComponent.swift */; }; + 4E630F322B9F887C0008F887 /* PhysicsComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F312B9F887C0008F887 /* PhysicsComponent.swift */; }; + 4E630F342B9F8FC00008F887 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F332B9F8FC00008F887 /* Player.swift */; }; + 4E630F372B9F91DE0008F887 /* PlayerSprite.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F362B9F91DE0008F887 /* PlayerSprite.swift */; }; + 4E630F392B9F943B0008F887 /* EntityManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630F382B9F943B0008F887 /* EntityManager.swift */; }; + 4E86605C2BA095460035530D /* Monster.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E86605B2BA095460035530D /* Monster.swift */; }; + 4E86605F2BA095E30035530D /* Collectible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E86605E2BA095E30035530D /* Collectible.swift */; }; + 4E8660622BA0964A0035530D /* Obstacle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8660612BA0964A0035530D /* Obstacle.swift */; }; + 4E8660642BA096600035530D /* Tool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8660632BA096600035530D /* Tool.swift */; }; + 4E8660662BA097D40035530D /* PhysicsConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8660652BA097D40035530D /* PhysicsConstants.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -36,6 +51,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 142D9F8E2BA15FBB005FE9E0 /* .swiftlint.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.yaml; path = .swiftlint.yml; sourceTree = ""; }; 4E630EF22B9F7E070008F887 /* star-dash.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "star-dash.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 4E630EF52B9F7E070008F887 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 4E630EF72B9F7E070008F887 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -49,6 +65,20 @@ 4E630F122B9F7E090008F887 /* star-dashUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "star-dashUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 4E630F162B9F7E090008F887 /* star_dashUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = star_dashUITests.swift; sourceTree = ""; }; 4E630F182B9F7E090008F887 /* star_dashUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = star_dashUITestsLaunchTests.swift; sourceTree = ""; }; + 4E630F262B9F7E770008F887 /* Entity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Entity.swift; sourceTree = ""; }; + 4E630F292B9F7EF60008F887 /* PositionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionComponent.swift; sourceTree = ""; }; + 4E630F2B2B9F7F460008F887 /* Component.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Component.swift; sourceTree = ""; }; + 4E630F2D2B9F81850008F887 /* HealthComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthComponent.swift; sourceTree = ""; }; + 4E630F2F2B9F83DE0008F887 /* SpriteComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpriteComponent.swift; sourceTree = ""; }; + 4E630F312B9F887C0008F887 /* PhysicsComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhysicsComponent.swift; sourceTree = ""; }; + 4E630F332B9F8FC00008F887 /* Player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Player.swift; sourceTree = ""; }; + 4E630F362B9F91DE0008F887 /* PlayerSprite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerSprite.swift; sourceTree = ""; }; + 4E630F382B9F943B0008F887 /* EntityManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntityManager.swift; sourceTree = ""; }; + 4E86605B2BA095460035530D /* Monster.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Monster.swift; sourceTree = ""; }; + 4E86605E2BA095E30035530D /* Collectible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Collectible.swift; sourceTree = ""; }; + 4E8660612BA0964A0035530D /* Obstacle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Obstacle.swift; sourceTree = ""; }; + 4E8660632BA096600035530D /* Tool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tool.swift; sourceTree = ""; }; + 4E8660652BA097D40035530D /* PhysicsConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhysicsConstants.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -82,6 +112,7 @@ 4E630EF42B9F7E070008F887 /* star-dash */, 4E630F0B2B9F7E090008F887 /* star-dashTests */, 4E630F152B9F7E090008F887 /* star-dashUITests */, + 142D9F8E2BA15FBB005FE9E0 /* .swiftlint.yml */, 4E630EF32B9F7E070008F887 /* Products */, ); sourceTree = ""; @@ -99,6 +130,9 @@ 4E630EF42B9F7E070008F887 /* star-dash */ = { isa = PBXGroup; children = ( + 4E86605D2BA095CC0035530D /* Constants */, + 4E630F352B9F91C20008F887 /* Enums */, + 4E630F252B9F7E500008F887 /* Entities */, 4E630EF52B9F7E070008F887 /* AppDelegate.swift */, 4E630EF72B9F7E070008F887 /* SceneDelegate.swift */, 4E630EF92B9F7E070008F887 /* ViewController.swift */, @@ -127,6 +161,57 @@ path = "star-dashUITests"; sourceTree = ""; }; + 4E630F252B9F7E500008F887 /* Entities */ = { + isa = PBXGroup; + children = ( + 4E8660602BA0961F0035530D /* GameEntities */, + 4E630F282B9F7EC20008F887 /* Components */, + 4E630F262B9F7E770008F887 /* Entity.swift */, + 4E630F382B9F943B0008F887 /* EntityManager.swift */, + ); + path = Entities; + sourceTree = ""; + }; + 4E630F282B9F7EC20008F887 /* Components */ = { + isa = PBXGroup; + children = ( + 4E630F292B9F7EF60008F887 /* PositionComponent.swift */, + 4E630F2B2B9F7F460008F887 /* Component.swift */, + 4E630F2D2B9F81850008F887 /* HealthComponent.swift */, + 4E630F2F2B9F83DE0008F887 /* SpriteComponent.swift */, + 4E630F312B9F887C0008F887 /* PhysicsComponent.swift */, + ); + path = Components; + sourceTree = ""; + }; + 4E630F352B9F91C20008F887 /* Enums */ = { + isa = PBXGroup; + children = ( + 4E630F362B9F91DE0008F887 /* PlayerSprite.swift */, + ); + path = Enums; + sourceTree = ""; + }; + 4E86605D2BA095CC0035530D /* Constants */ = { + isa = PBXGroup; + children = ( + 4E8660652BA097D40035530D /* PhysicsConstants.swift */, + ); + path = Constants; + sourceTree = ""; + }; + 4E8660602BA0961F0035530D /* GameEntities */ = { + isa = PBXGroup; + children = ( + 4E630F332B9F8FC00008F887 /* Player.swift */, + 4E86605B2BA095460035530D /* Monster.swift */, + 4E86605E2BA095E30035530D /* Collectible.swift */, + 4E8660612BA0964A0035530D /* Obstacle.swift */, + 4E8660632BA096600035530D /* Tool.swift */, + ); + path = GameEntities; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -137,6 +222,7 @@ 4E630EEE2B9F7E070008F887 /* Sources */, 4E630EEF2B9F7E070008F887 /* Frameworks */, 4E630EF02B9F7E070008F887 /* Resources */, + 142D9F8D2BA15F91005FE9E0 /* SwiftLint */, ); buildRules = ( ); @@ -231,6 +317,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 142D9F8F2BA15FBB005FE9E0 /* .swiftlint.yml in Resources */, 4E630F022B9F7E090008F887 /* LaunchScreen.storyboard in Resources */, 4E630EFF2B9F7E090008F887 /* Assets.xcassets in Resources */, 4E630EFD2B9F7E070008F887 /* Main.storyboard in Resources */, @@ -253,14 +340,49 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 142D9F8D2BA15F91005FE9E0 /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 4E630EEE2B9F7E070008F887 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4E630F272B9F7E770008F887 /* Entity.swift in Sources */, + 4E630F2C2B9F7F460008F887 /* Component.swift in Sources */, + 4E8660622BA0964A0035530D /* Obstacle.swift in Sources */, + 4E8660642BA096600035530D /* Tool.swift in Sources */, + 4E630F392B9F943B0008F887 /* EntityManager.swift in Sources */, + 4E630F302B9F83DE0008F887 /* SpriteComponent.swift in Sources */, + 4E86605F2BA095E30035530D /* Collectible.swift in Sources */, + 4E8660662BA097D40035530D /* PhysicsConstants.swift in Sources */, 4E630EFA2B9F7E070008F887 /* ViewController.swift in Sources */, + 4E630F322B9F887C0008F887 /* PhysicsComponent.swift in Sources */, 4E630EF62B9F7E070008F887 /* AppDelegate.swift in Sources */, + 4E630F2A2B9F7EF60008F887 /* PositionComponent.swift in Sources */, 4E630EF82B9F7E070008F887 /* SceneDelegate.swift in Sources */, + 4E630F342B9F8FC00008F887 /* Player.swift in Sources */, + 4E630F372B9F91DE0008F887 /* PlayerSprite.swift in Sources */, + 4E630F2E2B9F81850008F887 /* HealthComponent.swift in Sources */, + 4E86605C2BA095460035530D /* Monster.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -443,6 +565,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = VFS4882B2L; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "star-dash/Info.plist"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; @@ -471,6 +594,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = VFS4882B2L; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "star-dash/Info.plist"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; diff --git a/star-dash/star-dash.xcodeproj/project.xcworkspace/xcuserdata/lauruihan.xcuserdatad/UserInterfaceState.xcuserstate b/star-dash/star-dash.xcodeproj/project.xcworkspace/xcuserdata/lauruihan.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index d4d3ad0c..00000000 Binary files a/star-dash/star-dash.xcodeproj/project.xcworkspace/xcuserdata/lauruihan.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/star-dash/star-dash.xcodeproj/xcuserdata/lauruihan.xcuserdatad/xcschemes/xcschememanagement.plist b/star-dash/star-dash.xcodeproj/xcuserdata/lauruihan.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 0f276310..00000000 --- a/star-dash/star-dash.xcodeproj/xcuserdata/lauruihan.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,14 +0,0 @@ - - - - - SchemeUserState - - star-dash.xcscheme_^#shared#^_ - - orderHint - 0 - - - - diff --git a/star-dash/star-dash/AppDelegate.swift b/star-dash/star-dash/AppDelegate.swift index 494b9c4e..49fd0c8d 100644 --- a/star-dash/star-dash/AppDelegate.swift +++ b/star-dash/star-dash/AppDelegate.swift @@ -10,27 +10,26 @@ import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { - - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. - return true + true } // MARK: UISceneSession Lifecycle - func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, + options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. - return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { // Called when the user discards a scene session. - // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // If any sessions were discarded while the application was not running, this will be called shortly + // after application:didFinishLaunchingWithOptions. // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } - } - diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (1).imageset/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (1).imageset/Contents.json new file mode 100644 index 00000000..5e5def7c --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (1).imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Run (1).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (1).imageset/Run (1).png b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (1).imageset/Run (1).png new file mode 100644 index 00000000..cf5dcc63 Binary files /dev/null and b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (1).imageset/Run (1).png differ diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (2).imageset/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (2).imageset/Contents.json new file mode 100644 index 00000000..9b7210db --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (2).imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Run (2).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (2).imageset/Run (2).png b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (2).imageset/Run (2).png new file mode 100644 index 00000000..d786f71c Binary files /dev/null and b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (2).imageset/Run (2).png differ diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (3).imageset/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (3).imageset/Contents.json new file mode 100644 index 00000000..2c492b07 --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (3).imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Run (3).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (3).imageset/Run (3).png b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (3).imageset/Run (3).png new file mode 100644 index 00000000..447167c0 Binary files /dev/null and b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (3).imageset/Run (3).png differ diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (4).imageset/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (4).imageset/Contents.json new file mode 100644 index 00000000..7124cf1a --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (4).imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Run (4).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (4).imageset/Run (4).png b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (4).imageset/Run (4).png new file mode 100644 index 00000000..8e13992e Binary files /dev/null and b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (4).imageset/Run (4).png differ diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (5).imageset/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (5).imageset/Contents.json new file mode 100644 index 00000000..3fc105c4 --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (5).imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Run (5).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (5).imageset/Run (5).png b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (5).imageset/Run (5).png new file mode 100644 index 00000000..87967ddb Binary files /dev/null and b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (5).imageset/Run (5).png differ diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (6).imageset/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (6).imageset/Contents.json new file mode 100644 index 00000000..c45f5200 --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (6).imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Run (6).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (6).imageset/Run (6).png b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (6).imageset/Run (6).png new file mode 100644 index 00000000..443644f8 Binary files /dev/null and b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (6).imageset/Run (6).png differ diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (7).imageset/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (7).imageset/Contents.json new file mode 100644 index 00000000..6007409f --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (7).imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Run (7).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (7).imageset/Run (7).png b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (7).imageset/Run (7).png new file mode 100644 index 00000000..eaa52160 Binary files /dev/null and b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (7).imageset/Run (7).png differ diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (8).imageset/Contents.json b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (8).imageset/Contents.json new file mode 100644 index 00000000..b630afe8 --- /dev/null +++ b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (8).imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Run (8).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (8).imageset/Run (8).png b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (8).imageset/Run (8).png new file mode 100644 index 00000000..d0a63134 Binary files /dev/null and b/star-dash/star-dash/Assets.xcassets/red-nose.spriteatlas/Run (8).imageset/Run (8).png differ diff --git a/star-dash/star-dash/Constants/PhysicsConstants.swift b/star-dash/star-dash/Constants/PhysicsConstants.swift new file mode 100644 index 00000000..fee6dd8f --- /dev/null +++ b/star-dash/star-dash/Constants/PhysicsConstants.swift @@ -0,0 +1,31 @@ +// +// PhysicsConstants.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +struct PhysicsConstants { + private struct CollisionCategory { + static let player: UInt32 = 0b00001 + static let monster: UInt32 = 0b00010 + static let collectible: UInt32 = 0b00100 + static let obstacle: UInt32 = 0b01000 + static let tool: UInt32 = 0b10000 + } + + struct CollisionMask { + static let playerCollisionMask = CollisionCategory.monster + | CollisionCategory.collectible | CollisionCategory.obstacle | CollisionCategory.tool + + static let monsterCollisionMask = CollisionCategory.player | CollisionCategory.tool + + static let collectibleCollisionMask = CollisionCategory.player + + static let obstacleCollisionMask = CollisionCategory.player + + static let toolCollisionMask = CollisionCategory.player | CollisionCategory.monster + } +} diff --git a/star-dash/star-dash/Entities/Components/Component.swift b/star-dash/star-dash/Entities/Components/Component.swift new file mode 100644 index 00000000..90756b15 --- /dev/null +++ b/star-dash/star-dash/Entities/Components/Component.swift @@ -0,0 +1,20 @@ +// +// Component.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +typealias ComponentId = UUID + +class Component { + var entityId: EntityId + var id: ComponentId + + init(id: ComponentId, entityId: EntityId) { + self.id = id + self.entityId = entityId + } +} diff --git a/star-dash/star-dash/Entities/Components/HealthComponent.swift b/star-dash/star-dash/Entities/Components/HealthComponent.swift new file mode 100644 index 00000000..bd133179 --- /dev/null +++ b/star-dash/star-dash/Entities/Components/HealthComponent.swift @@ -0,0 +1,21 @@ +// +// HealthComponent.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class HealthComponent: Component { + var health: Int + + init(id: ComponentId, entityId: EntityId, health: Int) { + self.health = health + super.init(id: id, entityId: entityId) + } + + convenience init(entityId: EntityId, health: Int) { + self.init(id: UUID(), entityId: entityId, health: health) + } +} diff --git a/star-dash/star-dash/Entities/Components/PhysicsComponent.swift b/star-dash/star-dash/Entities/Components/PhysicsComponent.swift new file mode 100644 index 00000000..a3367fed --- /dev/null +++ b/star-dash/star-dash/Entities/Components/PhysicsComponent.swift @@ -0,0 +1,32 @@ +// +// PhysicsComponent.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class PhysicsComponent: Component { + var mass: CGFloat + var velocity: CGVector + var force: CGVector + var collisionMask: UInt32 + var affectedByGravity: Bool + + init(id: ComponentId, entityId: EntityId, mass: CGFloat, velocity: CGVector, + force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) { + self.mass = mass + self.velocity = velocity + self.force = force + self.collisionMask = collisionMask + self.affectedByGravity = affectedByGravity + super.init(id: id, entityId: entityId) + } + + convenience init(entityId: EntityId, mass: CGFloat, velocity: CGVector, + force: CGVector, collisionMask: UInt32, affectedByGravity: Bool) { + self.init(id: UUID(), entityId: entityId, mass: mass, velocity: velocity, + force: force, collisionMask: collisionMask, affectedByGravity: affectedByGravity) + } +} diff --git a/star-dash/star-dash/Entities/Components/PositionComponent.swift b/star-dash/star-dash/Entities/Components/PositionComponent.swift new file mode 100644 index 00000000..0c162dc7 --- /dev/null +++ b/star-dash/star-dash/Entities/Components/PositionComponent.swift @@ -0,0 +1,31 @@ +// +// PositionComponent.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class PositionComponent: Component { + var position: CGPoint + var rotation: Float + + init(id: UUID, entityId: UUID, position: CGPoint, rotation: Float) { + self.position = position + self.rotation = rotation + super.init(id: id, entityId: entityId) + } + + convenience init(entityId: UUID, position: CGPoint, rotation: Float) { + self.init(id: UUID(), entityId: entityId, position: position, rotation: rotation) + } + + func setPosition(position: CGPoint) { + self.position = position + } + + func setRotation(rotation: Float) { + self.rotation = rotation + } +} diff --git a/star-dash/star-dash/Entities/Components/SpriteComponent.swift b/star-dash/star-dash/Entities/Components/SpriteComponent.swift new file mode 100644 index 00000000..f9733f4f --- /dev/null +++ b/star-dash/star-dash/Entities/Components/SpriteComponent.swift @@ -0,0 +1,26 @@ +// +// SpriteComponent.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class SpriteComponent: Component { + // TODO: sprite could be single image or sprite set, could use enum to seperate, + // for sprite set will need to discuss how to rep animation + var image: String + var size: CGSize + + init(id: ComponentId, entityId: EntityId, image: String, size: CGSize) { + self.image = image + self.size = size + super.init(id: id, entityId: entityId) + } + + convenience init(entityId: EntityId, image: String, size: CGSize) { + self.init(id: UUID(), entityId: entityId, image: image, size: size) + } + +} diff --git a/star-dash/star-dash/Entities/Entity.swift b/star-dash/star-dash/Entities/Entity.swift new file mode 100644 index 00000000..75d7cb12 --- /dev/null +++ b/star-dash/star-dash/Entities/Entity.swift @@ -0,0 +1,16 @@ +// +// Entity.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +typealias EntityId = UUID + +protocol Entity { + var id: EntityId {get} + + func setUpAndAdd(to: EntityManager) +} diff --git a/star-dash/star-dash/Entities/EntityManager.swift b/star-dash/star-dash/Entities/EntityManager.swift new file mode 100644 index 00000000..c9706778 --- /dev/null +++ b/star-dash/star-dash/Entities/EntityManager.swift @@ -0,0 +1,44 @@ +// +// EntityManager.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +typealias ComponentSet = Set +typealias ComponentMap = [ComponentId: Component] +typealias EntityMap = [EntityId: Entity] +typealias EntityComponentMap = [EntityId: ComponentSet] + +class EntityManager { + var componentMap: ComponentMap + var entityMap: EntityMap + var entityComponentMap: EntityComponentMap + + init(componentMap: ComponentMap, entityMap: EntityMap, entityComponentMap: EntityComponentMap) { + self.componentMap = componentMap + self.entityMap = entityMap + self.entityComponentMap = entityComponentMap + } + + convenience init() { + self.init(componentMap: .init(), entityMap: .init(), entityComponentMap: .init()) + } + + func add(component: Component) { + guard self.componentMap[component.id] != nil else { + return + } + self.componentMap[component.id] = component + self.entityComponentMap[component.entityId]?.insert(component.id) + } + + func add(entity: Entity) { + guard self.entityMap[entity.id] != nil else { + return + } + self.entityMap[entity.id] = entity + } +} diff --git a/star-dash/star-dash/Entities/GameEntities/Collectible.swift b/star-dash/star-dash/Entities/GameEntities/Collectible.swift new file mode 100644 index 00000000..bdafa3d5 --- /dev/null +++ b/star-dash/star-dash/Entities/GameEntities/Collectible.swift @@ -0,0 +1,37 @@ +// +// Collectible.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class Collectible: Entity { + let id: EntityId + private let position: CGPoint + + init(id: EntityId, position: CGPoint) { + self.id = id + self.position = position + } + + convenience init(position: CGPoint) { + self.init(id: UUID(), position: position) + } + + func setUpAndAdd(to: EntityManager) { + let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) + let physicsComponent = PhysicsComponent( + entityId: self.id, + mass: .zero, + velocity: .zero, + force: .zero, + collisionMask: PhysicsConstants.CollisionMask.collectibleCollisionMask, + affectedByGravity: false) + + to.add(entity: self) + to.add(component: positionComponent) + to.add(component: physicsComponent) + } +} diff --git a/star-dash/star-dash/Entities/GameEntities/Monster.swift b/star-dash/star-dash/Entities/GameEntities/Monster.swift new file mode 100644 index 00000000..ebcf6301 --- /dev/null +++ b/star-dash/star-dash/Entities/GameEntities/Monster.swift @@ -0,0 +1,39 @@ +// +// Monster.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class Monster: Entity { + let id: EntityId + private let position: CGPoint + + init(id: EntityId, position: CGPoint) { + self.id = id + self.position = position + } + + convenience init(position: CGPoint) { + self.init(id: UUID(), position: position) + } + + func setUpAndAdd(to: EntityManager) { + let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) + let healthComponent = HealthComponent(entityId: self.id, health: 100) + let physicsComponent = PhysicsComponent( + entityId: self.id, + mass: .zero, + velocity: .zero, + force: .zero, + collisionMask: PhysicsConstants.CollisionMask.monsterCollisionMask, + affectedByGravity: false) + + to.add(entity: self) + to.add(component: positionComponent) + to.add(component: healthComponent) + to.add(component: physicsComponent) + } +} diff --git a/star-dash/star-dash/Entities/GameEntities/Obstacle.swift b/star-dash/star-dash/Entities/GameEntities/Obstacle.swift new file mode 100644 index 00000000..495394a7 --- /dev/null +++ b/star-dash/star-dash/Entities/GameEntities/Obstacle.swift @@ -0,0 +1,37 @@ +// +// Obstacle.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class Obstacle: Entity { + let id: EntityId + private let position: CGPoint + + init(id: EntityId, position: CGPoint) { + self.id = id + self.position = position + } + + convenience init(position: CGPoint) { + self.init(id: UUID(), position: position) + } + + func setUpAndAdd(to: EntityManager) { + let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) + let physicsComponent = PhysicsComponent( + entityId: self.id, + mass: .zero, + velocity: .zero, + force: .zero, + collisionMask: PhysicsConstants.CollisionMask.obstacleCollisionMask, + affectedByGravity: false) + + to.add(entity: self) + to.add(component: positionComponent) + to.add(component: physicsComponent) + } +} diff --git a/star-dash/star-dash/Entities/GameEntities/Player.swift b/star-dash/star-dash/Entities/GameEntities/Player.swift new file mode 100644 index 00000000..b9b922f4 --- /dev/null +++ b/star-dash/star-dash/Entities/GameEntities/Player.swift @@ -0,0 +1,44 @@ +// +// Player.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class Player: Entity { + let id: EntityId + private let position: CGPoint + private let playerSprite: PlayerSprite + + init(id: EntityId, position: CGPoint, playerSprite: PlayerSprite) { + self.id = id + self.position = position + self.playerSprite = playerSprite + } + + convenience init(position: CGPoint, playerSprite: PlayerSprite) { + self.init(id: UUID(), position: position, playerSprite: playerSprite) + } + + func setUpAndAdd(to: EntityManager) { + let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) + let healthComponent = HealthComponent(entityId: self.id, health: 100) + let physicsComponent = PhysicsComponent( + entityId: self.id, + mass: .zero, + velocity: .zero, + force: .zero, + collisionMask: PhysicsConstants.CollisionMask.playerCollisionMask, + affectedByGravity: true) + + let spriteComponent = SpriteComponent(entityId: self.id, image: "", size: .zero) + + to.add(entity: self) + to.add(component: positionComponent) + to.add(component: healthComponent) + to.add(component: physicsComponent) + to.add(component: spriteComponent) + } +} diff --git a/star-dash/star-dash/Entities/GameEntities/Tool.swift b/star-dash/star-dash/Entities/GameEntities/Tool.swift new file mode 100644 index 00000000..528c513b --- /dev/null +++ b/star-dash/star-dash/Entities/GameEntities/Tool.swift @@ -0,0 +1,37 @@ +// +// Tool.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +class Tool: Entity { + let id: EntityId + private let position: CGPoint + + init(id: EntityId, position: CGPoint) { + self.id = id + self.position = position + } + + convenience init(position: CGPoint) { + self.init(id: UUID(), position: position) + } + + func setUpAndAdd(to: EntityManager) { + let positionComponent = PositionComponent(entityId: self.id, position: self.position, rotation: .zero) + let physicsComponent = PhysicsComponent( + entityId: self.id, + mass: .zero, + velocity: .zero, + force: .zero, + collisionMask: PhysicsConstants.CollisionMask.toolCollisionMask, + affectedByGravity: false) + + to.add(entity: self) + to.add(component: positionComponent) + to.add(component: physicsComponent) + } +} diff --git a/star-dash/star-dash/Enums/PlayerSprite.swift b/star-dash/star-dash/Enums/PlayerSprite.swift new file mode 100644 index 00000000..8e18c6ee --- /dev/null +++ b/star-dash/star-dash/Enums/PlayerSprite.swift @@ -0,0 +1,12 @@ +// +// PlayerSprite.swift +// star-dash +// +// Created by Lau Rui han on 12/3/24. +// + +import Foundation + +enum PlayerSprite: String { + case RedNose = "red-nose" +} diff --git a/star-dash/star-dash/SceneDelegate.swift b/star-dash/star-dash/SceneDelegate.swift index ce5c0e6d..9fd4098f 100644 --- a/star-dash/star-dash/SceneDelegate.swift +++ b/star-dash/star-dash/SceneDelegate.swift @@ -11,19 +11,24 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? - - func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { - // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, + options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided + // UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. - // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). - guard let _ = (scene as? UIWindowScene) else { return } + // This delegate does not imply the connecting scene or session are new + // (see `application:configurationForConnectingSceneSession` instead). + guard (scene as? UIWindowScene) != nil else { + return + } } func sceneDidDisconnect(_ scene: UIScene) { // Called as the scene is being released by the system. // This occurs shortly after the scene enters the background, or when its session is discarded. // Release any resources associated with this scene that can be re-created the next time the scene connects. - // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). + // The scene may re-connect later, as its session was not necessarily discarded + // (see `application:didDiscardSceneSessions` instead). } func sceneDidBecomeActive(_ scene: UIScene) { @@ -46,7 +51,4 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // Use this method to save data, release shared resources, and store enough scene-specific state information // to restore the scene back to its current state. } - - } - diff --git a/star-dash/star-dash/ViewController.swift b/star-dash/star-dash/ViewController.swift index 978bebb0..5dc0e960 100644 --- a/star-dash/star-dash/ViewController.swift +++ b/star-dash/star-dash/ViewController.swift @@ -9,11 +9,4 @@ import UIKit class ViewController: UIViewController { - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - } - diff --git a/star-dash/star-dashTests/star_dashTests.swift b/star-dash/star-dashTests/star_dashTests.swift index a169f3cf..d03ea1c2 100644 --- a/star-dash/star-dashTests/star_dashTests.swift +++ b/star-dash/star-dashTests/star_dashTests.swift @@ -10,21 +10,22 @@ import XCTest final class star_dashTests: XCTestCase { - override func setUpWithError() throws { - // Put setup code here. This method is called before the invocation of each test method in the class. - } +// override func setUpWithError() throws { +// // Put setup code here. This method is called before the invocation of each test method in the class. +// } - override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } +// override func tearDownWithError() throws { +// // Put teardown code here. This method is called after the invocation of each test method in the class. +// } - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - // Any test you write for XCTest can be annotated as throws and async. - // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. - // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. - } +// func testExample() throws { +// // This is an example of a functional test case. +// // Use XCTAssert and related functions to verify your tests produce the correct results. +// // Any test you write for XCTest can be annotated as throws and async. +// // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. +// // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with +// // assertions afterwards. +// } func testPerformanceExample() throws { // This is an example of a performance test case. diff --git a/star-dash/star-dashUITests/star_dashUITests.swift b/star-dash/star-dashUITests/star_dashUITests.swift index b49ccd08..44bbcb08 100644 --- a/star-dash/star-dashUITests/star_dashUITests.swift +++ b/star-dash/star-dashUITests/star_dashUITests.swift @@ -15,12 +15,13 @@ final class star_dashUITests: XCTestCase { // In UI tests it is usually best to stop immediately when a failure occurs. continueAfterFailure = false - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + // In UI tests it’s important to set the initial state - such as interface orientation - + // required for your tests before they run. The setUp method is a good place to do this. } - override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } +// override func tearDownWithError() throws { +// // Put teardown code here. This method is called after the invocation of each test method in the class. +// } func testExample() throws { // UI tests must launch the application that they test.