Jump to content
Sign in to follow this  
Retro Lord

Making A.I shoot back?

Recommended Posts

I'm a bit lost on this one. I'm trying to figure out how to make the a.i fire at the player depending on if the player is left or right to the a.i

 

I basically tried something like this, but that don't work at all:

 if d=0 then missile1x=player1x : missile1y=player1y
 if d=1 then missile1x=missile1x+1
 if d=2 then missile1x=missile1x-1

 if player0x<player1x then d=2
 if player0x<player1x then d=1
 if missile1x<10 then d=0
 if missile1x>135 then d=0

Share this post


Link to post
Share on other sites

Would this help?

 dim fire = a
 c{1}=0
 c{2}=0
 player1x = 50 : player1y = 50
 player0x = 70 : player0y = 50
 e=60
 fire = 0
loop
   COLUBK = $00 : COLUP1= $5A : COLUP0= $0A
 if joy0up then player0y = player0y - 1
 if joy0down then player0y = player0y + 1
 if joy0left then player0x = player0x - 1              
 if joy0right then player0x = player0x + 1
 if player0x > player1x then fire = 1 : c=%00000010
 if  player0x < player1x then fire = 1 : c=%00000001
 if fire = 1 && c{0} then missile1x = player1x - e : missile1y = player1y - 1
 if fire = 1 && c{1} then missile1x = player1x + 1 + e : missile1y = player1y - 1
 if e>60 then e=0 : fire = 0 : missile1x = 0 : missile1y = 0
 e=e+1
 player1:
 %00000000
 %00000000
 %00000000
 %00111100
 %01111110
 %00000000
 %01111110
 %00011000
end
 player0:
 %11100000
end
 drawscreen
 goto loop 

spaceship code.bas.bin

Edited by ultima

Share this post


Link to post
Share on other sites

You forgot to change the caparison for setting d=1. You should also add a check for d=0 before setting d to 1 or 2. Otherwise the missle will change directions mid flight.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...