Author Topic: Tile Map[BB2D]  (Read 12205 times)

0 Members and 1 Guest are viewing this topic.

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Tile Map
« Reply #20 on: June 04, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Tile Map
« Reply #21 on: June 04, 2006 »
Works well :) Nice one. Now add some flip screen scrolling!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline zparticle

  • Atari ST
  • ***
  • Posts: 168
  • Karma: 11
    • View Profile
    • ScottShaver2000
Re: Tile Map
« Reply #22 on: June 05, 2006 »
Don't know if you are using BlitzMax or not but here is a bmax module I wrote for scrolling tile maps.

http://www.scottshaver2000.com/blitz/bmaxmods/sas.mod.zip

Here is a map editor for creating the maps.

http://www.scottshaver2000.com/blitz/sasmapeditor2/sasmapeditor2.zip



here is an example of a map in action.

Code: [Select]
'===============================================================================
'===============================================================================
' Sample4.bmx By Scott Shaver
'
' This sample displays a simple one layer LayeredTileMap and allows the user
' to move a character around the map with the cursor keys. Use the escape key
' to exit the program. The character can't go through the walls.
'
' Written: 6/23/2005
' Update 6/27/2005 -
' Added the code for detecting the wall collisions
'===============================================================================
'===============================================================================
Strict

Framework BRL.GlMax2D
Import BRL.System
Import BRL.Basic
Import BRL.pngloader
Import BRL.Retro
Import pub.igl
Import SAS.tilemaps


?Win32
SetGraphicsDriver(GLMax2DDriver())
?

' init the graphics mode
Graphics 800,600,32',85

' Load a LayeredTileMap file
Global map:LayeredTileMap = LayeredTileMap.Load("maps/Walls.smf")

' load the character image
SetMaskColor(255,255,255)
Global guy:TImage = LoadImage("maps/circleguy.png",MASKEDIMAGE)
Global charWidth:Int=30
Global charHeight:Int=30
Global halfCW:Int=charWidth/2
Global halfCH:Int=charHeight/2

' Set the viewport to the entire screen
map.ViewPort(50,50,GraphicsWidth()-100,GraphicsHeight()-100)

' some helper vars
Global halfVPW:Int = map.viewPortPixelWidth/2
Global halfVPH:Int = map.viewPortPixelHeight/2
Global centerVPX:Int = map.viewPortX + halfVPW
Global centerVPY:Int = map.viewPortY + halfVPH
Global scrollSpeed:Int=3
Global wallTileIndex=0

' set up the starting position of the character by finding a specific cell
Global sx:Float,sy:Float
map.MapCellToScreenCoords(1,1,sx,sy,0)

' blue background
SetClsColor(0,0,255)

' the main program loop
While Not KeyDown(KEY_ESCAPE)
Cls

Local lastX:Float = map.GetX()
Local lastY:Float = map.GetY()
Local cx:Float,cy:Float
Local temp:Float

' handle moving the map and character around with the cursor keys
If KeyDown(KEY_A) Or KeyDown(KEY_LEFT) Then
If sx+halfCW > centerVPX Then ' the character is right of the center of the screen
sx:-scrollSpeed
Else If lastX=0 Then ' edge of the map move the character
If sx > map.viewPortX Then sx:-scrollSpeed
If sx < map.viewPortX Then sx=map.viewPortX
Else ' character is centered move the map
map.SetPosition(lastX+scrollSpeed,lastY)
lastX = map.GetX()
EndIf
' check the characters upper left corner
map.ScreenToMapCell(sx,sy,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then map.MapCellToScreenCoords(cx+1,cy,sx,temp,0)
' check the characters lower left corner
map.ScreenToMapCell(sx,sy+charHeight-1,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then map.MapCellToScreenCoords(cx+1,cy,sx,temp,0)
EndIf
If KeyDown(KEY_D) Or KeyDown(KEY_RIGHT) Then
If sx+halfCW < centerVPX Then ' the character is left of the center of the screen
sx:+scrollSpeed
Else If lastX=-((map.cellPixelWidth*map.mapCellWidth) - map.viewPortPixelWidth) Then ' edge of the map move the character
If sx < map.viewPortX+map.viewPortPixelWidth-charWidth Then sx:+scrollSpeed
If sx > map.viewPortX+map.viewPortPixelWidth-charWidth Then sx=map.viewPortX+map.viewPortPixelWidth-charWidth
Else ' character is centered move the map
map.SetPosition(lastX-scrollSpeed,lastY)
lastX = map.GetX()
EndIf
' check the characters upper right corner
map.ScreenToMapCell(sx+charWidth,sy,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then
map.MapCellToScreenCoords(cx-1,cy,sx,temp,0)
sx:+(map.cellPixelWidth-charWidth)
EndIf
' check the characters lower right corner
map.ScreenToMapCell(sx+charWidth-1,sy+charHeight-1,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then
map.MapCellToScreenCoords(cx-1,cy,sx,temp,0)
sx:+(map.cellPixelWidth-charWidth)
EndIf
EndIf
If KeyDown(KEY_W) Or KeyDown(KEY_UP) Then
If sy+halfCH > centerVPY Then ' the character is below of the center of the screen
sy:-scrollSpeed
Else If lastY=0 Then ' edge of the map move the character
If sy > map.viewPortY Then sy:-scrollSpeed
If sy < map.viewPortY Then sy=map.viewPortY
Else ' character is centered move the map
map.SetPosition(lastX,lastY+scrollSpeed)
lastY = map.GetY()
EndIf
' check the characters upper left corner
map.ScreenToMapCell(sx,sy,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then map.MapCellToScreenCoords(cx,cy+1,temp,sy,0)
' check the characters upper right corner
map.ScreenToMapCell(sx+charWidth-1,sy,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then map.MapCellToScreenCoords(cx,cy+1,temp,sy,0)
EndIf
If KeyDown(KEY_S) Or KeyDown(KEY_DOWN) Then
If sy+halfCH < centerVPY Then ' the character is above of the center of the screen
sy:+scrollSpeed
Else If lastY=-((map.cellPixelHeight*map.mapCellHeight) - map.viewPortPixelHeight) Then ' edge of the map move the character
If sy < map.viewPortY+map.viewPortPixelHeight-charHeight Then sy:+scrollSpeed
If sy > map.viewPortY+map.viewPortPixelHeight-charHeight Then sy=map.viewPortY+map.viewPortPixelHeight-charHeight
Else ' character is centered move the map
map.SetPosition(lastX,lastY-scrollSpeed)
lastY = map.GetY()
EndIf
' check the characters lower left corner
map.ScreenToMapCell(sx,sy+charHeight-1,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then
map.MapCellToScreenCoords(cx,cy-1,temp,sy,0)
sy:+(map.cellPixelHeight-charHeight)
EndIf
' check the characters lower right corner
map.ScreenToMapCell(sx+charWidth-1,sy+charHeight-1,cx,cy,0)
If map.GetCell(cx,cy,0)=wallTileIndex Then
map.MapCellToScreenCoords(cx,cy-1,temp,sy,0)
sy:+(map.cellPixelHeight-charHeight)
EndIf
EndIf

' clear the background of the map with black
SetColor(0,0,0)
DrawRect(50,50,GraphicsWidth()-100,GraphicsHeight()-100)

' draw the map
map.Draw()

' draw the character shadow
SetAlpha(.5)
SetColor(0,0,0)
DrawImage(guy,sx+3,sy+3)
' draw the character
SetAlpha(1)
SetColor(255,255,255)
DrawImage(guy,sx,sy)

Flip
' FlushMem()
Wend




here is a screen shot a game I'm working on using this stuff.




Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Tile Map
« Reply #23 on: June 05, 2006 »
-
« Last Edit: August 06, 2025 by marclurr »

Offline asdflkj

  • C= 64
  • **
  • Posts: 45
  • Karma: 2
    • View Profile
Re: Tile Map
« Reply #24 on: June 05, 2006 »
Does anyone know if there is a way to save the data for the map in a text file, then load the data into the game? If there is a way to do this could some one please tell me how?

Thanks,
Mark-O

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Tile Map
« Reply #25 on: June 05, 2006 »
You need to look into the writefile and openfile commands etc.
It's pretty easy to save an array into a file.
If you get stuck with it, make a new thread and I'll do a quick example for you :)
Shockwave ^ Codigos
Challenge Trophies Won: