Scrolling tile maps with Hollywood

Discuss any general programming issues here
jalih
Posts: 276
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: Scrolling tile maps with Hollywood

Post by jalih »

Below is all the code required for the previous demo. Just to show, how easy it was to code with my simple helper routines...

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)
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Scrolling tile maps with Hollywood

Post by airsoftsoftwair »

Quite impressive stuff though the sprite is a bit large :) Maybe ask on http://eab.abime.net if you're looking for gfx artists...
jalih
Posts: 276
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: Scrolling tile maps with Hollywood

Post by jalih »

I decided to write a tile map editor in Hollywood after all. Actually, it will be more like an game editor as it allows defining collision rectangle data, setting tile terrain traveling cost for path finding purposes and other data that my game might need.

Current very early prototype is is running on top of my game support routines.
bitRocky
Posts: 120
Joined: Fri Nov 14, 2014 6:01 pm

Re: Scrolling tile maps with Hollywood

Post by bitRocky »

jalih wrote:Hi all,

I would like to write an 1942 style scrolling arcade game. Anyone here interested in joining the project? I really desperately need someone to draw the tile graphics, design levels and draw some additional art. Also someone to create sound effects and some nice music tunes would be a good to have around too.

Here is a little demo, I put together in five minutes. Binaries for Windows, AmigaOS4 and MorphOS included.
Here on MorphOS on a PowerBook 5,9 I get an requester saying
Hardware brushes cannot be used here!
File: flight.hws (current line: 65 - In function: CreateShadowBrush)
jalih
Posts: 276
Joined: Fri Jun 18, 2010 8:08 pm
Location: Finland

Re: Scrolling tile maps with Hollywood

Post by jalih »

I have put my source files with some examples available.

There are some examples, like platformer basics, collision detection using collision rectangles and scrolling tile map. Also included is a simple tile map editor.

My simple game framework is located inside the HGF folder. Tile map editor also serves as an example on how to use just parts of the framework.


Have fun and let me know, if you need any help!
Post Reply