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,22 +13,22 @@ func main() {
|
|||
screenWidth := float32(800)
|
||||
screenHeight := float32(450)
|
||||
|
||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics movement")
|
||||
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||
rl.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics movement")
|
||||
|
||||
// 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 and walls rectangle physics body
|
||||
floor := physics.NewBodyRectangle(raylib.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||
platformLeft := physics.NewBodyRectangle(raylib.NewVector2(screenWidth*0.25, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||
platformRight := physics.NewBodyRectangle(raylib.NewVector2(screenWidth*0.75, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||
wallLeft := physics.NewBodyRectangle(raylib.NewVector2(-5, screenHeight/2), 10, screenHeight, 10)
|
||||
wallRight := physics.NewBodyRectangle(raylib.NewVector2(screenWidth+5, screenHeight/2), 10, screenHeight, 10)
|
||||
floor := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||
platformLeft := physics.NewBodyRectangle(rl.NewVector2(screenWidth*0.25, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||
platformRight := physics.NewBodyRectangle(rl.NewVector2(screenWidth*0.75, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||
wallLeft := physics.NewBodyRectangle(rl.NewVector2(-5, screenHeight/2), 10, screenHeight, 10)
|
||||
wallRight := physics.NewBodyRectangle(rl.NewVector2(screenWidth+5, screenHeight/2), 10, screenHeight, 10)
|
||||
|
||||
// Disable dynamics to floor and walls physics bodies
|
||||
floor.Enabled = false
|
||||
|
@ -38,38 +38,38 @@ func main() {
|
|||
wallRight.Enabled = false
|
||||
|
||||
// Create movement physics body
|
||||
body := physics.NewBodyRectangle(raylib.NewVector2(screenWidth/2, screenHeight/2), 50, 50, 1)
|
||||
body := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight/2), 50, 50, 1)
|
||||
body.FreezeOrient = true // Constrain body rotation to avoid little collision torque amounts
|
||||
|
||||
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 movement physics body position, velocity and rotation
|
||||
body.Position = raylib.NewVector2(screenWidth/2, screenHeight/2)
|
||||
body.Velocity = raylib.NewVector2(0, 0)
|
||||
body.Position = rl.NewVector2(screenWidth/2, screenHeight/2)
|
||||
body.Velocity = rl.NewVector2(0, 0)
|
||||
body.SetRotation(0)
|
||||
}
|
||||
|
||||
// Physics body creation inputs
|
||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
||||
if rl.IsKeyDown(rl.KeyRight) {
|
||||
body.Velocity.X = velocity
|
||||
} else if raylib.IsKeyDown(raylib.KeyLeft) {
|
||||
} else if rl.IsKeyDown(rl.KeyLeft) {
|
||||
body.Velocity.X = -velocity
|
||||
}
|
||||
|
||||
if raylib.IsKeyDown(raylib.KeyUp) && body.IsGrounded {
|
||||
if rl.IsKeyDown(rl.KeyUp) && body.IsGrounded {
|
||||
body.Velocity.Y = -velocity * 4
|
||||
}
|
||||
|
||||
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() {
|
||||
|
@ -86,20 +86,20 @@ 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("Use 'ARROWS' to move player", 10, 10, 10, raylib.White)
|
||||
raylib.DrawText("Press 'R' to reset example", 10, 30, 10, raylib.White)
|
||||
rl.DrawText("Use 'ARROWS' to move player", 10, 10, 10, rl.White)
|
||||
rl.DrawText("Press 'R' to reset example", 10, 30, 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