Computer Science Canada

Sprite module

Author:  Nick [ Tue Oct 30, 2007 2:17 pm ]
Post subject:  Sprite module

here is the sprite module i made

atm it will only handle one sprite at a time but can be changed with a few adjustments

also it is located in my predefs folder so it is automatacally imported into my programs so what this means for you is you will either have to put it in your predef folder too

OR

change some of the procedure names as well as the module name itseldf and manually import it

so here it is

Turing:
/*
 * Sprite module - a set of routines for using sprites
 *
 * NB:  DO NOT IMPORT OR INCLUDE THIS FILE INTO YOUR PROGRAM.
 *      IT WILL BE IMPLICITLY IMPORTED.
 */


unit
module Sprite
    % export New, Free, Show, Hide, SetPosition, SetHeight, ChangePic, Animate,
    %     backgroundHeight

    export Set, Free, setBackground, draw, ADVDraw

    var picID : array 1 .. 5, 1 .. 5 of int
    var backGround : array 1 .. 5 of int := init (0, 0, 0, 0, 0)

    proc Set (picSet, picNum, picName : int)
        picID (picSet, picNum) := picName
    end Set

    proc setBackground (backNum : int)
        if backGround (backNum) > 0 then
            Pic.Free (backGround (backNum))
        end if
        backGround (backNum) := Pic.New (0, 0, maxx, maxy)
    end setBackground

    proc draw (picSet, picNum, backNum, x, y : int)
        if backGround (backNum) > 0 then
            Pic.Draw (backGround (backNum), 0, 0, picCopy)
        end if
        Pic.Draw (picID (picSet, picNum), x, y, picMerge)
        View.Update
    end draw

    proc Free (picSet, picNum : int)
        Pic.Free (picID (picSet, picNum))
    end Free

    proc ADVDraw (picSet, picNum, backNum, BX, BY, x, y : int)
        if backGround (backNum) > 0 then
            Pic.Draw (backGround (backNum), BX, BY, picCopy)
        end if
        Pic.Draw (picID (picSet, picNum), x, y, picMerge)
        View.Update
    end ADVDraw

end Sprite

Author:  CodeMonkey2000 [ Tue Oct 30, 2007 3:10 pm ]
Post subject:  RE:Sprite module

Not bad. I recall that there was a really good sprite module somewhere in the turing tutorials. The thing about that one is that you can have as many images as you want.

Author:  Clayton [ Tue Oct 30, 2007 3:59 pm ]
Post subject:  RE:Sprite module

You know, if you want to at least try and pass this off as one's own work, at least take away the header that is on every single unit that is in the predefs folder.

Author:  Nick [ Tue Oct 30, 2007 6:09 pm ]
Post subject:  RE:Sprite module

uhhh... if u look in the turing folder this wont be there

i just edited the old one... seemed easier than creating a whole new one

(ps the old one didnt work)

the reason behind editing the old one was to create some procedures that had the black text... i thought it'd look cooler

also if you use some of the other ones you'll notice that it is blue text thus meanign i HAD to create it

Author:  Nick [ Tue Oct 30, 2007 6:26 pm ]
Post subject:  RE:Sprite module

here is the original module that came with turing
Turing:
/*
 * Sprite module - a set of routines for using sprites
 *
 * NB:  DO NOT IMPORT OR INCLUDE THIS FILE INTO YOUR PROGRAM.
 *      IT WILL BE IMPLICITLY IMPORTED.
 */


unit
module Sprite
    export New, Free, Show, Hide, SetPosition, SetHeight, ChangePic, Animate,
        backgroundHeight

    const backgroundHeight : int := 0

    external "sprite_new" function New (picId : int) : int

    external "sprite_free" procedure Free (spriteId : int)

    external "sprite_show" procedure Show (spriteId : int)

    external "sprite_hide" procedure Hide (spriteId : int)

    external "sprite_setposition"
        procedure SetPosition (picId : int, x, y : int, centered : boolean)

    external "sprite_setheight"
        procedure SetHeight (spriteId : int, height : int)

    external "sprite_setheight"
        procedure SetPriority (spriteId : int, height : int)

    external "sprite_changepic"
        procedure ChangePic (spriteId : int, picId : int)

    external "sprite_animate"
        procedure Animate (spriteId : int, picId : int,
        x, y : int, centered : boolean)
end Sprite

Author:  Ultrahex [ Wed Oct 31, 2007 10:53 am ]
Post subject:  Re: Sprite module

ya this one isn't that useful there is a lot better sprite modules already created, but if you expand on this, or create a new one from scrap you might be able to go somewhere with it.

However... it will not be your own work when you edited BTW, you have to give rights of the original code you modified! (other wise its known as plagiarism in almost all schools) unless you properly cite in your code (yes in your code). What you modified, cause the idea was not originally yours on the setup of the module.

Author:  Nick [ Wed Oct 31, 2007 11:20 am ]
Post subject:  RE:Sprite module

well i did do it from scratch but then the file got deleted somehow so then i just commented out everything i didnt change and did everything else from scratch and maybe yes i will create a bettre one when i get some graphics my friend is working on but he is taking forever and i do better work with actual graphics to change around


: