News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

beat'em up AI!

Started by ATLUS, August 14, 2008, 10:30:41 AM

Previous topic - Next topic

ATLUS

 :)
PlayBASIC Code: [Select]
; PROJECT : Project1
; AUTHOR : ATLUS
; CREATED : 10.08.2008
; EDITED : 10.08.2008
; ---------------------------------------------------------------------
setfps 60
xp=100
yp=100
xai=400
yai=400
do
cls rgb(0,0,0)
//creat player
circle xp,yp,20,1
//creat enemi
circlec xai,yai,20,1,rgb(100,100,100)
//print distance

print distance(xp,xai,yp,yai)
//move player
if upkey()=true then yp=yp-4
if downkey()=true then yp=yp+4
if rightkey()=true then xp=xp+4
if leftkey()=true then xp=xp-4
//move enemi
if yp<yai then yai=yai-1
if yp>yai then yai=yai+1
if xp<xai then xai=xai-1
if xp>xai then xai=xai+1
//distance for player stops
if distance(xp,xai,yp,yai)<50 and xp-xai>0 then xai=xai-1
if distance(xp,xai,yp,yai)<50 and xp-xai<0 then xai=xai+1
if distance(xp,xai,yp,yai)<50 and xp-xai=0 then xai=xai+1
//if player and enemi point
if distance(xp,xai,yp,yai)<50 and xp>xai then xai=xai-1
if distance(xp,xai,yp,yai)<50 and xp<xai then xai=xai+1
//vertical
if distance(xp,xai,yp,yai)<50 and yp>yai then xai=xai+1
if distance(xp,xai,yp,yai)<50 and yp<yai then xai=xai+1
sync
loop
//////distance for player
function distance(x1,x2,y1,y2)
a=x1-x2
b=y1-y2
c=sqrt(a*a+b*b)
endfunction c