Update C sources, add new functions and rename package to
This commit is contained in:
parent
391c25482d
commit
08aa518a46
156 changed files with 34542 additions and 19573 deletions
|
@ -9,46 +9,46 @@ func main() {
|
|||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics demo")
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics demo")
|
||||
|
||||
// Physac logo drawing position
|
||||
logoX := screenWidth - raylib.MeasureText("Physac", 30) - 10
|
||||
logoX := screenWidth - rl.MeasureText("Physac", 30) - 10
|
||||
logoY := int32(15)
|
||||
|
||||
// Initialize physics and default physics bodies
|
||||
physics.Init()
|
||||
|
||||
// Create floor rectangle physics body
|
||||
floor := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||
floor := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
|
||||
// Create obstacle circle physics body
|
||||
circle := physics.NewBodyCircle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||
circle := physics.NewBodyCircle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||
circle.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
for !rl.WindowShouldClose() {
|
||||
|
||||
// Update created physics objects
|
||||
physics.Update()
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
||||
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||
physics.Reset()
|
||||
|
||||
floor = physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||
floor = physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||
floor.Enabled = false
|
||||
|
||||
circle = physics.NewBodyCircle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||
circle = physics.NewBodyCircle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||
circle.Enabled = false
|
||||
}
|
||||
|
||||
// Physics body creation inputs
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
physics.NewBodyPolygon(raylib.GetMousePosition(), float32(raylib.GetRandomValue(20, 80)), int(raylib.GetRandomValue(3, 8)), 10)
|
||||
} else if raylib.IsMouseButtonPressed(raylib.MouseRightButton) {
|
||||
physics.NewBodyCircle(raylib.GetMousePosition(), float32(raylib.GetRandomValue(10, 45)), 10)
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
physics.NewBodyPolygon(rl.GetMousePosition(), float32(rl.GetRandomValue(20, 80)), int(rl.GetRandomValue(3, 8)), 10)
|
||||
} else if rl.IsMouseButtonPressed(rl.MouseRightButton) {
|
||||
physics.NewBodyCircle(rl.GetMousePosition(), float32(rl.GetRandomValue(10, 45)), 10)
|
||||
}
|
||||
|
||||
// Destroy falling physics bodies
|
||||
|
@ -58,11 +58,11 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
raylib.DrawFPS(screenWidth-90, screenHeight-30)
|
||||
rl.DrawFPS(screenWidth-90, screenHeight-30)
|
||||
|
||||
// Draw created physics bodies
|
||||
for i, body := range physics.GetBodies() {
|
||||
|
@ -79,21 +79,21 @@ func main() {
|
|||
|
||||
vertexB := body.GetShapeVertex(jj)
|
||||
|
||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
||||
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawText("Left mouse button to create a polygon", 10, 10, 10, raylib.White)
|
||||
raylib.DrawText("Right mouse button to create a circle", 10, 25, 10, raylib.White)
|
||||
raylib.DrawText("Press 'R' to reset example", 10, 40, 10, raylib.White)
|
||||
rl.DrawText("Left mouse button to create a polygon", 10, 10, 10, rl.White)
|
||||
rl.DrawText("Right mouse button to create a circle", 10, 25, 10, rl.White)
|
||||
rl.DrawText("Press 'R' to reset example", 10, 40, 10, rl.White)
|
||||
|
||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
||||
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||
|
||||
raylib.EndDrawing()
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
physics.Close() // Unitialize physics
|
||||
|
||||
raylib.CloseWindow()
|
||||
rl.CloseWindow()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue