Work on improving the menus

This commit is contained in:
Michał 2024-01-23 17:23:57 +00:00
parent 40c43126ca
commit 65ec70dd4a
6 changed files with 96 additions and 97 deletions

View file

@ -1,36 +1,25 @@
package application
const (
// WindowTitle used as the Windows Title but also used for the name of the game
WindowTitle = "Colouring App"
// Defines the window proportions
WindowWidth = 800
WindowHeight = 600
// WindowFPS Max FPS the game should run at, used to calucalte delta time
WindowFPS = 144
var (
WindowTitle = "Colouring App"
WindowWidth int32 = 800
WindowHeight int32 = 600
WindowFPS int32 = 144
)
// Scene IDs used to determine which scene to run
const (
ScenePlayerData = iota
SceneTitle
SceneOptions
SceneGallery
SceneDrawing
)
// Directories used to store assets
const (
DirAssets = "./assets/"
DirUserData = "./userData/"
)
var (
// ShouldQuit is used to determine if the game should quit
ShouldQuit = false
// CurrentScene is the scene that is currently running, defaults to loading player data
ShouldQuit = false
CurrentScene = ScenePlayerData
)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

View file

@ -8,12 +8,12 @@ import (
)
func main() {
//raylib.SetConfigFlags(raylib.FlagWindowResizable)
raylib.SetConfigFlags(raylib.FlagWindowResizable)
raylib.InitWindow(application.WindowWidth, application.WindowHeight, application.WindowTitle)
raylib.InitAudioDevice()
raylib.SetTargetFPS(application.WindowFPS)
//raylib.SetTargetFPS(application.WindowFPS)
//raylib.SetExitKey(0) // disable exit key
// MAIN LOOP

View file

@ -20,18 +20,16 @@ func Drawing() {
strokes = []stroke{currentStroke}
undoneStrokes = []stroke{}
brushSize float32 = 1
color = raylib.Orange
)
brushSize float32 = 10
// Create canvas
raylib.BeginTextureMode(canvas)
raylib.ClearBackground(raylib.White)
raylib.EndTextureMode()
colourPickerVal = raylib.Orange
colourPickerHeight float32 = 200
)
refreshCanvas := func() {
raylib.BeginTextureMode(canvas)
raylib.ClearBackground(raylib.White)
for i := 1; i < len(strokes); i++ {
for j := 1; j < len(strokes[i].Points); j++ {
startPos := raylib.Vector2Subtract(strokes[i].Points[j-1], raylib.NewVector2(10, 10))
@ -40,79 +38,96 @@ func Drawing() {
raylib.DrawCircle(int32(endPos.X), int32(endPos.Y), strokes[i].Size/2, strokes[i].Color)
}
}
raylib.EndTextureMode()
}
// Create canvas
refreshCanvas()
for !application.ShouldQuit {
application.ShouldQuit = raylib.WindowShouldClose()
if application.CurrentScene != application.SceneDrawing {
break
}
if raylib.IsWindowResized() {
application.WindowWidth = int32(raylib.GetScreenWidth())
application.WindowHeight = int32(raylib.GetScreenHeight())
}
// INPUT
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
currentStroke = stroke{
Color: color,
Size: brushSize,
{
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
currentStroke = stroke{
Color: colourPickerVal,
Size: brushSize,
}
}
}
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
// if mouse is further than 5 pixels from last point, add it
var safeZone float32 = 5
if len(currentStroke.Points) == 0 {
currentStroke.Points = append(currentStroke.Points, raylib.GetMousePosition())
} else if raylib.Vector2Distance(currentStroke.Points[len(currentStroke.Points)-1], raylib.GetMousePosition()) > safeZone {
currentStroke.Points = append(currentStroke.Points, raylib.GetMousePosition())
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
// if mouse is further than 5 pixels from last point, add it
var safeZone float32 = 1
if len(currentStroke.Points) <= 1 {
currentStroke.Points = append(currentStroke.Points, raylib.GetMousePosition())
} else if raylib.Vector2Distance(currentStroke.Points[len(currentStroke.Points)-1], raylib.GetMousePosition()) > safeZone {
currentStroke.Points = append(currentStroke.Points, raylib.GetMousePosition())
}
//currentStroke.Points = append(currentStroke.Points, raylib.GetMousePosition())
}
if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) && currentStroke.Points != nil {
strokes = append(strokes, currentStroke)
currentStroke = stroke{}
undoneStrokes = []stroke{}
refreshCanvas()
}
//currentStroke.Points = append(currentStroke.Points, raylib.GetMousePosition())
}
if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) && currentStroke.Points != nil {
strokes = append(strokes, currentStroke)
currentStroke = stroke{}
undoneStrokes = []stroke{}
refreshCanvas()
}
if raylib.IsKeyDown(raylib.KeyLeftControl) && raylib.IsKeyDown(raylib.KeyLeftShift) && raylib.IsKeyPressed(raylib.KeyZ) {
if len(undoneStrokes) > 0 {
strokes = append(strokes, undoneStrokes[len(undoneStrokes)-1])
undoneStrokes = undoneStrokes[:len(undoneStrokes)-1]
if raylib.IsKeyDown(raylib.KeyLeftControl) && raylib.IsKeyDown(raylib.KeyLeftShift) && raylib.IsKeyPressed(raylib.KeyZ) {
if len(undoneStrokes) > 0 {
strokes = append(strokes, undoneStrokes[len(undoneStrokes)-1])
undoneStrokes = undoneStrokes[:len(undoneStrokes)-1]
}
refreshCanvas()
} else if raylib.IsKeyDown(raylib.KeyLeftControl) && raylib.IsKeyPressed(raylib.KeyZ) {
if len(strokes) > 0 {
undoneStrokes = append(undoneStrokes, strokes[len(strokes)-1])
strokes = strokes[:len(strokes)-1]
}
refreshCanvas()
}
refreshCanvas()
} else if raylib.IsKeyDown(raylib.KeyLeftControl) && raylib.IsKeyPressed(raylib.KeyZ) {
if len(strokes) > 0 {
undoneStrokes = append(undoneStrokes, strokes[len(strokes)-1])
strokes = strokes[:len(strokes)-1]
}
refreshCanvas()
}
// UPDATE
// DRAW
raylib.BeginDrawing()
raylib.ClearBackground(raylib.LightGray)
{
raylib.ClearBackground(raylib.White)
raylib.BeginScissorMode(10, 10, int32(canvasSize.X), int32(canvasSize.Y))
raylib.DrawTexturePro(canvas.Texture, raylib.NewRectangle(0, 0, float32(canvas.Texture.Width), float32(-canvas.Texture.Height)), raylib.NewRectangle(10, 10, canvasSize.X, canvasSize.Y), raylib.Vector2{}, 0, raylib.White)
for i := 1; i < len(currentStroke.Points); i++ {
raylib.DrawLineEx(currentStroke.Points[i-1], currentStroke.Points[i], currentStroke.Size, currentStroke.Color)
raylib.DrawCircle(int32(currentStroke.Points[i].X), int32(currentStroke.Points[i].Y), currentStroke.Size/2, currentStroke.Color)
// Canvas stuff
raylib.BeginScissorMode(10, 10, int32(canvasSize.X), int32(canvasSize.Y))
{
raylib.DrawTexturePro(canvas.Texture, raylib.NewRectangle(0, 0, float32(canvas.Texture.Width), float32(-canvas.Texture.Height)), raylib.NewRectangle(10, 10, canvasSize.X, canvasSize.Y), raylib.Vector2{}, 0, raylib.White)
for i := 1; i < len(currentStroke.Points); i++ {
raylib.DrawLineEx(currentStroke.Points[i-1], currentStroke.Points[i], currentStroke.Size, currentStroke.Color)
raylib.DrawCircle(int32(currentStroke.Points[i].X), int32(currentStroke.Points[i].Y), currentStroke.Size/2, currentStroke.Color)
}
raylib.DrawCircleLines(int32(raylib.GetMousePosition().X), int32(raylib.GetMousePosition().Y), brushSize/2, raylib.Black)
}
raylib.EndScissorMode()
raylib.DrawRectangleLines(10, 10, int32(canvasSize.X), int32(canvasSize.Y), raylib.Gray)
// UI stuff
if gui.Button(raylib.NewRectangle(float32(30+int32(canvasSize.X)), 10, 25, 25), gui.IconText(gui.ICON_CROSS, "")) {
application.CurrentScene = application.SceneTitle
}
if gui.Button(raylib.NewRectangle(float32(65+int32(canvasSize.X)), 10, 25, 25), gui.IconText(gui.ICON_FOLDER_SAVE, "")) {
}
colourPickerVal = gui.ColorPicker(raylib.NewRectangle(float32(30+int32(canvasSize.X)), 45, float32(application.WindowWidth)-float32(65+int32(canvasSize.X)), colourPickerHeight), "Color", colourPickerVal)
brushSize = gui.Slider(raylib.NewRectangle(float32(90+int32(canvasSize.X)), 65+colourPickerHeight, 200, 20), "Brush Size", "", brushSize, 1, 100)
raylib.DrawLine(20+int32(canvasSize.X), 10, 20+int32(canvasSize.X), 10+int32(canvasSize.Y), raylib.Gray)
raylib.DrawLine(30+int32(canvasSize.X), int32(55+colourPickerHeight), application.WindowWidth-10, int32(55+colourPickerHeight), raylib.Gray)
}
raylib.EndScissorMode()
raylib.DrawRectangleLines(10, 10, int32(canvasSize.X), int32(canvasSize.Y), raylib.Gray)
color = gui.ColorPicker(raylib.NewRectangle(float32(30+int32(canvasSize.X)), 10, application.WindowWidth-float32(65+int32(canvasSize.X)), 200), "Color", color)
brushSize = gui.Slider(raylib.NewRectangle(float32(90+int32(canvasSize.X)), 30+200, 200, 20), "Brush Size", "", brushSize, 1, 100)
raylib.DrawLine(20+int32(canvasSize.X), 10, 20+int32(canvasSize.X), 10+int32(canvasSize.Y), raylib.Gray)
raylib.DrawLine(30+int32(canvasSize.X), 20+200, application.WindowWidth-10, 20+200, raylib.Gray)
if gui.Button(raylib.NewRectangle(float32(30+int32(canvasSize.X)), application.WindowHeight-35, application.WindowWidth-float32(40+int32(canvasSize.X)), 25), "Main Menu") {
application.CurrentScene = application.SceneTitle
}
raylib.EndDrawing()
}

View file

@ -14,8 +14,8 @@ func Options() {
titleForwardPos float32 = 45
centerPos float32 = 10
backPos float32 = -application.WindowWidth + 10
forwardPos float32 = application.WindowWidth + 10
backPos = float32(-application.WindowWidth + 10)
forwardPos = float32(application.WindowWidth + 10)
rootPanel = true
controlsPanel = false
@ -68,7 +68,7 @@ func Options() {
raylib.EndScissorMode()
raylib.DrawLine(10, 40, 790, 40, raylib.White)
if gui.Button(raylib.NewRectangle(application.WindowWidth-110, 10, 100, 20), "Main Menu") {
if gui.Button(raylib.NewRectangle(float32(application.WindowWidth-110), 10, 100, 20), "Main Menu") {
application.CurrentScene = application.SceneTitle
}

View file

@ -10,10 +10,6 @@ import (
func Title() {
var (
titleText = application.WindowTitle
mapImage = raylib.LoadTexture(application.DirAssets + "Map.png")
//mapX = 0
//mapY = 0
)
for !application.ShouldQuit {
@ -22,32 +18,31 @@ func Title() {
break
}
// ToDo: Remove this
application.CurrentScene = application.SceneDrawing
if raylib.IsWindowResized() {
application.WindowWidth = int32(raylib.GetScreenWidth())
application.WindowHeight = int32(raylib.GetScreenHeight())
}
raylib.BeginDrawing()
raylib.ClearBackground(raylib.Black)
raylib.ClearBackground(raylib.White)
if gui.Button(raylib.NewRectangle(10, 10, 40, 40), gui.IconText(gui.ICON_CROSS, "")) {
application.ShouldQuit = true
}
raylib.DrawText(titleText, (application.WindowWidth-raylib.MeasureText(titleText, 20))/2, 20, 20, raylib.White)
if gui.Button(raylib.NewRectangle(application.WindowWidth-50, 10, 40, 40), gui.IconText(gui.ICON_GEAR, "")) {
raylib.DrawText(titleText, (application.WindowWidth-raylib.MeasureText(titleText, 20))/2, 20, 20, raylib.Black)
if gui.Button(raylib.NewRectangle(float32(application.WindowWidth-50), 10, 40, 40), gui.IconText(gui.ICON_GEAR, "")) {
application.CurrentScene = application.SceneOptions
}
//raylib.DrawLine(10, 60, 790, 60, 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()
if gui.Button(raylib.NewRectangle((application.WindowWidth-100)/2, application.WindowHeight-70, 100, 40), "Start") {
if gui.Button(raylib.NewRectangle(float32((application.WindowWidth-100)/2), float32(application.WindowHeight-70), 100, 40), "Start") {
application.CurrentScene = application.SceneDrawing
}
raylib.EndDrawing()
}
raylib.UnloadTexture(mapImage)
}