-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.swift
67 lines (53 loc) · 1.67 KB
/
App.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import RaylibKit
//MARK: - Application
@main struct ExampleCamera2DMouseZoom: Applet {
let ZOOM_INCREMENT: Float = 0.125
var player: Rectangle
var camera: Camera2D
init() {
Window.create(800, by: 450, title: "Example - Core - 2D Camera Mouse Zoom")
Renderer.background = .black
Application.target(fps: 60)
player = Rectangle(at: 400, 280, size: 40, 40)
camera = Camera2D()
}
mutating func update() {
if Mouse.right.isDown {
camera.translate(by: Mouse.delta)
}
if Mouse.wheel != 0 {
camera.offset = Mouse.position
camera.target = camera.toWorld(screen: Mouse.position)
camera.zoom += Mouse.wheel * ZOOM_INCREMENT;
camera.zoom.minimum(of: ZOOM_INCREMENT)
}
}
func draw() {
Renderer.camera(camera) {
/*
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
// just so we have something in the XY plane
rlPushMatrix();
rlTranslatef(0, 25*50, 0);
rlRotatef(90, 1, 0, 0);
DrawGrid(100, 50);
rlPopMatrix();
// Draw a reference circle
DrawCircle(100, 100, 50, YELLOW);
*/
Renderer2D.circle(at: 100, 100, radius: 50, color: .yellow)
}
Renderer2D.text("Mouse right button drag to move, mouse wheel to zoom", at: 10, 10, color: .white);
}
}
//MARK: - Game
struct Building {
var rect: Rectangle
var color: Color
static func random(offset: Float) -> Building {
let size = Vector2(.random(in: 50 ... 200), .random(in: 100 ... 800))
let position = Vector2(-6000 + offset, Window.height.toFloat - 130 - size.y)
let color = Color.rgb(.random(in: 200 ... 240), .random(in: 200 ... 240), .random(in: 200 ... 250))
return Building(rect: Rectangle(at: position, size: size), color: color)
}
}