rev: 3827f53bae88e48a594610914ba74b9512ead6dd tukan/testing/test_chipmunk.sc -rw-r--r-- 2.0 KiB View raw Log this file
3827f53bae88 — Leonard Ritter * more work on module system 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 =
    Shape.Segment
        space.static-body
        vec2 -20 0
        vec2 20 0
        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 =
    Body mass
        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
    printf "\r"
    for j in (range 0 ypos)
        printf " "
    printf BALL
    for j in (range 0 (50 - ypos))
        printf " "
    fflush (stdout)

    SDL_Delay 16
printf "\n"
fflush (stdout)