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

Username:   Password: 
 RegisterRegister   
 Can't get my sprite moving.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3, 4, 5  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Razgriz




PostPosted: Thu Feb 19, 2009 6:46 am   Post subject: Can't get my sprite moving.

Hello.

I'm new to the forums, and new to Turing. I'm currently working on making a small game. The only problem is I don't know how to get my sprite moving. I've been looking at tutorials for the past four hours straight and I don't know what to do to fix it. I've tried the Sprite.Animate command and I've tried the entire loop -> Input.KeyDown thing.

The bit looks like this . . .

Turing:
var x: int:=0
var y: int:=0
var x_velocity :int:=0
var y_velocity:int:=0
var pic := Pic.FileNew("kksprite.bmp")
var chars : array char of boolean
        loop
        Pic.Draw (pic,40,40,picCopy)
       
        Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                y:=y+15
            end if
            if chars (KEY_RIGHT_ARROW) then
                x:=x+15
            end if
            if chars (KEY_LEFT_ARROW) then
                x:=x-15
            end if
            if chars (KEY_DOWN_ARROW) then
                y:=y-15
            end if
            View.Update
            delay(10)
                cls
               
                View.Update
        end loop

All well and good, it draws the sprite but it won't move.

Any help is greatly appreciated.


Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="turing"]Code Here[/syntax]
Sponsor
Sponsor
Sponsor
sponsor
copthesaint




PostPosted: Thu Feb 19, 2009 7:09 am   Post subject: RE:Can\'t get my sprite moving.

Razgriz This isn't spritz first thing. If it was you wouldn't be using the delay. Now the reason it isn't moving is because you forgot to draws your picture at the y and x value. Instead you draw it at 40 x, and 40 y. Also if you want to, Make The background of whatever picture that is white then use picMerge instead of picCopy. This will make the white invisible.
Razgriz




PostPosted: Thu Feb 19, 2009 10:24 am   Post subject: RE:Can\'t get my sprite moving.

I don't understand what you mean in your post.

Primarily, as I said at the beginning, I am *new* to Turing and currently have no @#$%ing idea what you mean when you say "If it was you wouldn't be using the delay. [...] at the y and x value."

Secondly, using picMerge did absolutely nothing, as it looks 100% the same as it did when I used picDraw.

Specify, please. Perhaps with use of a code.
Turing:
colorback (green)
cls
var pic : int := Pic.FileNew ("krystalsprite.gif")
setscreen ("offscreenonly")
View.Update
Pic.Draw (pic,240,120,picMerge)

Note that I don't WANT the background to be white.

That's why it's green.
DemonWasp




PostPosted: Thu Feb 19, 2009 10:47 am   Post subject: RE:Can\'t get my sprite moving.

The problem with your code (in the second post) is that you're updating the screen, THEN drawing the picture to the back-buffer.

What you're implementing there is called "double buffering". All drawing commands (including pictures, the Draw package and sprites) are drawn solely to the back-buffer, which is drawn to the screen when you say View.Update().

The correct way of doing this is as follows:
Turing:

% Set up the screen for double-buffering (requires use of View.Update)
setscreen ("offscreenonly")

% Our background will be green
colorback (green)

% Initialise pic
var pic : int := Pic.FileNew ("krystalsprite.gif")

loop
    cls

    % Update variables here. This is where you would use Input.KeyDown.



    % Draw the scene here. This is where you would draw any background images, then any middle-ground elements, then any foreground elements, such as the following:
    Pic.Draw (pic,240,120,picMerge)

    % Force the back-buffer to be drawn to the screen.
    View.Update
end loop
Razgriz




PostPosted: Thu Feb 19, 2009 11:02 am   Post subject: RE:Can\'t get my sprite moving.

Okay, I am now thorougly confused.

So; if anyone could, please take this portion of my code and edit or at least comment on where I have gone wrong, because you've lost me on this.

Turing:
colorback (green)
cls
setscreen ("offscreenonly")
loop
var pic : int := Pic.FileNew ("krystalsprite.gif")
var x: int:=0
var y: int:=0
var x_velocity :int:=0
var y_velocity:int:=0
var chars : array char of boolean
        loop
        Pic.Draw (pic,40,40,picCopy)
       
        Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                y:=y+15
            end if
            if chars (KEY_RIGHT_ARROW) then
                x:=x+15
            end if
            if chars (KEY_LEFT_ARROW) then
                x:=x-15
            end if
            if chars (KEY_DOWN_ARROW) then
                y:=y-15
            end if
            View.Update
            delay(10)
                cls
               
               
        end loop

Pic.Draw (pic,240,120,picMerge)
View.Update
end loop


Thanks.
TheGuardian001




PostPosted: Thu Feb 19, 2009 11:07 am   Post subject: Re: RE:Can\'t get my sprite moving.

Razgriz @ Thu Feb 19, 2009 11:02 am wrote:
Okay, I am now thorougly confused.

So; if anyone could, please take this portion of my code and edit or at least comment on where I have gone wrong, because you've lost me on this.

Turing:

        loop
        Pic.Draw (pic,40,40,picCopy)  %THIS LINE RIGHT HERE

       
        Input.KeyDown (chars)
            if chars (KEY_UP_ARROW) then
                y:=y+15
            end if
            if chars (KEY_RIGHT_ARROW) then
                x:=x+15
            end if
            if chars (KEY_LEFT_ARROW) then
                x:=x-15
            end if
            if chars (KEY_DOWN_ARROW) then
                y:=y-15
            end if
            View.Update
            delay(10)
                cls
               
               
        end loop

Pic.Draw (pic,240,120,picMerge)
View.Update
end loop



The line to draw the character. When you say Pic.Draw(pic,40,40,picCopy), you are telling the program to ALWAYS draw the picture at 40,40. you should be using the variables for the characters location instead of a constant.
Razgriz




PostPosted: Thu Feb 19, 2009 11:09 am   Post subject: RE:Can\'t get my sprite moving.

Ohh.

Thanks.

*High fives the first person who made sense to me*
Razgriz




PostPosted: Thu Feb 19, 2009 12:02 pm   Post subject: RE:Can\'t get my sprite moving.

And, now, through two hours of looking I can't get the background to move with the character. It's a birds-eye view game, of course.

Can someone tell me two things:
1 - How to get rid of that @#$%ed white box around my sprite (Yes, I AM USING picMerge!)
and 2 - How to get the background to move.

Any help is appreciated.



Thanks.

-Krystal
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Thu Feb 19, 2009 2:45 pm   Post subject: RE:Can\'t get my sprite moving.

1. Are you sure that the white background is actually white and not some off-white colour? If it's not exactly white, it won't be treated as transparent, IIRC.

2. What do you mean by having the background move? Is the background some sort of large image you're going to load and draw, or what?
Razgriz




PostPosted: Thu Feb 19, 2009 7:05 pm   Post subject: Re: Can't get my sprite moving.

*All of that is aside, I have it working now.

But I could use some help with a collision detection map.

Attached is a map just used for testing itself... anyone who can help me with how to work a collision map working (Preferable with 0's being ground that can be moved across, and 1's being blocks, walls, etc.)



bg.GIF
 Description:
 Filesize:  28.73 KB
 Viewed:  118 Time(s)

bg.GIF


Razgriz




PostPosted: Thu Feb 19, 2009 7:06 pm   Post subject: Re: Can't get my sprite moving.

My original rough draft of said map looks like:

notepad:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
1000000000000000000000000000000000000000000000000000000000000000111111111111111111111111
1000000000000000000000000000000000000000000000000000000000000000111111111111111111111111
1000000000000000000000000000000000000000000000000000000000000000111111111111111111111111
1000000000000000000000000000000000000000000000000000000000000000111111111111111111111111
1000000000000000000000000000000000000000000000000000000000000000111111111111111111111111
1000000000000100000000000000000000000000000000000000000000000000111111111111111111111111
1000000000001110000000000000000000000000000000000000000000000000111111111111111111111111
1000000001111111000000000000000000000000000000000000000000000000111111111111111111111111
1000000001111111100000000011111111111000000000000000000000000000111111111111111111111111
1000000011111111110000000111111111111000000000000000000000000000111111111111111111111111
1000000011111111110000001111111111111000000000000000000000000000111111111111111111111111
1000000011111111110000001111111111111000000000000000000000000000111111111111111111111111
1000000011111111110000001111111111111000000000000000000000000000111111111111111111111111
1000000011111111110000001111100111111000000000000000000000000000111111111111111111111111
1000000011111111110000000000000000000000000000000000000000000000111111111111111111111111
1000000011110111110000000000000000000000000000000000000000000000111111111111111111111111
1000000000000011110000000000000000000000000000000000000000000000111111111111111111111111
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000111111111111111111111111111111101
1000000000000000000000000000000000000000000000000000000111111111111111111111111111111101
1000000000000000000000000000000000000000000000000000000111111111111111111111111111111101
1000000000000000000000000000000000000000000000000000000111111111111111111111111111111101
1000000000000000000000000000000000000000000000000000000111111111111111111111111111111101
1000000000000000000000000000000000000000000000000000000111111111111111111111111111111101
1000011100000000000000000000000000000000000000000000000111111111111111111111111111111101
1011111111000000000000000000000000000000000000000000000111111111111111111111111111111101
1011111111100000000000000000000000000000000000000000000111111111111111111111111111111101
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000001111100000000000000000001
1000000000000000000000000000000000000000000000000000000000000001111100000000000000000001
1000000000000000000000000000000000000000000000000000000000000001111100000000000000000001
1000000000000000000000000000000000000000000000000000000000000001111100000000000000000001
1000000000000000000000000000000000000000000000000000000000000001111100000000100000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1000000000000000000000000000000000000000000000000000000000000000000000001000000000000001
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111


That aside, I would also need to know where to put that in relation to my drawn pic, background and movement keys...
code looks like:
Turing:

%I don't know where I would put the collision map, or what the command to use it in the first place is.
  var pic2:int:=Pic.FileNew ("intropic.gif")
  var bgWidth :=Pic.Width (pic2)
    var bgHeight :=Pic.Height (pic2)
     var picWidth :=Pic.Width (pic2)
     var picHeight :=Pic.Width (pic2)
     var picX := (picWidth - maxx) div 2
    var picY := (picHeight - maxy) div 2
   var pix: int:=0
   var piy: int:=0
   Pic.Draw (pic2, -pix, -piy, picCopy)
 color(black)
 locate (24,10)
 put name, ": Wh-Where am I?"
 delay (2000)
 cls
 Pic.Draw (pic2, -pix, -piy, picCopy)
 locate (24,1)
 put "MOM: A bombshell went off.  You blacked out, and your fathers' whereabouts are unknown."
 delay (5000)
 cls
 Pic.Draw (pic2, -pix, -piy, picCopy)
 locate (24,1)
 put "I'm very worried.  The mechs are already starting to press on the military front lines."
 delay (5000)
 cls
 Pic.Draw (pic2, -pix, -piy, picCopy)
 locate (24,10)
 put "Please, ", name, ", Find my husband!"
 delay (2500)
 cls

colorback (green)
cls
process playstuff
    loop   
        Music.PlayFile ("portal - still alive (radio).mp3")
        end loop
    end playstuff
    fork playstuff
   

const SPEED :int:= 5
    var pic : int := Pic.FileNew ("ksprite.gif")
    var bg :int:=Pic.FileNew ("bg.gif")
    var bgHeight2 :=Pic.Height (bg)
    var picWidth2 :=Pic.Width (pic)
    var picHeight2 :=Pic.Height (pic)
    var bgWidth2 := Pic.Width (bg)
    var bgX := (bgWidth2 - maxx) div 2
    var bgY := (bgHeight2 - maxy) div 2
    var x :int
    var y2:int
    x := (bgWidth - picWidth) div 2
   y2 :=(bgHeight - picHeight) div 2
    var chars : array char of boolean
    loop
      setscreen ("offscreenonly")
      loop
    cls
    Pic.Draw (bg, -bgX, -bgY, picCopy)
    Pic.Draw (pic, x - bgX, y2 - bgY, picMerge)
    View.Update

    if hasch then
        var ch : string (1)
        getch (ch)
        if ch = KEY_UP_ARROW then
            y2 += SPEED
            if y2 - bgY + picHeight2 > maxy then
                bgY := y2 + picHeight2 - maxy
            end if
        elsif ch = KEY_DOWN_ARROW then
            y2 -= SPEED
            if y2 < bgY then
                bgY := y2
            end if
        elsif ch = KEY_LEFT_ARROW then
            x -= SPEED
            if x < bgX then
                bgX := x
            end if
        elsif ch = KEY_RIGHT_ARROW then
            x += SPEED
            if x - bgX + picWidth2 > maxx then
                bgX := x + picWidth2 - maxx
            end if
        end if
    end if
end loop


end loop


Also: I wish to make a key to talk to characters, for example the space bar or enter button

What command is this? There's KEY_DOWN_ARROW and whatnot, as well as KEY_SHIFT which is all I understand of it so far.

What do you do for space bar/enter?

Last but certainly not least, A problem with this is as follows:
All was well with character positioning until I added the background image called 'intropic', which comes in before the actual movement and sprite and all that noise, and all of it works perfectly fine, except instead of in the middle of the map where I want my sprite to start, its off in the middle of nowhere and cannot bee moved until down and left are pushed, and then you have to move back on to the map.
Razgriz




PostPosted: Fri Feb 20, 2009 10:52 am   Post subject: Re: Can't get my sprite moving.

Ah, and I forgot: When I finally understand how to make my character communicate with NPC's, I will need to get the screen to change like other RPG's (Close in view of people(s) speaking). What's the best way to do this?
Insectoid




PostPosted: Fri Feb 20, 2009 2:26 pm   Post subject: RE:Can\'t get my sprite moving.

Procedure.
Razgriz




PostPosted: Fri Feb 20, 2009 4:45 pm   Post subject: Re: RE:Can\'t get my sprite moving.

insectoid @ 20th February 2009 wrote:
Procedure.



Elaborate.
andrew.




PostPosted: Fri Feb 20, 2009 5:44 pm   Post subject: RE:Can\'t get my sprite moving.

Use a procedure:
Turing:
procedure talkScreen
    %do stuff
end talkScreen

loop
    %do some stuff
    talkScreen % this runs everything in the talkScreen procedure
end loop
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 5  [ 71 Posts ]
Goto page 1, 2, 3, 4, 5  Next
Jump to:   


Style:  
Search: