Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculate the dimension of an array for a sprite...
#8
Thanks but when I compile the code below I got these errors:

Quote:C:\FreeBASIC\fbc -s gui -w 1 "Tileeng3.bas"
Tileeng3.bas(257) : error 14: Expected identifier, found: ','

PUT (x, y), Water1, PSET ' Show it...
^
Tileeng3.bas(259) : error 14: Expected identifier, found: ','

PUT (x, y), Tree1, PSET
^
Tileeng3.bas(261) : error 14: Expected identifier, found: ','

PUT (x, y), Grass1, PSET ' grass.
^

Build error(s)

So what's wrong with this code?

Code:
DEFINT A-Z                              ' All variables are default integers.
'$DYNAMIC                               ' Dynamically sort memory for more...

DECLARE SUB InitVars ()                 ' Initializes variables.
DECLARE SUB LoadMap ()                  ' Loads a map.
DECLARE SUB LoadTiles ()                ' Load the tiles by simple Bload.
DECLARE SUB MoveUp ()                   ' Handles moving `up' event.
DECLARE SUB MoveDown ()                 ' Handles moving `down' event.
DECLARE SUB MoveLeft ()                 ' Handles moving `left' event.
DECLARE SUB MoveRight ()                ' Handles moving `right' event.
DECLARE SUB PutPlayerPic ()             ' Puts the player pic.
DECLARE SUB PutTile (x, y, TileNumber)  ' Put a tile.
DECLARE SUB SetupPalette ()             ' Setup n!Media palette.
DECLARE SUB ShowMap ()                  ' Show the map...

TYPE WorldDataType                      ' WorldData holds generic world info.
Rows            AS INTEGER             ' Number of rows in world.
Cols            AS INTEGER             ' Number of cols in world.
TopRow          AS INTEGER             ' Current player row in world.
TopCol          AS INTEGER             ' Current player col in world
Action          AS INTEGER             ' So we only do things when needed.
AnimCycle       AS INTEGER             ' Which frame player is on.
Direc           AS INTEGER             ' What direction player is going in.
PlayerY         AS INTEGER             ' Adjusted player y pos for more 3d.
END TYPE

TYPE MapType                            ' Map type, easy to add tile values.
Tile            AS INTEGER             ' Identifies tile in any spot...
END TYPE

CONST North = 1, South = 2, East = 3, West = 4  ' Tracks dirs of player.
CONST True = -1, False = 0                      ' Boolean vals for easiness.
CONST TileDir$ = "Images"                       ' Tile directory.

Dim Shared Tree1 as Integer
Dim Shared Grass1 as Integer
Dim Shared Water1 as Integer

Rem DIM SHARED Tree1(129), Grass1(129), Water1(129) ' Tree, grass, water tiles.
DIM SHARED WorldData AS WorldDataType           ' WorldData variables.
DIM SHARED Map(-9 TO 60, -9 TO 60) AS MapType   ' The map, memory hog, reduce
                                                ' for more mem, smaller map.
SCREEN 13,,,1

Tree1 = imagecreate(16, 16)
Grass1 = imagecreate(16, 16)
Water1 = imagecreate(16, 16)

CALL InitVars                                   ' Initialize variables.
CALL LoadMap                                    ' Load a/the map.
CALL LoadTiles                                  ' Load tiles.

Call ShowMap                                    ' Show map...

DO                                              ' Main heart loop of program.
kbd$ = INKEY$                                  ' `Transparent' input.
IF kbd$ <> "" THEN                             ' If other than nothing...
  SELECT CASE kbd$                              ' ... find what key it is...
   CASE Chr$(255) + "H"                         ' Hit up arrow.
    CALL MoveUp                                 ' Call up events.
    WorldData.Action = True                     ' An action happened.
   CASE Chr$(255) + "P"                         ' Hit down arrow.
    CALL MoveDown                               ' Call down events.
    WorldData.Action = True                     ' An action happened.
   CASE Chr$(255) + "K"                         ' Hit left arrow.
    CALL MoveLeft                               ' Call left events.
    WorldData.Action = True                     ' An action happened.
   CASE Chr$(255) + "M"                              ' Hit right arrow.
    CALL MoveRight                              ' Call right events.
    WorldData.Action = True                     ' An action happened.

   CASE CHR$(27)                                ' ESC; end.
    END
  END SELECT
END IF

IF WorldData.Action = True THEN                ' If an action did happen...
  CALL ShowMap                                  ' Show the map since we moved.
  WorldData.Action = False                      ' No more action.
END IF                                         ' This is the spot where
                                                '  you would check if they
LOOP                                            '  hit a village or something.


MainMap:
DATA 40,40
DATA -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
DATA -1,1,1,1,1,1,1,1,1,1,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1
DATA -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1
DATA -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1

REM $STATIC
SUB InitVars

WorldData.TopCol = 20                   ' Where they start in map (col).
WorldData.TopRow = 20                   ' Where they start in map (row).
WorldData.PlayerY = 96                  ' Y pixel location for player show.
                                        ' This is raised so it sorta looks
                                        ' like they are in front of the tile
                                        ' above them...
END SUB

SUB LoadMap

RESTORE MainMap                                 ' Read data from MainMap
READ WorldData.Rows, WorldData.Cols             ' Read row and column count.

FOR i = 1 TO WorldData.Rows
FOR j = 1 TO WorldData.Cols
  READ Map(j, i).Tile                           ' Read tile in...
NEXT j
NEXT i

END SUB

SUB LoadTiles

CHDIR TileDir$                          ' Goto tile directory.

BLoad "Grass1.bmp",VARPTR(Grass1)
BLoad "Water1.bmp",VARPTR(Water1)
BLoad "Tree1.bmp",VARPTR(Tree1)

CHDIR ".."                              ' Go back to initial dir.

END SUB

SUB MoveDown

WorldData.Direc = South

IF Map(WorldData.TopCol + 10, WorldData.TopRow + 7).Tile > 0 THEN
WorldData.TopRow = WorldData.TopRow + 1
END IF

END SUB

SUB MoveLeft

WorldData.Direc = West

IF Map(WorldData.TopCol + 9, WorldData.TopRow + 6).Tile > 0 THEN
WorldData.TopCol = WorldData.TopCol - 1
END IF

END SUB

SUB MoveRight

WorldData.Direc = East

IF Map(WorldData.TopCol + 11, WorldData.TopRow + 6).Tile > 0 THEN
WorldData.TopCol = WorldData.TopCol + 1
END IF

END SUB

SUB MoveUp

WorldData.Direc = North

IF Map(WorldData.TopCol + 10, WorldData.TopRow + 5).Tile > 0 THEN
WorldData.TopRow = WorldData.TopRow - 1
END IF

END SUB

SUB PutPlayerPic

LINE (160, WorldData.PlayerY)-STEP(15, 15), 15, B       ' Show `box' man.

END SUB

SUB PutTile (x, y, TileNumber)

SELECT CASE TileNumber                  ' Which tile to show?
CASE -2                                ' Negative tile (unwalkable)...
  PUT (x, y), Water1, PSET              ' Show it...
CASE -1
  PUT (x, y), Tree1, PSET
CASE 0, 1                              ' Anything undefined is by default
  PUT (x, y), Grass1, PSET              ' grass.
END SELECT

END SUB

SUB ShowMap

FOR i = 0 TO 19
FOR j = 0 TO 11
  CALL PutTile(i * 16, j * 16, Map(i + WorldData.TopCol, j + WorldData.TopRow).Tile)
NEXT j
NEXT i

CALL PutPlayerPic

END SUB
Reply


Messages In This Thread
Calculate the dimension of an array for a sprite... - by Anonymous - 04-19-2007, 10:48 PM
Calculate the dimension of an array for a sprite... - by Clay Dragon - 04-23-2007, 05:50 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)