Hi. I trying to get my code to work but having problems and got stuck on it. In my code i got a tank which is the AI were it start from the outside of the screen and move to the opposite of the screen.
For example if tanks start on top of screen, the tank will move towards the bottom.
here the function part of the code i got so far:
function alottank()
rem heres were the random take place
flag = 0
// get a random value between 1 and 4
moving_tanks = Random(1,4)
if Random(1,4) and flag = 0
flag = 1
select moving_tanks
case 1:
// moveleft : move the tank from left to right screen
// update moves tank from left to right of the screen
for tnk= 1 to 35
SetSpriteX ( tnk, GetSpriteX ( tnk) + speed# [ tnk] )
// when sprite hit right screen reset it
if ( GetSpriteX ( tnk) > 1200)
SetSpritePosition ( tnk,- 25, Random ( 0, 700 ) )
SetSpriteAngle( tnk, 270)
SetSpriteDepth(tnk,15)
speed# [ tnk] = Random ( 1, 30 ) / 10.0
endif
next tnk
endcase
case 2:
// moveright move the tank from right to left screen
for tnk= 1 to 35
SetSpriteX ( tnk, GetSpriteX ( tnk) - speed# [ tnk] )
// when sprite hit left screen reset it
if ( GetSpriteX ( tnk) < 10)
SetSpritePosition ( tnk, Random ( 1200, 1250 ), Random ( 5, 700 ) )
SetSpriteAngle( tnk, 90)
SetSpriteDepth(tnk,15)
speed# [ tnk] = Random ( 1, 30 ) / 10.0
endif
next tnk
endcase
case 3:
//moveup: // move the tank from bottom to up screen
for tnk= 1 to 35
SetSpriteY ( tnk, GetSpriteY ( tnk) - speed# [ tnk] )
// when sprite hit bottom screen reset it
if ( GetSpriteY ( tnk) < 15)
SetSpritePosition ( tnk, Random ( 0, 1100 ), Random ( 650, 700 ) )
SetSpriteAngle( tnk, 180)
SetSpriteDepth(tnk,15)
speed# [ tnk] = Random ( 1, 30 ) / 10.0
endif
next tnk
endcase
case 4:
// movedown: // move the tank from up to buttom screen
for tnk= 1 to 35
SetSpriteY ( tnk, GetSpriteY ( tnk) + speed# [ tnk] )
// when sprite has top the screen reset it
if ( GetSpriteY ( tnk) > 700)
SetSpritePosition ( tnk, Random ( 0, 1000 ), Random ( 0, 700 ) )
SetSpriteAngle( tnk, 0)
SetSpriteDepth(tnk,15)
speed# [ tnk] = Random ( 1, 30 ) / 10.0
endif
next tnk
endcase
endselect
endif
endfunction
okay i tried using the timer command, the sleep command but nothing works.
would
CASE/SELECT command will work is the
IF/THEN/ELSE better use.
i was trying to use
SLEEP() to put on top of the case statement but is just slow the fps.
i then put the command inside the case statement at the end but there was no differences.
for example
select moving_tanks
case 1:
// moveleft : move the tank from left to right screen
// update moves tank from left to right of the screen
for tnk= 1 to 35
SetSpriteX ( tnk, GetSpriteX ( tnk) + speed# [ tnk] )
// when sprite hit right screen reset it
if ( GetSpriteX ( tnk) > 1200)
SetSpritePosition ( tnk,- 25, Random ( 0, 700 ) )
SetSpriteAngle( tnk, 270)
SetSpriteDepth(tnk,15)
speed# [ tnk] = Random ( 1, 30 ) / 10.0
endif
next tnk
sleep(20)
endcase
now i got some ideas how it should work but can't get it in to code right.
my logic is that there should be some kind of
timer use but don't know were to put it and what kind of timer to use.
i also don't understand what is the
flag is use for.
any help of getting the code work and explanation what i am doing wrong would help me understand coding with AGK.
thank you.