Hello all. This is my first program, so if I'm making some elementary school mistake try not to laugh too hard. Or hit. Or yell... :-)
Anyway, I'd like to work my way up to a turn-based RPG strategy game in 2D and I'm taking it a piece at a time. I figured the first thing to master is a random map creator like the old school games used to use since that's how I want my game to work. This is my first attempt, and once I get this *very basic* version running, I'll start trying to improve it. But for now, I'm getting the dreaded "Memory Access Violation" error. From what I've found here in the forums, it appears that Blitz isn't loading my graphics correctly or I'm mishandling the TileImage variable somehow. That's my guess, but I don't see the glitch (yet). Note the TileImage command is where the debugger says "Image Does Not Exist."
Any one see what I'm missing? I'm using BIDE and the png files are in the same folder as the Blitz3d code. I have also tried adding the full folder description instead of just "picture.png" but that made no difference.
Thanks for any help.
==========================================================
;Draw map image and test world creation algorithm for tweaking
Global x=0 ;set coordinates x and y to 0 and make it a global variable
Global y=0
Global DrawMapImage
Global LandArea
StartWorld() ;start program
Function StartWorld()
Graphics 800,600 ;Set video mode
Setbuffer Backbuffer() ;Draw these images to the backbuffer
Grassmap=LoadImage("Grass 1.png") ;Load Images...
Oceanmap=LoadImage("Ocean 2.png")
Forestmap=LoadImage("Forest 1.png")
Desertmap=LoadImage("Desert Sand 1.png")
Icemap=LoadImage("Ice 1b.png")
CreateWorld() ;Call Function CreateWorld
End Function
;
Function CreateWorld() ;Function begin
LandArea=Rnd(0,4) ;Pick a random number between 0 and 4
Select LandArea ;Decide which land map tile was chosen randomly above
Case 0 ;If Grass chosen, set DrawMapImage accordingly
DrawMapImage=Grassmap ;and go to function to draw this image to
DrawMapTile() ;backbuffer screen
;Repeat as needed...
Case 1
DrawMapImage=Oceanmap
DrawMapTile()
Case 2
DrawMapImage=Forestmap
DrawMapTile()
Case 3
DrawMapImage=Desertmap
DrawMapTile()
Case 4
DrawMapImage=Icemap
DrawMapTile()
End Select ;Stop decision loop
Select y ;If screen full from top to bottom, then wait for user input
Case 576
Vwait ; Wait for screen refresh
Flip ; Put backbuffer image onto front screen and show image
key=Waitkey()
Select key
Case 28 ;If Enter key pressed do the following
CLS ;Clear screen
FreeImage Grassmap ;Free the following images from memory...
FreeImage Oceanmap ;Repeat as needed...
FreeImage Forestmap
FreeImage Desertmap
FreeImage Icemap
x=0 ;Reset coordinates to 0
y=0
StartWorld() ;Start program over again
Default ;If any other key is pressed
End ;End program
End Select
End Select
End Function
;
Function DrawMapTile() ;Declaring DrawMapTile function
TileImage DrawMapImage,x,y ;Draw whatever image is stored in DrawMapImage
;variable at coordinates x,y
;MAV occurring HERE! Debugger says image does not exist...
x=x+64 ;increment value x (horizontal) by 64 so we can control image placement
Select x ;If x reaches edge of screen - a value of 768
Case 768
y=y+64 ;increment vertical y variable by 64
x=0 ;and put x back to zero, starting us over from left to right, next row
Default ;If x equals anything other than 768
CreateWorld() ;Call CreateWorld and draw next row of images
End Select
End Function
Anyway, I'd like to work my way up to a turn-based RPG strategy game in 2D and I'm taking it a piece at a time. I figured the first thing to master is a random map creator like the old school games used to use since that's how I want my game to work. This is my first attempt, and once I get this *very basic* version running, I'll start trying to improve it. But for now, I'm getting the dreaded "Memory Access Violation" error. From what I've found here in the forums, it appears that Blitz isn't loading my graphics correctly or I'm mishandling the TileImage variable somehow. That's my guess, but I don't see the glitch (yet). Note the TileImage command is where the debugger says "Image Does Not Exist."
Any one see what I'm missing? I'm using BIDE and the png files are in the same folder as the Blitz3d code. I have also tried adding the full folder description instead of just "picture.png" but that made no difference.
Thanks for any help.
==========================================================
;Draw map image and test world creation algorithm for tweaking
Global x=0 ;set coordinates x and y to 0 and make it a global variable
Global y=0
Global DrawMapImage
Global LandArea
StartWorld() ;start program
Function StartWorld()
Graphics 800,600 ;Set video mode
Setbuffer Backbuffer() ;Draw these images to the backbuffer
Grassmap=LoadImage("Grass 1.png") ;Load Images...
Oceanmap=LoadImage("Ocean 2.png")
Forestmap=LoadImage("Forest 1.png")
Desertmap=LoadImage("Desert Sand 1.png")
Icemap=LoadImage("Ice 1b.png")
CreateWorld() ;Call Function CreateWorld
End Function
;
Function CreateWorld() ;Function begin
LandArea=Rnd(0,4) ;Pick a random number between 0 and 4
Select LandArea ;Decide which land map tile was chosen randomly above
Case 0 ;If Grass chosen, set DrawMapImage accordingly
DrawMapImage=Grassmap ;and go to function to draw this image to
DrawMapTile() ;backbuffer screen
;Repeat as needed...
Case 1
DrawMapImage=Oceanmap
DrawMapTile()
Case 2
DrawMapImage=Forestmap
DrawMapTile()
Case 3
DrawMapImage=Desertmap
DrawMapTile()
Case 4
DrawMapImage=Icemap
DrawMapTile()
End Select ;Stop decision loop
Select y ;If screen full from top to bottom, then wait for user input
Case 576
Vwait ; Wait for screen refresh
Flip ; Put backbuffer image onto front screen and show image
key=Waitkey()
Select key
Case 28 ;If Enter key pressed do the following
CLS ;Clear screen
FreeImage Grassmap ;Free the following images from memory...
FreeImage Oceanmap ;Repeat as needed...
FreeImage Forestmap
FreeImage Desertmap
FreeImage Icemap
x=0 ;Reset coordinates to 0
y=0
StartWorld() ;Start program over again
Default ;If any other key is pressed
End ;End program
End Select
End Select
End Function
;
Function DrawMapTile() ;Declaring DrawMapTile function
TileImage DrawMapImage,x,y ;Draw whatever image is stored in DrawMapImage
;variable at coordinates x,y
;MAV occurring HERE! Debugger says image does not exist...
x=x+64 ;increment value x (horizontal) by 64 so we can control image placement
Select x ;If x reaches edge of screen - a value of 768
Case 768
y=y+64 ;increment vertical y variable by 64
x=0 ;and put x back to zero, starting us over from left to right, next row
Default ;If x equals anything other than 768
CreateWorld() ;Call CreateWorld and draw next row of images
End Select
End Function