Code: Select all
@APPICON { Ic16x16 = "icons/my16x16icon.png",
Ic24x24 = "icons/my24x24icon.png",
Ic32x32 = "icons/my32x32icon.png",
Ic48x48 = "icons/my48x48icon.png",
Ic128x128 = "icons/my128x128icon.png",
Ic256x256 = "icons/my256x256icon.png",
Ic512x512 = "icons/my512x512icon.png"}
Const #SCREENW = 800
Const #SCREENH = 600
@DISPLAY { Width = #SCREENW, Height = #SCREENH, Title = "Test" , ScaleMode = #SCALEMODE_AUTO, Sizeable = True, SmoothScale = False}
; Include game framework
@INCLUDE "hgf/game.hws"
; Include game data
@BRUSH 1, "data/mapdata.png", { Transparency = $2B53C7, Hardware = True }
@BRUSH 2, "data/plane.png", { Transparency = $008080, Hardware = True }
;------------------------------------------------------------------------------
; Player object
;
player = {}
player.img = Image:new(2) ; Image from brush 2
player.pos = Point:new() ; Player position as Point
Function player:draw(vp)
game.buffer:drawImg(self.img.r:addpt(self.pos:add(vp.pos)), self.img, Point:new())
EndFunction
Function player:update(vp, dt)
If IsKeyDown("LEFT")
self.pos.x = self.pos.x - 240 * dt
If self.pos.x < 0 Then self.pos.x = 0
EndIf
If IsKeyDown("RIGHT")
self.pos.x = self.pos.x + 240 * dt
If self.pos.x > vp.r:dx() - self.img.r:dx() Then self.pos.x = vp.r:dx() - self.img.r:dx()
EndIf
If IsKeyDown("UP")
self.pos.y = self.pos.y - 240 * dt
If self.pos.y < 0 Then self.pos.y = 0
EndIf
If IsKeyDown("DOWN")
self.pos.y = self.pos.y + 240 * dt
If self.pos.y > vp.r:dy() - self.img.r:dy() Then self.pos.y = vp.r:dy() - self.img.r:dy()
EndIf
EndFunction
;----------------------------------------------------------------------------------------------
;
; Game setup
Function game.load()
; Load the map and tile set
map, ts = Map:load(1, 64, 64, "data/Level.map")
; Define view port for the tile map
vp = Viewport:new(736, 600, game.buffer.r:dx()/2 - 736/2, game.buffer.r:dy()/2 - 600/2)
; Position the player
player.pos.x = vp.r:dx()/2 - player.img.r:dx()/2
player.pos.y = vp.r:dy() - player.img.r:dy()
; Set the starting map position
x = 0
y = map.r:dy() - vp.r:dy()
map:move(x, y)
clr = $2B53C7 ; Background fill color for water animation
timer = 0.25 ; Timer for water animation, 1/4 seconds
CreateShadowBrush(3, 2, ARGB(80, #BLACK), 20)
EscapeQuit(True)
game:setUpdateRate(60)
EndFunction
; Game state "main" draw function
Function game.draw()
SetFillStyle(#FILLCOLOR)
game.buffer:drawrect(vp.r:addpt(vp.pos), clr)
SetFillStyle(#FILLNONE)
game.buffer:drawtilemap(map, ts, vp)
game.buffer:drawrect(vp.r:addpt(vp.pos), #RED)
DisplayBrush(3, player.pos.x-20, player.pos.y-20)
player:draw(vp)
fps:draw(Point:new( { x = 700, y = 24 }), "FPS: ")
EndFunction
; game state "main" update function
Function game.update(dt)
timer = timer - dt
If timer <= 0
clr = RGB(Rnd(23)+20,Rnd(43)+40,Rnd(105)+150)
timer = 0.25
EndIf
y = y - 80 * dt
If y < 0 Then y = 0
map:move(x, y)
player:update(vp, dt)
EndFunction
;----------------------------------------------------------------------------------------------
;
; Here we go!
game:go(True)