fix up chipmunk.demo, add a MAIN:
							parent
							
								
									2e888f1ee7
								
							
						
					
					
						commit
						7de21ca8be
					
				| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
! Copyright (C) 2010 Erik Charlebois
 | 
			
		||||
! See http:// factorcode.org/license.txt for BSD license.
 | 
			
		||||
USING: accessors chipmunk.ffi classes.struct game.worlds kernel locals
 | 
			
		||||
math method-chains opengl.gl random sequences specialized-arrays
 | 
			
		||||
USING: accessors alien chipmunk.ffi classes.struct game.worlds kernel
 | 
			
		||||
locals math method-chains opengl.gl random sequences specialized-arrays
 | 
			
		||||
specialized-arrays.instances.alien.c-types.void* ui ui.gadgets.worlds
 | 
			
		||||
ui.pixel-formats ;
 | 
			
		||||
IN: chipmunk.demo
 | 
			
		||||
| 
						 | 
				
			
			@ -53,7 +53,10 @@ CONSTANT: image-bitmap B{
 | 
			
		|||
    cpBodyAlloc 1.0 NAN: 0 cpBodyInit
 | 
			
		||||
    x y cpv >>p :> body
 | 
			
		||||
    cpCircleShapeAlloc body 0.95 0 0 cpv cpCircleShapeInit
 | 
			
		||||
    [ shape>> 0 >>e ] [ shape>> 0 >>u ] bi drop ;
 | 
			
		||||
    dup shape>>
 | 
			
		||||
        0 >>e
 | 
			
		||||
        0 >>u
 | 
			
		||||
        drop ;
 | 
			
		||||
 | 
			
		||||
TUPLE: chipmunk-world < game-world
 | 
			
		||||
    space ;
 | 
			
		||||
| 
						 | 
				
			
			@ -88,7 +91,7 @@ M:: chipmunk-world draw-world* ( world -- )
 | 
			
		|||
    space arbiters>>
 | 
			
		||||
    [ num>> ] [ arr>> swap <direct-void*-array> ] bi [
 | 
			
		||||
        cpArbiter memory>struct
 | 
			
		||||
        [ numContacts>> ] [ contacts>> swap <direct-cpContact-array> ] bi [
 | 
			
		||||
        [ numContacts>> ] [ contacts>> >c-ptr swap <direct-cpContact-array> ] bi [
 | 
			
		||||
            p>> [ x>> ] [ y>> ] bi glVertex2f
 | 
			
		||||
        ] each
 | 
			
		||||
    ] each
 | 
			
		||||
| 
						 | 
				
			
			@ -109,7 +112,7 @@ M:: chipmunk-world begin-game-world ( world -- )
 | 
			
		|||
                x image-width 2 / - 0.05 0.0 1.0 uniform-random-float * + 2 *
 | 
			
		||||
                image-height 2 / y - 0.05 0.0 1.0 uniform-random-float * + 2 *
 | 
			
		||||
                make-ball :> shape
 | 
			
		||||
                space shape body>> cpSpaceAddBody drop
 | 
			
		||||
                space shape shape>> body>> cpSpaceAddBody drop
 | 
			
		||||
                space shape cpSpaceAddShape drop
 | 
			
		||||
            ] when
 | 
			
		||||
        ] each
 | 
			
		||||
| 
						 | 
				
			
			@ -119,10 +122,12 @@ M:: chipmunk-world begin-game-world ( world -- )
 | 
			
		|||
    body -1000 -10 cpv >>p drop
 | 
			
		||||
    body 400 0 cpv >>v drop
 | 
			
		||||
 | 
			
		||||
    space cpCircleShapeAlloc body 8 0 0 cpv cpCircleShapeInit cpSpaceAddShape :> shape
 | 
			
		||||
    shape
 | 
			
		||||
    [ shape>> 0 >>e drop ]
 | 
			
		||||
    [ shape>> 0 >>u drop ] bi ;
 | 
			
		||||
    space cpCircleShapeAlloc [ body 8 0 0 cpv cpCircleShapeInit cpSpaceAddShape drop ] keep
 | 
			
		||||
        :> shape
 | 
			
		||||
    shape shape>>
 | 
			
		||||
        0 >>e
 | 
			
		||||
        0 >>u
 | 
			
		||||
        drop ;
 | 
			
		||||
 | 
			
		||||
M: chipmunk-world end-game-world
 | 
			
		||||
    space>>
 | 
			
		||||
| 
						 | 
				
			
			@ -145,3 +150,4 @@ M: chipmunk-world end-game-world
 | 
			
		|||
        open-window
 | 
			
		||||
    ] with-ui ;
 | 
			
		||||
 | 
			
		||||
MAIN: chipmunk-demo
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue