Well looky here, I now have the bare essentials for a grid based map editor!
` Project: Jack Rabbit Map Editor
` Created: 2015-07-25
` Include us some AGC files!
#Include "constants.agc"
SetVirtualResolution(1024, 768)
SetWindowSize(1024, 768, 0)
SetWindowTitle("Jack Rabbit - Tile Map Editor")
` Set up a test
Type thisTest
exist as integer
tileID as Integer
tileName as String
EndType
#constant width = 32
#constant height = 16
#constant gridSpace = 32
map as thisTest[width,height]
itemCount = 0
` Main Loop
Do
` Draw the grid
DrawGrid()
` If the user left-clicks to create a tile
If GetRawMouseLeftState() = 1
` Tile indices
x = GridSnap(GetPointerX(),gridSpace)/gridSpace
y = GridSnap(GetPointerY(),gridSpace)/gridSpace
` If in bounds create the sprite
If x >= 0 and x <= width-1 and y >= 0 and y <= height-1
If map[x,y].exist = 0
` set the flag to in use
map[x,y].exist = 1
map[x,y].tileID = CreateSprite(0)
SetSpriteSize(map[x,y].tileID, gridSpace, gridSpace)
SetSpritePosition(map[x,y].tileID, GridSnap(GetPointerX(), gridSpace), GridSnap(GetPointerY(), gridSpace))
itemCount = itemCount + 1
EndIf
Endif
Endif
` If the user right-clicks to delete a tile
If GetRawMouseRightState() = 1
posX = GetPointerX() ` Get the x position
posY = GetPointerY() ` Get the y position
` Tile indices
x = GridSnap(posX,gridSpace)/gridSpace
y = GridSnap(posY,gridSpace)/gridSpace
If x >= 0 and x <= width-1 and y >= 0 and y <= height-1
` Create the sprite
If map[x,y].exist = 1
DeleteSprite(map[x,y].tileID)
` Set the flag to not in use
map[x,y].exist = 0
itemCount = itemCount - 1
EndIf
Endif
EndIf
Print( itemCount )
Sync()
Loop
Function GridSnap(value, gridSize)
local result
result = value/gridSize
result = result*gridSize
EndFunction result
Function DrawGrid()
` Define the size of our grid
rows = width
cols = height
` Use these as the "line ending" variables
w = width * gridSpace
h = height * gridSpace
` Draw the rows
For x = 0 to rows
DrawLine(x * gridSpace, 0, x * gridSpace, h, MakeColor(75, 75, 75), MakeColor(75, 75, 75))
Next x
` Draw the columns
For y = 0 to cols
DrawLine(0, y * gridSpace, w, y * gridSpace, MakeColor(75, 75, 75), MakeColor(75, 75, 75))
Next y
EndFunction
I even figured out how to draw the grids and delete the tiles on my own. Yay! Easy to do once I understood exactly what I was doing wrong in the first place.
I can't figure out why the examples I was going off of showed the use of a for loop, when it seems to only be required when saving out the map/loading it back in. Maybe it was because the example was designed for a different technique? I guess that's what I get for trying to code something in AppGameKit basic based off of C++
@MrV:
I checked out that book you've been talking about, looks quite interesting! I shall be reading it as well soon!
----------------------------------------------------------------------
An update on my mother! She will be coming home today, she will have spent two weeks in the hospital exactly. It's weird how time has been going so slow, and yet so fast. We should be hearing her pathology results either today, or some other time before Saturday. Hoping for the best! Even if it does end up being cancer we will hopefully have caught it early and they may be able to cure her, so that's what we're really hoping for.
She's so sick of the hospital, and I'm sick of going there every day or so because every time I go there, within an hour or two I get a headache. I don't know if it's because of the lighting there, or the smell (constant cleaner!), or maybe some sounds or something like that, but I don't know how she has put up with it for two weeks! Insanity!
I will be very glad she's home finally, it will make life a bit easier for her!
Official Forum President from June 20th, 2015 - June 20th, 2016 (when my successor is elected, whomever that may be!).