The "useful" one is for bouncing around. I've thought of a compact way of implementing it. First, you have an array of the 8 velocities, including some wraparound:
Code: Select all
dimv(15):fort=0to7:readv(t):v(t+8)=v(t):next:data1,23,22,21,-1,-23,-22,-21
The bouncing enemy only uses the odd (diagonal) directions.
1) Check for a collision straight ahead
2) If blocked, rotate clockwise 90 degrees (i.e. turn right)
3) If still blocked, rotate another 180 degrees (i.e. turn left)
4) If still blocked, rotate counterclockwise 90 degrees (i.e. turn around)
Code: Select all
10 ifpeek(x+v(d))=wthend=d+2-4*(peek(x+v(d+2))=w):d=7and(v+2*(peek(x+v(d))=w))
Code: Select all
1 poke56,28:clr:poke648,28:?"{clr}":poke648,30:?"{clr}{wht}"
2 fort=0to21:poke37888+t*23,2:poke37909+t*21,2:next
Code: Select all
d(i)=6and(d(i)+peek(x(i)+30208))
Hopefully someone will find this AI tricks useful for some BASIC games. The "bouncing" AI could be useful for Breakout/Arkanoid type games. The "racing" AI, though...well maybe it could be useful for some sort of racing game, or "Dodge 'Em" type game?