Hi all, not sure if this is a noob mistake or an actual error.
I'm cobbling together a small tower defense to learn db for school - up to drawing the map in. At this point it's meant to use a couple of for loops to go through he x and y axes, then draw a 50x50 square, colour obtained by looking up the tower array using the map grid value.
In practice, it displays an oddly positioned staircase.
I'm confident the code is correct, though I've been known to be human at times, however if you replace the content of DrawMap() with a simple "box 8, 132, 182, 58", it will not draw(This is a manual entry of the cords it should be drawing at). Can anyone see a reason for this?
Also, does anyone have a link to the outlining feature in dbPro? I have it enabled but it seems to do nothing, and i can't seem to find documentation.
Thanks all.
Code listings, project attached as .rar:
ooze.dba (mainfile - variable declares, etc)
`#include "drawing.dba"
`#include "setup.dba"
Rem Project: ooze
Rem Created: Wednesday, May 26, 2010
Rem ***** Main Source File *****
Rem ***** Included Source File *****
dim iMap(255, 255)
dim towerList(10) AS TOWER
global terrainCount = 0
dim buttonList(9) AS BUTTONS
global mouseAction = 0
global backFrame AS FRAME
global infoFrame AS FRAME
global mapFrame AS FRAME
global buttonTemplate AS FRAME
global infoLineCount = 0
dim infoLines(8) AS STRING
TYPE FRAME
top AS INTEGER
left AS INTEGER
right AS INTEGER
bottom AS INTEGER
fore AS DWORD
back AS DWORD
ENDTYPE
TYPE BUTTONS
w AS INTEGER
h AS INTEGER
action as INTEGER
ENDTYPE
TYPE COORD
x AS INTEGER
y AS INTEGER
z AS INTEGER
ENDTYPE
TYPE TOWER
colour AS DWORD
health AS INTEGER
speed AS INTEGER
range AS INTEGER
ENDTYPE
`<> main function
main()
main.dba
Rem ***** Included Source File *****
FUNCTION main()
sync on
sync rate 30
set display mode 640, 516, screen depth()
set window layout 3, 1, 0
`button setups
print "Entering loop"
SetUpMap()
SetUpFrames()
SetUpButtons()
for iii = 0 to 8
infoLines(iii) = str$(iii)
next iii
Do
cls
DrawFrames()
DrawButtons()
DrawGrid()
MousePicture()
`DrawInfo()
MapNumbers()
DrawMap()
`DEBUGListButtons()
`DEBUGMousePos(mouseX(), mouseY(), mouseclick())
`DEBUGMousePic()
if (mouseclick())
infoLine("CLick: " + str$(mouseclick()))
if (mouseX() < backFrame.right)
ClickButtons(mouseX(), mouseY(), mouseclick())
endif
if (mouseX() >= mapFrame.left AND mouseX() <= mapFrame.right AND mouseY() >= mapFrame.top AND mouseY() <= mapFrame.bottom)
MapClick()
endif
endif
sync
loop
ENDFUNCTION
interface.dba (handles the interactions of the program with use input)
Rem ***** Included Source File *****
FUNCTION ClickButtons(mX AS INTEGER, mY AS INTEGER, mB as INTEGER)
tempY = (mY - 120) / 52 + 1
tempx = (mX - buttonTemplate.Left) / (buttonList(0).w + 4) + 1
if mB
`print "Clicked button " + str$(mB)
`print "X: " + str$(tempX)
`print "Y: " + str$(tempY)
if tempY = 1
select tempX
case 1:
mouseAction = 1
endcase
endselect
endif
endif
ENDFUNCTION
FUNCTION DEBUGMousePos(mX AS INTEGER, mY AS INTEGER, mB AS INTEGER)
tempY AS FLOAT
tempX AS FLOAT
tempY = floor((mY - 120) / 52) + 1
tempX = floor((mX - buttonTemplate.Left) / (buttonList(0).w + 4)) + 1
print " mX: " + str$(mX)
print " mY: " + str$(mY)
print " mB: " + str$(mB)
print " tempY: " + str$(tempY)
print " tempX: " + str$(tempX)
ENDFUNCTION
FUNCTION MousePicture()
if (mouseX() > mapFrame.left AND mouseX() < mapFrame.right AND mouseY() > mapFrame.top AND mouseY() < mapFrame.bottom)
select mouseAction
case 1:
top = mapFrame.top + mapGridY() * 50
left = mapFrame.left + mapGridX() * 50
bottom = mapFrame.top + mapGridY() * 50 + buttonList(0).h
right = mapFrame.left + mapGridX() * 50 + buttonList(0).w
ink RGB(0, 0, 255), RGB(0, 0, 0)
box left, top, right, bottom
endcase
endselect
endif
ENDFUNCTION
FUNCTION DEBUGMousePic()
top = mouseY() - (buttonList(0).w /2)
left = mouseX() - (buttonList(0).h / 2)
bottom = mouseY() + (buttonList(0).w / 2)
right = mouseX() + (buttonList(0).h / 2)
print "MAct: " + str$(mouseAction)
print "top: " + str$(top)
print "left: " + str$(left)
print "bottom: " + str$(bottom)
print "right: " + str$(right)
ENDFUNCTION
FUNCTION MapClick()
if (iMap(MapGridX(), MapGridY()) = 0)
iMap(MapGridX(), MapGridY()) = mouseAction
mouseAction = 0
endif
ENDFUNCTION
FUNCTION MapGridX()
tempX = (mouseX() - mapFrame.left) / 50
ENDFUNCTION tempX
FUNCTION MapGridY()
tempY = (mouseY() - mapFrame.top) / 50
ENDFUNCTION tempY
FUNCTION InfoLine(message AS STRING)
if (infoLineCount = 8)
for i = 0 to 7
infoLines(i) = infoLines(i+1)
next i
endif
infoLines(infoLineCount) = message
if (infoLineCount < 8)
inc infoLineCount
endif
ENDFUNCTION
FUNCTION MapNumbers()
ink 0, 255
for i = 0 to 10
for j = 0 to 10
gridX = (mapFrame.right - mapFrame.left) / 50
gridY = (mapFrame.bottom - mapFrame.top) / 50
text mapFrame.left + gridX + i * 50 , mapFrame.top + gridY + j * 50, str$(i) + ", " + str$(j)
next j
next i
ENDFUNCTION
drawing.dba (all the drawing functions. Problem in here)
Rem ***** Included Source File *****
FUNCTION DrawButtons()
coloum = 0
row = 0
drawLeft = 0
drawRight = 0
drawTop = 0
drawBottom = 0
for x = 0 to array count(buttonList())
if buttonList(x).action = 0
`disabled button
ink buttonTemplate.back, buttonTemplate.fore
else
ink buttonTemplate.fore, buttonTemplate.back
endif
if buttonList(x).h = 0 OR buttonList(x).w = 0
ink RGB(255, 255, 255), RGB(0, 0, 0)
print "Dead button at " + str$(x)
else
`box buttonTemplate.left, buttonTemplate.top, buttonTemplate.right, buttonTemplate.bottom
drawTop = buttonTemplate.top + row * 54
if coloum = 1
`print str$(buttonTemplate.left)
drawLeft = infoFrame.right - buttonList(x).w
coloum = 0
row = row + 1
else
drawLeft = buttonTemplate.left
coloum = 1
endif
drawRight = drawLeft + buttonList(x).w
drawBottom = drawTop + buttonlist(x).h
box drawLeft, drawTop, drawRight, drawBottom
endif
next x
ENDFUNCTION
FUNCTION DrawFrames()
print "Drawing Frames"
`back ground
iFore = RGB(75, 75, 200)
iBack = RGB(0, 0, 0)
ink iFore, iFore
box 0, 0, screen width(), screen height()
ink backFrame.fore, backFrame.back
box backFrame.left, backFrame.top, backFrame.right, backFrame.bottom
ink infoFrame.fore, infoFrame.back
box infoFrame.left, infoFrame.top, infoFrame.right, infoFrame.bottom
ink mapFrame.fore, mapFrame.back
box mapFrame.left, mapFrame.top, mapFrame.right, mapFrame.bottom
`ink buttonTemplate.fore, buttonTemplate.back
`box buttonTemplate.left, buttonTemplate.top, buttonTemplate.right, buttonTemplate.bottom
ENDFUNCTION
FUNCTION DrawGrid()
gridSize = 50
ink RGB(0, 0, 0), RGB(255, 255, 255)
for x = mapFrame.left to mapFrame.right step gridSize
for y = mapFrame.top to mapFrame.bottom step gridSize
line x, mapFrame.top, x, mapFrame.bottom
line mapFrame.left, y, mapFrame.right, y
next y
next x
ENDFUNCTION
FUNCTION DrawInfo()
set text size 9
ink RGB (255, 255, 255), infoFrame.fore
for i = 0 to 8
text infoFrame.left, infoFrame.top + (11 * i), infoLines(i)
next i
ENDFUNCTION
FUNCTION DrawMap()
baseX = mapFrame.left
baseY = mapFrame.top
drawLeft = baseX
drawTop = baseY
drawRight = drawLeft + 50
drawBottom = drawTop + 50
for x = 0 to 10
for y = 0 to 10
if (iMap(x, y) > 0)
ink towerList(iMap(x, y)).colour, mapFrame.fore
drawLeft = baseX + x * 50
drawTop = baseY + y * 50
drawRight = drawLeft + 50
drawBottom = drawTop + 50
box drawLeft, drawTop, drawRight, drawBottom
endif
next y
next x
ENDFUNCTION
setup.dba (inital setup work - map filling, frame positions, etc)
FUNCTION SetUpFrames()
backFrame.top = 8
backFrame.left = 8
backFrame.right = backFrame.left + 120
backFrame.bottom = backFrame.top + 500
backFrame.fore = RGB(30, 30, 30)
backFrame.back = RGB(0, 0, 0)
infoFrame.top = backFrame.top + 8
infoFrame.left = backFrame.left + 8
infoFrame.right = infoFrame.left + 104
infoFrame.bottom = infoFrame.top + 104
infoFrame.fore = RGB(200, 0, 0)
infoFrame.back = RGB(0, 0, 0)
mapFrame.top = backFrame.top
mapFrame.left = (screen width() - 8) - 500
mapFrame.right = screen width() - 8
mapFrame.bottom = backFrame.bottom
mapFrame.fore = RGB(255, 255, 255)
mapFrame.back = RGB(0, 0, 0)
buttonTemplate.top = infoFrame.bottom + 8
buttonTemplate.left = infoFrame.left
buttonTemplate.right = buttonTemplate.left + 50
buttonTemplate.bottom = buttonTemplate.top + 50
buttonTemplate.fore = RGB(0, 200, 0)
buttonTemplate.back = RGB(0, 0, 0)
ENDFUNCTION
FUNCTION SetUpButtons()
place = 0
REMSTART
w AS INTEGER
h AS INTEGER
action as INTEGER
REMEND
`basic tower
buttonList(place).w = 50
buttonList(place).h = 50
buttonList(place).action = 1
place = place+1
`remainder buttons
for x = place to array count(buttonList())
buttonList(place).w = 50
buttonList(place).h = 50
buttonList(place).action = 0
place = place+1
next x
ENDFUNCTION
FUNCTION DEBUGListButtons()
for x = 0 to 4
print "Button #" + str$(x)
print "w: " + str$(buttonList(x).w)
print "h: " + str$(buttonList(x).h)
print "action: "+ str$(buttonList(x).action)
print " "
next x
ENDFUNCTION
FUNCTION SetUpMap()
counter = 0
for x = 0 to 10
for y = 0 to 10
iMap(x, y) = 1
if counter = 15
cls
counter = 0
else
inc counter
endif
print "Map cord " + str$(x) + ", " + str$(y) + " is " + str$(iMap(x, y))
`**********************
`turning sync on will drastically lower load times
`**********************
`sync
if NOT iMap(x, y) = 0
wait key
endif
next y
next x
ENDFUNCTION
FUNCTION SetUpTowers()
remstart
TYPE TOWER
colour AS DWORD
health AS INTEGER
speed AS INTEGER
range AS INTEGER
remend
`dead tower
towerList(0).colour = RGB(0, 0, 0)
towerList(0).health = 0
towerList(0).speed = 0
towerList(0).range = 0
`basic tower
towerList(1).colour = RGB(255, 250, 5)
towerList(1).health = 10
towerList(1).speed = 2000
towerList(1).range = 3
ENDFUNCTION