Skip to content

Commit

Permalink
Merge pull request #3 from Vanessamae23/main
Browse files Browse the repository at this point in the history
Fix hasComponent and added more components
  • Loading branch information
Vanessamae23 authored Mar 17, 2024
2 parents f6227b4 + b10b91b commit 41bd7ba
Show file tree
Hide file tree
Showing 32 changed files with 538 additions and 93 deletions.
Binary file added .DS_Store
Binary file not shown.
48 changes: 34 additions & 14 deletions TowerForge/TowerForge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
3C9955C82BA5865C00D33FA5 /* ConcurrentEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C9955C72BA5865C00D33FA5 /* ConcurrentEvent.swift */; };
3C9955CA2BA5888F00D33FA5 /* SpawnEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C9955C92BA5888F00D33FA5 /* SpawnEvent.swift */; };
3C9955CC2BA5889800D33FA5 /* MoveEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C9955CB2BA5889800D33FA5 /* MoveEvent.swift */; };
52578B822BA61AAF00B4D76C /* PositionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52578B812BA61AAF00B4D76C /* PositionComponent.swift */; };
52578B872BA6209700B4D76C /* DamageComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52578B862BA6209700B4D76C /* DamageComponent.swift */; };
52578B8C2BA627B200B4D76C /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52578B8B2BA627B200B4D76C /* Team.swift */; };
527E3A242BA613F000FE1628 /* PlayerComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 527E3A232BA613EF00FE1628 /* PlayerComponent.swift */; };
529F91882BA6D7A7009551D9 /* SoldierUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 529F91872BA6D7A7009551D9 /* SoldierUnit.swift */; };
52DF5FA82BA32B2300135367 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FA72BA32B2300135367 /* AppDelegate.swift */; };
52DF5FAA2BA32B2300135367 /* GameScene.sks in Resources */ = {isa = PBXBuildFile; fileRef = 52DF5FA92BA32B2300135367 /* GameScene.sks */; };
52DF5FAC2BA32B2300135367 /* Actions.sks in Resources */ = {isa = PBXBuildFile; fileRef = 52DF5FAB2BA32B2300135367 /* Actions.sks */; };
Expand All @@ -45,10 +50,8 @@
52DF5FED2BA34D0300135367 /* TFComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FEC2BA34D0300135367 /* TFComponent.swift */; };
52DF5FEF2BA34EA000135367 /* TFEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FEE2BA34EA000135367 /* TFEntity.swift */; };
52DF5FF32BA351E100135367 /* SpriteComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FF22BA351E100135367 /* SpriteComponent.swift */; };
52DF5FF52BA3575100135367 /* collateDiagrams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FF42BA3575100135367 /* collateDiagrams.swift */; };
52DF5FF92BA35D2B00135367 /* MovableComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FF82BA35D2B00135367 /* MovableComponent.swift */; };
52DF5FFB2BA3601400135367 /* HealthComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FFA2BA3601400135367 /* HealthComponent.swift */; };
52DF5FFD2BA3608000135367 /* DamageComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FFC2BA3608000135367 /* DamageComponent.swift */; };
52DF5FFF2BA3656500135367 /* ShootingComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52DF5FFE2BA3656500135367 /* ShootingComponent.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -88,6 +91,11 @@
3C9955C72BA5865C00D33FA5 /* ConcurrentEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConcurrentEvent.swift; sourceTree = "<group>"; };
3C9955C92BA5888F00D33FA5 /* SpawnEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpawnEvent.swift; sourceTree = "<group>"; };
3C9955CB2BA5889800D33FA5 /* MoveEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveEvent.swift; sourceTree = "<group>"; };
52578B812BA61AAF00B4D76C /* PositionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionComponent.swift; sourceTree = "<group>"; };
52578B862BA6209700B4D76C /* DamageComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamageComponent.swift; sourceTree = "<group>"; };
52578B8B2BA627B200B4D76C /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = "<group>"; };
527E3A232BA613EF00FE1628 /* PlayerComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerComponent.swift; sourceTree = "<group>"; };
529F91872BA6D7A7009551D9 /* SoldierUnit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoldierUnit.swift; sourceTree = "<group>"; };
52DF5FA42BA32B2300135367 /* TowerForge.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TowerForge.app; sourceTree = BUILT_PRODUCTS_DIR; };
52DF5FA72BA32B2300135367 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
52DF5FA92BA32B2300135367 /* GameScene.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = GameScene.sks; sourceTree = "<group>"; };
Expand All @@ -111,10 +119,8 @@
52DF5FEC2BA34D0300135367 /* TFComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFComponent.swift; sourceTree = "<group>"; };
52DF5FEE2BA34EA000135367 /* TFEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TFEntity.swift; sourceTree = "<group>"; };
52DF5FF22BA351E100135367 /* SpriteComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpriteComponent.swift; sourceTree = "<group>"; };
52DF5FF42BA3575100135367 /* collateDiagrams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = collateDiagrams.swift; sourceTree = "<group>"; };
52DF5FF82BA35D2B00135367 /* MovableComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovableComponent.swift; sourceTree = "<group>"; };
52DF5FFA2BA3601400135367 /* HealthComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthComponent.swift; sourceTree = "<group>"; };
52DF5FFC2BA3608000135367 /* DamageComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamageComponent.swift; sourceTree = "<group>"; };
52DF5FFE2BA3656500135367 /* ShootingComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShootingComponent.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -152,6 +158,8 @@
3C9955AE2BA48FD200D33FA5 /* MeleeUnit.swift */,
3C9955B02BA4ACA100D33FA5 /* Arrow.swift */,
3C9955B32BA4B12000D33FA5 /* ArrowTower.swift */,
52578B8B2BA627B200B4D76C /* Team.swift */,
529F91872BA6D7A7009551D9 /* SoldierUnit.swift */,
);
path = Entities;
sourceTree = "<group>";
Expand Down Expand Up @@ -189,6 +197,16 @@
path = "Implemented Events";
sourceTree = "<group>";
};
52578B882BA620A900B4D76C /* BaseComponents */ = {
isa = PBXGroup;
children = (
52DF5FF22BA351E100135367 /* SpriteComponent.swift */,
52DF5FF82BA35D2B00135367 /* MovableComponent.swift */,
52578B812BA61AAF00B4D76C /* PositionComponent.swift */,
);
path = BaseComponents;
sourceTree = "<group>";
};
52DF5F9B2BA32B2200135367 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -223,7 +241,6 @@
52DF5FB12BA32B2300135367 /* Main.storyboard */,
52DF5FB42BA32B2600135367 /* Assets.xcassets */,
52DF5FB62BA32B2600135367 /* LaunchScreen.storyboard */,
52DF5FF42BA3575100135367 /* collateDiagrams.swift */,
);
path = TowerForge;
sourceTree = "<group>";
Expand Down Expand Up @@ -290,11 +307,11 @@
52DF5FF02BA3519D00135367 /* Components */ = {
isa = PBXGroup;
children = (
52DF5FF22BA351E100135367 /* SpriteComponent.swift */,
52DF5FF82BA35D2B00135367 /* MovableComponent.swift */,
52578B882BA620A900B4D76C /* BaseComponents */,
52DF5FFA2BA3601400135367 /* HealthComponent.swift */,
52DF5FFC2BA3608000135367 /* DamageComponent.swift */,
52DF5FFE2BA3656500135367 /* ShootingComponent.swift */,
527E3A232BA613EF00FE1628 /* PlayerComponent.swift */,
52578B862BA6209700B4D76C /* DamageComponent.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -455,19 +472,22 @@
files = (
3C9955A12BA47DA500D33FA5 /* BaseTower.swift in Sources */,
3C9955A52BA47DC600D33FA5 /* BaseProjectile.swift in Sources */,
52578B8C2BA627B200B4D76C /* Team.swift in Sources */,
52DF5FFF2BA3656500135367 /* ShootingComponent.swift in Sources */,
3C9955CC2BA5889800D33FA5 /* MoveEvent.swift in Sources */,
3C9955C22BA5838900D33FA5 /* EventOutput.swift in Sources */,
52DF5FAE2BA32B2300135367 /* GameScene.swift in Sources */,
52578B822BA61AAF00B4D76C /* PositionComponent.swift in Sources */,
3C9955A32BA47DBB00D33FA5 /* BaseUnit.swift in Sources */,
3C9955BA2BA5637200D33FA5 /* DamageEvent.swift in Sources */,
3C9955CA2BA5888F00D33FA5 /* SpawnEvent.swift in Sources */,
52DF5FF32BA351E100135367 /* SpriteComponent.swift in Sources */,
52578B872BA6209700B4D76C /* DamageComponent.swift in Sources */,
52DF5FB02BA32B2300135367 /* GameViewController.swift in Sources */,
529F91882BA6D7A7009551D9 /* SoldierUnit.swift in Sources */,
3C9955C02BA57E5500D33FA5 /* EventTarget.swift in Sources */,
52DF5FF92BA35D2B00135367 /* MovableComponent.swift in Sources */,
52DF5FDE2BA32D7E00135367 /* EntityManager.swift in Sources */,
52DF5FFD2BA3608000135367 /* DamageComponent.swift in Sources */,
3C9955C82BA5865C00D33FA5 /* ConcurrentEvent.swift in Sources */,
3C9955AD2BA483B100D33FA5 /* TFSystem.swift in Sources */,
3C9955BE2BA57E4B00D33FA5 /* EventManager.swift in Sources */,
Expand All @@ -478,12 +498,12 @@
52DF5FE12BA3349600135367 /* TFTextures.swift in Sources */,
52DF5FA82BA32B2300135367 /* AppDelegate.swift in Sources */,
3C769A742BA591BD00F454F9 /* SpawnSystem.swift in Sources */,
52DF5FF52BA3575100135367 /* collateDiagrams.swift in Sources */,
3C9955B12BA4ACA100D33FA5 /* Arrow.swift in Sources */,
3C769A722BA58DE700F454F9 /* MovementSystem.swift in Sources */,
52DF5FEB2BA3400C00135367 /* TFAnimatableNode.swift in Sources */,
52DF5FEF2BA34EA000135367 /* TFEntity.swift in Sources */,
52DF5FED2BA34D0300135367 /* TFComponent.swift in Sources */,
527E3A242BA613F000FE1628 /* PlayerComponent.swift in Sources */,
3C9955C52BA585DD00D33FA5 /* HealthSystem.swift in Sources */,
52DF5FFB2BA3601400135367 /* HealthComponent.swift in Sources */,
3C9955BC2BA563A800D33FA5 /* TFEvent.swift in Sources */,
Expand Down Expand Up @@ -676,8 +696,8 @@
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UIStatusBarHidden = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -709,8 +729,8 @@
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UIStatusBarHidden = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Bullet.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "LightHouse-1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Shooter-1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Shooter-2.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "road-tile.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 35 additions & 6 deletions TowerForge/TowerForge/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,45 @@ import SpriteKit
import GameplayKit

class GameScene: SKScene {

private var lastUpdatedTimeInterval = TimeInterval(0)
private var entityManager: EntityManager?

override func didMove(to view: SKView) {
let textureNames = ["melee-1", "melee-2"]
let tfTextures = TFTextures(textureNames: textureNames, textureAtlasName: "Sprites", mainTextureName: "melee-1")
let animatableNode = TFAnimatableNode(textures: tfTextures, height: 300, width: 300, animatableKey: "melee")
addChild(animatableNode)
animatableNode.playAnimation()
// let textureNames = ["melee-1", "melee-2"]
// let tfTextures = TFTextures(textureNames: textureNames, textureAtlasName: "Sprites", mainTextureName: "melee-1")
// let animatableNode = TFAnimatableNode(textures: tfTextures, height: 300, width: 300, animatableKey: "melee")
// addChild(animatableNode)
// animatableNode.playAnimation()
entityManager = EntityManager()
guard var entityManager = entityManager else {
return
}
let meleeUnit = MeleeUnit(position: CGPoint(x: 0, y: 100), entityManager: entityManager, attackRate: 1.0, velocity: CGVector(dx: 10.0, dy: 0.0))
let soldierUnit = SoldierUnit(position: CGPoint(x: 0, y: 50), entityManager: entityManager, attackRate: 1.0, velocity: CGVector(dx: 10.0, dy: 0.0))
let arrowTower = ArrowTower(position: CGPoint(x:0, y: 100), entityManager: entityManager)
entityManager.add(meleeUnit)
guard let sprite = meleeUnit.component(ofType: SpriteComponent.self),
let soldierSprite = soldierUnit.component(ofType: SpriteComponent.self),
let arrowTowerSprite = arrowTower.component(ofType: SpriteComponent.self) else {
return
}
addChild(sprite.node)
addChild(soldierSprite.node)
addChild(arrowTowerSprite.node)
sprite.node.playAnimation()
soldierSprite.node.playAnimation()
}

override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
guard let entityManager = entityManager else {
return
}
if lastUpdatedTimeInterval == TimeInterval(0) {
lastUpdatedTimeInterval = currentTime
}
let changeInTime = currentTime - lastUpdatedTimeInterval
lastUpdatedTimeInterval = currentTime
entityManager.update(changeInTime)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// MovableComponent.swift
// TowerForge
//
// Created by Vanessa Mae on 15/03/24.
//

import Foundation
import CoreGraphics

class MovableComponent: TFComponent {
public var velocity: CGVector
public var position: CGPoint

init(position: CGPoint, velocity: CGVector = .zero) {
self.velocity = velocity
self.position = position
super.init()
}

override func update(deltaTime: TimeInterval) {
guard let entity = entity,
let positionComponent = entity.component(ofType: PositionComponent.self),
let spriteComponent = entity.component(ofType: SpriteComponent.self) else {
return
}

let finalX = positionComponent.position.x + velocity.dx * CGFloat(deltaTime)
let finalY = positionComponent.position.y + velocity.dy * CGFloat(deltaTime)
positionComponent.changeTo(to: CGPoint(x: finalX, y: finalY))
spriteComponent.node.position = positionComponent.position
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// PositionComponent.swift
// TowerForge
//
// Created by MacBook Pro on 17/03/24.
//

import Foundation
import CoreGraphics

class PositionComponent: TFComponent {
var position: CGPoint

init(position: CGPoint) {
self.position = position
super.init()
}

func changeTo(to position: CGPoint) {
guard let entity = entity, let spriteComponent = entity.component(ofType: SpriteComponent.self) else {
return
}
self.position = position
}
}
Loading

0 comments on commit 41bd7ba

Please sign in to comment.