
-----------------------------------
Tallguy
Mon May 11, 2009 9:32 am

Sprite
-----------------------------------
so i've looked every where on compsci and can't find anything to help me

i wanna make a game with Sprites, sortta like this http://compsci.ca/v3/viewtopic.php?t=16534


how do i get the sprites moving for example to walk i  use the pictures in order in the walk folder 

know what i'm getting at? do i use an array like...



var dooku_walk : array 1 .. 13 of string

dooku_walk (1) := "Dooku/Walk/WalkC1.bmp"
dooku_walk (2) := "Dooku/Walk/WalkC2.bmp"
dooku_walk (3) := "Dooku/Walk/WalkC3.bmp"
dooku_walk (4) := "Dooku/Walk/WalkC4.bmp"
dooku_walk (5) := "Dooku/Walk/WalkC5.bmp"
dooku_walk (6) := "Dooku/Walk/WalkC6.bmp"
dooku_walk (7) := "Dooku/Walk/WalkC7.bmp"
dooku_walk (8) := "Dooku/Walk/WalkC8.bmp"
dooku_walk (9) := "Dooku/Walk/WalkC9.bmp"
dooku_walk (10) := "Dooku/Walk/WalkC10.bmp"
dooku_walk (11) := "Dooku/Walk/WalkC11.bmp"
dooku_walk (12) := "Dooku/Walk/WalkC12.bmp"
dooku_walk (13) := "Dooku/Walk/WalkC13.bmp"

var walk  := dooku_walk


i am throughly confused any suggestions? plz

-----------------------------------
DemonWasp
Mon May 11, 2009 11:31 am

RE:Sprite
-----------------------------------
You want to look for the Pic and Sprite modules in the Turing help (though honestly you can do it best with just Pic). Alternately, check out the tutorials here: http://compsci.ca/v3/viewtopic.php?t=8808 , particularly the Graphics section and the Pictures article.

-----------------------------------
DifinityRJ
Tue May 12, 2009 11:12 am

Re: Sprite
-----------------------------------
I didn't test the code, but from my experience with sprites, you can do this a bit more efficient.


Like so:

var dooku_walk : array 1 .. 13 of int

for a : 1 .. 13
    dooku_walk (a) := Pic.FileNew("Dooku/Walk/WalkC" + intstr (a) + ".bmp")
end for


*notice the array is 'int' not 'string'


If the actual program is in the folder with the sprites you don't need "Dooku/Walk/" ,  Just put "WalkC" +instr(a) + ".bmp"

If you need help on animation, I can surely help you, just PM me.

-----------------------------------
tjmoore1993
Tue May 12, 2009 4:04 pm

Re: Sprite
-----------------------------------
I didn't test the code, but from my experience with sprites, you can do this a bit more efficient.


Like so:

var dooku_walk : array 1 .. 13 of int

for a : 1 .. 13
    dooku_walk (a) := Pic.FileNew("Dooku/Walk/WalkC" + intstr (a) + ".bmp")
end for


*notice the array is 'int' not 'string'


If the actual program is in the folder with the sprites you don't need "Dooku/Walk/" ,  Just put "WalkC" +instr(a) + ".bmp"

If you need help on animation, I can surely help you, just PM me.


Bad idea. At first it works but then you'll come across errors
"Cannot allocate item. Out of id numbers (max 1000)"

The best way is to probably define the images outside of a loop.


var SpriteRight, SpriteLeft : array 1 .. 2 of int

SpriteRight (1) := Pic.FileNew ("C:\\1.bmp")
SpriteRight (2) := Pic.FileNew ("C:\\2.bmp")
SpriteLeft (1) := Pic.Mirror (SpriteRight (1))
SpriteLeft (2) := Pic.Mirror (SpriteRight (2))

var chars : array char of boolean
var CharacterX, CharacterY : int
CharacterX := 100
CharacterY := 20

View.Set ("offscreenonly")

Pic.SetTransparentColour (SpriteRight (1), 3)
Pic.Draw (SpriteRight (1), CharacterX, CharacterY, picMerge)

loop
    Input.KeyDown (chars)

    if chars (KEY_RIGHT_ARROW) and chars (KEY_LEFT_ARROW) then
    else
        if chars (KEY_RIGHT_ARROW) then
            for right : 1 .. 2
                cls
                CharacterX := CharacterX + 5
                Pic.SetTransparentColour (SpriteRight (right), 3)
                Pic.Draw (SpriteRight (right), CharacterX, CharacterY, picMerge)
                delay (20)
            end for
        end if
        if chars (KEY_LEFT_ARROW) then
            for left : 1 .. 2
                cls
                CharacterX := CharacterX - 5
                Pic.SetTransparentColour (SpriteLeft (left), 3)
                Pic.Draw (SpriteLeft (left), CharacterX, CharacterY, picMerge)
                delay (20)
            end for
        end if
        View.Update
    end if
end loop



-----------------------------------
tjmoore1993
Tue May 12, 2009 4:08 pm

RE:Sprite
-----------------------------------
Fixed :
- No errors
- LEFT AND RIGHT key glitch
- Updating
- Changing Direction

etc. :)

EDIT*
Correction, I did not fix the animation. I forgot to but I'm sure someone will reply with an answer!

-----------------------------------
Tallguy
Tue May 12, 2009 6:22 pm

RE:Sprite
-----------------------------------
sweet thanks both of you you have no idea how much you just helped me out, thanks, i did both of what you two suggested

i tried before without succes to get the pic.mirror to work, but you realy helped me out THANK YOU!!

setscreen ("graphics:700;500")
View.Set ("offscreenonly")
var x, y : int
x := 100
y := 100
var chars : array char of boolean

var dooku_walk, dooku_walkL : array 1 .. 13 of int

for a : 1 .. 13
    dooku_walk (a) := Pic.FileNew ("Sprintes/Dooku/Walk/WalkC" + intstr (a) + ".bmp")
    dooku_walkL (a) := Pic.Mirror (dooku_walk (a))
end for

var dooku_stand := Pic.FileNew ("Sprintes/Dooku/Stand/Stand1.bmp")
var dooku_standM := Pic.Mirror (dooku_stand)

loop
    cls

    Input.KeyDown (chars)

    if chars (KEY_RIGHT_ARROW) then
        if chars (KEY_RIGHT_ARROW) then
            x := x + 15
        end if
        for a : 1 .. 13
            Pic.Draw (dooku_walk (a), x, y, 0)
            View.Update
        end for
        delay (75)
        View.Update
    else
        Pic.Draw (dooku_stand, x, y, 0)
        View.Update
    end if

    if chars (KEY_LEFT_ARROW) then
        if chars (KEY_LEFT_ARROW) then
            x := x - 15
        end if
        for a : 1 .. 13
            Pic.Draw (dooku_walkL (a), x + 8, y, 0)
            View.Update
        end for
        delay (75)
        View.Update
    end if
end loop


-----------------------------------
tjmoore1993
Tue May 12, 2009 7:13 pm

Re: RE:Sprite
-----------------------------------
sweet thanks both of you you have no idea how much you just helped me out, thanks, i did both of what you two suggested

i tried before without succes to get the pic.mirror to work, but you realy helped me out THANK YOU!!

setscreen ("graphics:700;500")
View.Set ("offscreenonly")
var x, y : int
x := 100
y := 100
var chars : array char of boolean

var dooku_walk, dooku_walkL : array 1 .. 13 of int

for a : 1 .. 13
    dooku_walk (a) := Pic.FileNew ("Sprintes/Dooku/Walk/WalkC" + intstr (a) + ".bmp")
    dooku_walkL (a) := Pic.Mirror (dooku_walk (a))
end for

var dooku_stand := Pic.FileNew ("Sprintes/Dooku/Stand/Stand1.bmp")
var dooku_standM := Pic.Mirror (dooku_stand)

loop
    cls

    Input.KeyDown (chars)

    if chars (KEY_RIGHT_ARROW) then
        if chars (KEY_RIGHT_ARROW) then
            x := x + 15
        end if
        for a : 1 .. 13
            Pic.Draw (dooku_walk (a), x, y, 0)
            View.Update
        end for
        delay (75)
        View.Update
    else
        Pic.Draw (dooku_stand, x, y, 0)
        View.Update
    end if

    if chars (KEY_LEFT_ARROW) then
        if chars (KEY_LEFT_ARROW) then
            x := x - 15
        end if
        for a : 1 .. 13
            Pic.Draw (dooku_walkL (a), x + 8, y, 0)
            View.Update
        end for
        delay (75)
        View.Update
    end if
end loop


No problem, notice though how you have used two statements more then what was needed. Instead of using setscreen perhaps using View.Set share the line?

Example:

View.Set ("graphics:700;500, offscreenonly")

-----------------------------------
DifinityRJ
Wed May 13, 2009 10:35 am

Re: Sprite
-----------------------------------
I didn't test the code, but from my experience with sprites, you can do this a bit more efficient.


Like so:

var dooku_walk : array 1 .. 13 of int

for a : 1 .. 13
    dooku_walk (a) := Pic.FileNew("Dooku/Walk/WalkC" + intstr (a) + ".bmp")
end for


*notice the array is 'int' not 'string'


If the actual program is in the folder with the sprites you don't need "Dooku/Walk/" ,  Just put "WalkC" +instr(a) + ".bmp"

If you need help on animation, I can surely help you, just PM me.


Bad idea. At first it works but then you'll come across errors
"Cannot allocate item. Out of id numbers (max 1000)"

The best way is to probably define the images outside of a loop.


var SpriteRight, SpriteLeft : array 1 .. 2 of int

SpriteRight (1) := Pic.FileNew ("C:\\1.bmp")
SpriteRight (2) := Pic.FileNew ("C:\\2.bmp")
SpriteLeft (1) := Pic.Mirror (SpriteRight (1))
SpriteLeft (2) := Pic.Mirror (SpriteRight (2))

var chars : array char of boolean
var CharacterX, CharacterY : int
CharacterX := 100
CharacterY := 20

View.Set ("offscreenonly")

Pic.SetTransparentColour (SpriteRight (1), 3)
Pic.Draw (SpriteRight (1), CharacterX, CharacterY, picMerge)

loop
    Input.KeyDown (chars)

    if chars (KEY_RIGHT_ARROW) and chars (KEY_LEFT_ARROW) then
    else
        if chars (KEY_RIGHT_ARROW) then
            for right : 1 .. 2
                cls
                CharacterX := CharacterX + 5
                Pic.SetTransparentColour (SpriteRight (right), 3)
                Pic.Draw (SpriteRight (right), CharacterX, CharacterY, picMerge)
                delay (20)
            end for
        end if
        if chars (KEY_LEFT_ARROW) then
            for left : 1 .. 2
                cls
                CharacterX := CharacterX - 5
                Pic.SetTransparentColour (SpriteLeft (left), 3)
                Pic.Draw (SpriteLeft (left), CharacterX, CharacterY, picMerge)
                delay (20)
            end for
        end if
        View.Update
    end if
end loop



tjmoore, you are doing exactly what I am doing, except you are adding more work for yourself.  Your method works if you have two sprites, but when you have more sprites your going to have to keep repeating lines of code, that could be replaced by a for statement.

-----------------------------------
Tallguy
Fri May 15, 2009 9:17 am

Re: Sprite
-----------------------------------
okay, thanks for all the help, i'm still having a few kinks. i'm using the sprites from http://compsci.ca/v3/viewtopic.php?t=16534 because their the best ones i can find

the array thingy isn't working, it's not displaying the sprites in order

any ideas?

-----------------------------------
Tallguy
Fri May 15, 2009 11:31 am

RE:Sprite
-----------------------------------
i got it working, forgot to add delays lol

-----------------------------------
DanTheMan
Fri May 15, 2009 11:37 am

RE:Sprite
-----------------------------------
This may not have any relevance, but is this the correct file path for your sprites?

(Sprintes/Dooku/Walk/WalkC)

-----------------------------------
Tallguy
Fri May 15, 2009 11:42 am

RE:Sprite
-----------------------------------
yeah it is, my problem was it was displaying them at all thesame time because i forgot to add an delay
