def main(): hge = _hge.HGE(_hge.HGE_VERSION) quad = None sprite = None # use list, because scope problem radians = [0] x = [100] y = [100] def frameFunc(): if hge.Input_GetKeyState(_hge.HGEK_ESCAPE): return True v = 0.5 if hge.Input_GetKeyState(_hge.HGEK_UP): for i in range(4): y[0] -= v if hge.Input_GetKeyState(_hge.HGEK_DOWN): for i in range(4): y[0] += v if hge.Input_GetKeyState(_hge.HGEK_LEFT): for i in range(4): x[0] -= v if hge.Input_GetKeyState(_hge.HGEK_RIGHT): for i in range(4): x[0] += v radians[0] += math.pi/720 return False def renderFunc(): # Begin rendering quads. # This function must be called # before any actual rendering. hge.Gfx_BeginScene(0); # Clear screen with black color hge.Gfx_Clear(0); # Render quads here. This time just # one of them will serve our needs. hge.Gfx_RenderQuad(quad); sprite.RenderEx(x[0], y[0], radians[0], 1.0, 0.0) # End rendering and update the screen hge.Gfx_EndScene(); return False hge.System_SetStateFunc(_hge.HGE_FRAMEFUNC, frameFunc); hge.System_SetStateFunc(_hge.HGE_RENDERFUNC, renderFunc); hge.System_SetStateString( _hge.HGE_TITLE, "TEST") hge.System_SetStateBool(_hge.HGE_WINDOWED, True); if hge.System_Initiate(): # load texture import os texture = hge.Texture_Load(os.path.abspath("yuki.jpg"), 0, False) if not texture: print hge.System_GetErrorMessage() blend = _hge.BLEND_ALPHAADD | _hge.BLEND_COLORMUL | _hge.BLEND_ZWRITE v0 = _hge.hgeVertex(0, 0, 0, 0xFFFFA000, 0, 0) v1 = _hge.hgeVertex(200, 0, 0, 0xFFFFA000, 1, 0) v2 = _hge.hgeVertex(200, 200, 0, 0xFFFFA000, 1, 1) v3 = _hge.hgeVertex(0, 200, 0, 0xFFFFA000, 0, 1) quad = _hge.hgeQuad((v0, v1, v2, v3), texture, blend) w = hge.Texture_GetWidth(texture, False) h = hge.Texture_GetHeight(texture, False) sprite = _hge.hgeSprite(texture, 0, 0, w, h) sprite.SetHotSpot(w*0.5, h*0.5) if not hge.System_Start(): print hge.System_GetErrorMessage() else: print hge.System_GetErrorMessage() hge.System_Shutdown() hge.Release()
def main(): global hge, spr, bgSpr hge = _hge.HGE(_hge.HGE_VERSION); hge.System_SetStateFunc(_hge.HGE_FRAMEFUNC, frameFunc) hge.System_SetStateFunc(_hge.HGE_RENDERFUNC, renderFunc) hge.System_SetStateString( _hge.HGE_TITLE, "HGE Tutorial 07 - Thousand of Hares") hge.System_SetStateBool(_hge.HGE_USESOUND, False) hge.System_SetStateBool(_hge.HGE_WINDOWED, True) hge.System_SetStateInt(_hge.HGE_SCREENWIDTH, SCREEN_WIDTH) hge.System_SetStateInt(_hge.HGE_SCREENHEIGHT, SCREEN_HEIGHT) hge.System_SetStateInt(_hge.HGE_SCREENBPP, 32) if hge.System_Initiate(): # Load textures bgtex = hge.Texture_Load(os.path.abspath("bg2.png"), 0, False) tex = hge.Texture_Load(os.path.abspath("zazaka.png"), 0, False) if not bgtex or not tex: # If one of the data files is not found, # display an error message and shutdown print "Can't load BG2.PNG or ZAZAKA.PNG" hge.System_Shutdown() hge.Release() return # Load font, create sprites spr = _hge.hgeSprite(tex, 0, 0, 64, 64) spr.SetHotSpot(32, 32) bgSpr = _hge.hgeSprite(bgtex, 0, 0, 800, 600) bgSpr.SetBlendMode( _hge.BLEND_COLORADD | _hge.BLEND_ALPHABLEND | _hge.BLEND_NOZWRITE) bgSpr.SetColor(0xFF000000, 0) bgSpr.SetColor(0xFF000000, 1) bgSpr.SetColor(0xFF000040, 2) bgSpr.SetColor(0xFF000040, 3) # Initialize objects list for i in range(MAX_OBJECTS): objects.append(SprObject()) objects[i].x = hge.Random_Float(0, SCREEN_WIDTH) objects[i].y = hge.Random_Float(0, SCREEN_HEIGHT) objects[i].dx = hge.Random_Float(-200, 200) objects[i].dy = hge.Random_Float(-200, 200) objects[i].scale = hge.Random_Float(0.5, 2.0) objects[i].dscale = hge.Random_Float(-1.0, 1.0) objects[i].rot = hge.Random_Float(0, math.pi*2) objects[i].drot = hge.Random_Float(-1.0, 1.0) SetBlend(0) # Let's rock now! hge.System_Start() # Delete created objects and free loaded resources hge.Texture_Free(tex) hge.Texture_Free(bgtex) # Clean up and shutdown hge.System_Shutdown() hge.Release()