Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help With cleaning up and transparent pictures
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
romantic_programmer




PostPosted: Thu Nov 16, 2006 11:55 am   Post subject: Help With cleaning up and transparent pictures

IS their a more efficient way of drawing my character on screen. I tried using sprites but didnt understand it.... but i managed to come up with this. and it wont load transparent pictures either. so i was wounder if anyone could give me a little help on that please... and maybe hel;p me clean up my code? ty


code:

setscreen ("graphics:max,max;Title: Project Vexus v.2")
var chars : array char of boolean

%% Walk Right Settings
var walkRight1, walkRight2, walkRight3, walkRight4 : int
var walkRight, x, y : int
walkRight1 := Pic.FileNew ("Pictures/sprites/characters/boy_walkright_1.gif")
walkRight2 := Pic.FileNew ("Pictures/sprites/characters/boy_walkright_2.gif")
walkRight3 := Pic.FileNew ("Pictures/sprites/characters/boy_walkright_3.gif")
walkRight4 := Pic.FileNew ("Pictures/sprites/characters/boy_walkright_4.gif")
walkRight := 0
%% Walk Left Settings
var walkLeft1, walkLeft2, walkLeft3, walkLeft4 : int
var walkLeft : int
walkLeft1 := Pic.FileNew ("Pictures/sprites/characters/boy_walkleft_1.gif")
walkLeft2 := Pic.FileNew ("Pictures/sprites/characters/boy_walkleft_2.gif")
walkLeft3 := Pic.FileNew ("Pictures/sprites/characters/boy_walkleft_3.gif")
walkLeft4 := Pic.FileNew ("Pictures/sprites/characters/boy_walkleft_4.gif")
walkLeft := 0
%% Walk Up Settings

%% Walk Down Settings
var walkDown1, walkDown2, walkDown3, walkDown4 : int
var walkDown : int
walkDown1 := Pic.FileNew ("Pictures/sprites/characters/boy_walkdown_1.gif")
walkDown2 := Pic.FileNew ("Pictures/sprites/characters/boy_walkdown_2.gif")
walkDown3 := Pic.FileNew ("Pictures/sprites/characters/boy_walkdown_3.gif")
walkDown4 := Pic.FileNew ("Pictures/sprites/characters/boy_walkdown_4.gif")
walkDown := 0

%% Walk Down Settings
var walkUp1, walkUp2, walkUp3, walkUp4 : int
var walkUp : int
walkUp1 := Pic.FileNew ("Pictures/sprites/characters/boy_walkup_1.gif")
walkUp2 := Pic.FileNew ("Pictures/sprites/characters/boy_walkup_2.gif")
walkUp3 := Pic.FileNew ("Pictures/sprites/characters/boy_walkup_3.gif")
walkUp4 := Pic.FileNew ("Pictures/sprites/characters/boy_walkup_4.gif")
walkUp := 0















const DLY := 100
x := (maxx div 2)
y := (maxy div 2)
loop
    View.Update
    Input.KeyDown (chars)
    setscreen ("offscreenonly")
    delay (DLY)



    drawfillbox (0, 0, maxx, maxy, 0)

    if walkRight = 0 and walkLeft = 0 and walkDown = 0 and walkUp = 0 then
        Pic.Draw (walkRight1, x, y, picCopy)
    elsif walkRight = 1 and walkLeft = 0 and walkDown = 0 and walkUp = 0 then
        Pic.Draw (walkRight2, x, y, picCopy)
    elsif walkRight = 2 and walkLeft = 0 and walkDown = 0 and walkUp = 0 then
        Pic.Draw (walkRight3, x, y, picCopy)
    elsif walkRight = 3 and walkLeft = 0 and walkDown = 0 and walkUp = 0 then
        Pic.Draw (walkRight4, x, y, picCopy)
    end if


    if walkLeft = 0 and walkRight = 0 and walkDown = 0 and walkUp = 0 then
        Pic.Draw (walkLeft1, x, y, picCopy)
    elsif walkLeft = 1 and walkRight = 0 and walkDown = 0 and walkUp = 0 then
        Pic.Draw (walkLeft2, x, y, picCopy)
    elsif walkLeft = 2 and walkRight = 0 and walkDown = 0 and walkUp = 0 then
        Pic.Draw (walkLeft3, x, y, picCopy)
    elsif walkLeft = 3 and walkRight = 0 and walkDown = 0 and walkUp = 0 then
        Pic.Draw (walkLeft4, x, y, picCopy)
    end if


    if walkDown = 0 and walkRight = 0 and walkLeft = 0 and walkUp = 0 then
        Pic.Draw (walkDown1, x, y, picCopy)
    elsif walkDown = 1 and walkRight = 0 and walkLeft = 0 and walkUp = 0 then
        Pic.Draw (walkDown2, x, y, picCopy)
    elsif walkDown = 2 and walkRight = 0 and walkLeft = 0 and walkUp = 0 then
        Pic.Draw (walkDown3, x, y, picCopy)
    elsif walkDown = 3 and walkRight = 0 and walkLeft = 0 and walkUp = 0 then
        Pic.Draw (walkDown4, x, y, picCopy)
    end if


    if walkUp = 0 and walkRight = 0 and walkLeft = 0 and walkDown = 0 then
        Pic.Draw (walkUp1, x, y, picCopy)
    elsif walkUp = 1 and walkRight = 0 and walkLeft = 0 and walkDown = 0 then
        Pic.Draw (walkUp3, x, y, picCopy)
    elsif walkUp = 2 and walkRight = 0 and walkLeft = 0 and walkDown = 0 then
        Pic.Draw (walkUp3, x, y, picCopy)
    elsif walkUp = 3 and walkRight = 0 and walkLeft = 0 and walkDown = 0 then
        Pic.Draw (walkUp4, x, y, picCopy)
    end if










    if chars (KEY_RIGHT_ARROW) and walkRight = 0 then
        Pic.Draw (walkRight1, x, y, picCopy)
        walkUp := 0
        walkDown := 0
        walkRight := 1
        walkLeft := 0
        x += 4
    elsif chars (KEY_RIGHT_ARROW) and walkRight = 1 then
        Pic.Draw (walkRight2, x, y, picCopy)
        walkUp := 0
        walkDown := 0
        walkRight := 2
        walkLeft := 0
        x += 4
    elsif chars (KEY_RIGHT_ARROW) and walkRight = 2 then
        Pic.Draw (walkRight3, x, y, picCopy)
        walkUp := 0
        walkDown := 0
        walkRight := 3
        walkLeft := 0
        x += 4
    elsif chars (KEY_RIGHT_ARROW) and walkRight = 3 then
        Pic.Draw (walkRight4, x, y, picCopy)
        walkUp := 0
        walkDown := 0
        walkRight := 0
        walkLeft := 0
        x += 4
    else
        if chars (KEY_LEFT_ARROW) and walkLeft = 0 then
            Pic.Draw (walkLeft1, x, y, picCopy)
            walkUp := 0
            walkDown := 0
            walkLeft := 1
            walkRight := 0
            x -= 4
        elsif chars (KEY_LEFT_ARROW) and walkLeft = 1 then
            Pic.Draw (walkLeft2, x, y, picCopy)
            walkUp := 0
            walkDown := 0
            walkLeft := 2
            walkRight := 0
            x -= 4
        elsif chars (KEY_LEFT_ARROW) and walkLeft = 2 then
            Pic.Draw (walkLeft3, x, y, picCopy)
            walkUp := 0
            walkDown := 0
            walkLeft := 3
            walkRight := 0
            x -= 4
        elsif chars (KEY_LEFT_ARROW) and walkLeft = 3 then
            Pic.Draw (walkLeft4, x, y, picCopy)
            walkUp := 0
            walkDown := 0
            walkLeft := 0
            walkRight := 0
            x -= 4
        else
            if chars (KEY_DOWN_ARROW) and walkDown = 0 then
                Pic.Draw (walkDown1, x, y, picCopy)
                walkUp := 0
                walkDown := 1
                walkLeft := 0
                walkRight := 0
                y -= 4
            elsif chars (KEY_DOWN_ARROW) and walkDown = 1 then
                Pic.Draw (walkDown2, x, y, picCopy)
                walkUp := 0
                walkDown := 2
                walkLeft := 0
                walkRight := 0
                y -= 4
            elsif chars (KEY_DOWN_ARROW) and walkDown = 2 then
                Pic.Draw (walkDown3, x, y, picCopy)
                walkUp := 0
                walkDown := 3
                walkLeft := 0
                walkRight := 0
                y -= 4
            elsif chars (KEY_DOWN_ARROW) and walkDown = 3 then
                Pic.Draw (walkDown4, x, y, picCopy)
                walkUp := 0
                walkDown := 0
                walkLeft := 0
                walkRight := 0
                y -= 4

            else
                if chars (KEY_UP_ARROW) and walkUp = 0 then
                    Pic.Draw (walkUp1, x, y, picCopy)
                    walkUp := 1
                    walkDown := 0
                    walkLeft := 0
                    walkRight := 0
                    y += 4
                elsif chars (KEY_UP_ARROW) and walkUp = 1 then
                    Pic.Draw (walkUp2, x, y, picCopy)
                    walkUp := 2
                    walkDown := 0
                    walkLeft := 0
                    walkRight := 0
                    y += 4
                elsif chars (KEY_UP_ARROW) and walkUp = 2 then
                    Pic.Draw (walkUp3, x, y, picCopy)
                    walkUp := 3
                    walkDown := 0
                    walkLeft := 0
                    walkRight := 0
                    y += 4
                elsif chars (KEY_UP_ARROW) and walkUp = 3 then
                    Pic.Draw (walkUp4, x, y, picCopy)
                    walkUp := 0
                    walkDown := 0
                    walkLeft := 0
                    walkRight := 0
                    y += 4
                end if
            end if
        end if
    end if

end loop





The only problem with this code i have found is i dont know how to set transparensy. And when i load an image that has an transparent feature it will display the entire image as a black square. so i was woundering if possiable if some one could help me with transpairency and maybe suggesting a few ideas or helping me clean up my code if possiable ty.


yours truly
Romantic_programmer
Sponsor
Sponsor
Sponsor
sponsor
ZeroPaladn




PostPosted: Thu Nov 16, 2006 12:59 pm   Post subject: (No subject)

for you transparent colour problem, you could allways load up your pictures in paint, and any area that you would want transparent, change the colour to something you never use in your program. this is just an example code:
Turing:
Pic.SetTransparentColour (pic, colour)
% pic is the picture, while colour is the colour that you want to go transparent
% if the colour is obscure (not sure what it is), use RGB colouring (see provided tutorial)


The RGB Tutorial by TheZsterBunny should help ya out, otherwise use a turing friendly colour (such as brightgreen).

As for shortening your code that whole...
Turing:
walkRight1 := Pic.FileNew ("Pictures/sprites/characters/boy_walkright_1.gif")
walkRight2 := Pic.FileNew ("Pictures/sprites/characters/boy_walkright_2.gif")
walkRight3 := Pic.FileNew ("Pictures/sprites/characters/boy_walkright_3.gif")
walkRight4 := Pic.FileNew ("Pictures/sprites/characters/boy_walkright_4.gif")

... can be shortened, using arrays!
Turing:
for i : 1 .. 4
    walkRight (i) := Pic.FileNew ("Pictures/sprites/characters/boy_walkright" + i + ".gif")
end for

This may not shorten your code by much, but when you have lets say... 30 of these in sequence to declare, your fingers and your code will thank you.
NikG




PostPosted: Fri Nov 17, 2006 2:16 pm   Post subject: (No subject)

ZeroPaladn, is that the best example you could come up with for shortened code?

romantic_programmer, you can shorten your code A LOT!
I'll give you an example, and you can figure out the rest on your own.

All of this:
code:
if chars (KEY_RIGHT_ARROW) and walkRight = 0 then
        Pic.Draw (walkRight1, x, y, picCopy)
        walkUp := 0
        walkDown := 0
        walkRight := 1
        walkLeft := 0
        x += 4
    elsif chars (KEY_RIGHT_ARROW) and walkRight = 1 then
        Pic.Draw (walkRight2, x, y, picCopy)
        walkUp := 0
        walkDown := 0
        walkRight := 2
        walkLeft := 0
        x += 4
    elsif chars (KEY_RIGHT_ARROW) and walkRight = 2 then
        Pic.Draw (walkRight3, x, y, picCopy)
        walkUp := 0
        walkDown := 0
        walkRight := 3
        walkLeft := 0
        x += 4
    elsif chars (KEY_RIGHT_ARROW) and walkRight = 3 then
        Pic.Draw (walkRight4, x, y, picCopy)
        walkUp := 0
        walkDown := 0
        walkRight := 0
        walkLeft := 0
        x += 4
    else
...

can be shortened to this:
code:
if chars (KEY_RIGHT_ARROW) then
    walkUp := 0
    walkDown := 0
    walkRight += 1
    if walkRight >3 then
        walkRight :=0
    end if
    Pic.Draw (walkRightImg(walkRight), x, y, picCopy) %Using ZeroPaladn's suggestion with an array names walkRightImg
    walkLeft := 0
    x += 4
elsif chars (KEY_LEFT_ARROW) then
    ...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: