using import glm
using import ..tukan.libc
using import ..tukan.chipmunk
using import ..tukan.sdl
# Create an empty space.
let space = (Space)
space.gravity = (vec2 0 -10)
# Add a static line segment shape for the ground.
# We'll make it slightly tilted so the ball will roll off.
# We attach it to a static body to tell Chipmunk it shouldn't be movable.
let ground =
vec2 -20 0
vec2 20 0
ground.friction = 0
ground.elasticity = 1.0
'add space ground
# Now let's make a ball that falls onto the line and rolls off.
# First we need to make a cpBody to hold the physical properties of the object.
# These include the mass, position, velocity, angle, etc. of the object.
# Then we attach collision shapes to the cpBody to give it a size and shape.
let radius = 1.0
let mass = 1.0
# The moment of inertia is like mass for rotation
# Use the moment-for* functions to help you approximate it.
let ballBody =
moment-for-circle mass 0 radius (vec2 0)
ballBody.position = (vec2 0 50)
'add space ballBody
# Now we create the collision shape for the ball.
# You can create multiple collision shapes that point to the same body.
# They will all be attached to the body and move around to follow it.
let ballShape = (Shape.Circle ballBody radius)
'add space ballShape
#ballShape.friction = 0.0
ballShape.elasticity = 0.6
# Now that it's all set up, we simulate all the objects in the space by
# stepping forward through time in small increments called steps.
# It is *highly* recommended to use a fixed size time step.
let timeStep = (/ 60.0)
for i in (range 0 (14 * 60))
'step space (/ 1.0 60.0)
let pos = ballBody.position
#let vel = ballBody.velocity
local BALL = "O"
let ypos =
(pos.y + 0.5) as i32
for j in (range 0 ypos)
printf " "
for j in (range 0 (50 - ypos))
printf " "