CMPC
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Dwarfwalk v2

Go down

Dwarfwalk v2 Empty Dwarfwalk v2

Post by Corey Fri Jan 29, 2010 4:10 am

I apologize for it being in FB, but I'm sure it can be adapted to C++ or really any language. This is just a short proof-of-concept to demonstrate the capacity for an animated sprite engine to be implemented in Enoki. The code has been fully commented for convenience.
"sheet.png" is a 320x32 image.
Code:
#include once "fbgfx.bi" '//extended graphics support include file
#include once "fbpng.bi" '//PNG library by yetifoot
#ifndef gfxbuffer
#define gfxbuffer screenres 1,1,32,,-1  '//makes a null graphics buffer to enable graphics functions
#endif

gfxbuffer '//initialize graphics buffer

type sprite '//sprite polymorphism
    img(9) as fb.image ptr '//10 frames
    x as integer
    y as integer
    delay as integer
end type
dim as sprite spr
dim as fb.image ptr sheet '//declare sprite sheet pointer
dim counter as integer
spr.x = 10:spr.y=10
spr.delay = 5

sheet = imagecreate(320,32)
sheet = png_load( "sheet.png" ) '//load sheet into pointer

for iteration as integer = 0 to 9
    spr.img(iteration) = imagecreate(32,32) '//create a new image
    get sheet,((iteration*32),0)-((iteration*32)+31,31),spr.img(iteration) '//read frame from sheet
next iteration

screen 18,32
do until MultiKey(FB.SC_ESCAPE)
    counter += 1
    put (spr.x,spr.y), spr.img(counter / spr.delay mod 10) ,pset '//binary BLIT each frame
    screensync
loop
sleep
Corey
Corey
Mod

Posts : 462

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum