Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2brain committed Nov 10, 2023
1 parent 5830da3 commit c61ef10
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 59 deletions.
92 changes: 47 additions & 45 deletions examples/core/input_gamepad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,163 +21,165 @@ func main() {

rl.SetTargetFPS(60)

var gamepad int32 = 0 // which gamepad to display

for !rl.WindowShouldClose() {
rl.BeginDrawing()

rl.ClearBackground(rl.RayWhite)

if rl.IsGamepadAvailable(rl.GamepadPlayer1) {
rl.DrawText(fmt.Sprintf("GP1: %s", rl.GetGamepadName(rl.GamepadPlayer1)), 10, 10, 10, rl.Black)
if rl.IsGamepadAvailable(gamepad) {
rl.DrawText(fmt.Sprintf("GP1: %s", rl.GetGamepadName(gamepad)), 10, 10, 10, rl.Black)

if rl.GetGamepadName(rl.GamepadPlayer1) == xbox360NameID {
if rl.GetGamepadName(gamepad) == xbox360NameID {
rl.DrawTexture(texXboxPad, 0, 0, rl.DarkGray)

// Draw buttons: xbox home
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonHome) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddle) {
rl.DrawCircle(394, 89, 19, rl.Red)
}

// Draw buttons: basic
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonStart) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddleRight) {
rl.DrawCircle(436, 150, 9, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonSelect) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddleLeft) {
rl.DrawCircle(352, 150, 9, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonX) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceLeft) {
rl.DrawCircle(501, 151, 15, rl.Blue)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonA) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceDown) {
rl.DrawCircle(536, 187, 15, rl.Lime)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonB) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceRight) {
rl.DrawCircle(572, 151, 15, rl.Maroon)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonY) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceUp) {
rl.DrawCircle(536, 115, 15, rl.Gold)
}

// Draw buttons: d-pad
rl.DrawRectangle(317, 202, 19, 71, rl.Black)
rl.DrawRectangle(293, 228, 69, 19, rl.Black)
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonUp) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceUp) {
rl.DrawRectangle(317, 202, 19, 26, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonDown) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceDown) {
rl.DrawRectangle(317, 202+45, 19, 26, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonLeft) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceLeft) {
rl.DrawRectangle(292, 228, 25, 19, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonRight) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceRight) {
rl.DrawRectangle(292+44, 228, 26, 19, rl.Red)
}

// Draw buttons: left-right back
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonLb) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftTrigger1) {
rl.DrawCircle(259, 61, 20, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonRb) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightTrigger1) {
rl.DrawCircle(536, 61, 20, rl.Red)
}

// Draw axis: left joystick
rl.DrawCircle(259, 152, 39, rl.Black)
rl.DrawCircle(259, 152, 34, rl.LightGray)
rl.DrawCircle(int32(259+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLeftX)*20)),
int32(152-(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLeftY)*20)), 25, rl.Black)
rl.DrawCircle(int32(259+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftX)*20)),
int32(152-(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftY)*20)), 25, rl.Black)

// Draw axis: right joystick
rl.DrawCircle(461, 237, 38, rl.Black)
rl.DrawCircle(461, 237, 33, rl.LightGray)
rl.DrawCircle(int32(461+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRightX)*20)),
int32(237-(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRightY)*20)), 25, rl.Black)
rl.DrawCircle(int32(461+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightX)*20)),
int32(237-(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightY)*20)), 25, rl.Black)

// Draw axis: left-right triggers
rl.DrawRectangle(170, 30, 15, 70, rl.Gray)
rl.DrawRectangle(604, 30, 15, 70, rl.Gray)
rl.DrawRectangle(170, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLt))/2.0)*70), rl.Red)
rl.DrawRectangle(604, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRt))/2.0)*70), rl.Red)
rl.DrawRectangle(170, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftTrigger))/2.0)*70), rl.Red)
rl.DrawRectangle(604, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightTrigger))/2.0)*70), rl.Red)

} else if rl.GetGamepadName(rl.GamepadPlayer1) == ps3NameID {
} else if rl.GetGamepadName(gamepad) == ps3NameID {
rl.DrawTexture(texPs3Pad, 0, 0, rl.DarkGray)

// Draw buttons: ps
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonPs) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddle) {
rl.DrawCircle(396, 222, 13, rl.Red)
}

// Draw buttons: basic
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonSelect) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddleLeft) {
rl.DrawRectangle(328, 170, 32, 13, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonStart) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddleRight) {
rl.DrawTriangle(rl.NewVector2(436, 168), rl.NewVector2(436, 185), rl.NewVector2(464, 177), rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonTriangle) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceUp) {
rl.DrawCircle(557, 144, 13, rl.Lime)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonCircle) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceRight) {
rl.DrawCircle(586, 173, 13, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonCross) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceDown) {
rl.DrawCircle(557, 203, 13, rl.Violet)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonSquare) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceLeft) {
rl.DrawCircle(527, 173, 13, rl.Pink)
}

// Draw buttons: d-pad
rl.DrawRectangle(225, 132, 24, 84, rl.Black)
rl.DrawRectangle(195, 161, 84, 25, rl.Black)
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonUp) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceUp) {
rl.DrawRectangle(225, 132, 24, 29, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonDown) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceDown) {
rl.DrawRectangle(225, 132+54, 24, 30, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonLeft) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceLeft) {
rl.DrawRectangle(195, 161, 30, 25, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonRight) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceRight) {
rl.DrawRectangle(195+54, 161, 30, 25, rl.Red)
}

// Draw buttons: left-right back buttons
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonL1) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftTrigger1) {
rl.DrawCircle(239, 82, 20, rl.Red)
}
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonR1) {
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightTrigger1) {
rl.DrawCircle(557, 82, 20, rl.Red)
}

// Draw axis: left joystick
rl.DrawCircle(319, 255, 35, rl.Black)
rl.DrawCircle(319, 255, 31, rl.LightGray)
rl.DrawCircle(int32(319+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisLeftX)*20)),
int32(255+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisLeftY)*20)), 25, rl.Black)
rl.DrawCircle(int32(319+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftX)*20)),
int32(255+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftY)*20)), 25, rl.Black)

// Draw axis: right joystick
rl.DrawCircle(475, 255, 35, rl.Black)
rl.DrawCircle(475, 255, 31, rl.LightGray)
rl.DrawCircle(int32(475+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisRightX)*20)),
int32(255+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisRightY)*20)), 25, rl.Black)
rl.DrawCircle(int32(475+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightX)*20)),
int32(255+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightY)*20)), 25, rl.Black)

// Draw axis: left-right triggers
rl.DrawRectangle(169, 48, 15, 70, rl.Gray)
rl.DrawRectangle(611, 48, 15, 70, rl.Gray)
rl.DrawRectangle(169, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisL2))/2.0)*70), rl.Red)
rl.DrawRectangle(611, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisR2))/2.0)*70), rl.Red)
rl.DrawRectangle(169, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftTrigger))/2.0)*70), rl.Red)
rl.DrawRectangle(611, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightTrigger))/2.0)*70), rl.Red)
} else {
rl.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, rl.Gray)

// TODO: Draw generic gamepad
}

rl.DrawText(fmt.Sprintf("DETECTED AXIS [%d]:", rl.GetGamepadAxisCount(rl.GamepadPlayer1)), 10, 50, 10, rl.Maroon)
rl.DrawText(fmt.Sprintf("DETECTED AXIS [%d]:", rl.GetGamepadAxisCount(gamepad)), 10, 50, 10, rl.Maroon)

for i := int32(0); i < rl.GetGamepadAxisCount(rl.GamepadPlayer1); i++ {
rl.DrawText(fmt.Sprintf("AXIS %d: %.02f", i, rl.GetGamepadAxisMovement(rl.GamepadPlayer1, i)), 20, 70+20*i, 10, rl.DarkGray)
for i := int32(0); i < rl.GetGamepadAxisCount(gamepad); i++ {
rl.DrawText(fmt.Sprintf("AXIS %d: %.02f", i, rl.GetGamepadAxisMovement(gamepad, i)), 20, 70+20*i, 10, rl.DarkGray)
}

if rl.GetGamepadButtonPressed() != -1 {
Expand Down
10 changes: 7 additions & 3 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module examples

go 1.19
go 1.21

replace github.com/gen2brain/raylib-go/raylib => ../raylib

replace github.com/gen2brain/raylib-go/raygui => ../raygui

require (
github.com/gen2brain/raylib-go/easings v0.0.0-20231021203613-2d673bb5f4b3
github.com/gen2brain/raylib-go/physics v0.0.0-20231021203613-2d673bb5f4b3
github.com/gen2brain/raylib-go/raygui v0.0.0-20231021203613-2d673bb5f4b3
github.com/gen2brain/raylib-go/raylib v0.0.0-20231021203613-2d673bb5f4b3
github.com/gen2brain/raylib-go/raygui v0.0.0-20231110085703-5830da3d8795
github.com/gen2brain/raylib-go/raylib v0.0.0-20231110085703-5830da3d8795
github.com/jakecoffman/cp v1.2.1
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b
)
4 changes: 0 additions & 4 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ github.com/gen2brain/raylib-go/easings v0.0.0-20231021203613-2d673bb5f4b3 h1:X96
github.com/gen2brain/raylib-go/easings v0.0.0-20231021203613-2d673bb5f4b3/go.mod h1:UuXithI7f7GZ22PJtaZDXHzWzdXx0OCyuxaakj9gt9k=
github.com/gen2brain/raylib-go/physics v0.0.0-20231021203613-2d673bb5f4b3 h1:TYu6QaR/DPgFgoluAUUj5Iftn76bjXCmCTYAlt5UHaU=
github.com/gen2brain/raylib-go/physics v0.0.0-20231021203613-2d673bb5f4b3/go.mod h1:ViQH1zqfv7oSbhxKUWDV5JgnYHHkf/DGQ9HrVNEPTd0=
github.com/gen2brain/raylib-go/raygui v0.0.0-20231021203613-2d673bb5f4b3 h1:LYkdSAU1c6r4PZaYPGb9HC5ph+ndBErukpGwQCvxGc4=
github.com/gen2brain/raylib-go/raygui v0.0.0-20231021203613-2d673bb5f4b3/go.mod h1:uYchFLZ2wwfI+gRV8i0qHk6DKk5ZL/6VNrY/Nmzw5Ps=
github.com/gen2brain/raylib-go/raylib v0.0.0-20231021203613-2d673bb5f4b3 h1:wbY2Fut4NYPoeVDidD+WthGT1g+Ou9+Mywy5TYtrJt0=
github.com/gen2brain/raylib-go/raylib v0.0.0-20231021203613-2d673bb5f4b3/go.mod h1:AwtGA3aTtYdezNxEVbfchaLw/z+CuRDh2Mlxy0FbBro=
github.com/jakecoffman/cp v1.2.1 h1:zkhc2Gpo9l4NLUZfeG3j33+3bQD7MkqPa+n5PdX+5mI=
github.com/jakecoffman/cp v1.2.1/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b h1:+67TGbwfgeB5o03Rx+ZBW44zAQ+wUujcwdRA0p9CbJI=
Expand Down
8 changes: 4 additions & 4 deletions examples/shaders/mesh_instancing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func main() {
transforms := make([]rl.Matrix, MAX_INSTANCES)

shader := rl.LoadShader("glsl330/base_lighting_instanced.vs", "glsl330/lighting.fs")
shader.UpdateLocation(rl.LocMatrixMvp, rl.GetShaderLocation(shader, "mvp"))
shader.UpdateLocation(rl.LocVectorView, rl.GetShaderLocation(shader, "viewPos"))
shader.UpdateLocation(rl.LocMatrixModel, rl.GetShaderLocationAttrib(shader, "instanceTransform"))
shader.UpdateLocation(rl.ShaderLocMatrixMvp, rl.GetShaderLocation(shader, "mvp"))
shader.UpdateLocation(rl.ShaderLocVectorView, rl.GetShaderLocation(shader, "viewPos"))
shader.UpdateLocation(rl.ShaderLocMatrixModel, rl.GetShaderLocationAttrib(shader, "instanceTransform"))

// ambient light level
ambientLoc := rl.GetShaderLocation(shader, "ambient")
Expand Down Expand Up @@ -162,7 +162,7 @@ func main() {
}

// Update the light shader with the camera view position
rl.SetShaderValue(shader, shader.GetLocation(rl.LocVectorView),
rl.SetShaderValue(shader, shader.GetLocation(rl.ShaderLocVectorView),
[]float32{camera.Position.X, camera.Position.Y, camera.Position.Z}, rl.ShaderUniformVec3)

// Apply per-instance transformations
Expand Down
4 changes: 2 additions & 2 deletions examples/textures/image_generation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func main() {

rl.InitWindow(int32(screenWidth), int32(screenHeight), "raylib [textures] example - procedural images generation")

verticalGradient := rl.GenImageGradientV(screenWidth, screenHeight, rl.Red, rl.Blue)
horizontalGradient := rl.GenImageGradientH(screenWidth, screenHeight, rl.Red, rl.Blue)
verticalGradient := rl.GenImageGradientLinear(screenWidth, screenHeight, 0, rl.Red, rl.Blue)
horizontalGradient := rl.GenImageGradientLinear(screenWidth, screenHeight, 90, rl.Red, rl.Blue)
radialGradient := rl.GenImageGradientRadial(screenWidth, screenHeight, 0, rl.White, rl.Black)
checked := rl.GenImageChecked(screenWidth, screenHeight, 32, 32, rl.Red, rl.Blue)
whiteNoise := rl.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
Expand Down
2 changes: 1 addition & 1 deletion examples/textures/textured_curve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func drawTexturedCurve() {
func drawCurve() {

if showCurve {
rl.DrawLineBezierCubic(curveStartPos, curveEndPos, curveStartPosTangent, curveEndPosTangent, 2, rl.Blue)
rl.DrawSplineSegmentBezierCubic(curveStartPos, curveEndPos, curveStartPosTangent, curveEndPosTangent, 2, rl.Blue)
}
rl.DrawLineV(curveStartPos, curveStartPosTangent, rl.SkyBlue)
rl.DrawLineV(curveEndPos, curveEndPosTangent, rl.Purple)
Expand Down

0 comments on commit c61ef10

Please sign in to comment.