Results 1 to 7 of 7

Thread: image_synchronization (game)

  1. #1

    image_synchronization (game)

    here's a little kind of image synchronization game (not really), but it could be if there's more time to spend with it...

    a) try to cover the face of the woman on original image face zone and that's all if you near the target you will get an info.

    b) better to make a "pause" and try to get nearer with "step"s button ..

       ' Empty GUI script created on 09-18-2013 13:00:25 by largo_winch/maurice_fischer(thinAir)
     ' version 1
     
    
     Uses "UI", "console"
     Begin ControlID
       %MY_TIMER = 500               
       %pause    '= 300             
       %start    '= 400
       %continue '= 600                 
       %myCanvas '= 800              
       %btnClose '= 900
     End ControlID
     
    
     Global hDlg As Long, continue As Long
     
    
     Function TBMain () As Long                                      
        Dialog New Pixels, 0, "Image+Synchronize_Animation 1f",-1,-1, 460,400, %WS_OVERLAPPEDWINDOW To hDlg    
        Control Add Button, hDlg, %pause, "pause", 110,10,70,24
        Control Add Button, hDlg, %start, "step", 280,10,70,24
        Control Add Button, hDlg, %continue, "continue", 190,10,70,24
        Control Add Canvas, hDlg, %myCanvas, "", 10,40,440,350, %WS_BORDER
        Control Add Button, hDlg, %btnClose, "Click to close", 20,10,80,24 Call btnCloseProc      
        Canvas_Attach hDlg, %myCanvas,%TRUE                            
        Dialog Show Modal hDlg, Call DlgProc
     End Function
     
    
     CallBack Function DlgProc() As Long    
        Select Case CBMSG
           Case %WM_INITDIALOG                                          
                 Dialog Set Timer CBHNDL, %MY_TIMER, %pause : continue = 1             
           Case %WM_COMMAND
              Select Case CBCTL
                 Case %pause : continue = 0
                 Case %continue : continue = 1
                 Case %start : moveBoxImage()
              End Select
           Case %WM_TIMER
              If continue Then MoveBoxImage
              Dialog Set Text hDlg, "Image+Synchronize 1f  " + Time$
           Case %WM_DESTROY
              Dialog Kill Timer CBHNDL, %MY_TIMER
        End Select
     End Function
     
    
     Sub MoveBoxImage()
        Local x,y As Long                    
        Static vx As Double  
        Static vy As Double  
        Static yPush As Double
        Local sImageSmall As String = APP_SourcePath+ "woman1a.bmp"
        Local sImageBackground As String = APP_SourcePath+"woman1.bmp"
        Local nWidth, nHeight As Long   
        Canvas_BitmapGetFileInfo(sImageBackground, nWidth, nHeight)
        Canvas_Clear
        vx=Rnd(10,150)
        If vx=>69 And vx<=72 Then  
        'If vx=>87 And vx <=90 Then  
        Sleep 1500
        MsgBox 0,"x: near target "+Str$(vx)
        'sleep 1500
        End If
         
        vy=Rnd(10,150)
        If vy=>18 And vy <=21 Then  
        Sleep 1500
        MsgBox 0,"y: near target "+Str$(vy)
        End If     
         
        '--------------- target ------------------
        If vx=70 And vy=19 Then
        MsgBox 0, "you've won!"
        End If
        '--------------- target ------------------
         
        Canvas_BitmapRender(sImageBackground)                 
        Canvas_SetPos(vx,vy)    
             Canvas_Font "Comic Sans MS", 18, 0            
             Canvas_SetPos(vx,vy)
             Canvas_Scale Pixels                
             Canvas_Print ""+Str$(vx)+","+Str$(vy)
             Canvas_BitmapRender(sImageSmall)                 
             Canvas_Color(Rgb(255,10,100))                  
             Canvas_SetPos(20,320)
        '--------------------------------- simple box anima ------------------- >
     '   Canvas_SetPos(x,y)
     '   x = Rnd(40,300) : y = Rnd(40,210)   
     '   Canvas_Box (x,y, x+30,y+30,,%BLUE,%GREEN)                  
           Canvas_Redraw                                         
     End Sub
     
    
     CallBack Function btnCloseProc()
       If CBMSG = %WM_COMMAND Then
         If CBCTLMSG = %BN_CLICKED Then
           Dialog End CBHNDL
         End If
       End If
     End Function
    
    both images you can find in zip folder and *.tbasic example..

    bye, largo
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by largo_winch; 18-09-2013 at 17:55.

  2. #2

    infos

    ps: important: the "random factor" rules the imple holden "image-synch." example. I will make up my mind to give user more possibilities to rule or ship the image for covering at correct place to original image behind. the idea of this game was to fit one picture over another by approaching and because of seeing a lot of agency movies in cinema there's a few compatibility to really image-detection-software (for hitting or catching gangster for example) info ends.

    if you see a chance to improve the first edition of this game or give tipps I am happy to see it.

    bye, largo
    Last edited by largo_winch; 19-09-2013 at 10:53.

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    I like the concept of the game, but I think it looks like it plays itself currently.

    What about these modifications:

    • player has some budget of "energy points" on the begining
    • turn based gameplay - you can specify how many points you want to move horizontally and vertically
      • each such a move eats a bit of energy

    • if energy >= and image is matching => victory
    • if energy = 0 and image is not matching => failed


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    thanks petr, sounds good, I will improve the little game in such directions

    this edition: I have problem to update the "score" and the values should stay there but after running new randoms the score is again down at "O". I don't know why.

    only if you push "pause" and go with "step" button you earn the score and it's correct.

    thinbasic example:

       ' Empty GUI script created on 09-18-2013 13:00:25 by largo_winch/maurice_fischer(thinAir)
     ' version 1g
     
    
     Uses "UI", "console"
     #MINVERSION 1.8.8.0  
     
    
     Begin ControlID
       %MY_TIMER = 500               
       %pause     
       %start     
       %continue  
       %myCanvas  
       %btnClose  
       %score
       %ctimer
     End ControlID
     
    
     Global hDlg As Long, continue As Long
     
    
     Function TBMain () As Long                                      
        Dialog New Pixels, 0, "Image+Synchronize_Animation 1g",-1,-1, 460,400, %WS_OVERLAPPEDWINDOW To hDlg    
        Control Add Button, hDlg, %pause, "pause", 110,10,70,24
        Control Add Button, hDlg, %start, "step", 280,10,70,24
        Control Add Textbox, hDlg, %cTimer, "", 350,10,70,24, %WS_BORDER Or %WS_TABSTOP
        Control Add Button, hDlg, %continue, "continue", 190,10,70,24
        Control Add Canvas, hDlg, %myCanvas, "", 10,40,440,350, %WS_BORDER
        Control Add Button, hDlg, %btnClose, "Click to close", 20,10,80,24 Call btnCloseProc      
        Canvas_Attach hDlg, %myCanvas,%TRUE                            
       
        Dialog Show Modal hDlg, Call DlgProc
     End Function
     
    
     CallBack Function DlgProc() As Long    
        Local myTimer As cTimer
        myTimer = New cTimer()
        myTimer.Start
     
    
        Select Case CBMSG
           Case %WM_INITDIALOG                                          
                 Dialog Set Timer CBHNDL, %MY_TIMER, %pause : continue = 1                     
           Case %WM_COMMAND
              Select Case CBCTL
                 Case %pause : continue = 0
                 Case %continue : continue = 1
                 Case %start : moveBoxImage()
                 'Case %ctimer : ': continue = 1 :
                 'Control Set Text CBHNDL, %cTimer,"Time " + myTimer.ElapsedToString(%CTIMER_SECONDS, "#0.0000")                           
              End Select
           Case %WM_TIMER       
              If continue Then MoveBoxImage
              Dialog Set Text hDlg, "Image+Synchronize 1g  " + Time$
           Case %WM_DESTROY
              Dialog Kill Timer CBHNDL, %MY_TIMER
        End Select
     End Function
     
    
     Sub MoveBoxImage()
        Local x,y,level,score As Long                     
        Static vx As Double  
        Static vy As Double  
        Static yPush As Double
        Local sImageSmall As String = APP_SourcePath+ "woman1a.bmp"
        Local sImageBackground As String = APP_SourcePath+"woman1.bmp"
        Local nWidth, nHeight As Long                                          
        Local myTimer As cTimer
        myTimer = New cTimer()
        myTimer.Start
     
    
        score = 0
        level = 1  
        'GetAsyncKeyState(-1)
         
        Canvas_BitmapGetFileInfo(sImageBackground, nWidth, nHeight)
        Canvas_Clear
        vx=Rnd(10,150)
        If vx=>69 And vx<=72 Then  
        'If vx=>87 And vx <=90 Then  
        score += 10 : Beep  
        MsgBox 0,"x: near target "+Str$(vx)
        Sleep 150
        End If      
         
        vy=Rnd(10,150)
        If vy=>18 And vy <=21 Then     
        score += 10 : Beep  
        Sleep 150
        MsgBox 0,"y: near target "+Str$(vy)
        End If     
         
        '--------------- target ------------------
        If vx=70 And vy=19 Then
        MsgBox 0, "you've won!"
        score += 100 : Beep  
        End If
        '--------------- target ------------------
     
    
        Canvas_BitmapRender(sImageBackground)                 
        Canvas_SetPos(vx,vy)    
             Canvas_Font "Comic Sans MS", 12, 0            
             Canvas_SetPos(vx,vy)
             Canvas_Scale Pixels                
             Canvas_Print ""+Str$(vx)+","+Str$(vy)
             Canvas_BitmapRender(sImageSmall)                 
             Canvas_Color(Rgb(255,10,100))                  
             Canvas_SetPos(20,320)
              
             Canvas_Color %YELLOW, %BLACK   
             Canvas_SetPos(160, 320)   
             Canvas_Print(" Level " & level & "    Score " & score &  "    Time " & myTimer.ElapsedToString(%CTIMER_SECONDS, "#0.0000")) '"0"
             Canvas_Redraw                                         
     End Sub
     
    
     CallBack Function btnCloseProc()
       If CBMSG = %WM_COMMAND Then
         If CBCTLMSG = %BN_CLICKED Then
           Dialog End CBHNDL
         End If
       End If
     End Function
    
    you can run the example without loading the images.

    bye, largo
    Attached Images Attached Images
    Last edited by largo_winch; 21-09-2013 at 12:19.

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi,

    I think the issue is in fact you had score as local variable - it forgets its value after procedure ends.
    Second problem is that you assigned zero to score variable in each call.

    Just modifying the start of the routine this way will fix the issue:
    Sub MoveBoxImage()
       Local x,y,level As Long
       Static score As Long                    
       Static vx As Double 
       Static vy As Double 
       Static yPush As Double
       Local sImageSmall As String = APP_SourcePath+ "woman1a.bmp"
       Local sImageBackground As String = APP_SourcePath+"woman1.bmp"
       Local nWidth, nHeight As Long                                         
       Local myTimer As cTimer
       myTimer = New cTimer()
       myTimer.Start
     
       level = 1 
       'GetAsyncKeyState(-1)
         
       Canvas_BitmapGetFileInfo(sImageBackground, nWidth, nHeight)
    
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6

    random_modus (image-game)

    thanks petr for your "static" help!

    here's the final version of "robot" modus (self running).

    the user modus will come in next weeks or months.

       ' Empty GUI script created on 09-18-2013/09-26-2013 13:00:25 by largo_winch/maurice_fischer(thinAir)
    
     ' version 1kk
    
     
    
     Uses "UI" ', "console"
     #MINVERSION 1.8.8.0  
     
    
     Begin ControlID
       %MY_TIMER = 500               
       %pause     
       %start     
       %continue  
       %myCanvas  
       %btnClose  
       %score                              
       %energy=150
       %ctimer
     End ControlID
     
    
     Global hDlg As Long, continue As Long
     
    
     Function TBMain () As Long                                      
        Dialog New Pixels, 0, "Image+Synchronize_Animation 1k",-1,-1, 460,400, %WS_OVERLAPPEDWINDOW To hDlg    
        Control Add Button, hDlg, %pause, "pause", 110,10,70,24
        Control Add Button, hDlg, %start, "step", 280,10,70,24
        Control Add Textbox, hDlg, %energy, "energy_55%", 350,10,90,24, %WS_BORDER Or %WS_TABSTOP
        Control Set Color, hDlg,%energy,Rgb(0,0,0),Rgb(250,0,0)
        Control Add Button, hDlg, %continue, "continue", 190,10,70,24
        Control Add Canvas, hDlg, %myCanvas, "", 10,40,440,350, %WS_BORDER
        Control Add Button, hDlg, %btnClose, "Click to close", 20,10,80,24 Call btnCloseProc      
        Canvas_Attach hDlg, %myCanvas,%TRUE                            
       
        Dialog Show Modal hDlg, Call DlgProc
     End Function
     
    
     CallBack Function DlgProc() As Long    
        Static myTimer As cTimer
        myTimer = New cTimer()
        myTimer.Start
     
    
        Select Case CBMSG
           Case %WM_INITDIALOG                                          
                 Dialog Set Timer CBHNDL, %MY_TIMER, %pause : continue = 1                     
           Case %WM_COMMAND
              Select Case CBCTL
                 Case %pause : continue = 0
                 Case %continue : continue = 1
                 Case %start : moveBoxImage()
              End Select
           Case %WM_TIMER       
              If continue Then MoveBoxImage
              Dialog Set Text hDlg, "Image+Synchronize 1k  " + Time$
           Case %WM_DESTROY
              Dialog Kill Timer CBHNDL, %MY_TIMER
        End Select
     End Function
     
    
     Sub MoveBoxImage()
        Local x,y,gameover As Long 'level,
        Static level As Long
        Static score As Long                   
        Static energy As Long  
        Static vx As Double
        Static vy As Double
        Static yPush As Double
        Local sImageSmall As String = APP_SourcePath+ "woman1a.bmp"
        Local sImageBackground As String = APP_SourcePath+"woman1.bmp"
        Local nWidth, nHeight As Long                                         
        'Local myTimer As cTimer
        Static myTimer As cTimer
        myTimer = New cTimer()
        myTimer.Start
        
        level = 1                      
        'GetAsyncKeyState(-1)
            
        Canvas_BitmapGetFileInfo(sImageBackground, nWidth, nHeight)
        Canvas_Clear    
           
        vx=Rnd(10,150)
        If vx=>68 And vx<=72 Then  
        energy+=5 'energy=energy-15  
        'score+=10  
        Score =score+10*level  
        level = Int(score/10+1)
        Control Set Text, hDlg, %energy,"energy_lost: "+Format$(energy)       
        MsgBox 0,"x: near target "+Str$(vx)                        
        Sleep 150
        End If                                                     
         
        If energy >= 55 And vx => 68 Then
        Control Set Text, hDlg, %energy,"%energy_lost: "+Format$(energy)
        Dialog Kill Timer hDlg, %MY_TIMER
        MsgBox 0, "energy lost, game_over"
        Dialog End hDlg                                              
        End If
             
        vy=Rnd(10,150)
        If vy=>18 And vy <=22 Then     
        score+=10  
        energy+=5
        level = Int(score/10+1)
        Control Set Text, hDlg, %energy,"energy_lost: "+Format$(energy)
        Sleep 150
        MsgBox 0,"y: near target "+Str$(vy)
        End If     
         
        If energy >= 55 And vy => 18 Then
        Control Set Text, hDlg, %energy,"energy_lost: "+Format$(energy)
        Dialog Kill Timer hDlg, %MY_TIMER
        MsgBox 0, "energy lost, game_over"
        Dialog End hDlg
        End If
         
        '--------------- target ------------------
        If vx=70 And vy=19 Then
        MsgBox 0, "you've won!"
        score += 100 : Beep  
        energy+= 100 : Beep  
        End If
        '--------------- target ------------------
         
        If myTimer.Elapsed(%CTIMER_SECONDS) >= 0.880 Then
           MsgBox 0, "times-Up, you have Level " & level & "  Score of " & score       
         End If      
         
        If GetAsyncKeyState(%VK_ESCAPE) Then 
         Dialog End hDlg
        End If
         
        Canvas_BitmapRender(sImageBackground)                 
        Canvas_SetPos(vx,vy)    
             Canvas_Font "Comic Sans MS", 12, 0            
             Canvas_SetPos(vx,vy)
             Canvas_Scale Pixels                
             Canvas_Print ""+Str$(vx)+","+Str$(vy)
             Canvas_BitmapRender(sImageSmall)                 
             Canvas_Color(Rgb(255,10,100))                  
             Canvas_SetPos(20,320)         
             Canvas_Color %YELLOW, %BLACK   
             Canvas_SetPos(60, 320)   
             Canvas_Print(" Level " & level & "    Score " & Format$(score) &  "    Time " & myTimer.ElapsedToString(%CTIMER_SECONDS, "#0.0000")) '"0"    
             Canvas_Redraw                                                 
     End Sub
     
    
     CallBack Function btnCloseProc()
       If CBMSG = %WM_COMMAND Then
         If CBCTLMSG = %BN_CLICKED Then
           Dialog End CBHNDL
         End If
       End If
     End Function
    
    bye, largo
    Last edited by largo_winch; 07-10-2013 at 20:34.

  7. #7
    here's a simple "countdown" feature for my game. push "countdown" button and than 25 seconds the robot modus will play. If you want to have another countdown you can type it into textbox right top. that's all. if you want to test this version an exe file is included in zip file.

    bye, largo
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. Game: UFO on the run
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 19
    Last Post: 27-10-2008, 21:59
  2. Game: Game modes
    By Michael Hartlef in forum CM contest 2009
    Replies: 16
    Last Post: 05-10-2008, 04:58
  3. Fun game
    By Michael Clease in forum Gaming
    Replies: 4
    Last Post: 02-06-2008, 07:21
  4. lights out game
    By sandyrepope in forum General
    Replies: 9
    Last Post: 13-12-2007, 07:59
  5. A little but very serious game in 96k
    By ErosOlmi in forum Gaming
    Replies: 3
    Last Post: 12-05-2007, 20:24

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •