
-----------------------------------
Razgriz
Thu Feb 19, 2009 6:46 am

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 . . .

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 :) [syntax="turing"]Code Here[/syntax]

-----------------------------------
copthesaint
Thu Feb 19, 2009 7:09 am

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
Thu Feb 19, 2009 10:24 am

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.  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
Thu Feb 19, 2009 10:47 am

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:

% 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
Thu Feb 19, 2009 11:02 am

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.

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
Thu Feb 19, 2009 11:07 am

Re: 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.


        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
Thu Feb 19, 2009 11:09 am

RE:Can\'t get my sprite  moving.
-----------------------------------
Ohh.

Thanks.

*High fives the first person who made sense to me*

-----------------------------------
Razgriz
Thu Feb 19, 2009 12:02 pm

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

-----------------------------------
DemonWasp
Thu Feb 19, 2009 2:45 pm

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
Thu Feb 19, 2009 7:05 pm

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.)

-----------------------------------
Razgriz
Thu Feb 19, 2009 7:06 pm

Re: Can't get my sprite  moving.
-----------------------------------
My original rough draft of said map looks like:


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:

%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
Fri Feb 20, 2009 10:52 am

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
Fri Feb 20, 2009 2:26 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
Procedure.

-----------------------------------
Razgriz
Fri Feb 20, 2009 4:45 pm

Re: RE:Can\'t get my sprite  moving.
-----------------------------------
Procedure.


Elaborate.

-----------------------------------
andrew.
Fri Feb 20, 2009 5:44 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
Use a procedure:
procedure talkScreen
    %do stuff
end talkScreen

loop
    %do some stuff
    talkScreen % this runs everything in the talkScreen procedure
end loop


-----------------------------------
Razgriz
Fri Feb 20, 2009 7:26 pm

Re: RE:Can\'t get my sprite  moving.
-----------------------------------
Use a procedure:
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?

-----------------------------------
saltpro15
Fri Feb 20, 2009 7:34 pm

Re: Can't get my sprite  moving.
-----------------------------------

var chars : array char of boolean
loop
Input.KeyDown
if chars = "t" then
%talkScreen here
exit
end loop


something like that

-----------------------------------
Razgriz
Fri Feb 20, 2009 8:58 pm

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'.
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


-----------------------------------
michaelp
Fri Feb 20, 2009 9:18 pm

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.

-----------------------------------
Razgriz
Fri Feb 20, 2009 9:24 pm

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.

-----------------------------------
saltpro15
Fri Feb 20, 2009 9:46 pm

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


 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

-----------------------------------
Razgriz
Fri Feb 20, 2009 10:08 pm

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


 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.

-----------------------------------
saltpro15
Fri Feb 20, 2009 10:23 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
no problem, not to sound like a prick, but is this your first year of compsci?

-----------------------------------
Razgriz
Fri Feb 20, 2009 10:33 pm

Re: Can't get my sprite  moving.
-----------------------------------
First year of any of this.  New to the program and new to the forums.

-----------------------------------
Razgriz
Sat Feb 21, 2009 12:05 am

Re: Can't get my sprite  moving.
-----------------------------------
Trying to edit it in...


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'

-----------------------------------
andrew.
Sat Feb 21, 2009 9:17 am

Re: RE:Can\'t get my sprite  moving.
-----------------------------------

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.

-----------------------------------
saltpro15
Sat Feb 21, 2009 9:45 am

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 :)

-----------------------------------
Insectoid
Sat Feb 21, 2009 9:50 am

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.

-----------------------------------
Razgriz
Sat Feb 21, 2009 11:21 am

RE:Can\'t get my sprite  moving.
-----------------------------------
Okay.

Thanks guys.  I'll try it out ASAP.

-----------------------------------
Razgriz
Sat Feb 21, 2009 11:49 am

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.

-----------------------------------
Insectoid
Sat Feb 21, 2009 12:23 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
is this going to be an ascii map?

-----------------------------------
Razgriz
Sat Feb 21, 2009 12:45 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
What do you mean?

The example of my collision map is on page 1.

-----------------------------------
Razgriz
Mon Feb 23, 2009 10:19 am

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.

-----------------------------------
DemonWasp
Mon Feb 23, 2009 11:06 am

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).

-----------------------------------
Razgriz
Mon Feb 23, 2009 11:09 am

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.

-----------------------------------
DemonWasp
Mon Feb 23, 2009 11:52 am

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:

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).


10
5
XXXXXXXXXX
X  XX    X
X  XX    X
X      XXX
XXXXXXXXXX


Edit: wooo 666 bits :D

-----------------------------------
Razgriz
Mon Feb 23, 2009 1:19 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
Awesome, thanks.

I'll try this as soon as I'm able.

-----------------------------------
Razgriz
Mon Feb 23, 2009 2:18 pm

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.

-----------------------------------
DemonWasp
Mon Feb 23, 2009 2:26 pm

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.

-----------------------------------
Razgriz
Mon Feb 23, 2009 2:29 pm

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?

-----------------------------------
DemonWasp
Mon Feb 23, 2009 2:49 pm

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.

-----------------------------------
Razgriz
Mon Feb 23, 2009 4:35 pm

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.

-----------------------------------
Razgriz
Mon Feb 23, 2009 4:42 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
Oh, and, One more problem  . . .

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 [syntax="turing"]Code Here[/syntax]

-----------------------------------
Razgriz
Mon Feb 23, 2009 4:55 pm

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?

-----------------------------------
DemonWasp
Mon Feb 23, 2009 10:54 pm

Re: Can't get my sprite  moving.
-----------------------------------
After an MSN session with Razgriz, the attached code and map emerged.

-----------------------------------
Razgriz
Tue Feb 24, 2009 6:54 am

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 :}

-----------------------------------
Razgriz
Tue Feb 24, 2009 1:24 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
Question: How do I change the red square  back to my sprite?

-----------------------------------
DemonWasp
Tue Feb 24, 2009 2:41 pm

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.

-----------------------------------
Razgriz
Tue Feb 24, 2009 5:07 pm

RE:Can\'t get my sprite  moving.
-----------------------------------
I commented all this noise:

  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

-----------------------------------
Razgriz
Wed Feb 25, 2009 6:51 am

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.

-----------------------------------
DemonWasp
Wed Feb 25, 2009 8:14 am

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.

-----------------------------------
Razgriz
Wed Feb 25, 2009 9:20 am

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.

-----------------------------------
saltpro15
Wed Feb 25, 2009 9:24 am

RE:Can\'t get my sprite  moving.
-----------------------------------
@Razgriz, I go to e.l. crossley, we got the day off :D

-----------------------------------
Razgriz
Wed Feb 25, 2009 9:32 am

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?

-----------------------------------
saltpro15
Wed Feb 25, 2009 9:36 am

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

-----------------------------------
Razgriz
Wed Feb 25, 2009 9:41 am

RE:Can\'t get my sprite  moving.
-----------------------------------
Yes, he seems to be good for that. XD

-----------------------------------
DemonWasp
Wed Feb 25, 2009 11:33 am

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:


.....
.XXX.
.X.X. 