UseJPEGImageDecoder() UseJPEGImageEncoder() UsePNGImageDecoder() UsePNGImageEncoder() IncludePath "Includes" XIncludeFile "UBE.pbi" ;XIncludeFile "UBE Import.pbi" Enumeration 1 #SPRITE_GRASS #SPRITE_BOX #SPRITE_TANK #SPRITE_TANKWEAPON #SPRITE_BULLET EndEnumeration #FieldSize = 80 Structure Field Terrain.i Object.i EndStructure Structure Player X.f Y.f Rotation.f Velocity.f Color.i Light.i EndStructure Structure Bullet X.f Y.f Rotation.f Velocity.f Light.i EndStructure Structure Level Width.i Height.i Array Field.Field(0) List Player.Player() List Bullet.Bullet() EndStructure Procedure.i LevelField(*Level.Level, X.i, Y.i) ProcedureReturn *Level\Field(*Level\Width*Y+X) EndProcedure Procedure CreateLevel(*Level.Level, Width.i, Height.i) Protected Field.i, LastField.i, Player.i With *Level ClearStructure(*Level, Level) InitializeStructure(*Level, Level) \Width = Width \Height = Height LastField = Height*Width-1 Dim \Field(LastField) For Field = 0 To LastField \Field(Field)\Terrain = #SPRITE_GRASS Select Field Case 26, 27, 28, 31, 32, 33 \Field(Field)\Object = #SPRITE_BOX Case 74, 75, 76, 79, 80, 81 \Field(Field)\Object = #SPRITE_BOX EndSelect Next EndWith EndProcedure Procedure AddPlayer(*Level.Level, X.f, Y.i, Color.i, Rotation.f) AddElement(*Level\Player()) With *Level\Player() \X = X \Y = Y \Color = Color \Rotation = Radian(Rotation) \Light = UBE_CreateLight(#PB_Any, X, Y) UBE_SetLightColor(\Light, Color) UBE_SetLightIntensity(\Light, 0.4) EndWith ProcedureReturn *Level\Player() EndProcedure Procedure AddBullet(*Level.Level, *Player.Player) AddElement(*Level\Bullet()) With *Level\Bullet() \X = *Player\X + Sin(*Player\Rotation)*#FieldSize*0.4 \Y = *Player\Y - Cos(*Player\Rotation)*#FieldSize*0.4 \Rotation = *Player\Rotation \Velocity = 11.0 \Light = UBE_CreateLight(#PB_Any, \X, \Y) UBE_SetLightColor(\Light, $80E0FF) UBE_SetLightIntensity(\Light, 1) EndWith ProcedureReturn *Level\Player() EndProcedure Procedure DisplayLevel(*Level.Level) Protected X.i, Y.i For Y = 0 To *Level\Height-1 For X = 0 To *Level\Width-1 With *Level\Field(*Level\Width*Y+X) If \Terrain UBE_DisplaySprite(\Terrain, #FieldSize*0.5+X*#FieldSize, #FieldSize*0.5+Y*#FieldSize) EndIf If \Object UBE_DisplaySprite(\Object, #FieldSize*0.5+X*#FieldSize, #FieldSize*0.5+Y*#FieldSize) EndIf EndWith Next Next ForEach *Level\Player() With *Level\Player() \X + Sin(\Rotation)*\Velocity \Y - Cos(\Rotation)*\Velocity UBE_SetLightPosition(\Light, \X, \Y) UBE_SetSpriteRotation(#SPRITE_TANK, Degree(\Rotation)) UBE_DisplaySprite(#SPRITE_TANK, \X, \Y) UBE_SetSpriteRotation(#SPRITE_TANKWEAPON, Degree(\Rotation)) UBE_DisplaySprite(#SPRITE_TANKWEAPON, \X, \Y) EndWith Next ForEach *Level\Bullet() With *Level\Bullet() \X + Sin(\Rotation)*\Velocity \Y - Cos(\Rotation)*\Velocity UBE_SetLightPosition(\Light, \X, \Y, 64) UBE_SetSpriteRotation(#SPRITE_BULLET, Degree(\Rotation)) UBE_DisplaySprite(#SPRITE_BULLET, \X, \Y) If \X < -#FieldSize*2 Or \Y < -#FieldSize*2 Or \X > (*Level\Width+2)*#FieldSize Or \Y > (*Level\Height+2)*#FieldSize UBE_FreeLight(\Light) DeleteElement(*Level\Bullet()) ElseIf \X >= 0 And \Y >= 0 And \X < *Level\Width*#FieldSize And \Y < *Level\Height*#FieldSize And *Level\Field(*Level\Width*Int(\Y/#FieldSize)+Int(\X/#FieldSize))\Object UBE_FreeLight(\Light) DeleteElement(*Level\Bullet()) EndIf EndWith Next EndProcedure Define Level.Level CreateLevel(@Level, 12, 9) Define *MyPlayer.Player = AddPlayer(@Level, #FieldSize, #FieldSize, $FFFF8000, 135) AddPlayer(@Level, 11*#FieldSize, 8*#FieldSize, $FF8000FF, 315) UBE_OpenWindow(960, 720, 32, "Moving", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) UBE_InitShader() UBE_CreateSprite(#SPRITE_GRASS, UBE_LoadTexture(#PB_Any, "Media\Grass 001.png")) UBE_SetSpriteTexture(#SPRITE_GRASS, 1, UBE_LoadTexture(#PB_Any, "Media\Grass 001 nm.png")) UBE_SetSpriteShader(#SPRITE_GRASS, #UBE_SPRITESHADER_NORMALMAP) UBE_SetSpriteShine(#SPRITE_GRASS, 1.0) UBE_ZoomSprite(#SPRITE_GRASS, #FieldSize, #FieldSize) UBE_CreateSprite(#SPRITE_BOX, UBE_LoadTexture(#PB_Any, "Media\Box.png")) UBE_SetSpriteTexture(#SPRITE_BOX, 1, UBE_LoadTexture(#PB_Any, "Media\Box nm.png")) UBE_SetSpriteShader(#SPRITE_BOX, #UBE_SPRITESHADER_NORMALMAP) UBE_SetSpriteShine(#SPRITE_BOX, 1.0) UBE_ZoomSprite(#SPRITE_BOX, #FieldSize, #FieldSize) UBE_CreateSprite(#SPRITE_TANK, UBE_LoadTexture(#PB_Any, "Media\Tank.png")) UBE_SetSpriteTexture(#SPRITE_TANK, 1, UBE_LoadTexture(#PB_Any, "Media\Tank nm.png")) UBE_SetSpriteShader(#SPRITE_TANK, #UBE_SPRITESHADER_NORMALMAP) UBE_SetSpriteShine(#SPRITE_TANK, 1.0) UBE_ZoomSprite(#SPRITE_TANK, #FieldSize, #FieldSize) UBE_CreateSprite(#SPRITE_TANKWEAPON, UBE_LoadTexture(#PB_Any, "Media\Tank Weapon.png")) UBE_SetSpriteTexture(#SPRITE_TANKWEAPON, 1, UBE_LoadTexture(#PB_Any, "Media\Tank Weapon nm.png")) UBE_SetSpriteShader(#SPRITE_TANKWEAPON, #UBE_SPRITESHADER_NORMALMAP) UBE_SetSpriteShine(#SPRITE_TANKWEAPON, 1.0) UBE_ZoomSprite(#SPRITE_TANKWEAPON, #FieldSize, #FieldSize) UBE_CreateSprite(#SPRITE_BULLET, UBE_LoadTexture(#PB_Any, "Media\Sphere.png")) UBE_SetSpriteTexture(#SPRITE_BULLET, 1, UBE_LoadTexture(#PB_Any, "Media\Sphere nm.png")) UBE_SetSpriteShader(#SPRITE_BULLET, #UBE_SPRITESHADER_NORMALMAP) UBE_SetSpriteShine(#SPRITE_BULLET, 2.0) UBE_ZoomSprite(#SPRITE_BULLET, 8, 8) UBE_SetSunDirection(0.5, 0.5, 0.8) UBE_SetSunColor($FFEBF8FF, 2.3) ; Global X.i, Y.i UBE_SetSunDirection(1, 1, -0.5) Repeat Repeat Global Event.i = UBE_WindowEvent() Select Event Case #PB_Event_CloseWindow Global Quit.b = 1 EndSelect Until Event = 0 UBE_ExamineKeyboard() UBE_ExamineShaderLights() If UBE_KeyboardReleased(27) Quit = 1 EndIf If UBE_KeyboardPushed(#VK_UP) *MyPlayer\Velocity + 0.1 If *MyPlayer\Velocity > 2 *MyPlayer\Velocity = 2 EndIf ElseIf UBE_KeyboardPushed(#VK_DOWN) *MyPlayer\Velocity - 0.1 If *MyPlayer\Velocity < -2 *MyPlayer\Velocity = -2 EndIf Else *MyPlayer\Velocity * 0.95 EndIf If UBE_KeyboardPushed(#VK_LEFT) *MyPlayer\Rotation - 0.03 ElseIf UBE_KeyboardPushed(#VK_RIGHT) *MyPlayer\Rotation + 0.03 EndIf If UBE_KeyboardReleased(#VK_SPACE) AddBullet(@Level, *MyPlayer) EndIf UBE_ClearScreen() DisplayLevel(Level) UBE_FlipBuffers() Delay(2) Until Quit = 1 End ; IDE Options = PureBasic 4.60 (Windows - x86) ; CursorPosition = 113 ; FirstLine = 88 ; Folding = --- ; EnableXP