From: jxnshi Date: Tue, 11 Mar 2025 14:29:43 +0000 (+0100) Subject: First commit X-Git-Url: https://jxnshi.xyz/repos?a=commitdiff_plain;h=d39915a042a784501471b24f1e372ea24edaeda5;p=they-gone.git First commit --- d39915a042a784501471b24f1e372ea24edaeda5 diff --git a/assets/assets.go b/assets/assets.go new file mode 100644 index 0000000..66ad5a2 --- /dev/null +++ b/assets/assets.go @@ -0,0 +1,6 @@ +package assets + +import _ "embed" + +//go:embed player.png +var Player []byte diff --git a/assets/player.png b/assets/player.png new file mode 100644 index 0000000..518a87a Binary files /dev/null and b/assets/player.png differ diff --git a/entity.go b/entity.go new file mode 100644 index 0000000..665ae45 --- /dev/null +++ b/entity.go @@ -0,0 +1,47 @@ +package main + +import rl "github.com/gen2brain/raylib-go/raylib" + +type Entity struct { + Texture rl.Texture2D + Position rl.Vector2 + Size rl.Vector2 + Flip bool +} + +func NewEntity( + texture rl.Texture2D, + position rl.Vector2, + size rl.Vector2, +) Entity { + return Entity{ + Texture: texture, + Position: position, + Size: size, + } +} + +func DrawEntity(entity Entity) { + srcRect := rl.Rectangle{ + Width: entity.Size.X, + Height: entity.Size.Y, + } + + if entity.Flip { + srcRect.Width = -srcRect.Width + } + + dstRect := rl.Rectangle{ + X: entity.Position.X, + Y: entity.Position.Y, + Width: entity.Size.X, + Height: entity.Size.Y, + } + + origin := rl.Vector2{ + X: entity.Size.X / 2, + Y: entity.Size.Y, + } + + rl.DrawTexturePro(entity.Texture, srcRect, dstRect, origin, 0, rl.RayWhite) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4a16dda --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module they-gone + +go 1.24.0 + +require ( + github.com/ebitengine/purego v0.8.2 // indirect + github.com/gen2brain/raylib-go/raylib v0.0.0-20250215042252-db8e47f0e5c5 // indirect + golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect + golang.org/x/sys v0.31.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2d289cc --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I= +github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/gen2brain/raylib-go/raylib v0.0.0-20250215042252-db8e47f0e5c5 h1:k8ZAxLgb/p5TvCi5VHFHM8JdnjwShNK4A0bLIwbktAU= +github.com/gen2brain/raylib-go/raylib v0.0.0-20250215042252-db8e47f0e5c5/go.mod h1:BaY76bZk7nw1/kVOSQObPY1v1iwVE1KHAGMfvI6oK1Q= +golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw= +golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= diff --git a/main.go b/main.go new file mode 100644 index 0000000..f6fb20b --- /dev/null +++ b/main.go @@ -0,0 +1,90 @@ +package main + +import ( + rl "github.com/gen2brain/raylib-go/raylib" + + "they-gone/assets" +) + +const mapSize = 100 + +type Tile uint8 + +type App struct { + Camera rl.Camera2D + Entities []Entity +} + +func moveVector() rl.Vector2 { + var vector rl.Vector2 + + if rl.IsKeyDown(rl.KeyA) { vector.X -= 1 } + if rl.IsKeyDown(rl.KeyD) { vector.X += 1 } + + if rl.IsKeyDown(rl.KeyW) { vector.Y -= 1 } + if rl.IsKeyDown(rl.KeyS) { vector.Y += 1 } + + return vector +} + +func main() { + const windowWidth int = 800 + const windowHeight int = 600 + + const playerSpeed float32 = 3 + + rl.InitWindow(int32(windowWidth), int32(windowHeight), "They left.") + defer rl.CloseWindow() + + rl.SetTargetFPS(30) + + playerImage := rl.LoadImageFromMemory(".png", assets.Player, int32(len(assets.Player))) + + playerTexture := rl.LoadTextureFromImage(playerImage) + defer rl.UnloadTexture(playerTexture) + + rl.UnloadImage(playerImage) + + playerSize := rl.Vector2{ 300, 300 } + + app := App{ + Camera: rl.Camera2D{ + Offset: rl.Vector2{ float32(windowWidth) / 2, float32(windowHeight) - playerSize.Y / 2 }, + Zoom: 1, + }, + Entities: make([]Entity, 0), + } + + { + player := NewEntity(playerTexture, rl.Vector2{}, playerSize) + app.Entities = append(app.Entities, player) + } + + player := &app.Entities[0] + + for !rl.WindowShouldClose() { + moveVec := moveVector() + + if moveVec.X > 0 { player.Flip = false } + if moveVec.X < 0 { player.Flip = true } + + player.Position.X += playerSpeed * moveVec.X + player.Position.Y += playerSpeed * moveVec.Y + + rl.BeginDrawing() + + rl.ClearBackground(rl.Black) + + { + rl.BeginMode2D(app.Camera) + + for _, entity := range app.Entities { + DrawEntity(entity) + } + + rl.EndMode2D() + } + + rl.EndDrawing() + } +}