Friday 10 August 2012

Game animation demo

Here a simple example for creating games with Rebol:

Here the source code:

Rebol [
    title: "Simple Animation Controls"  
    purpose: { How to move graphics around the screen     }
]
if not exists? %frames [make-dir %frames ]
change-dir %frames
frames: [%s1.png %s2.png     %s3.png   %s4.png   %s5.png       %s6.png   %s7.png %s8.png   %s9.png %s10.png %s11.png %s12.png %s13.png   %s14.png   %s15.png %s16.png %s17.png %s18.png  
    %f1.png   %f2.png   %f3.png   %f4.png   %f5.png   %f6.png
    %b1.png   %b2.png   %b3.png   %b4.png   %b5.png   %b6.png
    ]
foreach image frames [
    if not exists? image [ request-download/to rejoin [http://www.maxvessi.net/rebsite/animazione/ to-url image]   image]
   
    ]
pos: 200x50
view layout [
    title "Game animation demo"
    a: box 74.117.66 600x220 with [pane: layout/offset [
        backdrop 74.117.66
        at 200x50
        anim   rate 6 frames [   %s1.png %s2.png     %s3.png   %s4.png   %s5.png       %s6.png   %s7.png %s8.png   %s9.png %s10.png %s11.png %s12.png %s13.png   %s14.png   %s15.png %s16.png %s17.png %s18.png   ]
        ]0x0]
    across  
    button "forward" keycode [right] [
        tmp: [ %f1.png   %f2.png   %f3.png   %f4.png   %f5.png   %f6.png ]  
        loop 2 [
            for i 1 6 1 [
            a/pane: layout/offset compose [
                backdrop 74.117.66
                at (pos: pos + 10x0)
                image (tmp/:i)
                ] 0x0
            show a
            wait 0.17
            ]
        ]  
        a/pane:   layout/offset   compose [
            backdrop 74.117.66
            at (pos)
            anim   rate 6 frames [ %s1.png   %s2.png   %s3.png   %s4.png   %s5.png   %s6.png %s7.png %s8.png %s9.png %s10.png %s11.png %s13.png %s13.png %s14.png %s15.png %s16.png %s17.png %s18.png ]  
            ] 0x0  
        show a
        ]
    button "backward"   keycode [left] [
        tmp: [ %b1.png   %b2.png   %b3.png   %b4.png   %b5.png   %b6.png ]  
        loop 2 [
            for i 1 6 1 [
            a/pane: layout/offset compose [
                backdrop 74.117.66
                at (pos: pos - 10x0)
                image (tmp/:i)
                ] 0x0
            show a
            wait 0.17
            ]
        ]  
        a/pane:   layout/offset   compose [
            backdrop 74.117.66
            at (pos)
            anim   rate 6 frames [ %s1.png   %s2.png   %s3.png   %s4.png   %s5.png   %s6.png %s7.png %s8.png %s9.png %s10.png %s11.png %s13.png %s13.png %s14.png %s15.png %s16.png %s17.png %s18.png ]  
            ] 0x0  
        show a
        ]  
    return
    text "You can use also the arrow to move character"
    ]

No comments:

Post a Comment