forums

TNT Basic Forums > Beyond Basic
Hello
< Last Thread     Next Thread >
Author
Thread        Post A Reply

10-21-2005 01:44

Posted by:
Schroder

Location:
NC ,USA

Click Here to Email Schroder   Find more posts by Schroder

Hello!, i will just jump out there and say that im brand new at design and programming. I am having some trouble getting started, i have done the tron and the pong demo set up but i am still having trouble starting my own project. i dont know where to start! i have some ideas but i dont know where to start codeing and what to code. i have read the basic manuel as well but as i said i am brand new at this and its alittle complex. so any insight or pointers on how to get going would be great thanks.

Schroder

10-21-2005 08:21

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Ah, I'm in my element...

Hi Schroder, you've come to the right place. Starting a new project can be one of the hardest things you will ever do, not because it's overly complicated, but because it's just very daunting. What do you type first?

A full answer to your post would require more than a simple reply, you could devote an entire web site to this sort of topic and still not cover everything, so I will be necessarily brief. Here are a few pointers that should help you out:

1) Start here!. This is not a true introductio to programming, but it's a good start with TNT.

2) Don't write a game! Never start out to write a game, that is complicated enough. Write little 'code snippets'. Try getting a picture to display on screen until you press a button. Try moving a sprite around the screen the cursor keys. These sorts of things will only take a few lines of code, so are easy to debug (find out what is going wrong, if anything) and are a good starting block.

3) Break things down. Use a top down approach to the problem. Using my first 'try it' as an example, look at the things the snippet should do. Display an image will need an image to display, you will need to show it then display it until a button is pressed. Take these tasks individually and refer to the manual as to how to do them. If you keep breaking things down you should eventually end up finding a TNT function or command which does it for you.

4) Look on the net. Don't look for TNT, you're already here, try reading up on 'pseudocode', a language inspecific way of breaking up programming tasks into component parts. Back to my example again, we get something like:

Set up display
repeat
draw picture
until button pressed

This may not look like anything, but it's actually pseudocode that is very easy to convert to 'real' code.

Try these and get bac kif you need anything else...

Danny (nods)

10-21-2005 15:47

Posted by:
Schroder

Location:
NC ,USA

Click Here to Email Schroder   Find more posts by Schroder

thanks for your help but heres what im working with. im tring to get my little red ball i have created to be able to be controlable. i can load an image and make it move across the screen but i cant control it. i have tried using the trong controls system as a basic outline as to what i need to do however it doesnt seem to work. any insight on what i might be doing wrong or any sugetions would be great.

thanks again ,Schroder

10-21-2005 16:41

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

No probs, we can help there too. Take a look at this post and see if it covers what you are looking for. There is another one here that's also worth a look. If neither of this cut the mustard, get back to us with a more detailed description of how you actually want to control your ball (do you need physics for example?) and I'll see what I can do.

Danny (nods)

10-21-2005 19:13

Posted by:
Schroder

Location:
NC ,USA

Click Here to Email Schroder   Find more posts by Schroder

great thanks that worked perfect. i now have my image able to go around the screen. i am now working on getting two of them together on screen and working on my colisions. i wil mess around with it but i might need some help later. but thanks again for your help before i am now just starting to understand code
Schroder

10-22-2005 16:13

Posted by:
Schroder

Location:
NC ,USA

Click Here to Email Schroder   Find more posts by Schroder

ok here is what i am working on. what i would like to do is have two images on screen and the object is to push the other image off. (wrestling) ok here is what i have so far:
Hide Mouse

Graphics Mode 640, 480
set pen color white
fill oval 0,0 to 640,480
Load Images 128
Sprite 0,0,0
Draw Frame

int x=0
int y=0

repeat
if right then x=x+1
if left then x=x-1
if down then y=y+1
if up then y=y-1
Sprite 0,x,y,0
Draw Frame
forever

ok so i tried to mess with the code and make it to where you have 2 but i couldnt get it to work. so any help would be apricieated
THANKS!
Schroder

10-22-2005 18:40

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Cool idea...

OK Schroder, let's take it a bit at a time:

Two sprites? Doddle, just add two more variables, say x1 and y1, to hold the position of the new image, add two more sprite calls (one after each of your sprite 0 calls) to draw the other image (sprite 1,x1,y1,1 for example), and extend your draw loop to check for four more keys, say 'w', 'a', 's' and 'z' for example (to control the other wrestler). I'll let you work out how to check for the other keys... ;)

Collisions? There are two schools of thought on this one, you can either check for the distance between the two sprites or do a 'sprite col()' check. The difference is small in speed terms, but sprite col is easier to handle. "if sprite col(0, 1) <>-1 'you have a collision!"

That's the easy bit! You now have two problems. You should have two sprites on screen which can move and collide. When they do though, nothing will happen. Why? Well you've checked to see if the two images overlap (a collision), but you've not told the code what to do if this happens. That's problem number one. You can't stop the sprites from moving any more if they collide because you actually want them to, you want them to push each other round. The 'pushing' sprite should move as normal, but the other should perform the same movement (almost like one set of keys moving both sprites). And here's problem two... Which is the 'pushing' sprite? This bit you're going to have to think about, it will probably involve some RPG style stats such strength, weight and momentum, and a calculation or two... Have fun!
For starters, I'd just add the other sprite and check for collisions, leave movement for the second image till you have an answer to problem two. When you get a collision, move the other sprite by the same amount as the first (hint: you'll need to store the amount of movement, and check for collisions after movement, otherwise they could get stuck together!).

Well, that's a fair bit to be going on with, so give this a go and get back if you get stuck.

Danny (nods)

10-23-2005 21:32

Posted by:
Schroder

Location:
NC ,USA

Click Here to Email Schroder   Find more posts by Schroder

ok dan as you said one step at a time...

ok i have my sprite able to move however for some reason i cant get the second sprie to show up on the screen, i dont know why either. so here is my code and see if you can figure why the second sprite isnt showing up

Hide Mouse

Graphics Mode 640, 480

set pen color white
fill rect 0,0 to 640,480
load images 128

Draw Frame

int x=0
int y=0

repeat
if right then x=x+1
if left then x=x-1
if down then y=y+1
if up then y=y-1
Sprite 0,x,y,0

Draw Frame

int x1=1
int y1=1

load images 129

if pressed (2) then x1=x+1
if pressed (0) then x1=x-1
if pressed (1) then y1=y+1
if pressed (13) then y1=y-1
sprite 1,x1,y1,1
draw frame
forever

i have tried and i dont know why its not coming up. i think its a small mistake in the code . as i said im fresh at this programming stuff. i like your idea also for the RPG element thing, that would be cool. it might be a good idea to switch from wrestling style to more of a tag. anyway.....

thanks for your help
Schroder

10-23-2005 22:22

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Mmmmm....

Well mate, that's a bit of a mess. You've got things going on all over the place there. A bit of advice from someone who's been doing this sort of thing for over twenty years now, there are three main parts to a program of this type (technically there are more in case someone wants to jump in and correct me, but three will do for now). There is 'Initialisation' (though you probably spell it with a 'Zee'!): here you declare the variables you are going to use, set the default values, load graphics and 'set the scene' so to speak. Then comes 'The Loop', here you check for and respond to input and redraw the screen. Finally you have 'Termination', this frees up space, saves data and generally bugs out. You are doing all sorts of things all through the code, but we can remedy this...

First, your second sprite is in bank 129? Move it to bank 128. You can have as many images in a bank as you want (as long as you don't want over 16,000 or so), number the first '0' and the second '1'.

OK, you're ready to enter this (a revised version of your code):

Hide Mouse 'Initialise...

Graphics Mode 640, 480

set pen color white
fill rect 0,0 to 640,480
load images 128

int x=340
int y=240
int x1=300
int y1=240

repeat 'Loop...

if right then x=x+1
if left then x=x-1
if down then y=y+1
if up then y=y-1

if pressed (2) then x1=x1+1
if pressed (0) then x1=x1-1
if pressed (1) then y1=y1+1
if pressed (13) then y1=y1-1

Sprite 0,x,y,0
sprite 1,x1,y1,1

draw frame

forever 'Terminate (sort of...)


All I've done here is tidy up the code a bit, changed the second key check block to alter the correct variables (you were changing x1 but basing it on x) and removed a bit of unnecessary stuff in the middle. I've labelled the sections to add clarity. This should work fine now (though I've not tested it).

OK Schroder, any thing else just drop me a line...

Danny (nods)

10-24-2005 23:35

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Hi, there are a few things i want to say.

first, i noticed you load the image bank in the loop. Just think about it. The loop is repeated continuously - so you're reloading everyframe. Think about the games you've played - they load everything in the beginning, then it's done (imagine if large games reloaded everything each frame! it's useles, because once images are loaded once they're in the memory until you unload).

secondly, you called "Draw frame" twice. Please note that it is "Draw FRAME" and not "Draw SPRITE". You need to call it only once when everything has been drawn and the image is ready to be displayed, not after each drawing drawing opeartion (unless you want the objects to appear one after the other, but this is not what you want to get i believe)

thirdly, you init you variables during the loop (int i=1) which means that everyframe "i" is set back to value 1. Unless you want your sprite to stick forever at position 1, you should not do that.

I think what you must understand is that the repeat loop repeats all over, and everything you put inside will be executed every frame.

Good luck!

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.