forums

TNT Basic Forums > Programming Q&A
Need help with procedure
< Last Thread     Next Thread >
Author
Thread        Post A Reply

11-29-2005 17:53

Posted by:
Gustav

Location:
Lund, Sweden

Click Here to Email Gustav   Find more posts by Gustav

Umm, i kind of started programming 3 days ago ( no experience at all, im 14)
and I am making a game where you are a guy who is walking around on a black screen watching out for Cro-Mag rally savegame icons with randomized movement.
I want to create a new enemy sprite every second (random place on screen).
heh.

AND not to forget, im new to this so my code looks like hell.

hide mouse
graphics mode 1024,768
global int moving=true
global int x=0,y=0,a=-1,tx=1024,ex=random(0,1024),ey=random(0,768) ' x=player's x, y=player's y, tx=scrolling text x, ex and ey =enemy x and y
float walkingspeed=1
load images 128
draw frame

repeat
ex=ex+random(-10,10)
ey=ey+random(-10,10)
a=sprite col(1,2 to 100)
if a <> -1 then moving=false
if moving=false then GameOver()

if moving
if up then y=y-walkingspeed
if down then y=y+walkingspeed
if left then x=x-walkingspeed
if right then x=x+walkingspeed

end if
sprite 1,x,y,0
sprite 2,ex,ey,4
CreateEnemy()
draw frame
until mouse button

procedure GameOver() 'this is ok, ignore this
set pen colour red
Fill rect 0,0 to 1024,300
fill rect 0,500 to 1024,768
sprite 3,tx,350,5
tx=tx-2
if tx < -300 then end
end proc

Procedure CreateEnemy() ' !!!!!!!!!!!!!!!!
int Count=3
if timer = timer + 1000
sprite Count,ex,ey,4
end if
Count=Count + 1
end proc


I know this code is bad, but hey, third day of programming in my life.
Please help me.

11-29-2005 19:45

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

hide mouse
graphics mode 1024,768
global int moving=true
global int x=0,y=0,a=-1,tx=1024,ex[1000],ey[1000] ' x=player's x, y=player's y, tx=scrolling text x, ex and ey =enemy x and y


ex and ey are now arrays.
You can have up to 1000 icons.

'Set up the positions that they will start at when they are created
int n
For n=0 to 999
ex[n]=random(0,1024)
ey[n]=random(0,768)
Next

float walkingspeed=1
load images 128
draw frame

repeat
a=sprite col(1,2 to 100)
if a <> -1 then moving=false
if moving=false then GameOver()

if moving
if up then y=y-walkingspeed
if down then y=y+walkingspeed
if left then x=x-walkingspeed
if right then x=x+walkingspeed

end if
sprite 1,x,y,0

'Update the icons
int n
For n=0 to count
if sprite exists(2+n)
ex[n]=ex[n]+ranom(-10,10)
ey[n]=ey[n]+random(-10,10)
sprite 2+n,ex[n],ey[n],4
End if

CreateEnemy()
draw frame
until mouse button

procedure GameOver() 'this is ok, ignore this
set pen colour red
Fill rect 0,0 to 1024,300
fill rect 0,500 to 1024,768
sprite 3,tx,350,5
tx=tx-2
if tx < -300 then end
end proc

Procedure CreateEnemy()
Count has to be a global integer
if timer = timer + 1000 'I don't know about this
'You might want to make timer a global integer.
'If so, put timer=timer+1 in the repeat statement, replace If timer = timer + 1000 with If timer = 100 and add a line right below here that resets the variable timer to zero: Timer=0

sprite Count,ex[count],ey[count],4
end if
Count=Count + 1
end proc

11-29-2005 19:48

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Oops!

Right after the end if for If sprite exists(n) add a Next

11-30-2005 15:34

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Nearly right...

I shouldn't think your icons ever get created do they? The reason is because you only create one when the current time is equal to the current time plus 1000, and this will never happen. Say timer=2000, your code will create an icon when 2000=2000+1000, which, to say the least, isn't very often ;)
If you add something like myTime=timer outside of your main loop then check it with if timer-myTime>999 and if it is, reset it with myTime=timer you should find it works OK...

Danny (nods)

11-30-2005 15:35

Posted by:
Gustav

Location:
Lund, Sweden

Click Here to Email Gustav   Find more posts by Gustav

But...

I thought timer was a command! In the help html file it says:
number = Timer
I think...

So thing is, I wanted the game to add an enemy exactly every second (controlled by timer, 1000 millisec).
Instead of making timer an Integer and adding 1 every frame, which would mean that a second on my computer would be
If timer>72
and on another users computer the game would be different.
In unity you can time something with Time.deltaTime

Oh i have no idea what im babbling about. Incoming headache!

11-30-2005 19:57

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Not quite.

Timer is not a command, it's a 'system variable' which gets updated every 1000th of a second. You can read from it, write to it or set it to something else, TNT will just go right on bumping it up...
By the way, for day three you are doing a grand job, keep up the good work!

Danny (nods)

12-13-2005 23:03

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

I think you got carried away there Dan, I'm pretty sure 'Timer' is read only.

Cheers,

Mark

12-14-2005 00:39

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

DOH!

Just tried it... timer is read only, Sorry!

My code still works though, as I don't actually change timer, I just imply that it can be done, I really should check these things first... (it's usually a system variable ;) )

(a very shy) 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.