Computer Science Canada

Can't get my sprite moving.

Author:  Razgriz [ 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]

Author:  copthesaint [ 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.

Author:  Razgriz [ 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.

Author:  DemonWasp [ 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

Author:  Razgriz [ 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.

Author:  TheGuardian001 [ 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.

Author:  Razgriz [ 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*

Author:  Razgriz [ 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

Author:  DemonWasp [ 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?

Author:  Razgriz [ 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.)

Author:  Razgriz [ 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.

Author:  Razgriz [ 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?

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

Procedure.

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

insectoid @ 20th February 2009 wrote:
Procedure.



Elaborate.

Author:  andrew. [ 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

Author:  Razgriz [ Fri Feb 20, 2009 7:26 pm ]
Post subject:  Re: RE:Can\'t get my sprite moving.

andrew. @ 20th February 2009 wrote:
Use a procedure:
Turing:
procedure talkScreen
    %do stuff
end talkScreen

loop
    %do some stuff
    talkScreen % this runs everything in the talkScreen procedure
end loop

Alright, thanks for that but:
How would I bind a key (Like T for example) to open the talk-procedure?

Author:  saltpro15 [ Fri Feb 20, 2009 7:34 pm ]
Post subject:  Re: Can't get my sprite moving.

Turing:

var chars : array char of boolean
loop
Input.KeyDown
if chars = "t" then
%talkScreen here
exit
end loop


something like that

Author:  Razgriz [ Fri Feb 20, 2009 8:58 pm ]
Post subject:  Re: Can't get my sprite moving.

If someone would, could they show me what it would be done like in my program?
Will post.
Note that it starts just at the music input portion. All that is below this is the required variables and whatnot, I just need to know how and where I would enter the process for 'TalkScreen'.
Turing:
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 x2 :int
    var y2:int
    x2 := (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, x2 - 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
            x2 -= SPEED
            if x2 < bgX then
                bgX := x2
            end if
        elsif ch = KEY_RIGHT_ARROW then
            x2 += SPEED
            if x2 - bgX + picWidth2 > maxx then
                bgX := x2 + picWidth2 - maxx
            end if
                   end if
        end if
    end loop
end loop

Author:  michaelp [ Fri Feb 20, 2009 9:18 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Some comments about your program:
1. Why is the setscreen call in a loop? You only need to call it once at the start of your program.
2. Why do you have 2 loops?
3. Fix your indenting, it makes it very hard to read and help.
4. Why are you using hasch for your keyboard input? Why not Input.Keydown? Your got the array set up for it.
5. I'm not sure if this matters, but I THINK that drawing usually goes at the end of the main loop.

Hope you try some of this.

Author:  Razgriz [ Fri Feb 20, 2009 9:24 pm ]
Post subject:  RE:Can\'t get my sprite moving.

1) It seemed to work and like I said six thousand @#$%ing times, Im NEW.
2) Same as above.
3) I'll see what I can do
4) I used what someone else recommended, so don't chew me out about it
5)The program works, so let it alone. If you can't show me where I would put what I want to put I don't want or need your input.

Author:  saltpro15 [ Fri Feb 20, 2009 9:46 pm ]
Post subject:  Re: Can't get my sprite moving.

alright, I'm going to be very generous and fix most of this for you, but don't expect me to do all your programs for you

Turing:

 setscreen ("offscreenonly")
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 x2 :int
    var y2:int
    x2 := (bgWidth - picWidth) div 2
   y2 :=(bgHeight - picHeight) div 2
 
 
     
      loop
 
    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
            x2 -= SPEED
            if x2 < bgX then
                bgX := x2
            end if
        elsif ch = KEY_RIGHT_ARROW then
            x2 += SPEED
            if x2 - bgX + picWidth2 > maxx then
                bgX := x2 + picWidth2 - maxx
       elsif ch = "t"   then   
         % PUT PROCEDURE RIGHT HERE < -----------------------------------------------------
          end if
        end if
      end if

    Pic.Draw (bg, -bgX, -bgY, picCopy)
    Pic.Draw (pic, x2 - bgX, y2 - bgY, picMerge)
    View.Update
    cls
end loop



that should fix it, there may be one small error, I'm just coding off the top of my head

Author:  Razgriz [ Fri Feb 20, 2009 10:08 pm ]
Post subject:  Re: Can't get my sprite moving.

saltpro15 @ 20th February 2009 wrote:
alright, I'm going to be very generous and fix most of this for you, but don't expect me to do all your programs for you

Turing:

 setscreen ("offscreenonly")
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 x2 :int
    var y2:int
    x2 := (bgWidth - picWidth) div 2
   y2 :=(bgHeight - picHeight) div 2
 
 
     
      loop
 
    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
            x2 -= SPEED
            if x2 < bgX then
                bgX := x2
            end if
        elsif ch = KEY_RIGHT_ARROW then
            x2 += SPEED
            if x2 - bgX + picWidth2 > maxx then
                bgX := x2 + picWidth2 - maxx
       elsif ch = "t"   then   
         % PUT PROCEDURE RIGHT HERE < -----------------------------------------------------
          end if
        end if
      end if

    Pic.Draw (bg, -bgX, -bgY, picCopy)
    Pic.Draw (pic, x2 - bgX, y2 - bgY, picMerge)
    View.Update
    cls
end loop



that should fix it, there may be one small error, I'm just coding off the top of my head


^ Thanks, and, I'm sorry to sound rude.

Not the greatest night.

Nonetheless, I didn't expect you to do it for me, I just wanted a bit of a pointer.


Thanks.

Author:  saltpro15 [ Fri Feb 20, 2009 10:23 pm ]
Post subject:  RE:Can\'t get my sprite moving.

no problem, not to sound like a prick, but is this your first year of compsci?

Author:  Razgriz [ Fri Feb 20, 2009 10:33 pm ]
Post subject:  Re: Can't get my sprite moving.

First year of any of this. New to the program and new to the forums.

Author:  Razgriz [ Sat Feb 21, 2009 12:05 am ]
Post subject:  Re: Can't get my sprite moving.

Trying to edit it in...

Turing:

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 x2 :int
    var y2:int
    x2 := (bgWidth - picWidth) div 2
   y2 :=(bgHeight - picHeight) div 2
 
 
     
      loop
 
    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
            x2 -= SPEED
            if x2 < bgX then
                bgX := x2
            end if
        elsif ch = KEY_RIGHT_ARROW then
            x2 += SPEED
            if x2 - bgX + picWidth2 > maxx then
                bgX := x2 + picWidth2 - maxx
       elsif ch = "t"   then   
         procedure talkScreen
    Pic.Draw ("tscreen.gif")
end talkScreen

loop
    %do some stuff
    talkScreen %this runs everything in the talkScreen procedure
end loop

Got some errors....
first and foremost... 'Process's may only be declared at the program or module level' -> Dont know what to do.
Second... 'Argument is the wrong type'

Author:  andrew. [ Sat Feb 21, 2009 9:17 am ]
Post subject:  Re: RE:Can\'t get my sprite moving.

Razgriz @ Fri Feb 20, 2009 9:24 pm wrote:

5)The program works, so let it alone. If you can't show me where I would put what I want to put I don't want or need your input.
Jst because the program works, doesn't mean you're doing it right. saltpro is right, you should learn to code better now before it becomes a habit.

Author:  saltpro15 [ Sat Feb 21, 2009 9:45 am ]
Post subject:  RE:Can\'t get my sprite moving.

"procedure talkScreen " you don't need procedure, just talkScreen, otherwise you're declaring it twice, that should solve both errors Smile

Author:  Insectoid [ Sat Feb 21, 2009 9:50 am ]
Post subject:  RE:Can\'t get my sprite moving.

you are also missing 2 'end if's and an 'end loop'. Procedures cannot be declared in a loop or if statement.

Author:  Razgriz [ Sat Feb 21, 2009 11:21 am ]
Post subject:  RE:Can\'t get my sprite moving.

Okay.

Thanks guys. I'll try it out ASAP.

Author:  Razgriz [ Sat Feb 21, 2009 11:49 am ]
Post subject:  RE:Can\'t get my sprite moving.

What about the collision map?

I still haven't figured out how to perfect it to sync with my map, or how to implement it into Turing.

Author:  Insectoid [ Sat Feb 21, 2009 12:23 pm ]
Post subject:  RE:Can\'t get my sprite moving.

is this going to be an ascii map?

Author:  Razgriz [ Sat Feb 21, 2009 12:45 pm ]
Post subject:  RE:Can\'t get my sprite moving.

What do you mean?

The example of my collision map is on page 1.

Author:  Razgriz [ Mon Feb 23, 2009 10:19 am ]
Post subject:  Collision detection :(

Is anybody up to helping?
I've been trying to figure it out on my own but it's been... ... Less than successful.

Author:  DemonWasp [ Mon Feb 23, 2009 11:06 am ]
Post subject:  RE:Can\'t get my sprite moving.

We need a bit more information about what you want your program to do; specifically, how does your character move?

If you want your character to move on a grid (he is in one square at a time and one square only) then you probably want to store his position (and the position of obstacles in the grid) as coordinates for your grid. Think of a grid like in Battleship, with letters on one axis and numbers on another (A9, B3, etc) except that instead of using letters, you'll need to use numbers in Turing.

If you want free movement (character isn't on a grid, which is more like real life) then that will be more complex, and you won't be able to use your ASCII map for detecting collisions very easily (it could be done, but it'd be pretty ugly).

Author:  Razgriz [ Mon Feb 23, 2009 11:09 am ]
Post subject:  RE:Can\'t get my sprite moving.

In such a case, then, I would prefer the grid-type.

So, looking at the map that I drew on paint, How would I go about making the collisions?

For example, so the character doesn't go out-of-map, or through the rock, or over the water.

Author:  DemonWasp [ Mon Feb 23, 2009 11:52 am ]
Post subject:  RE:Can\'t get my sprite moving.

If you're going for grid-based movement, you want something like this:

1. The location of each player, NPC and other creature in the game is given by their x and y coordinates, which refer to the column they're in. You probably want most characters to move by 1 grid unit at a time.

2. Each grid element has a different character for what it contains. You could use spaces for "passable space" and 'X' for impassable areas (map boundary, rocks, water, etc).

3. Every time a player (or other character) moves, check the grid square they want to move into - if it's a space (passable) then they can move through; if not then they stay where they are.

It looks a little like this:
code:

var playerX, playerY : int % These refer to the position IN THE GRID, not in pixels.
const GRID_SIZE : int := 15 % The number of pixels in each grid square. This is necessary for drawing players at the correct position on the map.

% Figure out the player's location somehow...

% Now let's make a structure to store our map (just a two-dimensional array of characters)
const MAP_PASSABLE : char := ' '
const MAP_IMPASSABLE : char := 'X'
var mapCols, mapRows : int % The size of the map
var map : array 1..mapCols, 1..mapRows of char

% Load the map from a file (see file below)
var stream : int
open, stream, "mymap", get
get : stream, mapCols
get : stream, mapRows
for r : 1..mapRows
    for c : 1..mapCols
        get : stream, map ( c, r )
    end for
end for

% Main game loop
loop
    % Get input here and determine what to do with it. This probably includes having variables "playerDestinationX", "playerDestinationY" which give the direction the player is headed in. Don't just move the player, as you still need to check against your grid (that's next).

    % Check whether the player can move to their destination
    if map ( playerDestinationX, playerDestinationY ) = MAP_PASSABLE then
        % If they can, then move them there.
        playerX := playerDestinationX
        playerY := playerDestinationY
    else
        put "Can't move there!" % Or some more appropriate error message...
    end if

    % Draw stuff here as you've been doing. Don't forget to convert from grid-coordinates to pixel-coordinates (hint: this involves multiplying by the size of each grid unit - GRID_SIZE)

end loop


Now you need an input file that contains your map. This file is pretty simple; it just contains the number of rows in the map and the number of columns, then the map itself (X and space - I'm sure you can use find-and-replace to convert your existing map, or you can use your map and just change MAP_IMPASSABLE and MAP_PASSABLE above).

code:

10
5
XXXXXXXXXX
X  XX    X
X  XX    X
X      XXX
XXXXXXXXXX


Edit: wooo 666 bits Very Happy

Author:  Razgriz [ Mon Feb 23, 2009 1:19 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Awesome, thanks.

I'll try this as soon as I'm able.

Author:  Razgriz [ Mon Feb 23, 2009 2:18 pm ]
Post subject:  RE:Can\'t get my sprite moving.

So okay,

'10
5 '

Presumably, the 10 and 5 are the length and width, right?

X's are where the character cannot go, and the blanks are where I can.

Author:  DemonWasp [ Mon Feb 23, 2009 2:26 pm ]
Post subject:  RE:Can\'t get my sprite moving.

You need to know the length and the width (columns and rows) of the map. Technically you can get the size of the map other ways, but the easiest way is to just have the map-maker put it right in the file.

Essentially, you're correct.

Author:  Razgriz [ Mon Feb 23, 2009 2:29 pm ]
Post subject:  RE:Can\'t get my sprite moving.

So, logically, since I don't know the grid-dimentions on paint, how would I go about fitting it properly?

Like, the picture is 800x800 pixels, but theres not that many characters across.

Is there a different way of doing this?

Author:  DemonWasp [ Mon Feb 23, 2009 2:49 pm ]
Post subject:  RE:Can\'t get my sprite moving.

You have to decide how many pixels you want per grid square (see the GRID_SIZE constant). Your map-image's size will then have to be determined as follows:

The image will be (number of map columns) * GRID_SIZE pixels wide.
The image will be (number of map rows) * GRID_SIZE pixels tall.

Author:  Razgriz [ Mon Feb 23, 2009 4:35 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Ahh. Okay, awesome stuff.

Thanks for all the help. I'm going to add your MSN, it's probably faster than this, and I'm not on this as much.

Author:  Razgriz [ Mon Feb 23, 2009 4:42 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Oh, and, One more problem . . .

Turing:
const SPEED :int:= 5
    var pic : int := Pic.FileNew ("ksprite.gif")
    var bg :int:=Pic.FileNew ("bg2.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 x2 :int
    var y2:int
    x2 := (bgWidth - picWidth) div 2
   y2 :=(bgHeight - picHeight) div 2
% Omitted

    Pic.Draw (bg, -bgX, -bgY, picCopy)
    Pic.Draw (pic, x2 - bgX, y2 - bgY, picMerge)
    View.Update
    cls
end loop


Not sure exactly why, but my character spawns off-map in the bottom corner, and I have to press the down and left arrow keys before I can see her.

How would I go about fixing this?


Mod Edit: No spaces in the syntax tags
code:
[syntax="turing"]Code Here[/syntax]

Author:  Razgriz [ Mon Feb 23, 2009 4:55 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Eh, what if my map is now 5000 x 5000 pixels?XD;;

Would that change a great deal?

Author:  DemonWasp [ Mon Feb 23, 2009 10:54 pm ]
Post subject:  Re: Can't get my sprite moving.

After an MSN session with Razgriz, the attached code and map emerged.

Author:  Razgriz [ Tue Feb 24, 2009 6:54 am ]
Post subject:  RE:Can\'t get my sprite moving.

Been working a lot on the map, and it's going great. Got everything that needs to be impassable that way, so...

Thanks :}

Author:  Razgriz [ Tue Feb 24, 2009 1:24 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Question: How do I change the red square back to my sprite?

Author:  DemonWasp [ Tue Feb 24, 2009 2:41 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Look for the Draw.FillBox command in the main loop. Comment that out, and replace with a Pic.Draw ( playerPic ... ) command - fill it in yourself. Don't forget to multiply by GRID_SIZE, or it won't line up with the grid.

Author:  Razgriz [ Tue Feb 24, 2009 5:07 pm ]
Post subject:  RE:Can\'t get my sprite moving.

I commented all this noise:
Turing:

  Pic.Draw (background, 0, 0, picCopy)
        for x : 1 .. mapCols
                for y : 1 .. mapRows
                        if map (x, y) = MAP_IMPASSABLE then
                                %Draw.FillBox ((x - 1) * GRID_SIZE, (y - 1) * GRID_SIZE, x * GRID_SIZE, y * GRID_SIZE, grey)
                        end if
                end for
        end for


        % Draw some rulers to guide us (if we're debugging)
       /* if DEBUG then
                for x : 0 .. maxx by GRID_SIZE
                        Draw.Line (x, 0, x, maxy, black)
                end for
                for y : 0 .. maxy by GRID_SIZE
                        Draw.Line (0, y, maxx, y, black)
                end for

                var mouseX, mouseY, mouseButton : int
                Mouse.Where (mouseX, mouseY, mouseButton)
                put "(X, Y) = (", mouseX div GRID_SIZE + 1, ", ", mouseY div GRID_SIZE + 1, ")"

        end if*/


        % Note: multiplying the player coordinates (which are coordinates to the grid) by the size of each grid square.
        % You can also use an offset (I believe your code has a bgX and bgY) to move the entire display. I'll let you figure that out.
        Draw.FillBox ((playerX - 1) * GRID_SIZE, (playerY - 1) * GRID_SIZE, playerX * GRID_SIZE, playerY * GRID_SIZE, 12)
        View.Update ()
        Time.DelaySinceLast (100)         % Slow us down just a little
end loop


and it makes the grid invisible but still operates... but now I'm confused. O-o

Author:  Razgriz [ Wed Feb 25, 2009 6:51 am ]
Post subject:  RE:Can\'t get my sprite moving.

Disregard, I managed to figure that one out...

Thanks to the assistance of DemonWasp, I'm not set to start making multiple maps...(Yay?)

Maybe someone can help me with that.

Author:  DemonWasp [ Wed Feb 25, 2009 8:14 am ]
Post subject:  RE:Can\'t get my sprite moving.

Re: Commenting all of that out: You don't need to. Notice it says "if DEBUG then ..." ? Just set DEBUG to false at the top of the file.

Multiple areas soon.

Author:  Razgriz [ Wed Feb 25, 2009 9:20 am ]
Post subject:  RE:Can\'t get my sprite moving.

Awesome.

Thanks mate :}

Now, I'm at school.

I had a question, but I forget...


Um. . .

Let me think, I should remember soon.

Author:  saltpro15 [ Wed Feb 25, 2009 9:24 am ]
Post subject:  RE:Can\'t get my sprite moving.

@Razgriz, I go to e.l. crossley, we got the day off Very Happy

Author:  Razgriz [ Wed Feb 25, 2009 9:32 am ]
Post subject:  RE:Can\'t get my sprite moving.

You suck >W< I wish I had the day off.

Anyway I believe my question was...
is going into a house the same as going onto a new map?

Author:  saltpro15 [ Wed Feb 25, 2009 9:36 am ]
Post subject:  RE:Can\'t get my sprite moving.

depends on how you load your maps, but I hear fallout 3 calling me so hopefully DemonWasp can do a better job answering than I can

Author:  Razgriz [ Wed Feb 25, 2009 9:41 am ]
Post subject:  RE:Can\'t get my sprite moving.

Yes, he seems to be good for that. XD

Author:  DemonWasp [ Wed Feb 25, 2009 11:33 am ]
Post subject:  RE:Can\'t get my sprite moving.

There are a few different styles that RPGs seem to choose between. I'll list the ones that I've seen before; if you know of others you can also list them. Once you choose a type, we can start on a proper design for how to handle multiple areas.

Type A
This is the simplest type (easiest to implement, but least usable). It's common in older handheld RPG games.

In this type, all areas are of a given size (we have 40x40 at this point). Whenever the player exits the map to the North, South, East or West, there's another area there that gets loaded and displayed. The areas are arranged in a grid, which makes determining where to go next easy.

This method does not handle stairs particularly well as the only way to leave the area is via the edge of the area, and it's a little inflexible (doesn't let you have areas larger or smaller than the default). Entering any building is equivalent to just walking into a closed-off area by an entrance, like the following:

code:

.....
.XXX.
.X.X. <-- in the middle space there is "inside" the building. It's not that special.
.X.X.


Type B
As Type A, but there are also special squares that transport you to a new area (for example, stairs, teleporters, ships...). This adds quite a bit of complexity, but also adds considerable realism.

This method is still inflexible because it requires you to constrain all areas to the size you've already decided on, or split them over multiple "areas".

Entering a building can happen in multiple ways in this type. Either you can handle it like Type A (the walls are impassable, the door is not) or you can handle it as if the door was a staircase (transports you to a new area for the interior) - the second choice is a little like the Baldur's Gate / BG2 / Neverwinter Nights / NWN2 method.

Type C
As Type B, but in addition, areas can be of variable size. This is the most complicated option, but also the most flexible. This is the exact type used by BG/BG2/NWN/NWN2.

Warning: you're starting to get quite a bit more complicated, regardless of which of the above you choose. I recommend doing some of the excellent Turing Walkthrough/tutorial to strengthen your core understanding before we proceed.

The implementation of Type A is probably most simply done with Turing's records (see the tutorials...). Type B and C are probably better done with classes.

Author:  Razgriz [ Wed Feb 25, 2009 11:40 am ]
Post subject:  RE:Can\'t get my sprite moving.

Alright.

For the basicness of my game I would stick to A, simply because Ican manage to keep all areas the same size.

Doesn't matter too much at this point about realism for me, I just want to make a game.

Perhaps in time I'll update my game to another movement type.

Author:  Razgriz [ Wed Feb 25, 2009 1:12 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Computer system at school @#$%ed me over, lost my file from it so I got the previous from portable drive...

Now when I try to get it to draw my sprite it says 'playerPic' cannot have subscripts..


Whats' happened?

Author:  Razgriz [ Wed Feb 25, 2009 1:15 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Nevermind, I got it... but whatever the hell the computer did, it totally destroyed my entire file and everything in it.

Author:  DemonWasp [ Wed Feb 25, 2009 1:54 pm ]
Post subject:  Re: Can't get my sprite moving.

Design
Normally I'd do most of this in my head, but instead I'll do a walkthrough here.

Thinking about your game world, we see that you have a World, which is composed of multiple Areas, which is composed of grid squares. Overall, your world is just one rather large grid, but it's segmented into discrete units called "Areas" that you travel to and from.

So we have a basic design now: the World is composed of Areas. Areas are composed of a two-dimensional array of grid squares (at the moment, this is a variable called "map", and each grid square is represented as a character. At the moment, it's loaded from a fairly simple file - which we'll need to change.

Another feature that we'll start with right off-the-bat is the ability to have different worlds. Each time you run the program, you'll have only one World loaded (as well as its multiple areas) - by default, you'd give out the World for Evermore, but if I wanted I could make a world for The Lord of the Rings or whatever else and load that instead. If that sounds complicated, don't worry, that's one of the easy parts.

What do Area and World look like?
Now we need to determine which properties our World and Area have. I'll start with the most basic implementations for the moment.

Worlds have:
- name
- an array of Areas

Areas have:
- a name
- a 2d array of grid squares
- some way of identifying which area the player goes to if they leave via N/S/E/W edge.

So what we'll do is have a world file (example: Evermore.world). In that file, we'll have something like this (everything after a # is a comment and won't appear in the file):

code:

Demonstration   # The world name
2              # The number of areas in the world

1 West Side   # The area number, the area name
XXXXX... # (put the map in here...)
-1  # Area to go to if we exit to the (direction);
2    # negative one (-1) means "nowhere"
-1  # Order is North, East, South, West
-1

2 East Side
XXXXX... (put the map in here...)
-1
-1
-1
1


So we see that we have a simple world with an East Side and a West Side. You can go from one to the other, but you can't leave in any other direction. The reason that we number each area is so that it's easier for the human writing that file to figure out which area is which number (because once you have more than about 20 areas, you'd be forced to count every time you wanted to link one side of an area into the next area...)

The Implementation
The above leads to the following for our data structure:
[syntax="Turing]

const MAX_AREAS : int := 64 % This is whatever we want, we just need a number at the moment (we can get around this later with flexible arrays...)

const AREA_SIZE : int := 40 % This is what we've already got, it's just a constant now.

const AREA_NONE : int := -1 % This is for the -1 in the file for the area. This is the flag for "can't go that way!"

type Area:
record
name : string
map : array 1..AREA_SIZE, 1..AREA_SIZE of char % This is just like the existing map variable; the only difference is that we can have more than one of them now.
n, e, s, w : int % The index (in the 'areas' array in World) of the area to move to.
end record

type World:
record
name : string
areas : array 1..MAX_AREAS of Area
end record
[/syntax]

Of course, just having the data structure is unhelpful, as we'll need methods to deal with the data. I'll give you a chance to implement these; if you run into problems I can give you a hand

Turing:

function loadArea ( stream : int ) : Area
    % This is a helper function for loadWorld below.
    % It will receive the input stream from loadWorld and will create a new Area variable and return it, after loading its contents.
    % Most of the work for this method has already been done. Look at the code for loading maps in the existing Evermore.t file.
end loadArea

function loadWorld ( worldName : string ) : World
    % This is the main loading function. It will open the named file (note: worldName should be something like "Evermore", but we need to read from "Evermore.world", so you'll have to add ".world".
    % When it comes to loading areas, this method should make use of loadArea, above
end loadWorld


To test your implementations, you can use the attached sample and the following call:
Turing:

var sampleWorld : World := loadWorld ("sample")

Author:  saltpro15 [ Wed Feb 25, 2009 2:00 pm ]
Post subject:  RE:Can\'t get my sprite moving.

I vote for someone to sticky this thread, DemonWasp just covered more about games than I learned all year in gr10 CS *claps

Author:  DemonWasp [ Wed Feb 25, 2009 2:10 pm ]
Post subject:  RE:Can\'t get my sprite moving.

re: sticky - fine by me. I'd move the pertinent sections to a walkthrough, but I'm having trouble seeing where a proper tutorial would start and stop. I'll put in some thought and see if I come up with anything tutorial-worthy.

Also, mods: if you could correct the missing quote in one of my [ syntax ] tags above, I'd be grateful.

Edit: Took a quick look, seems the topic of 2d grid-movement and collision detection is actually already covered by a tutorial by CodeMonkey2000. If you were meaning the whole "multiple areas" thing, then I could probably come up with a tutorial on how to design simple programs (Is there actually any demand for that? Are people likely to use it?).

Author:  Razgriz [ Wed Feb 25, 2009 7:47 pm ]
Post subject:  Re: Can't get my sprite moving.

DemonWasp @ 25th February 2009 wrote:
Design


code:

Demonstration   # The world name
2              # The number of areas in the world

1 West Side   # The area number, the area name
XXXXX... # (put the map in here...)
-1  # Area to go to if we exit to the (direction);
2    # negative one (-1) means "nowhere"
-1  # Order is North, East, South, West
-1

2 East Side
XXXXX... (put the map in here...)
-1
-1
-1
1




So I would do that in notepad?

Author:  saltpro15 [ Wed Feb 25, 2009 7:51 pm ]
Post subject:  RE:Can\'t get my sprite moving.

you can, any text editor should work I believe

Author:  DemonWasp [ Wed Feb 25, 2009 7:55 pm ]
Post subject:  RE:Can\'t get my sprite moving.

Any text editor that doesn't add formatting information or similar garbage. Notepad works fine.

Author:  Razgriz [ Thu Feb 26, 2009 6:52 am ]
Post subject:  RE:Can\'t get my sprite moving.

Re:Sticky

Yeah, I think it'd be good there for any others who've had my problem..

plus my first thread would become a sticky. (Woo!)
;D

Author:  Razgriz [ Sun Feb 07, 2010 10:34 am ]
Post subject:  Re: Can't get my sprite moving.

Ahem; if I may ressurect the dead..

I forget all of my turing coding! I'm just now getting back into Turing because I was so intensely bored one day. I want to make a game [much like the one I started here a year ago]. Problem is, after a year of inactivity, I don't remember a thing. Anyone who could give some refreshers and some advice would be a personal hero.

Thanks.

Also, I seem to ahve lost the code of the game I was working on. I don't know if I ever gave anyone on here the full version, but in the event that I did, if you could send it to me, greatly appreciated.

Author:  SNIPERDUDE [ Sun Feb 07, 2010 2:00 pm ]
Post subject:  Re: Can't get my sprite moving.

Quick summary:
Check up on the Turing Walkthrough for more.
Turing:
var x : int
const y : real := 1.3
var c : char
var s : string := "Hello World!"
var a : array 1 .. 5 of int

setscreen ("graphics:450;450, nobuttonbar, offscreenonly, title:TEST!")

fcn adds (x1 : int, x2 : real) : real
    result x1 + x2
end adds

proc prints
    put s
end prints

loop
    for i : 0 .. 20 by 2
        if i mod 8 = 0 then
            put  "GO"
        elsif i = 18 then
            put "QWERTY"
        else
            put "GONE"
        end if
    end for
end loop

Hopefully that'll jog your memory somewhat.

Author:  Razgriz [ Sun Feb 07, 2010 3:09 pm ]
Post subject:  Re: Can't get my sprite moving.

And it has. Thank you very much. I'll likely post some new code from my new one when I have some progress, thanks.

Author:  SNIPERDUDE [ Sun Feb 07, 2010 3:18 pm ]
Post subject:  RE:Can\'t get my sprite moving.

No problem


: