Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:40 24 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 : tron game

Author Message
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2119
Posted: 11:10pm 19 Sep 2024
Copy link to clipboard 
Print this post

old tron game for ili9341. the gui touch areas are left right at the bottom of screen and up down right side of screen. 3 chasers tested pico 2

'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.
'
 OPTION EXPLICIT
 OPTION DEFAULT NONE
 OPTION DEFAULT INTEGER
 OPTION BASE 1 'arrays start at 1
 option autorun on
 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,199,80,40 ':line 0,239,80,239,rgb(blue)'left button
 gui area 2,140,199,80,40 ':line 140,239,220,239,rgb(blue)'right button
 gui area 3,279,40,40,80 ':line 319,40,319,120,rgb(blue)'up button
 gui area 4,279,159,40,80 ':line 319,179,319,239,rgb(blue)'down button

'draw direction buttons
 'triangle 2,312,66,305,66,319,rgb(yellow),1 'left button
 'triangle 192,312,130,305,130,319,rgb(yellow),1 'right button
 'triangle 471,112,479,180,464,180,rgb(yellow),1 'up button
 'triangle 471,300,479,236,464,236,rgb(yellow),1 'down button
 
do
'init players start positions
 px=260:py=rnd*120+60:pdx=-1:pdy=0
 cx(1)=rnd*100+80:cy(1)=50:cdx(1)=0:cdy(1)=1:cpa(1)=1
 cx(2)=rnd*100+80:cy(2)=190:cdx(2)=0:cdy(2)=-1:cpa(2)=1
 cx(3)=rnd*50+50:cy(3)=rnd*80+80:cdx(3)=1:cdy(3)=0:cpa(3)=1
 
'draw play area & 4 random triangles on border
 box 0,0,319,239,1,rgb(white),rgb(black)
 ts=rnd*160+40
 triangle 0,ts,12,ts+8,0,ts+16,rgb(White)
 ts=rnd*160+40
 triangle 319,ts,307,ts+8,319,ts+16,rgb(White)
 ts=rnd*240+40
 triangle ts,0,ts+8,10,ts+16,0,rgb(White)
 ts=rnd*240+40
 triangle ts,239,ts+8,228,ts+16,239,rgb(White)
 line 0,239,80,239,1,rgb(blue)'left button
 line 140,239,220,239,1,rgb(blue)'right button
 line 319,40,319,120,1,rgb(blue)'up button
 line 319,179,319,239,1,rgb(blue)'down button
 'main
 do
'check user button pressed
   tr=TOUCH(REF)
   if tr>0 then
     select case tr
       case 1 'left pressed
         if pdx=0 then pdy=0:pdx=-1
       case 2 'right pressed
         if pdx=0 then pdy=0:pdx=1
       case 3 'up pressed
         if pdy=0 then pdx=0:pdy=-1
       case 4 'down pressed
         if pdy=0 then pdx=0:pdy=1
     end select
   end if
   px=px+pdx:py=py+pdy
'has player crashed  
   if pixel (px,py) >0 then 'player crashed
     box 0,0,319,239,1,rgb(white),rgb(black)
     text 60,100,"You Lost",l,5:pause 5000:exit do
   end if
   pixel px,py,rgb(magenta)      
'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)
 'has computer player crashed      
       if pixel (cx(cm),cy(cm)) >0 then
         cpa(cm)=0'computer crashed
         if cpa(1)+cpa(2)+cpa(3)=0 then 'all crashed
           box 0,0,319,239,1,rgb(white),rgb(black)
           text 70,100,"You Won",l,5:pause 5000:exit do
         end if
       end if
         pixel cx(cm),cy(cm),rgb(yellow)
     end if  
   next cm
   
   pause 50
 loop
 
 loop



 
MarkF
Regular Member

Joined: 01/08/2023
Location: Australia
Posts: 47
Posted: 02:13am 20 Sep 2024
Copy link to clipboard 
Print this post

Cool game. Thanks for posting.
 
MarkF
Regular Member

Joined: 01/08/2023
Location: Australia
Posts: 47
Posted: 05:02am 27 Sep 2024
Copy link to clipboard 
Print this post

Hi all. I converted the Tron game for use on the PicoMiteVGA.

Added
- keyboard control
- instructions at the bottom
- made the game a bit easier (compdiff = computer difficulty).

'Tron ili9488
'By stanleyella
'PicoMiteVGA version by MarkF
'Keyboard control with arrow keys
'Added compdiff so that the computer players may crash

Option DEFAULT NONE
Option DEFAULT INTEGER
Option BASE 1 'arrays start at 1
'option autorun on
Dim px,py,pdx,pdy
Dim cx(3),cy(3),cdx(3),cdy(3),cpa(3)
Dim ts,tr,csc=0,psc=0,cm
Dim compdiff=85 'Computer players difficulty 100=hard 40=easy
Randomize Timer
MODE 2
CLS

Do
 'init players' start positions
 px=160:py=Rnd*120+60:pdx=-1:pdy=0
 cx(1)=Rnd*100+80:cy(1)=50:cdx(1)=0:cdy(1)=1:cpa(1)=1
 cx(2)=Rnd*100+80:cy(2)=190:cdx(2)=0:cdy(2)=-1:cpa(2)=1
 cx(3)=Rnd*50+50:cy(3)=Rnd*80+80:cdx(3)=1:cdy(3)=0:cpa(3)=1

 'screen setup
 Box 0,0,319,207,3,RGB(white),RGB(black)
 Text 5,210,"Blue = human : Red = computer",n,7,1,RGB(white)
 Text 5,220,"Use the arrow keys to change direction           ",n,7,1,RGB(white)

 'main
 Do
   'check user key pressed
   key$ = Inkey$
   Select Case Asc(key$)
     Case &H82     'left
       If pdx=0 Then pdy=0:pdx=-1
     Case &H83     'right
       If pdx=0 Then pdy=0:pdx=1
     Case &H80     'up
       If pdy=0 Then pdx=0:pdy=-1
     Case &H81     'down
       If pdy=0 Then pdx=0:pdy=1
   End Select
   px=px+pdx:py=py+pdy
   'has player crashed
   If Pixel(px,py) >0 Then 'player crashed
       Text 250,220,"YOU LOST",n,7,1,RGB(red):Pause 5000:Exit
   EndIf
   Pixel px,py,RGB(blue)
   '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
           If Int(Rnd*100) < compdiff Then
             cdx(cm)=0:cdy(cm)=(py>cy(cm))-(py<cy(cm))
           EndIf
         EndIf
       Else
         If Pixel(cx(cm),cy(cm)+cdy(cm)) >0 Then
           If Int(Rnd*100) < compdiff Then
             cdy(cm)=0:cdx(cm)=(px>cx(cm))-(px<cx(cm))
           EndIf
         EndIf
       EndIf
       cx(cm)=cx(cm)+cdx(cm):cy(cm)=cy(cm)+cdy(cm)
       'has computer player crashed
       If Pixel(cx(cm),cy(cm)) >0 Then
         cpa(cm)=0 'computer crashed
         If cpa(1)+cpa(2)+cpa(3)=0 Then 'all crashed
         Text 250,220,"YOU WON",n,7,1,RGB(blue):Pause 5000:Exit
         EndIf
       EndIf
       Pixel cx(cm),cy(cm),RGB(red)
     EndIf
   Next cm
   Pause 50
 Loop
Loop




Edited 2024-09-27 17:50 by MarkF
 
Print this page


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

© JAQ Software 2024