It is currently Sat Mar 25, 2017 12:39 pm



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  [ 22 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: gr.render in an apk instead of the editor
Unread postPosted: Sat Mar 11, 2017 2:09 pm 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1288
mjcoon wrote:
roy wrote:
How can we open an apk to see the bas and data inside.

Stanley? https://play.google.com/store/apps/details?id=fr.xgouchet.packageexplorer

Mike.


Thanks Mike

Regards Roy


Report this post
Top
 Profile  
 
 Post subject: Re: gr.render in an apk instead of the editor
Unread postPosted: Sat Mar 11, 2017 2:11 pm 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1288
dms wrote:
Roy,

I use a program called Total Commander(file explorer).
WIth it you can open an APK as a zipfile and as such see/extract/copy the files from within to where-ever you want

regards
danny


Thanks danny


Pleased you got your app speed up ;)

Regards Roy


Report this post
Top
 Profile  
 
 Post subject: Re: gr.render in an apk instead of the editor
Unread postPosted: Sun Mar 12, 2017 3:25 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 794
Location: France
Hi dms,

nice game of patience :)

to move a graphic object I use 2 smalls functions I wrote:

Code:
Fn.def LastPtr(ptr)  % Puts the graphic object 'ptr' above all others (and so always visible).
  gr.getDL ndl[],1
  array.length sz, ndl[]
  if !ptr | sz=1 | ndl[sz] =ptr then array.delete ndl[] : Fn.rtn 0
  array.search ndl[],ptr,n
  if n
    for nn=n to sz-1 : ndl[nn] =ndl[nn+1] : next
    ndl[sz] =ptr : gr.newDL ndl[]
  endif
  array.delete ndl[]
Fn.end

Fn.def move(ptr, arx, ary, speed)   % move smoothly the bitmap 'ptr' to arx,ary
LastPtr( ptr )
if speed>1
do
  gr.get.position ptr,dpx,dpy
  ix =int((dpx-arx)/speed)
  iy =int((dpy-ary)/speed)
  if abs(ix)<3 & abs(iy)<3 then D_u.break
  gr.modify ptr, "x",dpx-ix, "y",dpy-iy
  gr.render
until 0
endif
gr.modify ptr, "x",arx, "y",ary
gr.render
Fn.end

Fn.def move2(ptr, arx, ary, pas)   % move smoothly the bitmap 'ptr' to arx,ary  ( use around 12 pixels for 'pas' => 'step' in french)
LastPtr( ptr )
if pas>1
  gr.get.position ptr,dpx,dpy
  ex =int((arx-dpx)/pas) : ey =int((ary-dpy)/pas)
  for e=1 to pas-1 : gr.move ptr, ex, ey : gr.render : next
endif
gr.modify ptr, "x",arx, "y",ary : gr.render
Fn.end

move2 is for a regular move.

It could be fine if the distributed card went to the location of the card it replaces ;)

Could you say what happens when no card adds can make 10 ?

Why only 43 cards at start ? OOOPS 52-9 = 43 i understood :) :) :)

Cheers

Gilles.

PS: I would like to make a french version with your permission. Do you give me ?

_________________
"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: gr.render in an apk instead of the editor
Unread postPosted: Sun Mar 12, 2017 7:10 am 
Offline

Joined: Sat Mar 11, 2017 5:49 am
Posts: 13
Hi gilles,

The spirit of this forum is to share code so that we can all learn from each other.
So Yes you have my permission to use the code and make a french version of it.

Just to answer your question, if you are unable to make ten, the game is over.
But, it is not only ten, 2 jacks, 2 queens and 2 kings is also fine

Regards
Danny


Report this post
Top
 Profile  
 
 Post subject: Re: gr.render in an apk instead of the editor
Unread postPosted: Sun Mar 12, 2017 7:25 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 794
Location: France
Thanks Danny,

I'll not use your code but I'll write my own soon... ;)

Cheers

Gilles

NB : a 10 is also fine if i well understand the rules...

_________________
"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: gr.render in an apk instead of the editor
Unread postPosted: Sun Mar 12, 2017 7:44 am 
Offline

Joined: Sat Mar 11, 2017 5:49 am
Posts: 13
Hi gilles

Indeed a ten is also fine.
Sorry for not mentioning it

Regards
Danny


Report this post
Top
 Profile  
 
 Post subject: Re: gr.render in an apk instead of the editor
Unread postPosted: Sun Mar 12, 2017 8:04 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 794
Location: France
Here is my attempt.

It could be very interesting to write the code for the 'game over' detection! UPDATED : done

Code:
REM copie de Maketen de 'dms' alias Danny sur le forum

Fn.def clc(n,ncp)    % card color   1=trèfle, 2=pique, 3=coeur, 4=carreau
Fn.rtn int(n/(8+0.1+5*(ncp=52)))+1
Fn.end

Fn.def vlc(n,ncp)    % card value
d =8+5*(ncp=52) : noc =mod(n,d) : noc+=d*(noc=0)
if ncp=32 then Fn.rtn val(word$("1 7 8 9 10 11 12 13",noc)) else Fn.rtn noc
Fn.end

Fn.def LastPtr(ptr)  % puts the graphic pointer 'ptr' above all others (and so always visible).
  gr.getDL ndl[],1
  array.length sz, ndl[]
  if !ptr | sz=1 | ndl[sz] =ptr then array.delete ndl[] : Fn.rtn 0
  array.search ndl[],ptr,n
  if n
    for nn=n to sz-1 : ndl[nn] =ndl[nn+1] : next
    ndl[sz] =ptr : gr.newDL ndl[]
  endif
  array.delete ndl[]
Fn.end

Fn.def move(ptr, arx, ary, speed)   % move smoothly the bitmap 'ptr' to arx,ary
LastPtr( ptr )
if speed>1
do
  gr.get.position ptr,dpx,dpy
  ix =int((dpx-arx)/speed)
  iy =int((dpy-ary)/speed)
  if abs(ix)<3 & abs(iy)<3 then D_u.break
  gr.modify ptr, "x",dpx-ix, "y",dpy-iy
  gr.render
until 0
endif
gr.modify ptr, "x",arx, "y",ary
gr.render
Fn.end

Fn.def move2(ptr, arx, ary, pas)   % move smoothly the bitmap 'ptr' to arx,ary  (with 'pas' around 12 pixels)
LastPtr( ptr )
if pas>1
  gr.get.position ptr,dpx,dpy
  ex =int((arx-dpx)/pas) : ey =int((ary-dpy)/pas)
  for e=1 to pas-1 : gr.move ptr, ex, ey : gr.render : next
endif
gr.modify ptr, "x",arx, "y",ary : gr.render
Fn.end

FN.DEF RectR(x,y, c, lx,ly, fill)     %  make rectangle with rounded corners.
GR.ARC nul, x, y, x+c, y+c, -90, -90, fill     % top left
GR.ARC nul, x+lx-c,y, x+lx, y+c, -90, 90, fill   % top right
GR.ARC nul, x, y+ly-c,x+c, y+ly, -180, -90, fill   % bottom left
GR.ARC nul, x+lx-c, y+ly-c, x+lx, y+ly, 0, 90, fill  % bottom right
if !fill
  GR.LINE r1, x+c/2, y, x+lx-c/2, y     % left
  GR.LINE r2, x, y+c/2, x, y+ly-c/2     % up
  GR.LINE r3, x+c/2, y+ly, x+lx-c/2, y+ly  % right
  GR.LINE r4, x+lx, y+c/2, x+lx, y+ly-c/2  % down
else
  c*=0.4
  gr.rect nul, x+c, y, x+lx-c, y+ly
  gr.rect nul, x, y+c, x+lx, y+ly-c
endif
FN.END

gr.open 255,84,140,78,0,1   % kind of green
gr.screen w,h
scx = 800
scy = 1280
sx  = w/scx
sy  = h/scy
gr.scale sx,sy
path$ ="Maketen/"
gr.bitmap.load bmps, path$ + "52_cards.png"
ncp =52 : dcx =158 : dcy =246 : bdos =2 : ptr =1 : vlr =2
DIM bc[ncp], dos[6], p[ncp,2]

GOSUB MakeCards

DO
  GOSUB InitGame
  new =0 : gover =0
  DO
    do
      gr.touch touched,x,y
      if !background() then gr.render
    until touched | quit | new
    if quit | new then d_u.continue
    do
      gr.touch touched,x,y
    until !touched
    x/=sx : y/=sy
    gr.modify curs, "x",x ,"y",y

    for c=1 to ncp
      if gr_collision (curs, p[c,ptr]) then f_n.break     % what card I'm touching.
    next

    if c<=ncp & nc
      if !tch
        vc =vlc(p[c,vlr],ncp)
        gr.get.position p[c,ptr], pcx, pcy
        oldpcx =pcx : oldpcy =pcy
        gr.modify cadre, "x", pcx-10, "y", pcy-10 : gr.show cadre
        tch =c
        if vc=10 & nc
          move2(p[nc,ptr], pcx,pcy, 8)
          gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
          nc-- : tch =0 : gr.hide cadre
        endif
      else
        tch =0 : gr.hide cadre
        gr.get.position p[c,ptr], pcx, pcy
        nvc =vlc(p[c,vlr],ncp)
        if (nvc>10 & nvc=vc) | nvc+vc=10
          if nc
            move2(p[nc,ptr], oldpcx,oldpcy, 8)
            gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
            nc--
          endif
          if nc
            move2(p[nc,ptr], pcx,pcy, 8)
            gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
            nc--
          endif
        endif
      endif
      gr.modify ptnc, "text", int$(nc)+" cards"
      if !nc then gr.modify ptnc, "text", "end of game..." else GOSUB GameOver
    endif
    if gover then nc=0 : POPUP "  GAME OVER  "

  UNTIL new
UNTIL quit
END

OnBackKey:
  GOSUB BoiteMenu
back.resume

BoiteMenu:
  Dialog.message win$,"       What do you want ?", ok, " Exit ", " We continue ? ", " Cancel "
  new  =(ok=1 | ok=2) : quit =(ok=1)
return

GameOver:  % detection
c$ =""
for yy=1 to 3
  for xx=1 to 3
    gr.modify curs, "x",gx+(xx-1)*(dcx+40), "y",gy+(yy-1)*(dcy+40)
    for c=1 to ncp
      if gr_collision(curs, p[c,ptr]) then f_n.break
    next
    c$+=format$("%%", vlc(p[c,vlr],ncp))    % a string of the 9 cards values.
  next
next
if !IS_IN("10",c$)
  f1 =0 : f2 =0 : f3 =0
  for c=1 to 9
    v =val(word$(c$,c))
    if v=11
      f1++
    elseif v=12
      f2++
    elseif v=13
      f3++
    endif
  next
  if f1<2 & f2<2 & f3<2
    gover =1
    for cc=1 to 9
      v1 =val(word$(c$,cc))
      for c=1 to 9
        v2 =val(word$(c$,c)) : if c<>cc & v1+v2=10 then gover =0 : f_n.break
      next
      if !gover then f_n.break
    next
  endif
endif
return

MakeCards:
for c=1 to ncp         %  all cards bitmaps.
  cc =clc(c,ncp) : vc =vlc(c,ncp)
  gr.bitmap.crop bc[c], bmps, (vc-1)*dcx, (cc-1)*dcy, dcx, dcy
next
for d=1 to 6
gr.bitmap.crop nul, bmps, (d-1)*dcx, 4*dcy, dcx, dcy : gr.bitmap.scale dos[d], nul, 90, 130 : gr.bitmap.delete nul
next
gr.bitmap.delete bmps
gr.bitmap.create cadr, dcx+20, dcy+20
gr.bitmap.drawinto.start cadr
gr.set.stroke 8
gr.color 255, 200, 200, 200, 0
RectR(0,0, 30, dcx+20, dcy+20, 0)
gr.bitmap.drawinto.end
return

InitGame:
GR.CLS
gx  =(scx-3*(dcx+20))/2
gy  =0.6*dcy
pqx =gx
pqy =gy+3*(dcy+20)
ch$ =""
for c=1 to ncp     % make the deck (52 graphicals objects with the 'back' & at the same place)
  do
    n =int(rnd()*ncp)+1
  until !IS_IN(format$("%%",n),ch$)    %  unique...
  ch$+=format$("%%",n)
  p[c,vlr] =n-ncp*(n>ncp)
  gr.bitmap.draw p[c,ptr], dos[bdos], pqx, pqy
next
gr.color 0 : gr.point curs, 0, 0
gr.color 255, 255, 255, 0, 2
gr.set.stroke 2
gr.text.size 50
gr.text.align 2
gr.text.draw nul, scx/2, 80, "-   M a k e  T e n   -"
gr.color 255,0,240,255,1
gr.text.size 30
gr.text.align 1
gr.text.draw nul, 60, pqy+200, "Touch 2 cards or 1 if it's a 10."
gr.text.draw nul, 60, pqy+240, "If their sum =10 or if they are 2 same figures then"
gr.text.draw nul, 60, pqy+280, "new cards will be distributed at their place."
nc =ncp : dy=0
for c=1 to 9          %  distribution of the 9 cards.
  if c=1 | c=4 | c=7 then dx=1 : dy++ : else dx++
  cx =gx +(dx-1)*(dcx+20)
  cy =gy +(dy-1)*(dcy+20)
  move2( p[nc,ptr], cx, cy, 8)
  gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
  nc--
next
gr.bitmap.draw cadre, cadr, gx+(2-1)*(dcx+20)-10, gy+(2-1)*(dcy+20)-10 : gr.hide cadre
gr.color 255, 255, 255, 0, 2
gr.text.size 40
gr.text.draw ptnc, pqx+1.1*dcx, pqy+60, int$(nc)+" cards"
return

_________________
"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: gr.render in an apk instead of the editor
Unread postPosted: Mon Mar 13, 2017 2:08 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 794
Location: France
OOOPS ! a small BUG corrected... and deleting some unnecessary code.

Code:
REM copie de Maketen de 'dms' alias Danny sur le forum

Fn.def clc(n,ncp)    % card color   1=clover, 2=spade, 3=heart, 4=diamond
Fn.rtn int(n/(8+0.1+5*(ncp=52)))+1
Fn.end

Fn.def vlc(n,ncp)    % card value
d =8+5*(ncp=52) : noc =mod(n,d) : noc+=d*(noc=0)
if ncp=32 then Fn.rtn val(word$("1 7 8 9 10 11 12 13",noc)) else Fn.rtn noc
Fn.end

Fn.def LastPtr(ptr)  % puts the graphic pointer 'ptr' above all others (and so always visible).
  gr.getDL ndl[],1
  array.length sz, ndl[]
  if !ptr | sz=1 | ndl[sz] =ptr then array.delete ndl[] : Fn.rtn 0
  array.search ndl[],ptr,n
  if n
    for nn=n to sz-1 : ndl[nn] =ndl[nn+1] : next
    ndl[sz] =ptr : gr.newDL ndl[]
  endif
  array.delete ndl[]
Fn.end

Fn.def move2(ptr, arx, ary, pas)   % move smoothly the bitmap 'ptr' to arx,ary  (with 'pas' around 12 pixels)
LastPtr( ptr )
if pas>1
  gr.get.position ptr,dpx,dpy
  ex =int((arx-dpx)/pas) : ey =int((ary-dpy)/pas)
  for e=1 to pas-1 : gr.move ptr, ex, ey : gr.render : next
endif
gr.modify ptr, "x",arx, "y",ary : gr.render
Fn.end

FN.DEF RectR(x,y, c, lx,ly, fill)     %  make rectangle with rounded corners.
GR.ARC nul, x, y, x+c, y+c, -90, -90, fill     % top left
GR.ARC nul, x+lx-c,y, x+lx, y+c, -90, 90, fill   % top right
GR.ARC nul, x, y+ly-c,x+c, y+ly, -180, -90, fill   % bottom left
GR.ARC nul, x+lx-c, y+ly-c, x+lx, y+ly, 0, 90, fill  % bottom right
if !fill
  GR.LINE r1, x+c/2, y, x+lx-c/2, y     % left
  GR.LINE r2, x, y+c/2, x, y+ly-c/2     % up
  GR.LINE r3, x+c/2, y+ly, x+lx-c/2, y+ly  % right
  GR.LINE r4, x+lx, y+c/2, x+lx, y+ly-c/2  % down
else
  c*=0.4
  gr.rect nul, x+c, y, x+lx-c, y+ly
  gr.rect nul, x, y+c, x+lx, y+ly-c
endif
FN.END

gr.open 255,84,140,78,0,1   % kind of green
gr.screen w,h
scx = 800
scy = 1280
sx  = w/scx
sy  = h/scy
gr.scale sx,sy
path$ ="Maketen/"    % the game directory under DATA/
gr.bitmap.load bmps, path$ + "52_cards.png"
ncp =52 : dcx =158 : dcy =246 : bdos =2 : ptr =1 : vlr =2
DIM bc[ncp], dos[6], p[ncp,2]

GOSUB MakeCards

DO
  GOSUB InitGame
  new =0 : gover =0
  DO
    do
      gr.touch touched,x,y
      if !background() then gr.render
    until touched | quit | new
    if quit | new then d_u.continue
    do
      gr.touch touched,x,y
    until !touched
    x/=sx : y/=sy
    gr.modify curs, "x",x ,"y",y

    for c=1 to ncp
      if gr_collision (curs, p[c,ptr]) then f_n.break     % what card I'm touching.
    next

    if c<=ncp & nc
      if !tch
        vc =vlc(p[c,vlr],ncp)
        gr.get.position p[c,ptr], pcx, pcy
        oldpcx =pcx : oldpcy =pcy : oldptr =p[c,ptr]
        gr.modify cadre, "x", pcx-10, "y", pcy-10 : gr.show cadre
        tch =c
        if vc=10 & nc
          move2(p[nc,ptr], pcx,pcy, 8)
          gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
          nc-- : tch =0 : gr.hide cadre
        endif
      else
        tch =0
        gr.get.position p[c,ptr], pcx, pcy
        nvc =vlc(p[c,vlr],ncp)
        if ((nvc>10 & nvc=vc) | nvc+vc=10) & p[c,ptr]<>oldptr
          if nc
            move2(p[nc,ptr], pcx,pcy, 8)
            gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
            nc--
          endif
          if nc
            move2(p[nc,ptr], oldpcx,oldpcy, 8)
            gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
            nc--
          endif
        endif
        gr.hide cadre
      endif
      gr.modify ptnc, "text", int$(nc)+" cards"
      if !nc then gr.modify ptnc, "text", "end of game..." else GOSUB GameOver
    endif
    if gover then nc=0 : POPUP "  GAME OVER  "

  UNTIL new
UNTIL quit
END

OnBackKey:
  GOSUB BoiteMenu
back.resume

BoiteMenu:
  Dialog.message win$,"       What do you want ?", ok, " Exit ", " We continue ? ", " Cancel "
  new  =(ok=1 | ok=2) : quit =(ok=1)
return

GameOver:  % detection
c$ =""
for yy=1 to 3
  for xx=1 to 3
    gr.modify curs, "x",gx+(xx-1)*(dcx+40), "y",gy+(yy-1)*(dcy+40)
    for c=1 to ncp
      if gr_collision(curs, p[c,ptr]) then f_n.break
    next
    c$+=format$("%%", vlc(p[c,vlr],ncp))    % a string of the 9 cards values.
  next
next
if !IS_IN("10",c$)
  f1 =0 : f2 =0 : f3 =0
  for c=1 to 9
    v =val(word$(c$,c))
    if v=11
      f1++
    elseif v=12
      f2++
    elseif v=13
      f3++
    endif
  next
  if f1<2 & f2<2 & f3<2
    gover =1
    for cc=1 to 9
      v1 =val(word$(c$,cc))
      for c=1 to 9
        v2 =val(word$(c$,c)) : if c<>cc & v1+v2=10 then gover =0 : f_n.break
      next
      if !gover then f_n.break
    next
  endif
endif
return

MakeCards:
for c=1 to ncp         %  all cards bitmaps.
  cc =clc(c,ncp) : vc =vlc(c,ncp)
  gr.bitmap.crop bc[c], bmps, (vc-1)*dcx, (cc-1)*dcy, dcx, dcy
next
for d=1 to 6
  gr.bitmap.crop nul, bmps, (d-1)*dcx, 4*dcy, dcx, dcy
  gr.bitmap.scale dos[d], nul, 90, 130 : gr.bitmap.delete nul
next
gr.bitmap.delete bmps     % free memory of the original .png file.
gr.bitmap.create cadr, dcx+20, dcy+20
gr.bitmap.drawinto.start cadr          % create the bitmap to show the selected card.
gr.set.stroke 8
gr.color 255, 200, 200, 200, 0
RectR(0,0, 30, dcx+20, dcy+20, 0)
gr.bitmap.drawinto.end
return

InitGame:
GR.CLS
gx  =(scx-3*(dcx+20))/2
gy  =0.6*dcy
pqx =gx
pqy =gy+3*(dcy+20)
ch$ =""
for c=1 to ncp     % make & shuffle the deck (52 graphicals objects with the 'back' & at the same place)
  do
    n =int(rnd()*ncp)+1
  until !IS_IN(format$("%%",n),ch$)    %  unique...
  ch$+=format$("%%",n)
  p[c,vlr] =n-ncp*(n>ncp)
  gr.bitmap.draw p[c,ptr], dos[bdos], pqx, pqy
next
gr.color 0 : gr.point curs, 0,0
gr.color 255, 255, 255, 0, 2
gr.set.stroke 2
gr.text.size 50
gr.text.align 2
gr.text.draw nul, scx/2, 80, "-   M a k e  T e n   -"
gr.color 255,0,0,0,0
RectR(40,20, 30, scx-80, 100, 0)
RectR(pqx+dcx-10, pqy+10, 30, 360, 80, 0)
RectR(40,pqy+160, 30, scx-80, 140, 0)
gr.color 255,0,240,255,1
gr.text.size 30
gr.text.align 1
gr.text.draw nul, 60, pqy+200, "Touch 2 cards or 1 if it's a 10."
gr.text.draw nul, 60, pqy+240, "If their sum =10 or if they are 2 same figures then"
gr.text.draw nul, 60, pqy+280, "new cards will be distributed at their place."
nc =ncp : dy=0
for c=1 to 9          %  distribution of the 9 cards.
  if c=1 | c=4 | c=7 then dx=1 : dy++ : else dx++
  cx =gx +(dx-1)*(dcx+20)
  cy =gy +(dy-1)*(dcy+20)
  move2( p[nc,ptr], cx, cy, 8)
  gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
  nc--
next
gr.bitmap.draw cadre, cadr, gx+(2-1)*(dcx+20)-10, gy+(2-1)*(dcy+20)-10 : gr.hide cadre
gr.color 255, 255, 255, 0, 2
gr.text.size 40
gr.text.draw ptnc, pqx+1.1*dcx, pqy+60, int$(nc)+" cards"
return

_________________
"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: gr.render in an apk instead of the editor
Unread postPosted: Tue Mar 14, 2017 7:00 am 
Offline

Joined: Sat Mar 02, 2013 11:04 am
Posts: 794
Location: France
A latest version, more respectful of the rule... please Danny say me !

Code:
REM copie de Maketen de Danny alias 'dms' sur le forum.

Fn.def clc(n,ncp)    % card color   1=clover, 2=spade, 3=heart, 4=diamond
Fn.rtn int(n/(8+0.1+5*(ncp=52)))+1
Fn.end

Fn.def vlc(n,ncp)    % card value
d =8+5*(ncp=52) : noc =mod(n,d) : noc+=d*(noc=0)
if ncp=32 then Fn.rtn val(word$("1 7 8 9 10 11 12 13",noc)) else Fn.rtn noc
Fn.end

Fn.def LastPtr(ptr)  % puts the graphic pointer 'ptr' above all others (and so always visible).
  gr.getDL ndl[],1
  array.length sz, ndl[]
  if !ptr | sz=1 | ndl[sz] =ptr then array.delete ndl[] : Fn.rtn 0
  array.search ndl[],ptr,n
  if n
    for nn=n to sz-1 : ndl[nn] =ndl[nn+1] : next
    ndl[sz] =ptr : gr.newDL ndl[]
  endif
  array.delete ndl[]
Fn.end

Fn.def move2(ptr, arx, ary, pas)   % move smoothly the bitmap 'ptr' to arx,ary  (with 'pas' around 12 pixels)
LastPtr( ptr )
if pas>1
  gr.get.position ptr,dpx,dpy
  ex =int((arx-dpx)/pas) : ey =int((ary-dpy)/pas)
  for e=1 to pas-1 : gr.move ptr, ex, ey : gr.render : next
endif
gr.modify ptr, "x",arx, "y",ary : gr.render
Fn.end

FN.DEF RectR(x,y, c, lx,ly, fill)     %  make rectangle with rounded corners.
GR.ARC nul, x, y, x+c, y+c, -90, -90, fill     % top left
GR.ARC nul, x+lx-c,y, x+lx, y+c, -90, 90, fill   % top right
GR.ARC nul, x, y+ly-c,x+c, y+ly, -180, -90, fill   % bottom left
GR.ARC nul, x+lx-c, y+ly-c, x+lx, y+ly, 0, 90, fill  % bottom right
if !fill
  GR.LINE r1, x+c/2, y, x+lx-c/2, y     % left
  GR.LINE r2, x, y+c/2, x, y+ly-c/2     % up
  GR.LINE r3, x+c/2, y+ly, x+lx-c/2, y+ly  % right
  GR.LINE r4, x+lx, y+c/2, x+lx, y+ly-c/2  % down
else
  c*=0.4
  gr.rect nul, x+c, y, x+lx-c, y+ly
  gr.rect nul, x, y+c, x+lx, y+ly-c
endif
FN.END

gr.open 255,84,140,78,0,1   % kind of green
gr.screen w,h
scx = 800
scy = 1280
sx  = w/scx
sy  = h/scy
gr.scale sx,sy
path$ ="Maketen/"
gr.bitmap.load bmps, path$ + "52_cards.png"
ncp =52 : dcx =158 : dcy =246 : bdos =2 : ptr =1 : vlr =2
DIM bc[ncp], dos[6], p[ncp,2], f[3]

GOSUB MakeCards

DO
  GOSUB InitGame
  new =0 : gover =0
  DO
    do
      gr.touch touched,x,y
      if !background() then gr.render
    until touched | quit | new
    if quit | new then d_u.continue
    do
      gr.touch touched,x,y
    until !touched
    x/=sx : y/=sy
    gr.modify curs, "x",x ,"y",y

    for c=1 to ncp
      if gr_collision (curs, p[c,ptr]) then f_n.break     % what card I'm touching.
    next

    if c<=ncp & ntc
      gr.get.position p[c,ptr], pcx, pcy
      if pcy>=(gy+3*dcy) then d_u.continue   %  out of one the 9 cards
      if !tch
        vc =vlc(p[c,vlr],ncp)
        oldpcx =pcx : oldpcy =pcy : oldptr =p[c,ptr] : oldc =c
        gr.modify cadre, "x", pcx-10, "y", pcy-10 : gr.show cadre
        tch =1
        if vc=10
          tch =0 : gr.hide cadre
          move2(p[c,ptr], scx,gy+3*dcy, 6) : ntc--
          if nc then move2(p[nc,ptr], pcx,pcy, 8) : gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]] : nc--
        endif
      else
        nvc =vlc(p[c,vlr],ncp) : gr.hide cadre : tch =0
        if ((nvc>10 & nvc=vc) | nvc+vc=10) & p[c,ptr]<>oldptr
          move2(p[c,ptr], scx,gy+3*dcy, 6) : ntc--
          move2(p[oldc,ptr], scx,gy+3*dcy, 6) : ntc--
          if nc then move2(p[nc,ptr], pcx,pcy, 8) : gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]] : nc--
          if nc then move2(p[nc,ptr], oldpcx,oldpcy, 8) : gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]] : nc--
        endif
      endif
      gr.modify ptnc, "text", int$(nc)+" cards left."
      if !ntc then gr.modify ptnc, "text", "end of game..." else GOSUB GameOver
    endif
    if gover then ntc=0 : POPUP "  GAME OVER  "

  UNTIL new
UNTIL quit
END

OnBackKey:
  GOSUB BoiteMenu
back.resume

BoiteMenu:
  Dialog.message win$,"       What do you want ?", ok, " Exit ", " We continue ? ", " Cancel "
  new  =(ok=1 | ok=2) : quit =(ok=1)
return

GameOver:  % detection
c$ ="" : nn =0
for yy=1 to 3
  for xx=1 to 3
    gr.modify curs, "x",gx+(xx-1)*(dcx+40), "y",gy+(yy-1)*(dcy+40)
    for c=1 to ncp
      if gr_collision(curs, p[c,ptr]) then f_n.break
    next
    if c<=ncp then c$+=format$("%%", vlc(p[c,vlr],ncp)) : nn++   % a string of the value of the displayed cards.
  next
next
if !IS_IN("10",c$)
  array.fill f[],0
  for c=1 to nn
    v =val(word$(c$,c)) : if v>10 then f[v-10]++
  next
  if f[1]<2 & f[2]<2 & f[3]<2
    gover =1
    for cc=1 to nn
      v1 =val(word$(c$,cc))
      for c=1 to nn
        v2 =val(word$(c$,c)) : if c<>cc & v1+v2=10 then gover =0 : f_n.break
      next
      if !gover then f_n.break
    next
  endif
endif
return

MakeCards:
for c=1 to ncp         %  all cards bitmaps.
  cc =clc(c,ncp) : vc =vlc(c,ncp)
  gr.bitmap.crop bc[c], bmps, (vc-1)*dcx, (cc-1)*dcy, dcx, dcy
next
for d=1 to 6
  gr.bitmap.crop nul, bmps, (d-1)*dcx, 4*dcy, dcx, dcy
  gr.bitmap.scale dos[d], nul, 100, 140 : gr.bitmap.delete nul
next
gr.bitmap.delete bmps     % free memory of the original .png file.
gr.bitmap.create cadr, dcx+20, dcy+20
gr.bitmap.drawinto.start cadr          % create the bitmap to show the selected card.
gr.set.stroke 8
gr.color 255, 200, 200, 200, 0
RectR(0,0, 30, dcx+20, dcy+20, 0)
gr.bitmap.drawinto.end
return

InitGame:
GR.CLS
gx  =(scx-3*(dcx+20))/2
gy  =0.6*dcy
pqx =gx
pqy =gy+3*(dcy+20)+15
ch$ =""
ntc =ncp : t =0
for c=1 to ncp     % make the deck (52 graphicals objects with the 'back' & at the same place)
  do
    n =int(rnd()*ncp)+1
  until !IS_IN(format$("%%",n),ch$)    %  unique...
  ch$+=format$("%%",n)
  p[c,vlr] =n-ncp*(n>ncp) : t+=0.33
  gr.bitmap.draw p[c,ptr], dos[bdos], pqx+t, pqy-t %: gr.render
next
gr.color 0 : gr.point curs, 0,0
gr.color 255, 255, 255, 0, 2
gr.set.stroke 2
gr.text.size 50
gr.text.align 2
gr.text.draw nul, scx/2, 80, "-   M a k e  T e n   -"
gr.color 255,0,0,0,0
RectR(40,20, 30, scx-80, 100, 0)
RectR(pqx+dcx-10, pqy+10, 30, 360, 80, 0)
RectR(40,pqy+160, 30, scx-80, 140, 0)
gr.color 255,0,240,255,1
gr.text.size 30
gr.text.align 1
gr.text.draw nul, 60, pqy+200, "Touch 2 cards or 1 if it's a 10."
gr.text.draw nul, 60, pqy+240, "If their sum =10 or if they are 2 same figures then"
gr.text.draw nul, 60, pqy+280, "new cards will be distributed at their place."
nc =ncp : dy=0
for c=1 to 9          %  distribution of the 9 cards.
  if c=1 | c=4 | c=7 then dx=1 : dy++ : else dx++
  cx =gx +(dx-1)*(dcx+20)
  cy =gy +(dy-1)*(dcy+20)
  move2( p[nc,ptr], cx, cy, 8)
  gr.modify p[nc,ptr], "bitmap", bc[p[nc,vlr]]
  nc--
next
gr.bitmap.draw cadre, cadr, gx+(2-1)*(dcx+20)-10, gy+(2-1)*(dcy+20)-10 : gr.hide cadre
gr.color 255, 255, 255, 0, 2
gr.text.size 40
gr.text.draw ptnc, pqx+1.1*dcx, pqy+60, int$(nc)+" cards left."
return

_________________
"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: gr.render in an apk instead of the editor
Unread postPosted: Wed Mar 15, 2017 12:27 pm 
Offline

Joined: Sat Mar 11, 2017 5:49 am
Posts: 13
Hi gilles

Whow i have to say, looks much more attractive
than mine
Maybe one more point to add, if the cards are all done, ASIN
you cleared the deck, auto start a new game
Thats what i have done in my version

Regards
Danny


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2, 3  Next


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