Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tutorials in DocC bundle #98

Merged
merged 3 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ Framework to write Godot Game Extensions using the Swift Programming Language.

## Topics

###
### Articles and Tutorials

- <doc:SwiftGodot-Tutorials>
- <doc:Variants>
- <doc:Signals>
- <doc:CustomTypes>

### Godot Nodes
- ``Node``
- ``Viewport``
- ``Window``
Expand All @@ -32,7 +39,3 @@ Framework to write Godot Game Extensions using the Swift Programming Language.
- ``Timer``
- ``WorldEnvironment``


### <!--@START_MENU_TOKEN@-->Group<!--@END_MENU_TOKEN@-->

- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@-->
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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,19 @@
//
// MainLevel.swift
//
//
// Created by Marquis Kurt on 7/22/23.
//

import Foundation
import SwiftGodot

class MainLevel: Node2D {
required init() {
super.init()
}

required init(nativeHandle: UnsafeRawPointer) {
fatalError("init(nativeHandle:) not implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MainLevel.swift
//
//
// Created by Marquis Kurt on 7/22/23.
//

import Foundation
import SwiftGodot

class MainLevel: Node2D {
var player: PlayerController?
var spawnpoint: Node2D?
var teleportArea: Area2D?

required init() {
super.init()
}

required init(nativeHandle: UnsafeRawPointer) {
fatalError("init(nativeHandle:) not implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// MainLevel.swift
//
//
// Created by Marquis Kurt on 7/22/23.
//

import Foundation
import SwiftGodot

class MainLevel: Node2D {
var player: PlayerController?
var spawnpoint: Node2D?
var teleportArea: Area2D?

required init() {
super.init()
}

required init(nativeHandle: UnsafeRawPointer) {
fatalError("init(nativeHandle:) not implemented")
}

override func _ready() {
self.player = getNodeOrNull(path: "CharacterBody2D") as? PlayerController
self.teleportArea = getNodeOrNull(path: "Telepoint") as? Area2D
self.spawnpoint = getNodeOrNull(path: "Spawnpoint") as? Node2D
super._ready()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// MainLevel.swift
//
//
// Created by Marquis Kurt on 7/22/23.
//

import Foundation
import SwiftGodot

class MainLevel: Node2D {
var player: PlayerController?
var spawnpoint: Node2D?
var teleportArea: Area2D?

required init() {
super.init()
}

required init(nativeHandle: UnsafeRawPointer) {
fatalError("init(nativeHandle:) not implemented")
}

override func _ready() {
self.player = getNodeOrNull(path: "CharacterBody2D") as? PlayerController
self.teleportArea = getNodeOrNull(path: "Telepoint") as? Area2D
self.spawnpoint = getNodeOrNull(path: "Spawnpoint") as? Node2D
super._ready()
}

private func teleportPlayerToTop() {
guard let player, let spawnpoint else {
GD.pushWarning("Player or spawnpoint is missing.")
return
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// MainLevel.swift
//
//
// Created by Marquis Kurt on 7/22/23.
//

import Foundation
import SwiftGodot

class MainLevel: Node2D {
var player: PlayerController?
var spawnpoint: Node2D?
var teleportArea: Area2D?

required init() {
super.init()
}

required init(nativeHandle: UnsafeRawPointer) {
fatalError("init(nativeHandle:) not implemented")
}

override func _ready() {
self.player = getNodeOrNull(path: "CharacterBody2D") as? PlayerController
self.teleportArea = getNodeOrNull(path: "Telepoint") as? Area2D
self.spawnpoint = getNodeOrNull(path: "Spawnpoint") as? Node2D
super._ready()
}

private func teleportPlayerToTop() {
guard let player, let spawnpoint else {
GD.pushWarning("Player or spawnpoint is missing.")
return
}

player.position = Vector2(x: player.position.x, y: spawnpoint.position.y)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// MainLevel.swift
//
//
// Created by Marquis Kurt on 7/22/23.
//

import Foundation
import SwiftGodot

class MainLevel: Node2D {
var player: PlayerController?
var spawnpoint: Node2D?
var teleportArea: Area2D?

required init() {
super.init()
}

required init(nativeHandle: UnsafeRawPointer) {
fatalError("init(nativeHandle:) not implemented")
}

override func _ready() {
self.player = getNodeOrNull(path: "CharacterBody2D") as? PlayerController
self.teleportArea = getNodeOrNull(path: "Telepoint") as? Area2D
self.spawnpoint = getNodeOrNull(path: "Spawnpoint") as? Node2D

teleportArea?.bodyEntered.connect { [self] enteredBody in
if enteredBody.isClass(class: "\(PlayerController.self)") {
teleportPlayerToTop()
}
}

super._ready()
}

private func teleportPlayerToTop() {
guard let player, let spawnpoint else {
GD.pushWarning("Player or spawnpoint is missing.")
return
}

player.position = Vector2(x: player.position.x, y: spawnpoint.position.y)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// MainLevel.swift
//
//
// Created by Marquis Kurt on 7/22/23.
//

import Foundation
import SwiftGodot
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SimpleRunnerDriver",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "SimpleRunnerDriver",
targets: ["SimpleRunnerDriver"]),
],
dependencies: [
.package(url: "https://github.com/migueldeicaza/SwiftGodot", branch: "main")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "SimpleRunnerDriver"),
.testTarget(
name: "SimpleRunnerDriverTests",
dependencies: ["SimpleRunnerDriver"]),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SimpleRunnerDriver",
platforms: [.macOS(.v13)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "SimpleRunnerDriver",
type: .dynamic,
targets: ["SimpleRunnerDriver"]),
],
dependencies: [
.package(url: "https://github.com/migueldeicaza/SwiftGodot", branch: "main")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "SimpleRunnerDriver"),
.testTarget(
name: "SimpleRunnerDriverTests",
dependencies: ["SimpleRunnerDriver"]),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SimpleRunnerDriver",
platforms: [.macOS(.v13)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "SimpleRunnerDriver",
type: .dynamic,
targets: ["SimpleRunnerDriver"]
),
],
dependencies: [
.package(url: "https://github.com/migueldeicaza/SwiftGodot", branch: "main"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "SimpleRunnerDriver",
dependencies: ["SwiftGodot"],
swiftSettings: [.unsafeFlags(["-suppress-warnings"])],
linkerSettings: [.unsafeFlags(
["-Xlinker", "-undefined",
"-Xlinker", "dynamic_lookup"]
)]
),
.testTarget(
name: "SimpleRunnerDriverTests",
dependencies: ["SimpleRunnerDriver"]
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "SimpleRunnerDriver",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "SimpleRunnerDriver",
targets: ["SimpleRunnerDriver"]),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "SimpleRunnerDriver"),
.testTarget(
name: "SimpleRunnerDriverTests",
dependencies: ["SimpleRunnerDriver"]),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// PlayerController.swift
//
//
// Created by Marquis Kurt on 7/19/23.
//

import Foundation
import SwiftGodot

class PlayerController: CharacterBody2D {
var acceleration: Float = 100
var friction: Double = 100
var speed: Double = 200

var movementVector: Vector2 {
var movement = Vector2.zero
movement.x = Float(
Input.shared.getActionStrength(action: "move_right") - Input.shared.getActionStrength(action: "move_left"))
movement.y = 1.0
return movement.normalized()
}

required init() {
super.init()
}
required init(nativeHandle: UnsafeRawPointer) {
fatalError("init(nativeHandle:) not supported")
}

override func _physicsProcess(delta: Double) {
if Engine.shared.isEditorHint() { return }
if movementVector != .zero {
let acceleratedVector = Vector2(x: acceleration, y: acceleration)
let acceleratedMovement = movementVector * acceleratedVector
self.velocity = acceleratedMovement.limitLength(length: speed)
} else {
velocity = velocity.moveToward(to: .zero, delta: friction)
}
self.moveAndSlide()
super._physicsProcess(delta: delta)
}
}
Loading
Loading