Code: Select all
; To create a debug log (file: GS2D_DEBUG.LOG)
; remove the rem of the following constant
;#__DEBUG__ = 0
#SCREEN_Width = 320
#SCREEN_Height = 240
#SPR_MAP_LVL1_HEIGHT = 32 ;Sprites Heigh for MAP Level1
#SPR_MAP_LVL1_WIDTH = 32 ;Heigh Width fo MAP Level1
#NB_CHAR_BY_LINE = 28 ;28 Char by Line inside Font Image
;*** 31/07/2013
;FPS Manager
XIncludeFile "FPS_Manager.pbi"
;**************
;Lib Sprites and Layers
XIncludeFile "GLMFS2D.pbi"
; Next MUST be after the include because the constant #GLMFS_FREQ_MIN
; is declared in GLMFS2D.pbi
Enumeration #GLMFS_FREQ_MIN
#SEQWATER
#SEQFIRE
EndEnumeration
; XIncludeFile
; ***********
;-** Datas **
; ***********
DataSection
;Fonts
DS_IMG_Font_GOBLINS: : IncludeBinary "IMG_FONT_G&G.png"
DS_IMG_Font_APPLE: : IncludeBinary "IMG_FONT_APPLE.png"
;Some sprites
DS_SpriteZombies: : IncludeBinary "GNG_Zombies.png"
DS_SpriteLvl1: : IncludeBinary "GNG_MAP_Sprite_Lvl01.png"
;Define the layers
DS_Layers_Lvl1:
Data.i 5 ;LayerTotal
Data.i 20,15 ;MapWidth x MapHeight
Data.i #SPR_MAP_LVL1_HEIGHT,#SPR_MAP_LVL1_WIDTH ;Sprite Width x Sprite Height
Data.s "BACKGROUND_MOUNTAIN" ;Layer's name
Data.i 00,00,00,00,00,72,73,00,72,74 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,75,76,00,75,77 , 78,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,79,80,81,83,84,81 , 85,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.s "BACKGROUND_YARD"
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 63,63,10,63,20,11,63,64,00,00 , 00,00,00,00,65,63,63,63,63,63
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.s "PLAYER_LAYER"
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 24,24,24,24,24,24,66,67,00,68 , 69,00,00,00,70,66,24,24,24,24
Data.i 71,71,71,71,71,71,71,00,00,00 , 00,00,00,00,00,71,71,71,71,71
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.s "FORGROUND_LAYER"
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 102,101,102,101,102,101,102,00,00,00 , 00,00,00,00,00,102,101,102,101,102
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.s "SEQUENCE"
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
;Add the #SEQWATER for the animated sprites in the layer
Data.i 00,00,00,00,00,00,00,#SEQWATER,#SEQWATER,#SEQWATER , #SEQWATER,#SEQWATER,#SEQWATER,#SEQWATER,#SEQWATER,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
Data.i 00,00,00,00,00,00,00,00,00,00 , 00,00,00,00,00,00,00,00,00,00
EndDataSection
#SPR_ZOMBIE_HEIGHT = 66 ;Height zombie sprite
#SPR_ZOMBIE_WIDTH = 46 ;Width zombie sprite
#SPEED_ZOMBIE = 1 ;Speed of the walking zombie
; ********************
;-** FONT Constants **
; ********************
; GOBLINS : 16x16
#FONT_GNG_WIDTH = 16
#FONT_GNG_HEIGHT = 16
; APPLE : 6x8
#FONT_APPLE_WIDTH = 6
#FONT_APPLE_HEIGHT = 8
; ----------------------------
;- *** Main ******************************
GS2D_Init(#SCREEN_Width, #SCREEN_Height)
Global.i ImgFontGNG, ImgFontAPPLE
Global.i FontGNG_White, FontGNG_Black, FontGNG_Grey, FontGNG_Red, FontGNG_Green, FontGNG_Blue, FontGNG_Red, FontGNG_Yellow
Global.i FontAPPLE_White, FontAPPLE_Black, FontAPPLE_Grey, FontAPPLE_Red, FontAPPLE_Green, FontAPPLE_Blue, FontAPPLE_Red, FontAPPLE_Yellow
Global.i ImGSpriteZombies, SprAnimZombie1, SprAnimZombie2, SprAnimZombie3
Global.i ImgMapLvl1, Water
Global.i PosX_Zombie1, CurFrameZombie3
Global.i refreshrate
Global.i POSX = 0, POSY = 0
;*** 31/07/2013
; FPS
Global fps.FPSObject
Global rate.i, time_passed.i
;**************
Global.i Event, Quit = 0
If OpenWindow(0, 0, 0, #SCREEN_Width, #SCREEN_Height, "Test Anim Sprite lib GS2D V"+#GLMFS_VERSION, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
If OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 1, 0, 0);, #PB_Screen_NoSynchronization)
ExamineDesktops()
;Loading fonts
ImgFontGNG = GS2D_CatchFont(?DS_IMG_Font_GOBLINS, "GOBLINS", #FONT_GNG_WIDTH, #FONT_GNG_HEIGHT, #NB_CHAR_BY_LINE, $FF00FF)
ImgFontAPPLE = GS2D_CatchFont(?DS_IMG_Font_APPLE, "APPLE", #FONT_APPLE_WIDTH, #FONT_APPLE_HEIGHT, #NB_CHAR_BY_LINE)
; Create sprite sheets
ImGSpriteZombies = GS2D_CatchAnimSprite(?DS_SpriteZombies, "ZOMBIE", #SPR_ZOMBIE_WIDTH, #SPR_ZOMBIE_HEIGHT, 18, $FF00FF)
ImgMapLvl1 = GS2D_CatchAnimSprite(?DS_SpriteLvl1, "MAP01", #SPR_MAP_LVL1_WIDTH, #SPR_MAP_LVL1_HEIGHT, 104, $FF00FF)
;or
;ImgMapLvl1 = GS2D_LoadAnimSprite("GNG_MAP_Sprite_Lvl01.png","MAP01", #SPR_MAP_LVL1_WIDTH, #SPR_MAP_LVL1_HEIGHT, 104, $FF00FF)
;Create the layer after the sprite
If ImgFontGNG And ImGSpriteZombies And ImgMapLvl1 And GS2D_CreateLayers("MAP01", ?DS_Layers_Lvl1)
;Create font yellow and red
FontGNG_Yellow = GS2D_CreateFontColor(ImgFontGNG, $00CCEE)
FontGNG_Red = GS2D_CreateFontColor(ImgFontGNG, $0000FF)
;And change the size of the red font
GS2D_ResizeFont(ImgFontGNG, FontGNG_Red, 8)
FontAPPLE_Green = GS2D_CreateFontColor(ImgFontAPPLE, $00FF00)
FontAPPLE_Grey = GS2D_CreateFontColor(ImgFontAPPLE, $808080)
;Change the size of the green font
GS2D_ResizeFont(ImgFontAPPLE, FontAPPLE_Green, 12)
;Create our animation from our sprite sheet
SprAnimZombie1 = GS2D_CreateAnimSprite(#PB_Any, "ZOMBIE", 7, 9, 400)
SprAnimZombie2 = GS2D_CreateAnimSprite(#PB_Any, "ZOMBIE", 16, 18, 400)
SprAnimZombie3 = GS2D_CreateAnimSprite(#PB_Any, "ZOMBIE", 1, 7, 1000, -1)
Water = GS2D_CreateAnimSprite(#PB_Any, "MAP01", 86, 88)
;Create an animation sequence for the sprite 'water"
GS2D_CreateSequence(#SEQWATER, water)
PosX_Zombie1 = Random(#SCREEN_Width-#SPR_ZOMBIE_WIDTH-3*32)
;*** 31/07/2013
; Manage FPS
time_passed = 0
fps = FPS_initFramerate()
rate = fps\FPS_getFramerate()
fps\FPS_setFramerate(60)
;**************
Repeat
Repeat
Event = WaitWindowEvent(5)
Select Event
Case #PB_Event_Gadget
If EventGadget() = 0
quit = 1
EndIf
Case #PB_Event_CloseWindow
quit = 1
EndSelect
Until Event = 0
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape) : quit = 1 : EndIf
If KeyboardPushed(#PB_Key_Left) : If POSX > 0 : POSX - 5 : EndIf : EndIf
If KeyboardPushed(#PB_Key_Right) : If POSX < (GSLayer()\MapWidth * #SPR_MAP_LVL1_WIDTH) - #SCREEN_Width : POSX + 5 : EndIf : EndIf
If KeyboardPushed(#PB_Key_Up) : If POSY > 0 : POSY - 5 : EndIf : EndIf
If KeyboardPushed(#PB_Key_Down) : If POSY < (GSLayer()\MapHeight * #SPR_MAP_LVL1_HEIGHT) - #SCREEN_Height : POSY + 5 : EndIf : EndIf
FlipBuffers()
ClearScreen(0)
; ---------------
;Display the layers in the correct order
GS2D_DrawLayer("BACKGROUND_MOUNTAIN",POSX/3,POSY/3)
GS2D_DrawLayer("BACKGROUND_YARD",POSX,POSY)
GS2D_DrawLayer("PLAYER_LAYER",POSX,POSY)
; ---------------
;Zombies
GS2D_DrawAnimSprite(SprAnimZombie2, 10, 5*32-#SPR_ZOMBIE_HEIGHT)
CurFrameZombie3 = GS2D_DrawAnimSprite(SprAnimZombie3, PosX_Zombie1, 5*32-#SPR_ZOMBIE_HEIGHT)
If CurFrameZombie3 = 7 And NextSprite = #False
GS2D_RemoveAnimSprite(SprAnimZombie3, #True)
NextSprite = #True
ElseIf NextSprite = #True
GS2D_DrawAnimSprite(SprAnimZombie1, PosX_Zombie1, 5*32-#SPR_ZOMBIE_HEIGHT)
PosX_Zombie1 + #SPEED_ZOMBIE
If PosX_Zombie1 > #SCREEN_Width And CurFrameZombie3 = 7 : PosX_Zombie1 = Random(#SCREEN_Width-#SPR_ZOMBIE_WIDTH-3*32) : NextSprite = #False : GS2D_RemoveAnimSprite(SprAnimZombie3, #False) : EndIf
EndIf
GS2D_DrawLayer("FORGROUND_LAYER",POSX,POSY)
GS2D_DrawLayer("SEQUENCE",POSX,POSY)
GS2D_DrawText(ImgFontGNG,0,224,"Hz:", FontGNG_Yellow)
GS2D_DrawText(ImgFontGNG,80,224,"FPS:", FontGNG_Yellow)
GS2D_DrawText(ImgFontGNG,145,228,Str(GS2D_GetFPS()), FontGNG_Red)
;*** 31/07/2013
If time_passed > 0
GS2D_DrawText(ImgFontGNG,50,228,Str(1000/time_passed), FontGNG_Red)
EndIf
GS2D_DrawText(ImgFontAPPLE,#SCREEN_Width-(GS2D_GetCharWidth(ImgFontAPPLE, FontAPPLE_Grey)*Len("Framerate: "+Str(fps\FPS_getFramerate()))),232, "Framerate: "+Str(fps\FPS_getFramerate()), FontAPPLE_Grey)
;**************
;A little advertisement for me :)
GS2D_DrawText(ImgFontAPPLE, Random(#SCREEN_Width-(GS2D_GetCharWidth(ImgFontAPPLE, FontAPPLE_Green)*Len("(c)Flaith 2012-2013"))), Random(#SCREEN_Height-(GS2D_GetCharHeight(ImgFontAPPLE, FontAPPLE_Green))), "(c)Flaith 2012-2013", FontAPPLE_Green)
; ---------------
;*** 31/07/2013
time_passed = fps\FPS_framerateDelay()
;**************
Until Quit = 1
GS2D_DEBUGLOG("END LOG---")
Else
;Error: Sprites not created
GS2D_DEBUGLOG("Cannot create sprites !!!")
End
EndIf
Else
;Error: Cannot create screen
GS2D_DEBUGLOG("Cannot open the screen !!!")
End
EndIf
EndIf