Author Topic: Touch control android  (Read 1817 times)

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4306
    • View Profile
    • Portfolio
Touch control android
« on: 2015-Jan-16 »
Hello, here a snippet that deals control on keyboard/joy/pad/touch.
The important part is the touch control as it gives a more human way to operate it.

I´m reading 2 mouses here considering primarily the last touch but not forgetting the one before that is kept pressed.

Unfortunantly this is not a full example but a code taken from my game, so it dosen´t work out of the box, you have to interpret it. :good:
Code: (glbasic) [Select]
// --------------------------------- //
// Project: HT_AVOCADO_MAYHEM
// Start: Friday, May 23, 2014
// Source: HI

SUB HI:

// ------------------------------------------------------------------------------------------------------------------- HUMAN INTERFACES

IF control=1 OR control=3
j0=GETJOYX(0)
IF j0>0.991 THEN j0=1 ;// Set to 1 on pad
IF j0<-0.991 THEN j0=-1
IF j0>0.25 OR j0<-0.25 ;// Set analog
ppx=INTEGER(j0*10.0)/10.0*2.4
ELSE
ppx=0
ENDIF
IF GETJOYBUTTON(0,0)>0 ;// BUTTON caanoo 0
but=1
ELSE
but=0
ENDIF
ENDIF
IF control=2
j0=GETJOYX(1)
IF j0<=-0.05 OR j0>=0.05
ppx=INTEGER(j0*100.0)/100.0*10

IF ppx>=2.4 THEN ppx=2.4
IF ppx<=-2.4 THEN ppx=-2.4
ELSE
ppx=0
ENDIF
IF GETJOYBUTTON(0,0)>0 ;// BUTTON caanoo 0
but=1
ELSE
but=0
ENDIF
ENDIF
IF control=4 ;// KEYBOARD
j0=0
IF KEY(205)=1 THEN j0=1.25
IF KEY(203)=1 THEN j0=-1.25
IF KEY(205)=1 AND KEY(203)=1 THEN j0=0
IF j0>0.2 OR j0<-0.2
ppx=INTEGER(j0*10.0)/10.0*2
ELSE
ppx=0
ENDIF
IF KEY(200)=1 ;// BUTTON key up
but=1
ELSE
but=0
ENDIF
ENDIF
IF control=5
j0=GETJOYX(0)
IF j0<=-0.001 OR j0>=0.001
ppx=INTEGER(j0*100.0)/100.0*10

IF ppx>=2.4 THEN ppx=2.4
IF ppx<=-2.4 THEN ppx=-2.4
ELSE
ppx=0
ENDIF

j1=GETJOYY(0) ;//jump strange?
IF j1>-.65
but=1
ELSE
but=0
ENDIF
ENDIF

//--- TOUCH SCREEN CONTROL - ANDROIDS
IF control=6

SETACTIVEMOUSE 0 ;// READ MOUSE A
MOUSESTATE mouax,mouay,mouaa,mouab

SETACTIVEMOUSE 1 ;// READ MOUSE B
MOUSESTATE moubx,mouby,mouba,moubb

;//--- TOUCH DETECT
IF comp=4 OR comp=10
IF mouaa=1 AND mouba=0 OR mouaa=1 AND mouba=1 AND moun=0 ;// FIRST MOUSE ---
IF mouax<tcxa AND mouay>tcy THEN j0=-1.25 ;// walk left
IF mouax>tcxb AND mouay>tcy THEN j0=1.25 ;// walk right

IF mouay<=tcy ;// jump
but=1
IF mouax<tcxa THEN j0=-1.25
IF mouax>tcxb THEN j0=1.25
ELSE
but=0
ENDIF

IF mouaa=1 AND mouba=0 THEN moun=1 ;// manten MOUN quando duplo apertado
IF mouaa=1 AND mouba=1 AND moun=0 THEN moun=0

ENDIF

IF mouba=1 AND mouaa=0 OR mouba=1 AND mouaa=1 AND moun=1 ;// SECOND MOUSE ---
IF moubx<tcxa AND mouby>tcy AND mouba=1 THEN j0=-1.25 ;// walk left
IF moubx>tcxb AND mouby>tcy AND mouba=1 THEN j0=1.25 ;// walk right

IF mouby<=tcy AND mouba=1 ;// jump
but=1
IF moubx<tcxa AND mouba=1 THEN j0=-1.25
IF moubx>tcxb AND mouba=1 THEN j0=1.25
ELSE
but=0
ENDIF

IF mouba=1 AND mouaa=0 THEN moun=0 ;// manten MOUN quando duplo apertado
IF mouba=1 AND mouaa=1 AND moun=1 THEN moun=1

ENDIF

IF mouaa=1 OR mouba=1
IF j0>0.2 OR j0<-0.2 ;// define speed
ppx=INTEGER(j0*10.0)/10.0*2
ELSE
ppx=0 ; j0=0
ENDIF
ELSE
ppx=0 ; j0=0
ENDIF
ENDIF
ENDIF
// ------------------------------------------------------------------------------------------------------------------- HUMAN INTERFACES [END]

ENDSUB