forums

TNT Basic Forums > Programming Q&A
Walls?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

11-04-2006 21:47

Posted by:
Ledorax

Location:
Sweden

Click Here to Email Ledorax   Find more posts by Ledorax

Hello,
I know this has been asked dozens of times before and you're all quite sick of it by now, but how am I supposed to do walls? I've been reading lots of posts on this forum but I still don't get it. I have a sprite in the map but I don't know how to make it so that the walls in the map will be inpassable(how do you spell that?).

Also, how do I animate a sprite?

Any help would be awesome.

11-04-2006 23:17

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

It's not too tricky...

TNT has no concept of what a 'wall' is, so you need to tell it what to do when a sprite tries to cross one. Basically you need to find out where your sprite will be if it moves by its normal amount, if that location will put it into a 'wall' then you just don't do the movement. That is about it...

Animating a sprite is just changing the picture that is displayed when the sprite is drawn on screen. This may sound a bit obvious but it really is that simple. You use the sprite call to draw the sprite, and this needs the sprite number you're refering to, the X and Y position to draw that sprite and its image. To animate the sprite you just need to change the image number.

hope this helps, but if not then post again with your problems and we'll see what we can do...

Danny (nods)

11-05-2006 00:42

Posted by:
Ledorax

Location:
Sweden

Click Here to Email Ledorax   Find more posts by Ledorax

But how do I know if the sprite tries to cross a wall or not? With an "if" I guess, but what do I put in it?

About animating sprites: I was guessing that's how it's done, but if I just put them all in a row, won't it be happening so fast that it can't be seen?

11-05-2006 14:57

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Look at the command 'map tile'. it allows you to know the ID of the tile at some location on the map. This way you can do something like:

' move 5 pixels to the right
int tile_type = map tile( (x+5)/map tile width, y/map tile height, 0)

if(tile_type<> 5) ' assuming tile #5 is a wall tile
x=x+5
end if

(this is only pseudo-code, adapt it to your needs)

"but if I just put them all in a row, won't it be happening so fast that it can't be seen?"

Ok, i think you don't understand the very basis of how display is done in TNT. I will discuss this issue instead, i think you will understand better. when you call a sprite command, it does NOT get display on screen automatically. TNT just remembers you want a sprite there, but it doesn't draw it. All drawing is done upon calling 'draw frame'.

That is, if you call:

sprite x,y,1
sprite x,y,2
sprite x,y,3
sprite x,y,4
sprite x,y,5
draw frame

only frame 5 will be visible.

To have an animation, you need to call something like:
sprite x,y,1
draw frame
sprite x,y,2
draw frame
sprite x,y,3
draw frame
sprite x,y,4
draw frame
sprite x,y,5
draw frame

now of course that only works for a small test. now you need to integrate it in a loop:

int frame=1
while true
sprite x,y,frame
frame=frame+1
if frame>5 then frame=1
wend

hope it helps

11-05-2006 14:58

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

hmmm in the last code snippet i forgot to add dram frame =)

int frame=1

while true

sprite x,y,frame
frame=frame+1
if frame>5 then frame=1

draw frame

wend

11-05-2006 19:39

Posted by:
Ledorax

Location:
Sweden

Click Here to Email Ledorax   Find more posts by Ledorax

Well...

Alright, I tried doing what you said and put it into a small test game (starting with the animating), but it doesn't work.

I have seven pictures for each direction. The first one is showed when standing still, the other six are for the walking animation. Or, that's what's supposed to happen. When I walk around, it changes picture to the first one for the direction, but it doesn't animate. Here's my code:
---------------------------------------------------------------
'Set up the graphics and stuff********************
Graphics Mode 640,480
Load Map 128
Open Map Viewport 1,0,80,0 to 560,480
Load Images 128
Int X=112,Y=32,DIR=3
Int Frame=0,Moving=0

repeat
'Walking******************************************
if up then Y=Y-1
if up then DIR=1
if right then X=X+1
if right then DIR=2
if down then Y=Y+1
if down then DIR=3
if left then X=X-1
if left then DIR=4
if not right or left or down or up then Moving=1'If nothing is pressed, stand still
if not right or left or down or up then Moving=0'Else start the animation
if Dir=1 and moving=0 then frame=0
if Dir=2 and moving=0 then frame=7
if Dir=3 and moving=0 then frame=14
if Dir=4 and moving=0 then frame=21
while moving=1 and DIR=1'if up is pressed, play north animation
frame=frame+1
if frame>6 then frame=1
wend
while moving=1 and DIR=2'if right is pressed, play east animation
frame=frame+1
if frame>13 then frame=8
wend
while moving=1 and DIR=3'if down is pressed, play south animation
frame=frame+1
if frame>20 then frame=15
wend
while moving=1 and DIR=4'if left is pressed, play west animation
frame=frame+1
if frame>27 then frame=22
wend
sprite 1,x,y,frame'show sprite
draw frame
forever
---------------------------------------------------------------

I have no clue what I did wrong. Any ideas?

11-05-2006 19:43

Posted by:
Ledorax

Location:
Sweden

Click Here to Email Ledorax   Find more posts by Ledorax

Hmm, I just realised it says:

"if not right or left or down or up then Moving=1'If nothing is pressed, stand still
if not right or left or down or up then Moving=0'Else start the animation"

The first one is supposed to say "if right or left...", but when I change it to that, the sprite refuses to move at all.

Now I'm really confused...

11-05-2006 22:30

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Several problems...

To start with you can't say 'if not this or that or the other', you need to say 'if not this and not that and not the other', this may solve your problem straight off...
Secondly, but far less importantly, you should check your logic... What you're saying makes sense (for the most part) but remember that you can combine statements under a single 'if' (check your manual), and remember that if one thing is true then the opposite can't also be true, so why check for it...
I could rewrite this code for you, but the point of programming is to solve logical problems and I think I'd do you more favours by just pointing you in the right direction than giving you an answer. By condensing your 'if' constructs it will make the code easier to understand and hopefully point towards what you want to happen in the long run.

Think on what I've said and take a look at the code again... It's a logic problem, so think on what you want it to do and draft it on paper first (if that helps, it helps me). Then code it. Have fun, and if you really can't get it then post again... I've been a programmer for nearly twenty years, and the main tools of the trade are not a keyboard, IDE and a manual, they are a pencil, some paper and a bloody great big eraser!

Danny (nods)

11-06-2006 00:10

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone


1.

if up then Y=Y-1
if up then DIR=1

should become...

if up
Y=Y-1
DIR=1
end if

2. You have wayyyy too many while loops here.

while moving=1 and DIR=2'if right is pressed, play east animation
frame=frame+1
if frame>13 then frame=8
wend

this loop will just go on forever. it loops until 'moving' or 'DIR' changes, however neither of the 2 is changed anywhere in the loop. i think same thing goes with all other loops.

At this point, i think you really don't understand the basic flow of a program, and i would strongly advise, before doing any game, to just spend some time just writing test programs, with different if/for/while/procedures/etc. and 'print's that mark the progression... just to see in what order the commands are executed and get used to it

for your info... i think you meant 'if' and note 'while'

11-06-2006 10:44

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

>>
I've been a programmer for nearly twenty years, and the main tools of the trade are not a keyboard, IDE and a manual, they are a pencil, some paper and a bloody great big eraser!
>>

For me, its a text editor and the delete key (and the shift and arrows too, for multiple selection of text chars, and the alphabetical and numerical keys).

I don't understand why you'd do your drafting on paper rather than on a text editor where you can copy and paste, and is much faster and economical, and envronmentally friendly and more flexible if you made your own text editor.... etc.

11-06-2006 10:55

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

My Try.

I am only a beginner too... So...

'Set up the graphics and stuff********************
Graphics Mode 640,480
Load Map 128
Open Map Viewport 1,0,80,0 to 560,480
Load Images 128
Int X=112,Y=32,DIR=3
Int Frame=0,Moving=0
int GameIsRunning=1
int PlayAnimation=0

While GameIsRunning=1
if UP
DIR=1
Y=Y-1
end if

if DOWN
DIR=3
Y=Y+1
end if

if LEFT
DIR=4
X=X-1
end if

if RIGHT
DIR=2
X=X+1
end if

If Dir=1
frame=frame+1
if frame>6 then frame=1
end if
if Dir=2
frame=frame+1
if frame>13 then frame=8
end if
If Dir=3
frame=frame+1
if frame>20 then frame=15
end if
if Dir=4
frame=frame+1
if frame>27 then frame=22
end if

sprite 1,x,y,frame

Draw Frame
wend

11-06-2006 10:57

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

By the way, While Loops don't run simultaneously with all other code that are outside the loop...

11-06-2006 13:17

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

It's a visibility thing...

quote:
I don't understand why you'd do your drafting on paper rather than on a text editor where you can copy and paste

You can see more of an over view of your project on paper, no scrolling. You can doodle, make quick notes (writing is still faster then typing), draw flow diagrams and you can take a pad with you down the pub without feeling like a total tit...

I prefer real manuals as well, so perhaps I'm just a bit of a fossil.

Danny (nods)

11-06-2006 18:54

Posted by:
Ledorax

Location:
Sweden

Click Here to Email Ledorax   Find more posts by Ledorax

Hurrah!

Wow, many replies.

All right, it works now! I'm not sure why but it seems the "whiles" didn't like me.
Anyway - though it works, the animation is really fast. Is there a good way to slow it down a little bit?

Thanks.

11-06-2006 19:38

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

You want 'Delay n'

Try Delay, followed by an amount of time in milliseconds (1000 is a second), just after the Draw Frame. You can fine tune it by experimenting with the number...

Danny (nods)

11-06-2006 22:06

Posted by:
Ledorax

Location:
Sweden

Click Here to Email Ledorax   Find more posts by Ledorax

Actually, I thought of that, but wouldn't it make other characters' animations look choppy and odd if they were moving at the same time?

11-06-2006 22:41

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

You could try adjusting your frame rate with the -set framerate- command

=)

11-06-2006 23:14

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

In fact don't use 'delay' i don't understand why danny told you to use it. If you use it, your game will run at different speeds on different computers. With set frame rate, you're sure the game will run at the same speed on any compouter at least as fast as yours.

But for a slowing down an animation, this is still not the wat to go, since your main character may have only 5 images, and still you don't want your game to go at 2 fps just to have your character animate properly.

there are several ways to go - one i'd suggest trying out, even though it's not the only one, is to make the 'frame' variable a float, and to increment it by 0.1 everyframe, or something like that. (i'm just not sure whether you'll need to convert it back to int before passing as parameter to 'sprite'.)

if you have more questions, don't hesitate to ask. And i slightly disapprove appleide throwing working code at you - make sure you understand evey bit of it, because you won't always be able to have somebody write the code for you.

You still don't seem to understand how while works, do you? if so, you should consider trying making test programs with only prints, as i suggested earlier. if you don't understand the basics, you'll hit the same problems every time you try adding something new to your game.

11-07-2006 09:02

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Yup, Delay was not good...

Sorry, Delay is not best (or even very good!).

To be honest I'd be tempted not to slow it at all... Wait till you put some more code in there and see if this self regulates the speed. Adjust things when it's all done.

Danny (nods)

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.