Posts: 34
Threads: 5
Joined: May 2005
In QB for screen 13 it will take width*height+4 bytes. But I'm not so sure about that... I found an old QB tile engine that use only the half of the result of this calculation... why is it working anyway?
http://members.tripod.com/~qb4lamerz/files/tileeng3.zip
Also, I want to know how to do it in FB for screen 19?
Is it exactly the same?
Thanks!
It's the number of *bytes*. A QB integer is 2 bytes, hence needing half as many integers.
If you're ever planning to use FreeBASIC, don't even worry about calculating that, we introduced a function called imagecreate, which does the calculations for you if you give it the x, y.
Just saying.
Posts: 357
Threads: 118
Joined: Oct 2004
Freebasic has solved that annoying little problem.
Code: dim sprite as integer
sprite = imagecreate(width, height)
EDIT, Don't end you commands with a semicolon. My bad, too much C.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Posts: 1,439
Threads: 15
Joined: Apr 2003
BASIC doesn't end lines with a semicolon...
Posts: 421
Threads: 22
Joined: Oct 2005
Yeah, that's C or something syntax, wallace...
In the beginning, there is darkness â the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
Posts: 34
Threads: 5
Joined: May 2005
Thanks everyone!
Wallace, when I print the "Sprite" variable, it gives me a huge number! The number has seven figures even if my sprite is small as 20x20 or 100x100! Is that the dimension I have to give to my sprite in FB screen mode 19!?
Posts: 92
Threads: 1
Joined: May 2006
No, just write the height and width values.
Code: dim sprite as integer
sprite = imagecreate(20, 20)
![[Image: rg_link.png]](http://ragnarokgames.googlepages.com/rg_link.png)
I'm a dog and I feel dirty baby
Posts: 34
Threads: 5
Joined: May 2005
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,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
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,-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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
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
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
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
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
Posts: 357
Threads: 118
Joined: Oct 2004
Not your code, it was mine.
Code: dim sprite as integer ptr
sprite = imagecreate(width, height)
Image create returns a POINTER to the array, that was my mistake.
Looking at your code I do see one thing though, I'm pretty sure that if you declare your sprite as a pointer (like you need to be now) you don't need to VARPTR in your BLOAD.
Also, this doesn't really matter, but I would recommend using ENUMs rather than CONSTs for things like true and false, and the directions.
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Posts: 34
Threads: 5
Joined: May 2005
Everything works perfectly now! Thanks a lot Wallace!
|