Skip to content

Commit

Permalink
Merge pull request #62 from Vanessamae23/main
Browse files Browse the repository at this point in the history
Add Wizard and fix position
  • Loading branch information
Vanessamae23 authored Mar 31, 2024
2 parents 8f51bed + b16d35f commit 5ddb4c8
Show file tree
Hide file tree
Showing 25 changed files with 227 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "sprite_0.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" : "sprite_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" : "sprite_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" : "wizard-ball0.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" : "soldier-frame.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.
8 changes: 8 additions & 0 deletions TowerForge/TowerForge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
520062562BA8E026000DBA30 /* PlayerSpawnable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520062552BA8E026000DBA30 /* PlayerSpawnable.swift */; };
520062582BA8ED73000DBA30 /* HomeComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520062572BA8ED73000DBA30 /* HomeComponent.swift */; };
523923E72BADC8530044BA61 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 523923E62BADC8530044BA61 /* LaunchScreen.storyboard */; };
523AA3BD2BB88ED10041E60D /* WizardBall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523AA3BC2BB88ED10041E60D /* WizardBall.swift */; };
523AA3BF2BB88FBF0041E60D /* WizardUnit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523AA3BE2BB88FBF0041E60D /* WizardUnit.swift */; };
5240D08F2BAE6D0A004F1486 /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5240D08E2BAE6D0A004F1486 /* Point.swift */; };
5240D0912BAF3453004F1486 /* Life.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5240D0902BAF3453004F1486 /* Life.swift */; };
5240D0962BB04E57004F1486 /* Nosifer-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 5240D0952BB04E57004F1486 /* Nosifer-Regular.ttf */; };
Expand Down Expand Up @@ -201,6 +203,8 @@
520062552BA8E026000DBA30 /* PlayerSpawnable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerSpawnable.swift; sourceTree = "<group>"; };
520062572BA8ED73000DBA30 /* HomeComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeComponent.swift; sourceTree = "<group>"; };
523923E62BADC8530044BA61 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
523AA3BC2BB88ED10041E60D /* WizardBall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WizardBall.swift; sourceTree = "<group>"; };
523AA3BE2BB88FBF0041E60D /* WizardUnit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WizardUnit.swift; sourceTree = "<group>"; };
5240D08E2BAE6D0A004F1486 /* Point.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Point.swift; sourceTree = "<group>"; };
5240D0902BAF3453004F1486 /* Life.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Life.swift; sourceTree = "<group>"; };
5240D0952BB04E57004F1486 /* Nosifer-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Nosifer-Regular.ttf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -689,6 +693,7 @@
3C9955AE2BA48FD200D33FA5 /* MeleeUnit.swift */,
529F91872BA6D7A7009551D9 /* SoldierUnit.swift */,
3C9955B32BA4B12000D33FA5 /* ArrowTower.swift */,
523AA3BE2BB88FBF0041E60D /* WizardUnit.swift */,
);
path = SpawnableEntities;
sourceTree = "<group>";
Expand All @@ -702,6 +707,7 @@
5240D0902BAF3453004F1486 /* Life.swift */,
527A07772BB3F31100CD9D08 /* Death.swift */,
527A077D2BB3F75700CD9D08 /* Timer.swift */,
523AA3BC2BB88ED10041E60D /* WizardBall.swift */,
);
path = GameEntities;
sourceTree = "<group>";
Expand Down Expand Up @@ -1000,6 +1006,7 @@
52DF5FAE2BA32B2300135367 /* GameScene.swift in Sources */,
52578B822BA61AAF00B4D76C /* PositionComponent.swift in Sources */,
3C9955A32BA47DBB00D33FA5 /* BaseUnit.swift in Sources */,
523AA3BD2BB88ED10041E60D /* WizardBall.swift in Sources */,
527A07782BB3F31100CD9D08 /* Death.swift in Sources */,
3C9955BA2BA5637200D33FA5 /* DamageEvent.swift in Sources */,
3CE951632BAE037C008B2785 /* AiSystem.swift in Sources */,
Expand All @@ -1020,6 +1027,7 @@
529F91882BA6D7A7009551D9 /* SoldierUnit.swift in Sources */,
BAFFB9492BB0ABC400D8301F /* Logger.swift in Sources */,
3CAC4A732BB6B61C00A5D22E /* PlayerRenderStage.swift in Sources */,
523AA3BF2BB88FBF0041E60D /* WizardUnit.swift in Sources */,
3C9955C02BA57E5500D33FA5 /* EventTarget.swift in Sources */,
3CCF9CB12BAB1BCE004D170E /* GameWorld.swift in Sources */,
5295A2152BAAF335005018A8 /* UnitSelectionNode.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="NJ9-hN-4Nf">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="NJ9-hN-4Nf">
<device id="ipad12_9" orientation="landscape" layout="fullscreen" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -106,15 +106,15 @@
<string key="content">Death
</string>
<attributes>
<color key="NSColor" red="0.76470588235294112" green="0.0" blue="0.086274509803921567" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="49" name="Nosifer-Regular"/>
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
<font key="NSFont" size="49" name="AmericanTypewriter"/>
<paragraphStyle key="NSParagraphStyle" alignment="left" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
<fragment content="Match">
<attributes>
<color key="NSColor" red="0.76470588235294112" green="0.0" blue="0.086274509803921567" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="49" name="Nosifer-Regular"/>
<color key="NSColor" name="textColor" catalog="System" colorSpace="catalog"/>
<font key="NSFont" size="49" name="AmericanTypewriter"/>
<paragraphStyle key="NSParagraphStyle" alignment="left" lineBreakMode="wordWrapping" baseWritingDirection="natural" lineHeightMultiple="1" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
Expand Down Expand Up @@ -157,21 +157,21 @@
</string>
<attributes>
<color key="NSColor" red="0.76470588235294112" green="0.0" blue="0.086274509803921567" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="49" name="Nosifer-Regular"/>
<font key="NSFont" metaFont="system" size="49"/>
<paragraphStyle key="NSParagraphStyle" alignment="left" lineBreakMode="wordWrapping" baseWritingDirection="natural" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
<fragment content="The Flag">
<attributes>
<color key="NSColor" red="0.76470588235294112" green="0.0" blue="0.086274509803921567" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<font key="NSFont" size="49" name="Nosifer-Regular"/>
<font key="NSFont" metaFont="system" size="49"/>
<paragraphStyle key="NSParagraphStyle" alignment="left" lineBreakMode="wordWrapping" baseWritingDirection="natural" lineHeightMultiple="1" tighteningFactorForTruncation="0.0"/>
</attributes>
</fragment>
</attributedString>
</state>
<connections>
<action selector="deathMatchButtonPressed:" destination="bL0-ag-pcs" eventType="touchUpInside" id="kMc-3c-7jL"/>
<action selector="captureTheFlagButtonPressed:" destination="bL0-ag-pcs" eventType="touchUpInside" id="G4P-CB-6Hz"/>
</connections>
</button>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Flag" translatesAutoresizingMaskIntoConstraints="NO" id="PlF-Gy-tpz">
Expand Down Expand Up @@ -212,6 +212,7 @@
</view>
<navigationItem key="navigationItem" id="eHk-cd-vLs"/>
<connections>
<outlet property="captureTheFlagButton" destination="erv-RB-ZcW" id="o5k-6Q-PEr"/>
<outlet property="deathMatchButton" destination="TfO-fG-lEt" id="0Lp-kV-daK"/>
</connections>
</viewController>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class ShootingComponent: TFComponent {
var range: CGFloat
private(set) var lastShotTime = TimeInterval(0)
let attackPower: CGFloat
let shootingType: BaseProjectile.Type

init(fireRate: TimeInterval, range: CGFloat, attackPower: CGFloat) {
init(fireRate: TimeInterval, range: CGFloat, attackPower: CGFloat, shootingType: BaseProjectile.Type) {
self.fireRate = fireRate
self.range = range
self.attackPower = attackPower
self.shootingType = shootingType
super.init()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import Foundation

class BaseProjectile: TFEntity {
class BaseProjectile: TFEntity, Spawnable {
required init(position: CGPoint, player: Player) {
// TODO: to fill
}

init(textureNames: [String], size: CGSize, key: String, position: CGPoint,
player: Player, velocity: CGVector = .zero) {
super.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

class Bullet: BaseProjectile, Spawnable {
class Bullet: BaseProjectile {
static let textureNames: [String] = ["bullet"]
static let size = CGSize(width: 10, height: 10)
static let key = "bullet"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// WizardBall.swift
// TowerForge
//
// Created by Vanessa Mae on 31/03/24.
//

import Foundation

class WizardBall: BaseProjectile {
static let textureNames: [String] = ["Wizard-ball-0"]
static let size = CGSize(width: 10, height: 10)
static let key = "wizard-ball"
static let damage = 5.0
static let attackRate = 1.0
static let velocity = CGVector(dx: 100, dy: 0)

required init(position: CGPoint, player: Player) {
super.init(textureNames: WizardBall.textureNames,
size: WizardBall.size,
key: WizardBall.key,
position: position,
player: player,
velocity: WizardBall.velocity)
self.addComponent(DamageComponent(attackRate: WizardBall.attackRate,
attackPower: WizardBall.damage,
temporary: true))
}

override func collide(with other: any Collidable) -> TFEvent? {
let superEvent = super.collide(with: other)
guard let damageComponent = self.component(ofType: DamageComponent.self) else {
return superEvent
}
if let superEvent = superEvent {
return superEvent.concurrentlyWith(other.collide(with: damageComponent))
}
return other.collide(with: damageComponent)
}

override func collide(with healthComponent: HealthComponent) -> TFEvent? {
guard let damageComponent = self.component(ofType: DamageComponent.self) else {
return nil
}
return damageComponent.damage(healthComponent)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class ArrowTower: BaseTower, PlayerSpawnable {
player: player)
self.addComponent(ShootingComponent(fireRate: ArrowTower.fireRate,
range: ArrowTower.range,
attackPower: ArrowTower.damage))
attackPower: ArrowTower.damage, shootingType: Bullet.self))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ class SoldierUnit: BaseUnit, PlayerSpawnable {

self.addComponent(ShootingComponent(fireRate: SoldierUnit.attackRate,
range: SoldierUnit.range,
attackPower: SoldierUnit.attackPower))
attackPower: SoldierUnit.attackPower, shootingType: Bullet.self))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct SpawnableEntities {
[
MeleeUnit.self,
SoldierUnit.self,
WizardUnit.self,
ArrowTower.self
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// WizardUnit.swift
// TowerForge
//
// Created by Vanessa Mae on 31/03/24.
//

import Foundation

class WizardUnit: BaseUnit, PlayerSpawnable {
static let title: String = "wizard"
static let textureNames = ["Wizard-0", "Wizard-1", "Wizard-2"]
static let size = CGSize(width: 100, height: 100)
static let key = "shoot"
static let maxHealth = 100.0
static let damage = 10.0
static var cost = 5
static let attackRate = 1.0
static let velocity = CGVector(dx: 30.0, dy: 0.0)
static let range = 400.0
static let attackPower = 10.0

required init(position: CGPoint, player: Player) {
super.init(textureNames: WizardUnit.textureNames,
size: WizardUnit.size,
key: WizardUnit.key,
position: position,
maxHealth: WizardUnit.maxHealth,
velocity: WizardUnit.velocity,
player: player)

self.addComponent(ShootingComponent(fireRate: WizardUnit.attackRate,
range: WizardUnit.range,
attackPower: WizardUnit.attackPower, shootingType: WizardBall.self))
}
}
2 changes: 1 addition & 1 deletion TowerForge/TowerForge/GameModule/GameWorld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GameWorld {
}

func checkGameEnded() -> Bool {
gameMode.gameState == .WIN || gameMode.gameState == .LOSE
gameMode.gameState == .WIN || gameMode.gameState == .LOSE || gameMode.gameState == .DRAW
}

func spawnUnit(at location: CGPoint) {
Expand Down
Loading

0 comments on commit 5ddb4c8

Please sign in to comment.