forums

TNT Basic Forums > Programming Q&A
A few questions
< Last Thread     Next Thread >
Author
Thread        Post A Reply

08-02-2006 23:23

Posted by:
Redd

Location:
uh... *blink*

Click Here to Email Redd   Find more posts by Redd

I've been looking at TNT for a while, and am trying to make some stuff with it (go figure XD). However, I fail to solve these few problems:

1) I'm using Window Mode. Is there a way I can use the fade command on the window and NOT the whole screen?

2) I need the mouse to be used in different screens/locations, and am using sprites as the buttons. How am I to code that? Do I use an IF... THEN or is there some other way this could work out?

3) Sprites. Moving them with arrows. How do I code that? (I've looked at some tutorials but haven't got a clue of how it really works =p)

4) Using tiles. What is the simplest way to block a character from moving on a certain tile, and how do I move the whole map? (Same tutorial thing. Can't figure out on my own)

I can't think of any more questions at the moment (maybe because it's 1am?), so these will do for now.

Thanks for any eventual answers!
XD

08-03-2006 00:37

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Answers!

1) No. You would have to use a sprite or fill rect and set pen transparency.

2) Just use a while loop. Example:

while
for i=0 to numberOfButtons-1
if mouse x>buttonX and mouse x<buttonX+image width(buttonI) and mouse y>buttonY and mouse y<buttonY+image height(buttonI) and mouse button
clicked=i
end if
sprite i, buttonX, buttonY, buttonI
next
if click=1 then playGame()
draw frame
wend


3) Just use a while loop and make two ints, x and y.
Then, inside the while loop make your sprite (sprite 0, x, y, 0).
Finally, make it so when you press up y=y-speedOfSprite, and do this with down, left, and right.
And don't forget draw frame!

4) Go here:http://tntbasicfiles.sitesled.com/TNTBasicExamples.html and download Exact Tile Collisions, just to try it. I've also made box collision source too, sometimes exact don't work.
I will explain how it works if you'd like.

Hope this help you get a better starting with TNT Basic,
Jacob

08-03-2006 07:44

Posted by:
Stu

Location:
USA

Click Here to Email Stu   Find more posts by Stu

For your buttons, why not use TNT's built-in button functions? I used to use sprites for buttons, but then I found the button functions and they made life easier for me. I suppose it depends on what you're doing, but I think that buttons should be easier in general than sprites.
Here's some example code for moving a sprite.

int x, y
while true
if up = true
y = y - 5
else if down = true
y = y + 5
else if right = true
x = x + 5
end if
'And so on for all your needs, now you just need to load your sprite,
sprite 0, x, y, 0
'And finally, draw it
Draw Frame
wend



08-05-2006 18:27

Posted by:
Redd

Location:
uh... *blink*

Click Here to Email Redd   Find more posts by Redd

Even MORE doubts!!!!!!1!1!!!!111ONE

Right. I'll try those when the time comes.

Thanks Stu, I didn't see the buttons stuff at first, they help save quite some coding.

Next questions:

- How do I call up the same lines of code in different areas (like saving)?

- This is an RPG I'm making, so I need an inventory (oh... my... god...), and I think I'll be using arrays for it, but I haven't quite managed to understand how to work it out... can someone explain this?

- Are stats supposed to be saved as global integers?

- How do I save files?

Thanks again for any help.

08-05-2006 20:15

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Hi Redd! From what you're telling i think you're trying to make a really big game at your first try... please give yourself some time to learn =)


- How do I call up the same lines of code in different areas (like saving)?

using procedures... declare a procedure save:

procedure save()
' ... saving code here...
end proc

and whenever you need to save just call 'save()'. You SHOULD use procedures for more than saving. Separing your code into parts helps a lot keeping it clean and understandable


- This is an RPG I'm making, so I need an inventory (oh... my... god...), and I think I'll be using arrays for it, but I haven't quite managed to understand how to work it out... can someone explain this?

It depends on how you want to make it. If there are certain kinds of objects, and you can only have one object of each kind, maybe keep an array that holds which objects you have and which you don't. However, if you can, for instance, have multiple similar swords but each of them does not do the same damage because one is in better shape than the other, etc. i wouldn't even dare to try doing this in TNT. Maybe someone else will be able to point a good way of doing this, but personnaly i wouldn,t do it without objects and vectors... maybe keep it for later, or wait until someone else finds a better way (if any)

- Are stats supposed to be saved as global integers?

save them however you want :)

- How do I save files?

' read from a file
int ID=open file ("my file",true,"CREA")
string contents=file read string (ID)
file close ID

' write to a file
ID=create file ("my file","CREA")
file write ID,"blah blah blah"
file close ID

i have not run the code so it may not be perfect... it's just to give an idea... consolt the documentation that comes with TNT it's very handy =) if you need more help just tel me and i'll post real examples i tested

good luck :D

08-05-2006 23:32

Posted by:
Redd

Location:
uh... *blink*

Click Here to Email Redd   Find more posts by Redd

Believe it or not, this isn't my first time with TNT. I'm just a little too rusty, that's all. Making big games is how I practise.

No, I won't use weapons for inventory. There's another plan for that (everyone has his own).

Thanks for the saving code, I couldn't understand how it worked at first.

And procedures... knew it... Still, I really wanted someone to confirm it for me, so thanks for that. XD

For the inventory thing, I was thinking of having something like this:

invitem$ = name of item group
invitem = number of items in group
invitemtype = type of item (for healing, blah, blah)

---

If anyone has any additions to make, please do so ^^

Thanks.

08-05-2006 23:54

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

good! for the inventory thing, you might need to manually resize arrays (?) it's not hard but very annoying ;)

08-05-2006 23:55

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

anyway you'll see how it goes! ;) you understand your project better than i do

08-10-2006 11:09

Posted by:
Redd

Location:
uh... *blink*

Click Here to Email Redd   Find more posts by Redd

Files and Tiles

Thanks for the help so far, it's been great!

At this stage I'm at my last few questions, so here goes:

1 - Can someone please tell me how I can save stats?

2 - And how do I load them again?

3 - Let's say I have a sqaured area with grass and trees. What is the code used to block the player from walking over the trees? (I haven't understood the examples)

4 - So there will be different rooms in a location. What is the code which makes the player start at X, Y after being in room 1, and X2, Y2 after being in room 2?

I had another question, but forgot what it's all about. These should do, though.

08-10-2006 14:41

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

about saving and loading stats from/to a file, this code snippet shows everything (i've tested this one =) You can just paste in into TNT and run it, it creates fake stats, saves them to a file, then loads them again



global int fileID

global int energy, experience, level, magic


makeStats()
print "------- initial stats ----------"
printStats()

saveStats()

resetStats()
print "------- reseted stats ----------"
printStats()

loadStats()
print "------- stats loaded from file ----------"
printStats()

print "----------- over -----------"


procedure makeStats()
energy=5
experience=15
level=3
magic=25
end proc

procedure resetStats()
energy=0
experience=0
level=0
magic=0
end proc

procedure printStats()
print "energy: "
print energy
print "experience: "
print experience
print "level: "
print level
print "magic: "
print magic
end proc

procedure saveStats()

fileID=create file ("stats","GAME")
file write fileID,as string(energy)
file write fileID,as string(experience)
file write fileID,as string(level)
file write fileID,as string(magic)
close file fileID

end proc



procedure loadStats()

fileID=open file ("stats",true,"GAME")
string energyString=file read string (fileID)
string xpString=file read string (fileID)
string lvlString=file read string (fileID)
string magicString=file read string (fileID)
close file fileID

energy=as number(energyString)
experience=as number(xpString)
level=as number(lvlString)
magic=as number(magicString)

end proc



about your other questions... are you using maps? if so, you must check what tile the character is on with 'map tile (x/map tile width, y/map tile width, 0)' or something similar (read the docs about it =) and come back if you still don't understand)

if you're not using maps... well i really recommand you don't do that =D if you really want it this way i could explain a few techniques

08-10-2006 14:45

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

oh yeah... files saved like that end in /your user name/library/preferences

08-10-2006 15:48

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

TNT needs more tutorials i think =) i'd like to make some, but i'd like Mark to give a sign he's alive before i start working ;)

08-11-2006 04:06

Posted by:
Stu

Location:
USA

Click Here to Email Stu   Find more posts by Stu

About your collision with trees question, if you aren't using maps, it's still easy to do so long as you only deal with rectangles and squares. Here's some example source code, it's compressed in a zip, but I seem to recall that you might not be able to open it? Oh, well, here it is anyway. If you can't open it, I'll just post the source. If you can't understand it, I can explain the code.
Download

As for your question about rooms, you could store your entry points as integers, and keep a global int like "LastRoom" for example, in which you would store an integer value for the previous room. Then, if your sprite x and y variables are named px and py, and your two entry points by X,Y and X2, Y2:

if LastRoom = 1
px = X
py = Y
else if LastRoom = 2
px = X2
py = Y2
end if

08-11-2006 08:43

Posted by:
Redd

Location:
uh... *blink*

Click Here to Email Redd   Find more posts by Redd

Thanks for the snippet, someone!

about this part:
print "energy: "
print energy
print "experience: "
print experience
print "level: "
print level
print "magic: "
print magic


I'm not sure if it works correctly this way, but in other programming languages it saved lines in text fields:
print "energy: ";
print energy
print "experience: ";
print experience
print "level: ";
print level
print "magic: ";
print magic


The ; should have the next print write on the same line as the previous one.

---

I'm using maps, yes. I'm hoping this will prevent unwanted problems from arising.

I'll take a look at the example, Stu. Classic Macs don't handle archived bundles so well (since they're actually files >_>), so that's why I wouldn't be able to read it.

Well, if I can't, I'll just have to wait a day or two. XD

Thanks, everybody!

08-11-2006 15:17

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

about this:

print "energy: ";
print energy
print "experience: ";
print experience
print "level: ";
print level
print "magic: ";
print magic

rather try this:

int energy=12345
print "energy: "+as string(energy)

and if you're using maps, you probably don't need Stu's example.

to check collision with map, you must use, as i saifd, the 'map tile (x,y,z)' command. This way, you can get which tile can be found at each area on the map (x and y are in Tiles, not in Pixels) the method i recommend is:

if you need to move the character 10 pixels to the left, check what tile is located 10 pixels to thge left of the player. If this tile is a tile the character can walk on, then move it.

08-11-2006 22:11

Posted by:
Stu

Location:
USA

Click Here to Email Stu   Find more posts by Stu

quote:
I'm using maps, yes. I'm hoping this will prevent unwanted problems from arising.

I'll take a look at the example, Stu. Classic Macs don't handle archived bundles so well (since they're actually files >_>), so that's why I wouldn't be able to read it.


Well, since you are using maps, my example won't be very helpful anyway. It deals with limiting sprite movement within a square named by coordinate points, not maps.

08-13-2006 23:26

Posted by:
Redd

Location:
uh... *blink*

Click Here to Email Redd   Find more posts by Redd

Thanks for everything, guys!

Just one short message which I'm posting on any board with potential:

I'm building up a community for this game. If anyone can please help with anything (major or minor, I don't care), then follow this link and sign up.

Right now I'm the only one doing all the programming, so I'd appreciate it if anyone could help out.

Thanks =]

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.