mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2025-01-29 15:48:27 +00:00
drawing
This commit is contained in:
parent
2e2ae6b9a0
commit
31d14bdd7b
|
@ -10,8 +10,33 @@ import (
|
|||
func Game() {
|
||||
var (
|
||||
scenePaused = false
|
||||
|
||||
gridPos = raylib.NewVector2(0, 0)
|
||||
gridSize = raylib.NewVector2(100, (application.WindowHeight-20)/5)
|
||||
gridDensity float32 = 5
|
||||
|
||||
brushSize float32 = 1
|
||||
color = raylib.Orange
|
||||
canvas [][]raylib.Color
|
||||
)
|
||||
|
||||
// Create canvas
|
||||
for x := 0; x < int(gridSize.X); x++ {
|
||||
canvas = append(canvas, []raylib.Color{})
|
||||
for y := 0; y < int(gridSize.Y); y++ {
|
||||
canvas[x] = append(canvas[x], raylib.White)
|
||||
}
|
||||
}
|
||||
if gridPos.X >= 0 && gridPos.X < gridSize.X && gridPos.Y >= 0 && gridPos.Y < gridSize.Y {
|
||||
for x := int(gridPos.X - brushSize/2); x < int(gridPos.X+brushSize/2); x++ {
|
||||
for y := int(gridPos.Y - brushSize/2); y < int(gridPos.Y+brushSize/2); y++ {
|
||||
if x >= 0 && x < int(gridSize.X) && y >= 0 && y < int(gridSize.Y) {
|
||||
canvas[x][y] = color
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load resources here
|
||||
|
||||
for !application.ShouldQuit {
|
||||
|
@ -19,15 +44,58 @@ func Game() {
|
|||
if application.CurrentScene != application.SceneGame {
|
||||
break
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyEscape) {
|
||||
scenePaused = !scenePaused
|
||||
}
|
||||
|
||||
// INPUT
|
||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
||||
if gridPos.X >= 0 && gridPos.X < gridSize.X && gridPos.Y >= 0 && gridPos.Y < gridSize.Y {
|
||||
for x := int(gridPos.X - brushSize/2); x < int(gridPos.X+brushSize/2); x++ {
|
||||
for y := int(gridPos.Y - brushSize/2); y < int(gridPos.Y+brushSize/2); y++ {
|
||||
if x >= 0 && x < int(gridSize.X) && y >= 0 && y < int(gridSize.Y) {
|
||||
canvas[x][y] = color
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATE
|
||||
|
||||
// DRAW
|
||||
raylib.BeginDrawing()
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
|
||||
raylib.DrawText("Game", 100, 100, 20, raylib.White)
|
||||
gui.Grid(raylib.NewRectangle(10, 10, gridDensity*gridSize.X, gridDensity*gridSize.Y), "", gridDensity, 1, &gridPos)
|
||||
// Default grid doesnt show up
|
||||
raylib.DrawRectangle(0, 0, application.WindowWidth, application.WindowHeight, raylib.LightGray)
|
||||
|
||||
for x := 0; x < int(gridSize.X); x++ {
|
||||
for y := 0; y < int(gridSize.Y); y++ {
|
||||
pos := raylib.NewVector2(float32(x)*gridDensity, float32(y)*gridDensity)
|
||||
raylib.DrawRectangle(int32(pos.X)+10, int32(pos.Y)+10, int32(gridDensity), int32(gridDensity), canvas[x][y])
|
||||
}
|
||||
}
|
||||
raylib.DrawRectangleLines(10, 10, int32(gridDensity*gridSize.X), int32(gridDensity*gridSize.Y), raylib.Gray)
|
||||
|
||||
if gridPos.X >= 0 && gridPos.X < gridSize.X && gridPos.Y >= 0 && gridPos.Y < gridSize.Y {
|
||||
for x := int(gridPos.X - brushSize/2); x < int(gridPos.X+brushSize/2); x++ {
|
||||
for y := int(gridPos.Y - brushSize/2); y < int(gridPos.Y+brushSize/2); y++ {
|
||||
if x >= 0 && x < int(gridSize.X) && y >= 0 && y < int(gridSize.Y) {
|
||||
pos := raylib.NewVector2(float32(x)*gridDensity, float32(y)*gridDensity)
|
||||
raylib.DrawRectangle(int32(pos.X)+10, int32(pos.Y)+10, int32(gridDensity), int32(gridDensity), raylib.Fade(color, 0.5))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
color = gui.ColorPicker(raylib.NewRectangle(float32(30+int32(gridDensity*gridSize.X)), 10, application.WindowWidth-float32(65+int32(gridDensity*gridSize.X)), 200), "Color", color)
|
||||
|
||||
brushSize = gui.Slider(raylib.NewRectangle(float32(90+int32(gridDensity*gridSize.X)), 30+200, 200, 20), "Brush Size", "", brushSize, 1, 10)
|
||||
|
||||
raylib.DrawLine(20+int32(gridDensity*gridSize.X), 10, 20+int32(gridDensity*gridSize.X), 10+int32(gridDensity*gridSize.Y), raylib.Gray)
|
||||
raylib.DrawLine(30+int32(gridDensity*gridSize.X), 20+200, application.WindowWidth-10, 20+200, raylib.Gray)
|
||||
|
||||
if scenePaused {
|
||||
raylib.DrawRectangle(0, 0, application.WindowWidth, application.WindowHeight, raylib.Fade(raylib.Black, 0.5))
|
||||
|
|
|
@ -2,8 +2,6 @@ package scenes
|
|||
|
||||
import (
|
||||
"ColouringApp/application"
|
||||
"time"
|
||||
|
||||
raylib "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
|
@ -22,8 +20,8 @@ func PlayerData() {
|
|||
|
||||
raylib.EndDrawing()
|
||||
|
||||
// Just a placeholder
|
||||
time.Sleep(1 * time.Second)
|
||||
//time.Sleep(1 * time.Second)
|
||||
|
||||
application.CurrentScene = application.SceneTitle
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ func Title() {
|
|||
titleText = application.WindowTitle
|
||||
mapImage = raylib.LoadTexture(application.DirAssets + "Map.png")
|
||||
|
||||
mapX = 0
|
||||
mapY = 0
|
||||
//mapX = 0
|
||||
//mapY = 0
|
||||
)
|
||||
|
||||
for !application.ShouldQuit {
|
||||
|
@ -38,22 +38,10 @@ func Title() {
|
|||
application.ShouldQuit = true
|
||||
}
|
||||
|
||||
// Map thing?
|
||||
raylib.DrawRectangleLines(120, 39, application.WindowWidth-130, application.WindowHeight-49, raylib.White)
|
||||
raylib.BeginScissorMode(121, 40, application.WindowWidth-132, application.WindowHeight-51)
|
||||
|
||||
mapX += 1
|
||||
mapX = 0
|
||||
mapY = 0
|
||||
if mapX > 1920 {
|
||||
mapX = 0
|
||||
}
|
||||
|
||||
mapY += 1
|
||||
if mapY > 1080 {
|
||||
mapY = 0
|
||||
}
|
||||
raylib.DrawTexture(mapImage, int32(-mapX), int32(-mapY), raylib.White)
|
||||
//// Map thing?
|
||||
//raylib.DrawRectangleLines(120, 39, application.WindowWidth-130, application.WindowHeight-49, raylib.White)
|
||||
//raylib.BeginScissorMode(121, 40, application.WindowWidth-132, application.WindowHeight-51)
|
||||
//raylib.DrawTexture(mapImage, int32(-mapX), int32(-mapY), raylib.White)
|
||||
|
||||
raylib.EndScissorMode()
|
||||
raylib.EndDrawing()
|
||||
|
|
Loading…
Reference in a new issue