Jump to content



1

Is there any way to crunch this code?


2 replies to this topic

#1 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 20,911 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Sep 24, 2008 2:14 PM

Below is a bit of code where a bad guy in a maze randomly looks left and right for an opening:

  rem  *  New bad guy direction x (left/right)
newbaddx
  temp5=rand : if temp5<128 then goto leftrightcheck
  goto rightleftcheck

leftrightcheck
  temp5=badplayfx-1 : if !pfread(temp5,badplayfy) then goto badguygoleft
  temp5=badplayfx+2 : if !pfread(temp5,badplayfy) then goto badguygoright
  goto movebaddone

rightleftcheck
  temp5=badplayfx+2 : if !pfread(temp5,badplayfy) then goto badguygoright
  temp5=badplayfx-1 : if !pfread(temp5,badplayfy) then goto badguygoleft
  goto movebaddone

So he won't always choose one direction first, I randomly have him look left first, then right if necessary or right first, then left if necessary. As you can see, there are redundant lines. Is there some big brain way of doing the same thing with less code? Anything I can think of to get rid of the redundant lines uses more code than what I already have there.

If you need to see it in action, here is a demo that contains the code:

http://www.atariage....s...t&p=1590593

#2 Crazyace OFFLINE  

Crazyace

    Stargunner

  • 1,012 posts
  • Location:London / HK / Tokyo / San Fransisco

Posted Wed Sep 24, 2008 2:26 PM

How about..

  rem  *  New bad guy direction x (left/right)
newbaddx
  temp5=rand : if temp5<128 then goto leftrightcheck
 
  temp5=badplayfx+2 : if !pfread(temp5,badplayfy) then goto badguygoright

leftrightcheck
  temp5=badplayfx-1 : if !pfread(temp5,badplayfy) then goto badguygoleft
  temp5=badplayfx+2 : if !pfread(temp5,badplayfy) then goto badguygoright
 
 goto movebaddone


#3 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 20,911 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Sep 24, 2008 2:59 PM

View PostCrazyace, on Wed Sep 24, 2008 4:26 PM, said:

How about..

  rem  *  New bad guy direction x (left/right)
newbaddx
  temp5=rand : if temp5<128 then goto leftrightcheck
 
  temp5=badplayfx+2 : if !pfread(temp5,badplayfy) then goto badguygoright

leftrightcheck
  temp5=badplayfx-1 : if !pfread(temp5,badplayfy) then goto badguygoleft
  temp5=badplayfx+2 : if !pfread(temp5,badplayfy) then goto badguygoright
 
 goto movebaddone
Thanks. That cuts it down some. I was trying to get rid of all redundant lines, so I didn't think of that. :thumbsup:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users