Compare commits
1 Commits
master
...
3b6277fce0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b6277fce0 |
BIN
src/assets/player/player.pxo
Normal file
BIN
src/assets/player/player.pxo
Normal file
Binary file not shown.
@@ -3,7 +3,6 @@ package main
|
|||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "vendor:raylib"
|
import "vendor:raylib"
|
||||||
|
|
||||||
player: Player
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
fmt.println("Brackey's Game Jam 2026 :) ")
|
fmt.println("Brackey's Game Jam 2026 :) ")
|
||||||
@@ -11,43 +10,15 @@ main :: proc() {
|
|||||||
raylib.InitWindow(1920, 1080, "Game")
|
raylib.InitWindow(1920, 1080, "Game")
|
||||||
raylib.SetTargetFPS(60)
|
raylib.SetTargetFPS(60)
|
||||||
|
|
||||||
player = {
|
|
||||||
position = {0, 0},
|
|
||||||
camera = {
|
|
||||||
zoom = 2,
|
|
||||||
offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2},
|
|
||||||
target = {player.position.x + (32 / 2), player.position.y + (32 / 2)},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for (!raylib.WindowShouldClose()) {
|
for (!raylib.WindowShouldClose()) {
|
||||||
|
|
||||||
delta := raylib.GetFrameTime()
|
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
raylib.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.DARKBLUE)
|
raylib.ClearBackground(raylib.DARKBLUE)
|
||||||
raylib.BeginMode2D(player.camera)
|
|
||||||
|
|
||||||
raylib.DrawText("Ur mom", 100, 100, 50, raylib.BLACK)
|
raylib.DrawText("Ur mom", 100, 100, 50, raylib.BLACK)
|
||||||
|
|
||||||
draw()
|
|
||||||
|
|
||||||
raylib.EndMode2D()
|
|
||||||
raylib.EndDrawing()
|
raylib.EndDrawing()
|
||||||
|
|
||||||
update(delta)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
raylib.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private = "file")
|
|
||||||
update :: proc(delta: f32) {
|
|
||||||
update_player(&player, delta)
|
|
||||||
}
|
|
||||||
|
|
||||||
@(private = "file")
|
|
||||||
draw :: proc() {
|
|
||||||
draw_player(&player)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "core:fmt"
|
|
||||||
import "vendor:raylib"
|
|
||||||
|
|
||||||
PLAYER_SPEED :: 5
|
|
||||||
|
|
||||||
Player :: struct {
|
|
||||||
health: int,
|
|
||||||
current_world: string,
|
|
||||||
camera: raylib.Camera2D,
|
|
||||||
position: raylib.Vector2,
|
|
||||||
}
|
|
||||||
|
|
||||||
@(private = "file")
|
|
||||||
handle_player_camera :: proc(p: ^Player, delta: f32) {
|
|
||||||
player_center := raylib.Vector2{p.position.x + 16, p.position.y + 16}
|
|
||||||
|
|
||||||
smooth_speed :: 10.0
|
|
||||||
|
|
||||||
p.camera.target.x += (player_center.x - p.camera.target.x) * smooth_speed * delta
|
|
||||||
p.camera.target.y += (player_center.y - p.camera.target.y) * smooth_speed * delta
|
|
||||||
|
|
||||||
if (raylib.IsWindowResized()) {
|
|
||||||
p.camera.offset = {f32(raylib.GetScreenWidth()) * 0.5, f32(raylib.GetScreenHeight()) * 0.5}
|
|
||||||
}
|
|
||||||
|
|
||||||
// p.camera.target = {p.position.x + (32 / 2), p.position.y + (32 / 2)}
|
|
||||||
|
|
||||||
// if raylib.IsWindowResized() {
|
|
||||||
// p.camera.offset = {f32(raylib.GetScreenWidth()) / 2, f32(raylib.GetScreenHeight()) / 2}
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
@(private = "file")
|
|
||||||
handle_player_input :: proc(p: ^Player, delta: f32) {
|
|
||||||
dir: raylib.Vector2 = {0, 0}
|
|
||||||
|
|
||||||
if raylib.IsKeyDown(.W) do dir.y -= 1
|
|
||||||
if raylib.IsKeyDown(.S) do dir.y += 1
|
|
||||||
if raylib.IsKeyDown(.A) do dir.x -= 1
|
|
||||||
if raylib.IsKeyDown(.D) do dir.x += 1
|
|
||||||
|
|
||||||
if dir.x != 0 || dir.y != 0 {
|
|
||||||
dir = raylib.Vector2Normalize(dir)
|
|
||||||
dir = dir * PLAYER_SPEED
|
|
||||||
p.position = p.position + dir
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_player :: proc(p: ^Player) {
|
|
||||||
raylib.DrawRectangle(i32(p.position.x), i32(p.position.y), 32, 32, raylib.BLACK)
|
|
||||||
}
|
|
||||||
|
|
||||||
update_player :: proc(p: ^Player, delta: f32) {
|
|
||||||
handle_player_input(p, delta)
|
|
||||||
handle_player_camera(p, delta)
|
|
||||||
// fmt.println(p.position)
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user