Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:39 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : gui touch

     Page 2 of 2    
Author Message
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2134
Posted: 07:17pm 18 Mar 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  Do you need to CLS? Can you use GUI HIDE to hide all GUI controls and GUI SHOW to bring them back?

You can also use GUI REDRAW if the screen has become corrupted.

Then GUI SETUP n can set up controls on page n and you can swap them any time with GUI PAGE n.

Thanks, I'll try. I did try gui disable all ,cls ,gui enable all no luck.
gui area is invisible anyway.cls just stops it working.
I found I don't need cls, the filled box clears the area and leaves the buttons so they don't need redrawing.
Using exit do for collision and goto start: ... just temporary... honest :)
It's all new and interesting.
Edited 2023-03-19 08:40 by stanleyella
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2134
Posted: 12:41am 19 Mar 2023
Copy link to clipboard 
Print this post

  vegipete said  Looks fun...

Because I can't help compressing code:
  ' computer move
  if cdx% then   ' moving in x direction
    if pixel(cx%+cdx%) then  ' move blocked
      cdx% = 0
      cdy% = -1 + 2 * (py% > cy%)  ' turn toward player
    endif
  else           ' moving in y direction
    if pixel(cy%+cdy%) then  ' move blocked
      cdy% = 0
      cdx% = -1 + 2 * (px% > cx%)  ' turn toward player
    endif
  endif
  cx%=cx%+cdx%:cy%=cy%+cdy%
  if pixel(cx%,cy%) > 0 then end   ' computer can't move!
  pixel cx%,cy%,rgb(cyan)


my effort, never used logic like this.
'computer move
if cdx%<>0 then
   if pixel (cx%+cdx%,cy%) >0 then
     cdx%=0:cdy%=(py%>cy%)-(py%<cy%)
   end if
else
   if pixel (cx%,cy%+cdy%) >0 then
     cdy%=0:cdx%=(px%>cx%)-(px%<cx%)
   end if
end if
cx%=cx%+cdx%:cy%=cy%+cdy%
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 02:00am 20 Mar 2023
Copy link to clipboard 
Print this post

  Stan said  has anyone tried using resistors and buttons and one a-d input pin? Each button giving a different voltage when pressed.

see: this There may well be other examples.

Bill
Keep safe. Live long and prosper.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2134
Posted: 04:53pm 20 Mar 2023
Copy link to clipboard 
Print this post

@Turbo46. Thanks for the link, it was my thoughts, the idea isn't new.
I've learnt lots about gui, pixel and using logic instead of if then.
It's going off thread but the buttons and resistors I'm going to try, wiring the board for 3.3 and 5V linear regs and ground 3.3V enable so a-d is less noisy, so I read.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6814
Posted: 05:19pm 20 Mar 2023
Copy link to clipboard 
Print this post

You can improve the ADC input by:

Fit a LM4040 3V3 shunt regulator between VREF and GND
OPTION VCC 3

The analogue inputs then read 0-3. The reduction in voltage reduces a lot of the noise on the supply lines as well as making the reference voltage more stable.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2134
Posted: 05:25pm 20 Mar 2023
Copy link to clipboard 
Print this post

Here's the finished game for ili9488 lcd to demo gui area touched and pixel read and logic that used 75% less code than if then. Hope someone finds it useful.
thanks for the help.
This version has 3 computer opponents.




'tron ili9488
'OPTION GUI CONTROLS Must be set up in command before use
'each control is 52 bytes,it's rounded up to 2048,
'so total controls is 2048/52=39. Use that even using only 4 controls.
'CLS disables gui area. use box to cls.
 OPTION EXPLICIT
 OPTION DEFAULT NONE
 OPTION DEFAULT INTEGER
 OPTION BASE 1 'arrays start at 1
 dim px,py,pdx,pdy
 dim cx(3),cy(3),cdx(3),cdy(3),cpa(3)
 dim ts,tr,csc=0,psc=0,cm
 
 cls
'define touch areas  
 gui area 1,0,285,72,26 'left button
 gui area 2,112,285,96,26 'right button
 gui area 3,448,0,32,72 'up button
 gui area 4,448,114,32,96 'down button
 
'draw direction buttons
 triangle 2,312,66,305,66,319,rgb(yellow),1
 triangle 192,312,130,305,130,319,rgb(yellow),1
 triangle 471,2,479,66,464,66,rgb(yellow),1
 triangle 471,192,479,130,464,130,rgb(yellow),1
start:
'init players start positions
 px=400:py=rnd*200+60:pdx=-1:pdy=0
 cx(1)=rnd*300+80:cy(1)=70:cdx(1)=0:cdy(1)=1:cpa(1)=1
 cx(2)=rnd*300+80:cy(2)=230:cdx(2)=0:cdy(2)=-1:cpa(2)=1
 cx(3)=rnd*80+80:cy(3)=rnd*80+220:cdx(3)=1:cdy(3)=0:cpa(3)=1
 
'draw play area & 4 random triangles on border
 box 0,0,463,303,1,rgb(white),rgb(black)
 ts=int(rnd*200)+60
 triangle 0,ts,12,ts+8,0,ts+16,rgb(White)
 ts=int(rnd*200)+60
 triangle 461,ts,449,ts+8,461,ts+16,rgb(White)
 ts=int(rnd*360)+60
 triangle ts,0,ts+8,10,ts+16,0,rgb(White)
 ts=int(rnd*360)+60
 triangle ts,303,ts+8,293,ts+16,303,rgb(White)
 'main
 do
   if pixel (px,py) >0 then 'player crashed
     box 0,0,463,303,1,rgb(white),rgb(black)
     text 150,140,"You Lost",l,5:pause 5000:exit do
   end if
   pixel px,py,rgb(magenta)
   px=px+pdx:py=py+pdy
'check user button pressed
   tr=TOUCH(REF)
   if tr>0 then
     select case tr
       case 1 'left
         if pdx=0 then pdy=0:pdx=-1
       case 2 'right
         if pdx=0 then pdy=0:pdx=1
       case 3 'up
         if pdy=0 then pdx=0:pdy=-1
       case 4 'down
         if pdy=0 then pdx=0:pdy=1
     end select
   end if
'computer move
   for cm=1 to 3
     if cpa(cm)=1 then
       if cdx(cm)<>0 then
         if pixel (cx(cm)+cdx(cm),cy(cm)) >0 then
           cdx(cm)=0:cdy(cm)=(py>cy(cm))-(py<cy(cm))
         end if
       else
         if pixel (cx(cm),cy(cm)+cdy(cm)) >0 then
           cdy(cm)=0:cdx(cm)=(px>cx(cm))-(px<cx(cm))
         end if
       end if  
       cx(cm)=cx(cm)+cdx(cm):cy(cm)=cy(cm)+cdy(cm)
       if pixel (cx(cm),cy(cm)) >0 then
         cpa(cm)=0'computer crashed
         if cpa(1)+cpa(2)+cpa(3)=0 then
           box 0,0,463,303,1,rgb(white),rgb(black)
           text 200,140,"You Won",l,5:pause 5000:exit do
         end if
       else  
         pixel cx(cm),cy(cm),rgb(yellow)
       end if
     end if  
   next cm
   
   pause 50
 loop
 
 goto start
Edited 2023-03-21 03:28 by stanleyella
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2134
Posted: 06:06pm 20 Mar 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  You can improve the ADC input by:

Fit a LM4040 3V3 shunt regulator between VREF and GND
OPTION VCC 3

The analogue inputs then read 0-3. The reduction in voltage reduces a lot of the noise on the supply lines as well as making the reference voltage more stable.


thanks. 3 pin and resistor. no idea. powering from 3.3v reg and ground 3.3v enable.5v powers the display.
Edited 2023-03-21 07:40 by stanleyella
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024