It is currently Sat May 27, 2017 11:41 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  [ 14 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: touch and move objects
Unread postPosted: Thu Apr 27, 2017 7:09 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
Maybe this?



Code:

REM Start of BASIC! Program
! move and drag multiple objects
GR.OPEN 255,0,0,0,0,1
GR.SCREEN w,h

n=10
sq=w/8
DIM player[n],v[n]

FOR I=1 TO n
GR.COLOR 255,RND()*100+50,RND()*100+50,RND()*100+50,1
sx=RND()*w
sy=RND()*h
GR.RECT player[I],sx-sq,sy-sq,sx+sq,sy+sq
GR.SHOW player[I]
NEXT
GR.RENDER


loop:
FOR I=n TO 1 STEP -1

DO
  GR.GET.VALUE player[I],"left",left,"right",right,"top",top,"bottom",bottom


  GR.BOUNDED.TOUCH touched, left, top, right, bottom

  IF touched

do
   GR.TOUCH touched,x,y

 

  IF touched&!drag THEN GOSUB touch
  IF touched&drag THEN GOSUB hold
  IF !touched&drag THEN LET Drag=0

UNTIL !touched
endif
NEXT

GOTO loop

EXIT

!-----------------------------------
touch:
LET ox=x:LET oy=y:LET Drag=i
RETURN

hold:
GR.MOVE player[I],x-ox, y-oy
GR.RENDER
LET ox=x:LET oy=y
RETURN
!-----------------------------------





Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Thu Apr 27, 2017 7:31 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
Actually this is it..

1) wait for a screen touch
2) scan in z order to find top bounded object touched
3) drag object until user lets go
4) go back to 1)



Code:
REM Start of BASIC! Program
! move and drag multiple objects
GR.OPEN 255,0,0,0,0,1
GR.SCREEN w,h

n=10
sq=w/8
DIM player[n],v[n]

FOR I=1 TO n
GR.COLOR 255,RND()*100+50,RND()*100+50,RND()*100+50,1
sx=RND()*w
sy=RND()*h
GR.RECT player[I],sx-sq,sy-sq,sx+sq,sy+sq
GR.SHOW player[I]
NEXT
GR.RENDER


loop:
! wait for any touch
do
pause 100
gr.touch touch,x,y
until touch

! now scan top to bottom z order
FOR I=n TO 1 STEP -1
  GR.GET.VALUE player[I],"left",left,"right",right,"top",top,"bottom",bottom

  GR.BOUNDED.TOUCH touched, left, top, right, bottom

  IF touched then GOSUB dragit
next
goto loop

dragit:
! move around player[I]
do
   GR.TOUCH touched,x,y

  IF touched&!drag THEN GOSUB touch
  IF touched&drag THEN GOSUB hold
  IF !touched&drag THEN LET Drag=0

UNTIL !touched
! finger if off the screen
return

EXIT

!-----------------------------------
touch:
LET ox=x:LET oy=y:LET Drag=i
RETURN

hold:
GR.MOVE player[I],x-ox, y-oy
GR.RENDER
LET ox=x:LET oy=y
RETURN
!-----------------------------------






Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Sat Apr 29, 2017 1:40 pm 
Offline

Joined: Mon Nov 09, 2015 7:14 pm
Posts: 139
for the record, this is what i ended up with, what i am using. im not trying to plagerize this thing,.. its when you are using this with Dims you may have to wait a period of time for the GOSUB to roll around and the result is a thing looks choppy or there is a wait time. with these Dims i kind of truncate alot the subrountine GOTO and put the heart of the matter in a line because the result is it looks more fluid.


IF lvl4valBall1 = 1 Then
FOR I=1 TO n
DO
  GR.GET.VALUE lvl4sqr1,"left",left,"right",right,"top",top,"bottom",bottom
  GR.BOUNDED.TOUCH touched20, (left-sq)*scale_width, (top-sq)*scale_height, (right+sq)*scale_width, (bottom+sq)*scale_height
  IF touched 
   GR.TOUCH touched20,x,y
ENDIF
  IF touched20&!drag THEN
LET ox=x
LET oy=y
LET Drag=1
ENDIF
  IF touched20&drag&ABS(x-ox)+ABS(y-oy)>3 THEN
GR.MOVE lvl4grp1,x-ox, y-oy
GR.RENDER
LET ox=x
LET oy=y
ENDIF
  IF !touched20&drag THEN
LET Drag=0
PAUSE 20
ENDIF
UNTIL !Drag
NEXT
IF GR_COLLISION (lvl4sqr2, lvl4sqr1) | GR_COLLISION (lvl4sqr2, nr1) ~
| GR_COLLISION (lvl4sqr2, nr2) | GR_COLLISION (lvl4sqr2, nr3) ~
| GR_COLLISION (lvl4sqr2, nr4) | GR_COLLISION (lvl4sqr2, lvl4sqr3) Then
lvl4valrestart = 1
ENDIF
ENDIF


Report this post
Top
 Profile  
 
 Post subject: Re: touch and move objects
Unread postPosted: Sat Apr 29, 2017 4:22 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
Looks good...

yes, I probably should use a list instead of the player[] array..

agreed on making the code inline too


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


Who is online

Users browsing this forum: No registered users and 3 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