mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 13:11:33 +00:00
block delet
This commit is contained in:
@ -22,6 +22,14 @@ public struct Chunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mutating func setBlockInternally(at position: SIMD3<Int>, type: BlockType) {
|
mutating func setBlockInternally(at position: SIMD3<Int>, type: BlockType) {
|
||||||
|
if position.x >= Chunk.chunkSize || position.y >= Chunk.chunkSize || position.z >= Chunk.chunkSize {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if position.x < 0 || position.y < 0 || position.z < 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
blocks[position.x + position.y * Chunk.chunkSize + position.z * Chunk.chunkSize * Chunk.chunkSize].type = type
|
blocks[position.x + position.y * Chunk.chunkSize + position.z * Chunk.chunkSize * Chunk.chunkSize].type = type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,11 @@ class Game: GameDelegate {
|
|||||||
var projection: matrix_float4x4 = .identity
|
var projection: matrix_float4x4 = .identity
|
||||||
|
|
||||||
var boxes: [Box] = []
|
var boxes: [Box] = []
|
||||||
|
var chunk = Chunk(position: .zero)
|
||||||
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var chunk = Chunk(position: .zero)
|
player.position = SIMD3(0.5, Float(Chunk.chunkSize) + 0.5, 0.5)
|
||||||
let options: [BlockType] = [
|
let options: [BlockType] = [
|
||||||
.air,
|
.air,
|
||||||
.solid(.blue),
|
.solid(.blue),
|
||||||
@ -54,6 +56,26 @@ class Game: GameDelegate {
|
|||||||
]
|
]
|
||||||
chunk
|
chunk
|
||||||
.fill(allBy: { options[Int(arc4random_uniform(UInt32(options.count)))] })
|
.fill(allBy: { options[Int(arc4random_uniform(UInt32(options.count)))] })
|
||||||
|
}
|
||||||
|
|
||||||
|
func fixedUpdate(_ time: GameTime) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func update(_ time: GameTime) {
|
||||||
|
fpsCalculator.frame(deltaTime: time.delta) { fps in
|
||||||
|
print("FPS: \(fps)")
|
||||||
|
}
|
||||||
|
|
||||||
|
let deltaTime = min(Float(time.delta.asFloat), 1.0 / 15)
|
||||||
|
|
||||||
|
if let pad = GameController.current?.state {
|
||||||
|
if pad.pressed(.south) {
|
||||||
|
chunk
|
||||||
|
.setBlockInternally(at: SIMD3(player.position - SIMD3(0, 2, 0)), type: .air)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boxes = []
|
||||||
chunk.forEach { position, block in
|
chunk.forEach { position, block in
|
||||||
if block.type == .air {
|
if block.type == .air {
|
||||||
return
|
return
|
||||||
@ -70,19 +92,6 @@ class Game: GameDelegate {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player.position = SIMD3(0.5, Float(Chunk.chunkSize) + 0.5, 0.5)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fixedUpdate(_ time: GameTime) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func update(_ time: GameTime) {
|
|
||||||
fpsCalculator.frame(deltaTime: time.delta) { fps in
|
|
||||||
print("FPS: \(fps)")
|
|
||||||
}
|
|
||||||
|
|
||||||
let deltaTime = min(Float(time.delta.asFloat), 1.0 / 15)
|
|
||||||
|
|
||||||
player.update(deltaTime: deltaTime, boxes: boxes)
|
player.update(deltaTime: deltaTime, boxes: boxes)
|
||||||
camera.position = player.position
|
camera.position = player.position
|
||||||
|
Reference in New Issue
Block a user