Results 1 to 1 of 1

Thread: Collision question with Print message

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Germany, Bad Sooden-Allendorf
    Rep Power

    Collision question with Print message

    Hey Petr

    I have a question If its possible in General to Print a Message During a Game is running Like a Word AS "collision"
    Just before or at the Same time when an object Hit another object Here laser weapon to obstacle... Or obstacles against space ship

    I am asking because I have a Pong Game (oxygen) and would Like to make a short Message that the ball Hits the Paddle in my example...

    How would you Insert this "collision" Message to your funspace Shooter Game?
    Thanks in advance Frank

      '=         Simple space shooter, one of the first thinBASIC games :)         =
      '=                                                                           =
      '=                           Petr Schreiber, 2007                            =
      #DEFAULT BOUNDCHECK OFF     ' -- For maximum speed
      Uses "TBGL"
      Dim i As Long
      Dim hWnd as dword
      ' Lasers
      type tLasers
        X     as double
        Y     as double
        Z     as double
        S     as double
      end type
      %NUMLASERS = 10
      Dim Laser(%NUMLASERS) As tLasers
      dim LaserIndex as long
      ' Obstacles to shoot
      type tObstacles
        X     as double
        Y     as double
        Z     as double
        S     as double  
      end type
      Dim Obstacle(%NUMOBSTACLES) As tObstacles
      ' Player
      Dim PlayerX, PlayerY As Single
      Dim FlameSize as single
      ' Speed control
      Dim FrameRate as double
      ' Game statistics
      Dim Score As Long, Life As Long, GameOver As Long, HitColl as long
      Life = 100
      %PLAYERSHIP = 1
      %WORMHOLE   = 2
      MsgBox hWnd, "Welcome to the Space Shooter game"+$CRLF+$CRLF+"You have to control the small space ship inside terrible wormhole"+$CRLF+"You have too shoot obstacles as well" _
                   +$CRLF+"Use ARROWS and SPACEBAR to move and shoot, to quit game push ESC", %MB_OK or %MB_ICONINFORMATION, "Space Shooter"
      hWnd = TBGL_CreateWindowex("Space Shooter - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED)   ' Let's create window
      TBGL_ShowWindow                     ' Shows the window
      TBGL_LoadBMPFont APP_SourcePath+"Textures\TBGL_Font.bmp", 30        ' This loads font
      TBGL_NewList %PLAYERSHIP            ' Using display lists we can get better performance
      TBGL_NewList %WORMHOLE
        TBGL_Color 0,0,64
        For i = 1 to 20                   ' The wormhole effect is quite complex, so "precaching" it using display list is wise
            TBGL_Translate sin(timer+i),cos(timer+i),-i*2
            TBGL_Rotate 90,1,0,0
            TBGL_Torus 0.8,5
      For i = 1 To %NUMOBSTACLES
      TBGL_LineWidth 3
      ' We declare the use of 2 lights
      TBGL_UseLightSource %GL_LIGHT0, %TRUE
      TBGL_UseLightSource %GL_LIGHT1, %TRUE
      TBGL_UseLighting %TRUE
      TBGL_ResetKeyState()        ' Resets key status before keypress checking
      while tbgl_IsWindow(hWnd)
          TBGL_PolygonLook iif(tbgl_GetWindowKeyState(hWnd, %VK_tab), %GL_LINE, %GL_FILL)
        '---Script will run on different PCs so we must assure
        '---constant speed of movement by scaling movement relative to framerate
        FrameRate = tbgl_GetFrameRate
       TBGL_ClearFrame             ' Prepares clear frame
       TBGL_Camera 0,0,5,0,0,0     ' Setups camera
        TBGL_PushMatrix              ' The wormhole is rotating...
          TBGL_Rotate GetTickCount/10,0,0,1
          TBGL_CallList %WORMHOLE
          TBGL_Translate PlayerX, PlayerY, 0
          TBGL_Rotate GetTickCount/20,0,0,-1
          TBGL_CallList %PLAYERSHIP 
          TBGL_Color rnd*255,rnd*128,0
          FlameSize = rnd
          TBGL_UseBlend %TRUE
          TBGL_Translate 0,0,FlameSize/2
          drawElipsoid 0.05+rnd*0.05,0.05+rnd*0.05,FlameSize
          TBGL_UseBlend %FALSE
        TBGL_SetupLightSource %GL_LIGHT1, Laser(LaserIndex).x, Laser(LaserIndex).y, Laser(LaserIndex).z, 128, 0, 0, 255
        TBGL_SetupLightSource %GL_LIGHT0, PlayerX+5, PlayerY+5, 0, 128, 128, 128, 255
        TBGL_UseBlend %TRUE
        TBGL_Color 255,255,0
        TBGL_PrintBMP "Score:"+FORMAT$(Score),0,0, %TBGL_ALIGN_LEFT_UP
        TBGL_PrintBMP "Life :"+FORMAT$(Life)+"%",0,1,%TBGL_ALIGN_LEFT_UP
        TBGL_PrintBMP "collision :"+FORMAT$(hitcoll)+"%",0,2,%TBGL_ALIGN_LEFT_UP
        TBGL_UseBlend %FALSE
        TBGL_DrawFrame                ' Swaps the buffers - displays rendered image
        ' Controls test
        if tbgl_GetWindowKeyState( hWnd, %VK_UP) then
          PlayerY = PlayerY + 2/FrameRate
          If PlayerY > 1.8 Then PlayerY = 1.8
        elseif tbgl_GetWindowKeyState( hWnd, %VK_DOWN) then
          PlayerY = PlayerY - 2/FrameRate
          If PlayerY < -1.8 Then PlayerY = -1.8
        end if
        if tbgl_GetWindowKeyState( hWnd, %VK_RIGHT) then
          PlayerX = PlayerX + 2/FrameRate
          If PlayerX > 2 Then PlayerX = 2
        elseif tbgl_GetWindowKeyState( hWnd, %VK_LEFT) then
          PlayerX = PlayerX - 2/FrameRate
          If PlayerX < -2 Then PlayerX = -2
        end if
        if tbgl_GetWindowKeyOnce( hWnd, %VK_SPACE) then Shoot()
        if tbgl_GetWindowKeyState( hWnd, %VK_ESCAPE) OR GameOver = 1 then EXIT WHILE
      TBGL_DestroyWindow                 ' Closes OpenGL window
      Function drawElipsoid( x as single, y as single, z as single ) as long
          TBGL_Scale x, y, z
          TBGL_Sphere 1
      End Function
      Function RenderShip() As Long
          TBGL_Color 128,128,128
          drawElipsoid 0.25, 0.3, 1
          TBGL_Translate 0,0,0.5
          TBGL_Color 128,0,0
          drawElipsoid 0.05,0.75,0.25
          TBGL_Rotate 90,0,0,1
          drawElipsoid 0.05,0.75,0.25
            TBGL_Translate 0,0,0.45
            TBGL_Rotate 90,1,0,0
            TBGL_Torus 0.02,0.1
      End Function
      ' Lasers
      Function Shoot() As Long
        INCR LaserIndex
        IF LaserIndex > %NUMLASERS THEN LaserIndex = 1
        Laser(LaserIndex).x = PlayerX
        Laser(LaserIndex).y = PlayerY
        Laser(LaserIndex).z = -1
        Laser(LaserIndex).s = 15
      End Function
      Function RenderLasers() As Long
        Local i, j As Long
        TBGL_Color 0,255,0
        For i = 1 TO %NUMLASERS
          If Laser(i).s = 0 Then Exit For
          Laser(i).z =Laser(i).z - Laser(i).s / FrameRate
            TBGL_Translate Laser(i).x, Laser(i).y, Laser(i).z
            TBGL_BeginPoly %GL_LINES
              TBGL_Vertex 0,0,0
              TBGL_Vertex 0,0,-1
           static flag as integer 
           flag = 5
          ' Very simple collison detection with the boxes
          For j = 1 to %NUMOBSTACLES
            'if not flag > 5 Then
    '        print "collision" 'only a short message to print above
            'end if 
            If Laser(i).x < Obstacle(j).x+1 And Laser(i).x > Obstacle(j).x-1 AND _
               Laser(i).z < Obstacle(j).z+1 And Laser(i).z > Obstacle(j).z-1 AND _
               Laser(i).y < Obstacle(j).y+1 And Laser(i).y > Obstacle(j).y-1 THEN
                 Score = Score + 100
            End If
      End Function
      Function InitObstacle( index As Long ) As Long
          Obstacle(index).x = rnd(-2,2)
          Obstacle(index).y = rnd(-2,2)
          Obstacle(index).z = rnd(-90,-100)
          Obstacle(index).s = rnd(5,7)
      End Function
      Function RenderObstacles() As Long
        Local i As Long
        TBGL_Color 128,0,0  
        For i = 1 To %NUMOBSTACLES
          Obstacle(i).z = Obstacle(i).z + Obstacle(i).s / FrameRate
          If Obstacle(i).z > 0 Then initObstacle(i)
          ' Very simple collison detection with the player
          If Obstacle(i).x < PlayerX+1 And Obstacle(i).x > PlayerX-1 AND _
             Obstacle(i).y < PlayerY+1 And Obstacle(i).y > PlayerY-1 AND _
             Obstacle(i).z > -2 THEN
               Life = Life - 10
               IF Life <= 0 Then GameOver = 1
          End If
            TBGL_Translate Obstacle(i).x, Obstacle(i).y, Obstacle(i).z
            TBGL_Rotate timer*100,1,1,1
            TBGL_Box 1,1,1
      End Function
    Last edited by Lionheart008; 12-02-2024 at 17:59.
    you can't always get what you want, but if you try sometimes you might find, you get what you need

Similar Threads

  1. Print preview
    By k1attila1 in forum Suggest new module
    Replies: 1
    Last Post: 29-01-2015, 02:40
  2. TBGL sprite collision; I want to tune the box2circle collision a bit
    By Michael Hartlef in forum TBGL module by Petr Schreiber
    Replies: 3
    Last Post: 31-07-2009, 23:36
  3. Print functionality
    By ErosOlmi in forum thinAir General
    Replies: 0
    Last Post: 17-10-2005, 16:55

Members who have read this thread: 3

Posting Permissions

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