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
|
@ -13,50 +13,50 @@ func main() {
|
|||
screenWidth := float32(800)
|
||||
screenHeight := float32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics restitution")
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics restitution")
|
||||
|
||||
// Physac logo drawing position
|
||||
logoX := int32(screenWidth) - raylib.MeasureText("Physac", 30) - 10
|
||||
logoX := int32(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(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||
floor := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||
floor.Restitution = 1
|
||||
|
||||
// Create circles physics body
|
||||
circleA := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.25, screenHeight/2), 30, 10)
|
||||
circleA := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.25, screenHeight/2), 30, 10)
|
||||
circleA.Restitution = 0
|
||||
circleB := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.5, screenHeight/2), 30, 10)
|
||||
circleB := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.5, screenHeight/2), 30, 10)
|
||||
circleB.Restitution = 0.5
|
||||
circleC := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.75, screenHeight/2), 30, 10)
|
||||
circleC := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.75, screenHeight/2), 30, 10)
|
||||
circleC.Restitution = 1
|
||||
|
||||
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
|
||||
// Reset circles physics bodies position and velocity
|
||||
circleA.Position = raylib.NewVector2(screenWidth*0.25, screenHeight/2)
|
||||
circleA.Velocity = raylib.NewVector2(0, 0)
|
||||
circleB.Position = raylib.NewVector2(screenWidth*0.5, screenHeight/2)
|
||||
circleB.Velocity = raylib.NewVector2(0, 0)
|
||||
circleC.Position = raylib.NewVector2(screenWidth*0.75, screenHeight/2)
|
||||
circleC.Velocity = raylib.NewVector2(0, 0)
|
||||
circleA.Position = rl.NewVector2(screenWidth*0.25, screenHeight/2)
|
||||
circleA.Velocity = rl.NewVector2(0, 0)
|
||||
circleB.Position = rl.NewVector2(screenWidth*0.5, screenHeight/2)
|
||||
circleB.Velocity = rl.NewVector2(0, 0)
|
||||
circleC.Position = rl.NewVector2(screenWidth*0.75, screenHeight/2)
|
||||
circleC.Velocity = rl.NewVector2(0, 0)
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
rl.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.Black)
|
||||
rl.ClearBackground(rl.Black)
|
||||
|
||||
raylib.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
||||
rl.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
||||
|
||||
// Draw created physics bodies
|
||||
for i, body := range physics.GetBodies() {
|
||||
|
@ -73,24 +73,24 @@ 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("Restitution amount", (int32(screenWidth)-raylib.MeasureText("Restitution amount", 30))/2, 75, 30, raylib.White)
|
||||
raylib.DrawText("0", int32(circleA.Position.X)-raylib.MeasureText("0", 20)/2, int32(circleA.Position.Y)-7, 20, raylib.White)
|
||||
raylib.DrawText("0.5", int32(circleB.Position.X)-raylib.MeasureText("0.5", 20)/2, int32(circleB.Position.Y)-7, 20, raylib.White)
|
||||
raylib.DrawText("1", int32(circleC.Position.X)-raylib.MeasureText("1", 20)/2, int32(circleC.Position.Y)-7, 20, raylib.White)
|
||||
rl.DrawText("Restitution amount", (int32(screenWidth)-rl.MeasureText("Restitution amount", 30))/2, 75, 30, rl.White)
|
||||
rl.DrawText("0", int32(circleA.Position.X)-rl.MeasureText("0", 20)/2, int32(circleA.Position.Y)-7, 20, rl.White)
|
||||
rl.DrawText("0.5", int32(circleB.Position.X)-rl.MeasureText("0.5", 20)/2, int32(circleB.Position.Y)-7, 20, rl.White)
|
||||
rl.DrawText("1", int32(circleC.Position.X)-rl.MeasureText("1", 20)/2, int32(circleC.Position.Y)-7, 20, rl.White)
|
||||
|
||||
raylib.DrawText("Press 'R' to reset example", 10, 10, 10, raylib.White)
|
||||
rl.DrawText("Press 'R' to reset example", 10, 10, 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