' 
' Written by Paul Grunewald (aka Stormy)
' Date: 07.28.2006
' Mail: Paul.Grunewald@gmail.com
'
#include "inc/2d_opengl.bi"

' Festlegung der Konstanten, die für den Bildschirm wichtig sind
const scrnX = 640
const scrnY = 480
const depth = 32
const fullscreen = &h0           ' Vollbildmodus ( &h0 = aus, &h1 = an )

DIM AS GFXType texture

' Initialisiere den Schirm
Init_ogl2D(scrnX, scrnY, depth, fullscreen)

glEnable GL_TEXTURE_2D						' Texturen erlauben.
load_texture ("resources/examples/space_hud.tga", texture)	' Lade eine Textur

WindowTitle "[ Clipping ]"

TYPE Player
 health_current AS INTEGER
 health_max AS INTEGER
 shield_current AS INTEGER
 shield_max AS INTEGER
 rockets_current AS INTEGER 
 rockets_max AS INTEGER 
END TYPE

DIM MyPlayer AS Player

With MyPlayer
 .health_current = 100
 .health_max = 100
 .shield_current = 50
 .shield_max = 250
 .rockets_current = 2
 .rockets_max = 5
End With

TYPE CoordsTex
 AS INTEGER X1, Y1, X2, Y2
END TYPE

DIM AS CoordsTex health_empty, health_full, shield_empty, shield_full, rockets_active, rockets_inactive

With shield_empty
 .X1 = 0: .Y1 = 0:  .X2 = 254: .Y2 = 46
End With
With shield_full
 .X1 = 0: .Y1 = 46:  .X2 = 254: .Y2 = 92
End With
With health_empty
 .X1 = 0: .Y1 = 92:  .X2 = 254: .Y2 = 138
End With
With health_full
 .X1 = 0: .Y1 = 138:  .X2 = 254: .Y2 = 184
End With
With rockets_active
 .X1 = 0: .Y1 = 207 :  .X2 = 24: .Y2 = 254
End With
With rockets_inactive
 .X1 = 25: .Y1 = 207:  .X2 = 49: .Y2 = 254
End With

DIM r AS INTEGER

do
  glCls  
  glColor3f 1,1,1
  With health_empty
   PutClip (texture, 20, 420, 0, .X1, .Y1, .X2, .Y2)
  End With
  With health_full
   PutClip (texture, 20, 420, 1, .X1, .Y1, .X1 + (255*(MyPlayer.health_current/MyPlayer.health_max)), .Y2)
  End With
  With shield_empty
   PutClip (texture, 280, 420, 0, .X1, .Y1, .X2, .Y2)
  End With
  With shield_full
   PutClip (texture, 280, 420, 1, .X1, .Y1, .X1 + (255*(MyPlayer.shield_current/MyPlayer.shield_max)), .Y2)
  End With
  
  FOR r = 1 TO MyPlayer.rockets_max
   IF MyPlayer.rockets_current >= r THEN 
    With rockets_active
    PutClip (texture, 10+(r-1)*50, 10, 0, .X1, .Y1, .X2, .Y2)
    End With   
   ELSE
    With rockets_inactive
    PutClip (texture, 10+(r-1)*50, 10, 0, .X1, .Y1, .X2, .Y2)
    End With      
   END IF
  NEXT r
  
  IF MULTIKEY(SC_UP) THEN
   IF MyPlayer.rockets_current < MyPlayer.rockets_max THEN MyPlayer.rockets_current += 1
  END IF

  IF MULTIKEY(SC_DOWN) THEN
   IF MyPlayer.rockets_current > 0 THEN MyPlayer.rockets_current -= 1
  END IF

  IF MULTIKEY(SC_RIGHT) THEN
    IF MyPlayer.health_current < MyPlayer.health_max THEN 
     MyPlayer.health_current+=1
    ELSE
    IF MyPlayer.shield_current < MyPlayer.shield_max THEN 
     MyPlayer.shield_current+=1
    END IF 
   END IF 
  END IF      

  IF MULTIKEY(SC_LEFT) THEN
    IF MyPlayer.shield_current > 0 THEN 
     MyPlayer.shield_current-=1
    ELSE
    IF MyPlayer.health_current > 0 THEN 
     MyPlayer.health_current-=1
    END IF 
   END IF 
  END IF      
   
  glFlush 
  flip 
  screensync
loop until multikey(SC_ESCAPE) ' Verlasse die Schleife sobald Escape gedrückt wird
