Qbasicnews.com
December 12, 2018, 08:30:47 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Calculate the dimension of an array for a sprite...  (Read 12268 times)
Clay Dragon
Member
*
Posts: 38


WWW
« on: April 16, 2007, 08:00:51 PM »

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!
Logged
Anonymous
Guest
« Reply #1 on: April 19, 2007, 02:48:51 PM »

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.
Logged
wallace
Wandering Guru
***
Posts: 368



WWW
« Reply #2 on: April 20, 2007, 09:38:10 AM »

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.
Logged

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.
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #3 on: April 20, 2007, 12:11:54 PM »

BASIC doesn't end lines with a semicolon...
Logged
Skyler
Ancient Guru
****
Posts: 564



« Reply #4 on: April 20, 2007, 02:57:03 PM »

Yeah, that's C or something syntax, wallace...
Logged

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
Clay Dragon
Member
*
Posts: 38


WWW
« Reply #5 on: April 22, 2007, 02:07:12 PM »

Thanks everyone! Cheesy

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!?
Logged
BadMrBox
Forum Regular
**
Posts: 140



« Reply #6 on: April 22, 2007, 05:43:33 PM »

No, just write the height and width values.
Code:
dim sprite as integer
sprite = imagecreate(20, 20)
Logged


I'm a dog and I feel dirty baby
Clay Dragon
Member
*
Posts: 38


WWW
« Reply #7 on: April 22, 2007, 09:50:43 PM »

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.


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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
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
Logged
wallace
Wandering Guru
***
Posts: 368



WWW
« Reply #8 on: April 23, 2007, 11:51:00 AM »

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.
Logged

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.
Clay Dragon
Member
*
Posts: 38


WWW
« Reply #9 on: April 25, 2007, 05:23:29 PM »

Everything works perfectly now! Thanks a lot Wallace! Cheesy
Logged
D.slert
New Member

Posts: 7


WWW
« Reply #10 on: October 08, 2009, 12:52:05 AM »

Are you talking about in the default web browswer?  If so then its web browser controlled.  If youre talking about the C# WebBrowser, then I think Prey showed some code for it on halomods.
Logged
Clippy
Member
*
Posts: 84



« Reply #11 on: October 08, 2009, 06:15:02 PM »

LOL, I hope you can wait another 2 - 1/2 years for the reply LOL! Roll Eyes
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!