Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Feljar

Pages: [1]
1
QB64 Discussion / Re: Trying to clean up some code
« on: June 16, 2018, 06:51:16 pm »
Thank you, I had a feeling that was it. I edited my post and added that before I knew you replied. I will work on it after the kids go to bed. Thank you again for your patience & advice

2
QB64 Discussion / Re: Trying to clean up some code
« on: June 16, 2018, 05:53:34 pm »
Hello again, last question for a while, I promise! I’ve spent a few hours off and on the last two days to get the tile placement correct. Using your example above, I’ve successfully been able to place tiles in the correct coordinates. What I can’t fiqure out, is how to determine what type of tile to place in the coordinates. I have a Read/Data for the tile type that should be placed,  it I can not seem to place it properly in the code so that it works.
 
DIM tiletype(1 to 3) AS LONG ‘tile graphics to draw
tiletype(1) = _LOADIMAGE(“sprites\grass.png”,32)
tiletype(2) = _LOADIMAGE(“sprites\snow.png”,32)
tiletype(3) = _LOADIMAGE(“sprites\mountains.png”,32)

RESTORE mapdata ‘reads 1,2 or 3 to determine what type of tile to place
FOR k = 1 to 84
READ mapdata
Next k


‘This sections decides the location in order to place tiles to create a map
TYPE tiles
x AS INTEGER
y AS INTEGER
END TYPE

DIM tiles(1 to 84) AS tiles ‘reads tile location for placement
RESTORE tiletypedata
FOR t=1 to 84
READ tiles(t).x, tiles(t).y
_PUTIMAGE(tiles(t).x, tiles(t).y), tiletype(mapdata) ‘ mapdata = 1, 2 or 3 as read from the mapdata
NEXT t

mapdata:
DATA 1,1,1,1,2,2,1,2,1,2,1,3,1,1,2 etc... until 84 entries
tiletypedata:
DATA 1,1,81,1,161,1 etc... until 84 entries

I believe I need to nest the coordinate getting inside the first set, so the logic order will be:

Read the map data to find type of tile (1 to 3)
Read the coordinates to place tile
_PUTIMAGE
Repeat 83 more times via For\Next

The results of my efforts vary depending on where I place things, but I haven’t been able to nail it down so it works properly. I’m guessing my fault is in the first data retrieval, for if I substitute a 1,2 or 3 in the _PUTIMAGE line, it draws a screen, but only of the 1,2, or 3 type of tiles. OR, when reading the tile type data, it reads the whole line and not bit by bit, so the Putimage gets goofed up. I tried putting “next k” at the end of the program instead of where it currently is, so every loop the it reads one tile type, them does the coordinates stuff, then loops back to the tile type, but it didn’t work.

Thank you for any insight, I greatly appreciate it. Utilizing the help you gave me above, will save me tremendous amounts of typing time

3
QB64 Discussion / Re: Trying to clean up some code
« on: June 14, 2018, 10:02:31 pm »
Yup totally missed it. I was putting numbers in the brackets. Didn’t occur to me until five seconds after I hit post.

4
QB64 Discussion / Re: Trying to clean up some code
« on: June 14, 2018, 09:32:28 pm »
Never mind! I found what I was doing wrong. It’s working perfectly now.

5
QB64 Discussion / Re: Trying to clean up some code
« on: June 14, 2018, 09:29:42 pm »
I had some time tonight to play around. I need some guidance. I only played with character graphics, no tiles at the moment.

DIM character (1 to 3) AS LONG
character(1) = _LOADIMAGE(“sprites\warrior.png”, 32)
character(2) = _LOADIMAGE(“sprites\wizard.png”, 32)
character(3) = _LOADIMAGE(“sprites\thief.png”, 32)
SCREEN _NEWIMAGE(1350,750,32)

_PUTIMAGE (50,50), character(1)

It worked. It put the warrior graphic on screen. If I put (2) in the bracket, the wizard graphic appears. But this doesn’t really help me unless I’m doing it wrong. I will still need the inner set of Select Case to choose which graphic to display (1), (2), or (3). I was under the impression I could type something like “character =1” or “character =2” and when using _PUTIMAGE (50,50), character, it would put whatever graphic that character variable was currently set at.

Using “_PUTIMAGE (50,50) , character”  yields an illegal function call
Using “_PUTIMAGE (50,50),  character&” yields an illegal function call
 
From experimenting, _PUTIMAGE (50,50), character(1) is the only thing that I can get to work and it only displays what I tell it to display, (1), (2), or (3). What am I doing wrong? Your example seemed simple enough, I have to be missing something

6
QB64 Discussion / Re: Trying to clean up some code
« on: June 14, 2018, 10:09:08 am »
Thanks for your input. I’m self taught so there is a tremendous amount I don’t yet know. I won’t have time to play with the code until the weekend, but I do have another question regarding the images. I have read that whenever you use _loadimage, that you should _putimage and then _freeimage to free it from memory. Before the select case loops, I _loadimage all the graphics I will need, then after the loops, I free them all. Using your example, how and when do I use _freeimage? Or use it at all? If I freeimage in an array, does that mess it up? Thanks again!

7
QB64 Discussion / Trying to clean up some code
« on: June 13, 2018, 09:16:48 pm »
Hey all. Been a long time since I’ve posted on the .net site. In my spare time, I’ve been programming a simple Final Fantasy type rpg. I’d like to know if there is a way I’m overlooking to consolidate some code. This particular snip of code is for drawing a player character on the screen at a specific location (tile). The screen consists of 84 tiles. The location of the tile that the character will be occupying is stored as a variable named “location” . The graphic of the character is stored as a variable named “player”. The graphic can change depending on which character you want to see on the map. It can be changed at will depending on who you want to see on the map, (wizard, warrior, thief, etc). My current code works perfectly but I am trying to slim down.

Select case location  ‘selects tile to draw a graphic in
          Case 1  ‘tile 1
          Select case player
                    Case 1
                    _putimage (2,2), warrior&  ‘draws warrior graphic in tile 1
                    Case 2
                    _putimage (2,2), wizard& ‘draws wizard graphic in tile 1
                   Case 3
                    _putimage (2,2), thief& ‘draws thief graphic in tile 2
          End select
          Case 2 ‘tile 2
          Select case player
                    Case 1
                    _putimage (80,2), warrior&  ‘draws warrior graphic in tile 2
                    Case 2
                    _putimage (80,2), wizard& ‘draws wizard graphic in tile 2
                    Case 3
                    _putimage (80,2), thief& ‘draws thief graphic in tile 2
          End select
End select


This repeats 82 more times until all tiles are included. I plan on expanding the graphic set for the player to utilize, but as you can see, each new graphic will add 84 lines of code for telling the program where to draw it. Is there a way to clean this up? Can Qb64 rename files? For example, if I want to display the wizard graphic, can it rename the wizard graphic file to a generic and use _putimage generic&? Then If I want the warrior graphic later, it will rename the wizard graphic file back to wizard and then label the warrior graphic file generic? I’m out of ideas
Thank you kindly

Pages: [1]