My project so far.. Just began development this evening.

Started by LemonWizard, January 14, 2009, 05:11:32 AM

Previous topic - Next topic

LemonWizard

PlayBASIC Code: [Select]
; PROJECT : Map Editor
; AUTHOR : N/A
; CREATED : 1/14/2009
; EDITED : 1/14/2009
; ---------------------------------------------------------------------
#include "Input"
Initialize:
mapx$=staticinput("Enter Mapx")
mapy$=staticinput("Enter Mapy")
tilesize=32
tiles=1
windowx=20
windowy=20
createimage 1, windowx*32, windowy*32
mapx=val(mapx$)
mapy=val(mapy$)
createimage 2, mapx*32, mapy*32
camerax=1
cameray=1
if mapx <20 then mapx=20
if mapy <20 then mapy=20
sync
dim map(mapx, mapy)
waitkey
gosub Loadtiles

Main:
gosub drawcam
gosub Grid
gosub Minput
goto Main


Grid:
rendertoimage 1
for temp=1 to windowy
line 0, temp*tilesize, mapx*tilesize , temp*tilesize
next temp

for temp=1 to windowx
line temp*tilesize, 0, temp*tilesize, mapy*tilesize
next temp
rendertoimage 0
sync
copyrect 1, 0, 0, windowx*32, windowy*32, 0, 0, 0
sync
Return

Minput:
mx=mouseX()
my=mouseY()
setcursor mx, my
print mx
print my
rendertoimage 0
drawimage tileset, mx, my, 0
sync
wait 10

return

Drawcam:
copyrect 2, camerax-windowx*32, cameray-windowy*32, camerax*32, cameray*32, 0, 0, 0
return

Loadtiles:
for temp=1 to tiles
tileset=loadnewimage("Tile"+str$(temp)+".bmp")
rendertoimage 0
drawimage tileset, 0,0, 0
sync
waitkey
wait 30
waitkey
next temp

return



To run this put a file that's 32*32 pixels into the same folder as the file and name it Tile1.bmp.
Or delete the code that loads and renders that single tile image ^^

so far I have a few small issues.
First of all it doesn't seem like I can do this:

PlayBASIC Code: [Select]
Loadtiles:
dim tileset(tiles)
for temp=1 to tiles
tileset(temp)=loadnewimage("Tile"+str$(temp)+".bmp")

next temp

return



and then use this:


drawimage tileset(1), 0, 0, 0


It keeps giving me a "The Array "Tileset()" is not defined.

Why is this 0_o.. I clearly allocate the array in the sub loop...can I not use an array to store images? It let me load them just fine but it simply won't draw them!

Moving on:
Specs:
Display size for editor "Window" is going to be 20 tiles by 20 tiles.
Tiles are by default 32 pixels by 32 pixels.
Later implementations will allow scrolling within the window and placing tiles.
The tile set itself will display on the right, and the user will easily be able to select any tile simply by clicking on it.
The window will allow scrolling, with use of the arrow keys for easy editing.
The editor will be full screen, or, take up as much space on the moniter as possible.
Maps will be able to be saved in a variety of formats.. maybe I can make it compatible with the mappy editor set...
Tiles will be stored in a large image file. Which is displayed. For now, the image file will be 10 by 10 tiles. (That's 100 tiles in one image!)

Later on, the Tile engine will be able to dynamically load maps without a need for an array pointer, or manually defined database.

I can explain how that will function later. ^^
Lots o' work to do.

kevin


QuoteWhy is this 0_o.. I clearly allocate the array in the sub loop...can I not use an array to store images? It let me load them just fine but it simply won't draw them!

  Your snippet works here.  What version of PB are you using ?


LemonWizard

Quote from: kevin on January 14, 2009, 05:37:25 AM

QuoteWhy is this 0_o.. I clearly allocate the array in the sub loop...can I not use an array to store images? It let me load them just fine but it simply won't draw them!

  Your snippet works here.  What version of PB are you using ?



The first snippet should work...
1.1.7.548 <--That is the version I am using.

The problem is I can't seem to use drawimage with an array of images loaded by loadnewimage.
I want to place it in an array like so:
dim tileset(tiles)
then have a temp loop load the tiles in for testing purposes...
later it'll be replaced by a routine that seperates each tile into the array from one large image...

The problem being.
Drawimage won't draw like this:

Drawimage tileset(1), 0, 0, 0

Maybe I should have posted a second snippet... I think I will.

LemonWizard

This one doesn't like to work.

PlayBASIC Code: [Select]
; PROJECT : Map Editor
; AUTHOR : N/A
; CREATED : 1/14/2009
; EDITED : 1/14/2009
; ---------------------------------------------------------------------
#include "Input"
Initialize:
mapx$=staticinput("Enter Mapx")
mapy$=staticinput("Enter Mapy")
tilesize=32
tiles=1
windowx=20
windowy=20
createimage 1, windowx*32, windowy*32
mapx=val(mapx$)
mapy=val(mapy$)
createimage 2, mapx*32, mapy*32
camerax=1
cameray=1
if mapx <20 then mapx=20
if mapy <20 then mapy=20
sync
dim map(mapx, mapy)
waitkey
gosub Loadtiles

Main:
gosub drawcam
gosub Grid
gosub Minput
goto Main


Grid:
rendertoimage 1
for temp=1 to windowy
line 0, temp*tilesize, mapx*tilesize , temp*tilesize
next temp

for temp=1 to windowx
line temp*tilesize, 0, temp*tilesize, mapy*tilesize
next temp
rendertoimage 0
sync
copyrect 1, 0, 0, windowx*32, windowy*32, 0, 0, 0
sync
Return

Minput:
mx=mouseX()
my=mouseY()
setcursor mx, my
print mx
print my
rendertoimage 0
drawimage tileset(1), mx, my, 0
sync
wait 10

return

Drawcam:
copyrect 2, camerax-windowx*32, cameray-windowy*32, camerax*32, cameray*32, 0, 0, 0
return

Loadtiles:
dim tileset(tiles)
for temp=1 to tiles
tileset(temp)=loadnewimage("Tile"+str$(temp)+".bmp")
rendertoimage 0
drawimage tileset(temp), 0,0, 0
sync
waitkey
wait 30
waitkey
next temp

return




kevin

Quote1.1.7.548 <--That is the version I am using.

Just for future reference, this is the version of the IDE you're using,  it's not the PlayBASIC version.  You can locate what version is installed from the IDE, by going to HELP ->ABOUT..   There are two fields,  Compiler Version is the one that refers to what edition of PB it is.

As for the problem,  the method you've described is used commonly used in PB programs.  So I suggest,  ZIP'ing up entire project folder and post it (including images).   This eliminates, differences in testing.

 

LemonWizard

Project Folder zipped and all.

kevin

  I see what the fault is,  in line 57 you're asking PB to drawimage from the Array tileset()  The trouble is you haven't dimensioned this array prior to it's use.  It's not dimensioned until line  68.  The fact the subroutine LoadImage is called at line 24, is irrelevant during compilation.  The compiler builds the code line by line, it doesn't follow the programs sub-routines.      

 You can fix this by simply moving the previous subroutine bellow this point


PlayBASIC Code: [Select]
#include "Input"
Initialize:
mapx$=staticinput("Enter Mapx")
mapy$=staticinput("Enter Mapy")
tilesize=32
tiles=1
windowx=20
windowy=20
createimage 1, windowx*32, windowy*32
mapx=val(mapx$)
mapy=val(mapy$)
createimage 2, mapx*32, mapy*32
camerax=1
cameray=1
if mapx <20 then mapx=20
if mapy <20 then mapy=20
sync
dim map(mapx, mapy)
waitkey
gosub Loadtiles

Main:
gosub drawcam
gosub Grid
gosub Minput
goto Main


Grid:
rendertoimage 1
for temp=1 to windowy
line 0, temp*tilesize, mapx*tilesize , temp*tilesize
next temp

for temp=1 to windowx
line temp*tilesize, 0, temp*tilesize, mapy*tilesize
next temp
rendertoimage 0
sync
copyrect 1, 0, 0, windowx*32, windowy*32, 0, 0, 0
sync
Return


Drawcam:
copyrect 2, camerax-windowx*32, cameray-windowy*32, camerax*32, cameray*32, 0, 0, 0
return

Loadtiles:
dim tileset(tiles)
for temp=1 to tiles
tileset(temp)=loadnewimage("Tile"+str$(temp)+".bmp")
rendertoimage 0
drawimage tileset(temp), 0,0, 0
sync
waitkey
wait 30
waitkey
next temp

return




Minput:
mx=mouseX()
my=mouseY()
setcursor mx, my
print mx
print my
rendertoimage 0
drawimage tileset(1), mx, my, 0
sync
wait 10

return




 

LemonWizard

ah. Thanks a bunch! that helps. *facepalm* I can't believe it compiles like that... no wonder!

kevin


?? It doesn't compile like that, The error you were getting was the compiler stopping. It's wasn't executing the program at all. 

  PB like most compiler today is Top-Down by design.  There's a few compilers that aren't,  that allow such behaviors (chicken before the egg syndrome) such as DB/DBpro but they're rapidly becoming exceptions.

  If you're coming from a DB background, then make sure you read the HELP->About->ProgramLayout article. 

LemonWizard

Alright. Thanks again! I'm loving the support offered here!

slayer93

QuotePB like most compiler today is Top-Down by design.  There's a few compilers that aren't,  that allow such behaviors (chicken before the egg syndrome) such as DB/DBpro but they're rapidly becoming exceptions.

  If you're coming from a DB background, then make sure you read the HELP->About->ProgramLayout article. 

Ha, when I started using PB coming from DB I got stuck on that too for a while, but I was able to find out what was happening and setup a different to structure my game. ::)