It is currently Thu Jun 29, 2017 9:08 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Crazy Ant game (same game as Roy's LogoBlueArrow)
Unread postPosted: Tue Apr 25, 2017 5:35 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 867
Location: France
Hi all

I hope that Roy you will not be angry with me :oops: :? :(

I wanted to reproduce a very very light version of your game, but I did not manage to perfectly handle collisions ...
In my opinion GR_COLLISION () can not be used because it only supports rectangles. So I tried with my excellent little procedure (which can be found here) but I can not get any better ...
I think is maybe because of the use of GR.ROTATE than the true ant (or rather the small point that I put between its antennae) coordonates can't be used... !?
Attachment:
Crazy_Ant.zip [1.28 MiB]
Downloaded 16 times
(copy the "Crazy_Ant" directory under DATA/, and the --Crazy_Ant.bas under SOURCE/ )
Attachment:
Screenshot_2017-04-25-14-17-50.png
Screenshot_2017-04-25-14-17-50.png [ 628.19 KiB | Viewed 548 times ]

Attachment:
Screenshot_2017-04-25-14-18-05.png
Screenshot_2017-04-25-14-18-05.png [ 454.11 KiB | Viewed 548 times ]


Code:
REM Crazy Ant same game than Roy's LogoBlueArrow   @Cassiope34  0417

Fn.def c2c(ax,ay,ar,bx,by,br)   %  return if 2 circles have collided.
  Fn.rtn (((ar+br)*(ar+br))>((ax-bx)*(ax-bx)+(ay-by)*(ay-by)))
Fn.end

Fn.def p2c(px,py,cx,cy,cr)      %  return if a point is inside a circles.
  Fn.rtn (((px-cx)*(px-cx)+(py-cy)*(py-cy))<=cr*cr)
Fn.end

gr.open 255,0,0,0,0,0     % black landscape
gr.screen w,h
scx =1280
scy =800
sx =w/scx : sy =h/scy
gr.scale sx, sy

File.Root tmp$
IstandAlone =Is_In("rfo-basic",tmp$)    % to know if it's an APK for the way to exit
path$ ="Crazy_Ant/"
filename$ ="CrazyAnt.sav"

cibMax =10
DIM fond[3], cib[cibMax], cx[cibMax+3],cy[cibMax+3],cr[cibMax+3]

gr.bitmap.load fond[1], path$+"sable1.jpg"  % 1280x800
gr.bitmap.load fond[2], path$+"sable2.jpg"
gr.bitmap.load fond[3], path$+"sable3.jpg"
gr.bitmap.load rock1, path$+"caillou1.png"  % 81x88
gr.bitmap.load rock2, path$+"caillou2.png"  % 86x92
gr.bitmap.load rock3, path$+"rose_des_sables.png"  % 153x153
gr.bitmap.load ant1, path$+"fourmis_noire2.png"    % 151x225
gr.bitmap.scale rock1, rock1, 120,120  % resized
gr.bitmap.scale ant1,ant1,40,65        % resized

ncib =2

DO

  ncib    +=1-1*(ncib=cibMax)
  GOSUB initGame
  speedMax =10
  speed    =2
  turn     =270
  new      =0

  Do

      gr.touch touched, tx, ty
      if !background() then gr.render
      if touched
        tx/=sx : ty/=sy
        if ty>scy-200
          if tx<200         : trnl+=0.6 : turn-=trnl : if turn<0 then turn =360
          elseif tx>scx-200 : trnr+=0.6 : turn+=trnr : if turn>360 then turn =0
          endif
        endif
      endif
      if !touched & (trnl | trnr) then trnl =0 : trnr =0

      if speed<speedMax then speed+=0.05
      fx -= speed*cos(toradians(turn+90))
      fy -= speed*sin(toradians(turn+90))
      if fx>scx : fx =0 : elseif fx<0 : fx =scx : endif
      if fy>scy : fy =0 : elseif fy<0 : fy =scy : endif

      gr.modify ant, "angle", turn, "x", fx, "y", fy
      gr.modify ant0, "x", fx-20, "y", fy-32
      gr.modify pt, "x", fx, "y", fy-30

      gr.get.position pt,px,py
      for c=1 to ncib+3
        if p2c(int(fx),int(fy-30),cx[c],cy[c],cr[c]) then collide =1 : f_n.break
      next
      if collide then pause 1000 : collide =0

  Until new | quit
UNTIL quit
if IstandAlone then END "Bye...!"
EXIT

OnBackKey:
  Dialog.message win$,"       What do you want ?", ok, " Exit ", " Another ? ", " Cancel "
  new  =(ok=2) : quit =(ok=1)
back.resume

initGame:
gr.cls
gr.bitmap.draw nul, fond[int(rnd()*3)+1], 0,0
gr.set.stroke 2

gr.color 20, 0,0,0,1
gr.circle nul, 100, scy-100, 80
gr.circle nul, scx-100, scy-100, 80

gr.color 255,0,255,0,1
for p=1 to 3 : cx[p] =100+int(rnd()*900) : cy[p] =30+int(rnd()*700) : next
gr.bitmap.draw rck1, rock1, cx[1], cy[1] : cr[1] =60
gr.bitmap.draw rck2, rock2, cx[2], cy[2] : cr[2] =43
gr.bitmap.draw rck3, rock3, cx[3], cy[3] : cr[3] =76
for c=1 to ncib
  cx[3+c] =80+int(rnd()*1000) : cy[3+c] =40+int(rnd()*700) : cr[3+c] =14
  gr.circle cib[c], cx[3+c], cy[3+c], cr[3+c]
next

fx =scx-50 : fy =scy/2
gr.rotate.start 270, fx, fy, ant          %  the ant
gr.bitmap.draw ant0, ant1, fx-20, fy-32
gr.color 255, 0,0,0,1
gr.point pt, fx, fy       %  debug mandibules...
gr.rotate.end
return


Please Roy or somebody if you have some idea ;) :)

Cheers

Gilles

_________________
"It is better to mobilize intelligence for stupid things, rather than mobilizing stupidity for intelligent things."
Galaxy TAB S 8.4, 2560x1600, Marshmallow 6.0.1
Galaxy Note II, 1280x720, JB4.1.2
Galaxy A3, 1280x720, Android 6.0.1


Report this post
Top
 Profile  
 
 Post subject: Re: Crazy Ant game (same game as Roy's LogoBlueArrow)
Unread postPosted: Wed Apr 26, 2017 10:10 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 834
Hello Gilles!

Long time ago...hope you are fine!

Interesting problem!
One minor issue is, that the three bitmap-based obstacles have an offset to the circles you are testing for. This is because the cx,cy coordinates represent not the center of the bitmaps, but their upper-left corner.

The bigger issue is, that apparently GR.ROTATE doesn't perform a "real" rotation of an object, but only "virtual" one.

To make it visible, i made your "debug-point" visible by a red circle and added an additional blue circle outside the GR.ROTATE

The blue one is the "real" debug-circle and the red one your "virtual" one. You can proof this by let it run and look closely: when "blue" hits "green", then the detection works!

So you would have to rotate the blue circle "manually" according to the rotation of the ant via GR.ROTATE ...which certainly would be a bit clumsy...but doable. (...but iwould have to think about how to do exactly...)

best regards, brochi


Code:
REM Crazy Ant same game than Roy's LogoBlueArrow   @Cassiope34  0417

FN.DEF c2c(ax,ay,ar,bx,by,br)   %  return if 2 circles have collided.
FN.RTN (((ar+br)*(ar+br))>((ax-bx)*(ax-bx)+(ay-by)*(ay-by)))
FN.END

FN.DEF p2c(px,py,cx,cy,cr)      %  return if a point is inside a circles.
FN.RTN (((px-cx)*(px-cx)+(py-cy)*(py-cy))<=cr*cr)
FN.END

GR.OPEN 255,0,0,0,0,0     % black landscape
GR.SCREEN w,h
scx =1280
scy =800
sx =w/scx : sy =h/scy
GR.SCALE sx, sy

FILE.ROOT tmp$
IstandAlone =IS_IN("rfo-basic",tmp$)    % to know if it's an APK for the way to exit
path$ ="Crazy_Ant/"
filename$ ="CrazyAnt.sav"

cibMax =10
DIM fond[3], cib[cibMax], cx[cibMax+3],cy[cibMax+3],cr[cibMax+3]

GR.BITMAP.LOAD fond[1], path$+"sable1.jpg"  % 1280x800
GR.BITMAP.LOAD fond[2], path$+"sable2.jpg"
GR.BITMAP.LOAD fond[3], path$+"sable3.jpg"
GR.BITMAP.LOAD rock1, path$+"caillou1.png"  % 81x88
GR.BITMAP.LOAD rock2, path$+"caillou2.png"  % 86x92
GR.BITMAP.LOAD rock3, path$+"rose_des_sables.png"  % 153x153
GR.BITMAP.LOAD ant1, path$+"fourmis_noire2.png"    % 151x225
GR.BITMAP.SCALE rock1, rock1, 120,120  % resized
GR.BITMAP.SCALE ant1,ant1,40,64        % resized

ncib =2

DO

ncib    +=1-1*(ncib=cibMax)
GOSUB initGame
speedMax =10
speed    =1
turn     =270
new      =0


DO

  GR.TOUCH touched, tx, ty
  IF !BACKGROUND() THEN GR.RENDER
  IF touched
   tx/=sx : ty/=sy
   IF ty>scy-200
    IF tx<200         : trnl+=0.6 : turn-=trnl : IF turn<0 THEN turn =360
    ELSEIF tx>scx-200 : trnr+=0.6 : turn+=trnr : IF turn>360 THEN turn =0
    ENDIF
   ENDIF
  ENDIF
  IF !touched & (trnl | trnr) THEN trnl =0 : trnr =0

  IF speed<speedMax THEN speed+=0.05
  fx -= speed*COS(TORADIANS(turn+90))
  fy -= speed*SIN(TORADIANS(turn+90))
  IF fx>scx : fx =0 : ELSEIF fx<0 : fx =scx : ENDIF
  IF fy>scy : fy =0 : ELSEIF fy<0 : fy =scy : ENDIF

  GR.MODIFY ant, "angle", turn, "x", fx, "y", fy
  GR.MODIFY ant0, "x", fx-20, "y", fy-32
  GR.MODIFY pt, "x", fx, "y", fy-30
  GR.MODIFY pt2, "x", fx, "y", fy-30
  GR.GET.POSITION pt,px,py
  FOR c=1 TO ncib+3
   IF p2c(INT(fx),INT(fy-30),cx[c],cy[c],cr[c]) THEN collide =1 : F_N.BREAK
  NEXT
  IF collide THEN PAUSE 500 : collide =0

UNTIL new | quit
UNTIL quit
IF IstandAlone THEN END "Bye...!"
EXIT

ONBACKKEY:
DIALOG.MESSAGE win$,"       What do you want ?", ok, " Exit ", " Another ? ", " Cancel "
new  =(ok=2) : quit =(ok=1)
BACK.RESUME

initGame:
GR.CLS
GR.BITMAP.DRAW nul, fond[INT(RND()*3)+1], 0,0
GR.SET.STROKE 2

GR.COLOR 20, 0,0,0,1
GR.CIRCLE nul, 100, scy-100, 80
GR.CIRCLE nul, scx-100, scy-100, 80

GR.COLOR 255,0,255,0,1
FOR p=1 TO 3 : cx[p] =100+INT(RND()*900) : cy[p] =30+INT(RND()*700) : NEXT
GR.BITMAP.DRAW rck1, rock1, cx[1], cy[1] : cr[1] =60
GR.BITMAP.DRAW rck2, rock2, cx[2], cy[2] : cr[2] =43
GR.BITMAP.DRAW rck3, rock3, cx[3], cy[3] : cr[3] =76

! ======== additional circels to show offset ===================
for i=1 to 3
gr.circle nn, cx[i], cy[i] , cr[i]
next

FOR c=1 TO ncib
cx[3+c] =80+INT(RND()*1000) : cy[3+c] =40+INT(RND()*700) : cr[3+c] =14
GR.CIRCLE cib[c], cx[3+c], cy[3+c], cr[3+c]
NEXT

fx =scx-50 : fy =scy/2
GR.ROTATE.START 0, fx, fy, ant          %  the ant
GR.BITMAP.DRAW ant0, ant1, fx-20, fy-32
GR.COLOR 255, 0,0,0,1
gr.color 255,255,0,0,1
!GR.point  pt, fx, fy      %  debug mandibules...
GR.circle pt, fx, fy , 5     %  debug mandibules.
GR.ROTATE.END

!=== additional circle outside rotate ("true debug-mandibules" circle)
gr.color 255,0,0,250,1
GR.circle pt2, fx, fy , 3     %  debug mandibules.

RETURN



Report this post
Top
 Profile  
 
 Post subject: Re: Crazy Ant game (same game as Roy's LogoBlueArrow)
Unread postPosted: Wed Apr 26, 2017 10:28 am 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 834
...here a "quick&dirty" test.

yellow circle gets rotated via GR.ROTATE
-> it seems to move over the screen, but in fact it stands still
--> compare x1,y1 -> always constant

red circle gets rotated "manually"
-> it does have the same path as yellow, but really changes it's pos.
--> compare x2,y2 -> continously changing


Code:
GR.OPEN         0,0,0,0,0,-1
GR.COLOR        255,255,255,0

GR.SCREEN       wi, he
cx            = wi/2
cy            = he/2

rr            = 100
GR.COLOR        255,55,55,250
GR.CIRCLE       center , cx, cy,3

GR.ROTATE.START 0, cx, cy, rot1
GR.COLOR        255,255,255,0
GR.CIRCLE       c1, cx,cy-rr,10
GR.ROTATE.END

GR.COLOR        255,250,25,0
px=cx:py=cy-rr
GR.CIRCLE       c2, px,py,7

GR.RENDER
PAUSE           100

dphi          = 2
dtdes         = 30


DO

phi         += dphi

GR.MODIFY      rot1,"angle", phi

phii =  toradians(phi)
xt =  rr * SIN ( phii )
yt = -rr * COS ( phii )
GR.MODIFY      c2, "x", xt+cx, "y", yt+cy


GR.GET.POSITION c1,x1,y1
GR.GET.POSITION c2,x2,y2
PRINT x1,y1,x2,y2

GR.RENDER

PAUSE          MAX(dtdes-CLOCK()+tic,1)
tic          = CLOCK()
UNTIL0


Report this post
Top
 Profile  
 
 Post subject: Re: Crazy Ant game (same game as Roy's LogoBlueArrow)
Unread postPosted: Wed Apr 26, 2017 12:15 pm 
Offline

Joined: Sat Dec 22, 2012 2:32 pm
Posts: 834
...finally less difficult than ecpected (see below)

remarks:
- why i need "turn+180" at one place i don't know yet, 180 was just found by looking/trying

- of corse the small circles pt and pt2 are not really needed, just for visualisation

- the only needed step is to introduce the variables xr/yr

...i hope i understood well and this is what you were looking for!?


best regards, brochi


Code:
REM Crazy Ant same game than Roy's LogoBlueArrow   @Cassiope34  0417

FN.DEF c2c(ax,ay,ar,bx,by,br)   %  return if 2 circles have collided.
FN.RTN (((ar+br)*(ar+br))>((ax-bx)*(ax-bx)+(ay-by)*(ay-by)))
FN.END

FN.DEF p2c(px,py,cx,cy,cr)      %  return if a point is inside a circles.
FN.RTN (((px-cx)*(px-cx)+(py-cy)*(py-cy))<=cr*cr)
FN.END

GR.OPEN 255,0,0,0,0,0     % black landscape
GR.SCREEN w,h
scx =1280
scy =800
sx =w/scx : sy =h/scy
GR.SCALE sx, sy

FILE.ROOT tmp$
IstandAlone =IS_IN("rfo-basic",tmp$)    % to know if it's an APK for the way to exit
path$ ="Crazy_Ant/"
filename$ ="CrazyAnt.sav"

cibMax =10
DIM fond[3], cib[cibMax], cx[cibMax+3],cy[cibMax+3],cr[cibMax+3]

GR.BITMAP.LOAD fond[1], path$+"sable1.jpg"  % 1280x800
GR.BITMAP.LOAD fond[2], path$+"sable2.jpg"
GR.BITMAP.LOAD fond[3], path$+"sable3.jpg"
GR.BITMAP.LOAD rock1, path$+"caillou1.png"  % 81x88
GR.BITMAP.LOAD rock2, path$+"caillou2.png"  % 86x92
GR.BITMAP.LOAD rock3, path$+"rose_des_sables.png"  % 153x153
GR.BITMAP.LOAD ant1, path$+"fourmis_noire2.png"    % 151x225
GR.BITMAP.SCALE rock1, rock1, 120,120  % resized
GR.BITMAP.SCALE ant1,ant1,40,64        % resized

ncib =2

DO

ncib    +=1-1*(ncib=cibMax)
GOSUB initGame
speedMax =10
speed    =1
turn     =270
new      =0


DO

  GR.TOUCH touched, tx, ty
  IF !BACKGROUND() THEN GR.RENDER
  IF touched
   tx/=sx : ty/=sy
   IF ty>scy-200
    IF tx<200         : trnl+=0.6 : turn-=trnl : IF turn<0 THEN turn =360
    ELSEIF tx>scx-200 : trnr+=0.6 : turn+=trnr : IF turn>360 THEN turn =0
    ENDIF
   ENDIF
  ENDIF
  IF !touched & (trnl | trnr) THEN trnl =0 : trnr =0

  IF speed<speedMax THEN speed+=0.05
  fx -= speed*COS(TORADIANS(turn+90))
  fy -= speed*SIN(TORADIANS(turn+90))
  IF fx>scx : fx =0 : ELSEIF fx<0 : fx =scx : ENDIF
  IF fy>scy : fy =0 : ELSEIF fy<0 : fy =scy : ENDIF

  GR.MODIFY ant, "angle", turn, "x", fx, "y", fy
  GR.MODIFY ant0, "x", fx-20, "y", fy-32
  GR.MODIFY pt, "x", fx, "y", fy-rr

  phi = -TORADIANS(turn+180)
  xr = rr * SIN( phi )
  yr = rr * cos( phi)
  GR.MODIFY pt2, "x", fx+xr, "y", fy+yr
 
  FOR c=1 TO ncib+3
   IF p2c(INT(fx+xr),INT(fy+yr),cx[c],cy[c],cr[c]) THEN collide =1 : F_N.BREAK
  NEXT
  IF collide THEN PAUSE 500 : collide =0

UNTIL new | quit
UNTIL quit
IF IstandAlone THEN END "Bye...!"
EXIT

ONBACKKEY:
DIALOG.MESSAGE win$,"       What do you want ?", ok, " Exit ", " Another ? ", " Cancel "
new  =(ok=2) : quit =(ok=1)
BACK.RESUME

initGame:
GR.CLS
GR.BITMAP.DRAW nul, fond[INT(RND()*3)+1], 0,0
GR.SET.STROKE 2

GR.COLOR 20, 0,0,0,1
GR.CIRCLE nul, 100, scy-100, 80
GR.CIRCLE nul, scx-100, scy-100, 80

GR.COLOR 255,0,255,0,1
FOR p=1 TO 3 : cx[p] =100+INT(RND()*900) : cy[p] =30+INT(RND()*700) : NEXT

cr[1] =60
cr[2] =43
cr[3] =76

GR.BITMAP.DRAW rck1, rock1, cx[1] -cr[1] , cy[1] -cr[1]
GR.BITMAP.DRAW rck2, rock2, cx[2] -cr[2] , cy[2] -cr[2]
GR.BITMAP.DRAW rck3, rock3, cx[3] -cr[3] , cy[3] -cr[3]

! ======== additional circels to show offset ===================
gr.color 255,0,255,0,0
FOR i=1 TO 3
GR.CIRCLE nn, cx[i], cy[i] , cr[i]
NEXT

gr.color 255,0,255,0,1
FOR c=1 TO ncib
cx[3+c] =80+INT(RND()*1000) : cy[3+c] =40+INT(RND()*700) : cr[3+c] =14
GR.CIRCLE cib[c], cx[3+c], cy[3+c], cr[3+c]
NEXT

fx =scx-50 : fy =scy/2 : rr=32
GR.ROTATE.START 0, fx, fy, ant          %  the ant
GR.BITMAP.DRAW ant0, ant1, fx-20, fy-rr
GR.COLOR 255, 0,0,0,1
GR.COLOR 255,255,0,0,1
!GR.point  pt, fx, fy-rr      %  debug mandibules...
GR.CIRCLE pt, fx, fy-rr , 5     %  debug mandibules.
GR.ROTATE.END

!=== additional circle outside rotate ("true debug-mandibules" circle)
GR.COLOR 255,0,0,250,1
GR.CIRCLE pt2, fx, fy-rr , 3     %  debug mandibules.

RETURN



Report this post
Top
 Profile  
 
 Post subject: Re: Crazy Ant game (same game as Roy's LogoBlueArrow)
Unread postPosted: Thu Apr 27, 2017 1:37 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 867
Location: France
Hello brochi, I missed you :)

My heart makes me worry but I am always there to torture my neuron: this is the most important :)

You are my hero ;) :)
It's a true pleasure to see somebody who understand all what I wanted to do and my english :) :)

With my little function p2c() I just need the circle center coordinates & it's radius and the true point coordinates you find to test the collides. You are my genius in the lamp.
I just have to give the point for tests more between the 2 ant's mandibules...

I hope Roy will be proud of us :)

I can go on...

Cheers

Gilles

_________________
"It is better to mobilize intelligence for stupid things, rather than mobilizing stupidity for intelligent things."
Galaxy TAB S 8.4, 2560x1600, Marshmallow 6.0.1
Galaxy Note II, 1280x720, JB4.1.2
Galaxy A3, 1280x720, Android 6.0.1


Report this post
Top
 Profile  
 
 Post subject: Re: Crazy Ant game (same game as Roy's LogoBlueArrow)
Unread postPosted: Thu Apr 27, 2017 3:36 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 5:19 am
Posts: 596
Location: Netherlands
Hi Gilles!

I completely agree with what you say about Brochi!
Sometimes he comes out of the blue, but his suggestions are always to the point.
I say this out of experience....

Keep on doing this Brochi; compliments!

Regards, Aat

_________________
To view all my Apps in the BASIC! repository: http://laughton.com/basic/programs/Author_Index/Aat.pdf

When Sod's Law equals Murphy's Law you are bound to be on the right track....!


Report this post
Top
 Profile  
 
 Post subject: Re: Crazy Ant game (same game as Roy's LogoBlueArrow)
Unread postPosted: Fri Apr 28, 2017 8:11 am 
Offline
User avatar

Joined: Sat Oct 04, 2014 5:45 am
Posts: 653
Aat wrote:
I completely agree with what you say about Brochi!

Yes there is always something to learn from Brochi 8-) Well done!
And do not forget Gilles's contributions, even if he sometimes run out of
ideas of what to program :lol:

Regards
Emile

_________________
Download and tutorial for RFODESIGNER
https://sites.google.com/site/rfodesigner/


Report this post
Top
 Profile  
 
 Post subject: Re: Crazy Ant game (same game as Roy's LogoBlueArrow)
Unread postPosted: Wed May 03, 2017 12:45 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
Very nice take on Blue Arrow. Gilles and Brochi ;)

Regards Roy


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred