The reason for this is a two purpose venture. To get better at programming and I am going to add a couple of features to this that will export the ships is a certain form to directly import into my game, allowing me to easily add a variety of ships easily, higher armored, higher speed, etc. This editor I plan on having settings to export in such a fashion keeping the image and the stats in the same file format, so I only have to deal with one proprietary file versus 2-4 for each different kind of ship.
Hm.. I should look up memblocks again, been forever since I worked with one...
**EDIT**
I just had to post it, I actually like this ship better than the one I made earlier.... My UFO drawing skills are getting better!
sync Rate 60 : ` Set sync to try to make the program run smooth.
`Board is the image board you draw on.
`board(x, y, 1) Hold the color value.
`Board(x, y, 2) determines if the value is valid or not, if not, hides the spot.
dim board(32, 32, 2)
`Template is where you can store your most common colors for easy access and consistancy.
dim template(10)
`Sets the font for the Rest and Save buttons.
d3d_font 1, "calibri", 11, 0, 1, 0
`Start Main loop.
do
`Clear the screen for a fresh render.
cls
`Change the color if there is a valid color change.
colValue = mouseInput(colRed, colGreen, colBlue)
`Function that calls a lot of rendering functions, and draws the screen.
renderScreen(colRed, colGreen, colBlue)
`Sets the color to draw with.
colRed = rgbR(colValue)
colGreen = rgbG(colValue)
colBlue = rgbB(colValue)
`Refresh
sync
loop
`This function deals with most of the mouse input.
function mouseInput(colRed, colGreen, colBlue)
`If LMB is pressed.
if mouseClick() = 1
`These are for the color sliders and lets you change the color values.
if mouseX() > 5 and mouseX() < 260
if mouseY() > 100 and mouseY() < 105
colRed = mouseX() - 5
endif
if mouseY() > 115 and mouseY() < 120
colGreen = mouseX() - 5
endif
if mouseY() > 130 and mouseY() < 135
colBlue = mouseX() - 5
endif
endif
`These are the ones that let you draw on the main board.
if mouseX() > 290 and mouseX() < 610
if mouseY() > 50 and mouseY() < 370
xBox = ( mouseX() - 290 ) / 10
yBox = ( mouseY() - 50 ) / 10
board(xBox, yBox, 2) = 1
board(xBox, yBox, 1) = rgb(colRed, colGreen, colBlue)
endif
endif
endif
`This is the RMB
if mouseClick() = 2
`This lets you 'erase' values from the drawing board.
if mouseX() > 290 and mouseX() < 610
if mouseY() > 50 and mouseY() < 370
xBox = ( mouseX() - 290 ) / 10
yBox = ( mouseY() - 50 ) / 10
board(xBox, yBox, 2) = 0
board(xBox, yBox, 1) = 0
endif
endif
endif
`These are to return the color values to the main loop.
`This is for when the sliders are slid, and will not be effected otherwise.
colVal = rgb(colRed, colGreen, colBlue)
`This is when you use the templates, this will set and load the color values.
colVal = SetTemplates(colVal)
EndFunction colVal
`This is the main rendering function, it controls all the drawing functions in the ap.
function renderScreen(red, green, blue)
`This clears the screen and puts a black border around the entire area.
d3d_color 0, 0, 0, 255
d3d_box 0, 0, 640, 480
d3d_color 150, 150, 150, 255
d3d_box 1, 1, 638, 478
`This is where it call the draw functions, most are self explainatory, and will be explained above the respective function when they are declared.
`I added the temp flag in case I need to debug these for any reason.
temp = drawRed(red)
temp = drawGreen(green)
temp = drawBlue(blue)
temp = drawPreview(red, green, blue)
temp = renderDrawSpace()
temp = drawResetButton()
temp = drawPreviewWindow()
temp = drawTemplates()
temp = drawSaveButton()
EndFunction 0
`This draws the red slider bar and the slider itself.
function drawRed(redVal)
`This allows for the gradient to be applied.
d3d_color 0, 0, 0, 255
d3d_box 5, 100, 269, 105
`This is the red box itself.
d3d_box 5, 100, 269, 105, 0, rgb(255, 0, 0), 0, rgb(255, 0, 0)
`This is the slider.
d3d_box 7+redVal, 95, 12+redVal, 110
d3d_color 200, 200, 200, 255
d3d_box 8+redVal, 96, 11+redVal, 109
endFunction 0
function drawGreen(greenVal)
`This allows for the gradient to be applied.
d3d_color 0, 0, 0, 255
d3d_box 5, 115, 269, 120
`This is the green box itself.
d3d_box 5, 115, 269, 120, 0, rgb(0, 255, 0), 0, rgb(0, 255, 0)
`This is the slider.
d3d_box 7+greenVal, 110, 12+greenVal, 125
d3d_color 200, 200, 200, 255
d3d_box 8+greenVal, 111, 11+greenVal, 124
endFunction 0
function drawBlue(blueVal)
`This allows for the gradient to be applied.
d3d_color 0, 0, 0, 255
d3d_box 5, 130, 269, 135
`This is the blue box itself.
d3d_box 5, 130, 269, 135, 0,rgb(0, 0, 255), 0, rgb(0, 0, 255)
`This is the slider.
d3d_box 7+blueVal, 125, 12+blueVal, 140
d3d_color 200, 200, 200, 255
d3d_box 8+blueVal, 126, 11+blueVal, 139
endFunction 0
`This function draws the color preview so you can see what you are drawing with.
function drawPreview(redVal, greenVal, blueVal)
`This applies a black border.
d3d_color 0, 0, 0, 255
d3d_box 4, 149, 106, 251
`The color preview itself.
d3d_color redVal, greenVal, blueVal, 255
d3d_box 5, 150, 105, 250
endFunction 0
`This function renders the drawing board.
`This builds the box, the border, the gridlines, the four cubes for each empty space a box for the known colors.
function renderDrawSpace()
`Applies the black border.
d3d_color 0, 0, 0, 255
d3d_box 289, 49, 611, 371
`Sets the stage to be drawn.
d3d_color 235, 235, 235, 255
d3d_box 290, 50, 610, 370
`This loop takes the values for the board array to apply the color to the board.
`It also creates a series of 4 sqaures in the spot if there is no valid values.
for x = 0 to 31 step 1
for y = 0 to 31 step 1
`Determine whether the value is valid. 1=valid.
if board(x, y, 2) = 1
`Draw the box.
d3d_color rgbR(board(x, y, 1)),rgbG(board(x, y, 1)),rgbB(board(x, y, 1)), 255
d3d_box (290 + (x*10)), (50 + (y*10)), (300 + (x*10)), (60 + (y*10))
else
`Draws the four cubes in case there is no valid values.
d3d_color 235, 235, 235, 255
d3d_box (290 + (x*10)), (50 + (y*10)), (295 + (x*10)), (55 + (y*10))
d3d_box (295 + (x*10)), (55 + (y*10)), (300 + (x*10)), (60 + (y*10))
d3d_color 135, 135, 135, 255
d3d_Box (295 + (x*10)), (50 + (y*10)), (300 + (x*10)), (55 + (y*10))
d3d_Box (290 + (x*10)), (55 + (y*10)), (295 + (x*10)), (60 + (y*10))
endif
next y
next x
`This loop generates white dots that make squares that seperates the locations where the pixels can be placed.
d3d_color 255, 255, 255, 255
for x = 1 to 31 step 1
for y = 1 to 160 step 1
xOne = 290 + ( x * 10 )
yOne = 49 + ( y * 2 )
xTwo = 289 + ( y * 2 )
yTwo = 50 + ( x * 10 )
d3d_dot xOne, yOne
d3d_dot xTwo, yTwo
next y
next x
endFunction 0
`This draws and checks to see if you clicked the reset button.
`If you have, then it negated the array the colors are saved in.
function drawResetButton()
`Apply a black border.
D3D_Color 0, 0, 0, 255
d3d_box 289, 389, 341, 401
`The button itself.
d3d_color 165, 165, 165, 255
d3d_box 290, 390, 340, 400
`The text.
d3d_color 20, 20, 20, 255
d3d_startText
d3d_text 1, 315, 389, 1, "RESET"
d3d_endText
`If you click it, darkend the button and clear the array.
if mouseclick() = 1
if mouseX() > 290 and mouseX() < 340
if mouseY() > 390 and mouseY() < 400
d3d_color 0, 0, 0, 125
d3d_box 290, 390, 340, 400
for x = 0 to 31 step 1
for y = 0 to 31 step 1
`Invalidate the board without erasing the array.
board(x, y, 2) = 0
next y
next x
endif
endif
endif
endFunction 0
`Draws and checks to see if you clicked the save button.
`If you did, it darkens the button, and saves a file called "test.bmp" based off the preview of the picture on the left.
function drawSaveButton()
`Apply the black border.
D3D_Color 0, 0, 0, 255
d3d_box 349, 389, 451, 401
`Make the button itself.
d3d_color 165, 165, 165, 255
d3d_box 350, 390, 450, 400
`Make the text.
d3d_color 20, 20, 20, 255
d3d_startText
d3d_text 1, 400, 389, 1, "SAVE IMAGE"
d3d_endText
`if you click it, take a snapshot of the preview and save it.
if mouseclick() = 1
if mouseX() > 350 and mouseX() < 450
if mouseY() > 390 and mouseY() < 400
d3d_color 0, 0, 0, 125
d3d_box 350, 390, 450, 400
Get Image 1, 5, 255, 37, 287
Save Image "test.bmp", 1
endif
endif
endif
endFunction 0
`This renders the progress of the drawing in actual 32 x 32 to the left side of the screen.
Function DrawPreviewWindow()
`Sets the BG to black.
d3d_color 0, 0, 0, 255
d3d_box 5, 255, 37, 287
`Loops through each value to get the color values to print.
for x = 0 to 31 step 1
for y = 0 to 31 step 1
if board(x, y, 2) > 0
d3d_color rgbR(board(x, y, 1)), rgbG(board(x, y, 1)), rgbB(board(x, y, 1)), 255
d3d_dot 5+x, 255+y
endif
next y
next x
endfunction 0
`This draws the hot key templates under the color sliders.
Function DrawTemplates()
d3d_color 0, 0, 0, 255
d3d_box 114, 149, 225, 161
`cycles through the array to draw each color in the template.
for x = 0 to 9 step 1
d3d_color rgbR(template(x)), rgbG(template(x)), rgbB(template(x)), 255
d3d_box (115 + (x*11)), 150, (125 + (x * 11)), 160
next x
endfunction 0
`This function checks for certain key combos to set and change to a template hot key.
Function SetTemplates(curCol)
`You must hold shift and a numaric value between 1 and 0 to set these hot keys, alloing for up to 10 presets.
`This is the setting if's block.
if KEYSTATE(42) > 0
if KEYSTATE(2) > 0
template(0) = curCol
endif
if KEYSTATE(3) > 0
template(1) = curCol
endif
if KEYSTATE(4) > 0
template(2) = curCol
endif
if KEYSTATE(5) > 0
template(3) = curCol
endif
if KEYSTATE(6) > 0
template(4) = curCol
endif
if KEYSTATE(7) > 0
template(5) = curCol
endif
if KEYSTATE(8) > 0
template(6) = curCol
endif
if KEYSTATE(9) > 0
template(7) = curCol
endif
if KEYSTATE(10) > 0
template(8) = curCol
endif
if KEYSTATE(11) > 0
template(9) = curCol
endif
endif
`This is the retrieval if's block.
if KEYSTATE(42) = 0
if KEYSTATE(2) > 0
curCol = template(0)
endif
if KEYSTATE(3) > 0
curCol = template(1)
endif
if KEYSTATE(4) > 0
curCol = template(2)
endif
if KEYSTATE(5) > 0
curCol = template(3)
endif
if KEYSTATE(6) > 0
curCol = template(4)
endif
if KEYSTATE(7) > 0
curCol = template(5)
endif
if KEYSTATE(8) > 0
curCol = template(6)
endif
if KEYSTATE(9) > 0
curCol = template(7)
endif
if KEYSTATE(10) > 0
curCol = template(8)
endif
if KEYSTATE(11) > 0
curCol = template(9)
endif
endif
endfunction curCol
This is the commented code. If you have any questions, feel free to ask.
**EDIT**
Ok, with the dot commands, I switched it back to the built in DBPro commands from the d3d commands, and used lock/unlock pixels, and removed a little redundant rendering, and it went from 9-11fps to 30. Here is the update.
Sync On
sync Rate 60 : ` Set sync to try to make the program run smooth.
`Board is the image board you draw on.
`board(x, y, 1) Hold the color value.
`Board(x, y, 2) determines if the value is valid or not, if not, hides the spot.
dim board(32, 32, 2)
`Template is where you can store your most common colors for easy access and consistancy.
dim template(10)
`Sets the font for the Rest and Save buttons.
d3d_font 1, "calibri", 11, 0, 1, 0
`Start Main loop.
do
`Clear the screen for a fresh render.
cls
`Change the color if there is a valid color change.
colValue = mouseInput(colRed, colGreen, colBlue)
`Function that calls a lot of rendering functions, and draws the screen.
renderScreen(colRed, colGreen, colBlue)
`Sets the color to draw with.
colRed = rgbR(colValue)
colGreen = rgbG(colValue)
colBlue = rgbB(colValue)
d3d_starttext
d3d_text 1, 5, 5, 0, str$(screen fps())
d3d_endtext
`Refresh
sync
loop
`This function deals with most of the mouse input.
function mouseInput(colRed, colGreen, colBlue)
`If LMB is pressed.
if mouseClick() = 1
`These are for the color sliders and lets you change the color values.
if mouseX() > 5 and mouseX() < 260
if mouseY() > 100 and mouseY() < 105
colRed = mouseX() - 5
endif
if mouseY() > 115 and mouseY() < 120
colGreen = mouseX() - 5
endif
if mouseY() > 130 and mouseY() < 135
colBlue = mouseX() - 5
endif
endif
`These are the ones that let you draw on the main board.
if mouseX() > 290 and mouseX() < 610
if mouseY() > 50 and mouseY() < 370
xBox = ( mouseX() - 290 ) / 10
yBox = ( mouseY() - 50 ) / 10
board(xBox, yBox, 2) = 1
board(xBox, yBox, 1) = rgb(colRed, colGreen, colBlue)
endif
endif
endif
`This is the RMB
if mouseClick() = 2
`This lets you 'erase' values from the drawing board.
if mouseX() > 290 and mouseX() < 610
if mouseY() > 50 and mouseY() < 370
xBox = ( mouseX() - 290 ) / 10
yBox = ( mouseY() - 50 ) / 10
board(xBox, yBox, 2) = 0
board(xBox, yBox, 1) = 0
endif
endif
endif
`These are to return the color values to the main loop.
`This is for when the sliders are slid, and will not be effected otherwise.
colVal = rgb(colRed, colGreen, colBlue)
`This is when you use the templates, this will set and load the color values.
colVal = SetTemplates(colVal)
EndFunction colVal
`This is the main rendering function, it controls all the drawing functions in the ap.
function renderScreen(red, green, blue)
`This clears the screen and puts a black border around the entire area.
d3d_color 0, 0, 0, 255
d3d_box 0, 0, 640, 480
d3d_color 150, 150, 150, 255
d3d_box 1, 1, 638, 478
`This is where it call the draw functions, most are self explainatory, and will be explained above the respective function when they are declared.
`I added the temp flag in case I need to debug these for any reason.
temp = drawRed(red)
temp = drawGreen(green)
temp = drawBlue(blue)
temp = drawPreview(red, green, blue)
temp = renderDrawSpace()
temp = drawResetButton()
temp = drawPreviewWindow()
temp = drawTemplates()
temp = drawSaveButton()
EndFunction 0
`This draws the red slider bar and the slider itself.
function drawRed(redVal)
`This allows for the gradient to be applied.
d3d_color 0, 0, 0, 255
d3d_box 5, 100, 269, 105
`This is the red box itself.
d3d_box 5, 100, 269, 105, 0, rgb(255, 0, 0), 0, rgb(255, 0, 0)
`This is the slider.
d3d_box 7+redVal, 95, 12+redVal, 110
d3d_color 200, 200, 200, 255
d3d_box 8+redVal, 96, 11+redVal, 109
endFunction 0
function drawGreen(greenVal)
`This allows for the gradient to be applied.
d3d_color 0, 0, 0, 255
d3d_box 5, 115, 269, 120
`This is the green box itself.
d3d_box 5, 115, 269, 120, 0, rgb(0, 255, 0), 0, rgb(0, 255, 0)
`This is the slider.
d3d_box 7+greenVal, 110, 12+greenVal, 125
d3d_color 200, 200, 200, 255
d3d_box 8+greenVal, 111, 11+greenVal, 124
endFunction 0
function drawBlue(blueVal)
`This allows for the gradient to be applied.
d3d_color 0, 0, 0, 255
d3d_box 5, 130, 269, 135
`This is the blue box itself.
d3d_box 5, 130, 269, 135, 0,rgb(0, 0, 255), 0, rgb(0, 0, 255)
`This is the slider.
d3d_box 7+blueVal, 125, 12+blueVal, 140
d3d_color 200, 200, 200, 255
d3d_box 8+blueVal, 126, 11+blueVal, 139
endFunction 0
`This function draws the color preview so you can see what you are drawing with.
function drawPreview(redVal, greenVal, blueVal)
`This applies a black border.
d3d_color 0, 0, 0, 255
d3d_box 4, 149, 106, 251
`The color preview itself.
d3d_color redVal, greenVal, blueVal, 255
d3d_box 5, 150, 105, 250
endFunction 0
`This function renders the drawing board.
`This builds the box, the border, the gridlines, the four cubes for each empty space a box for the known colors.
function renderDrawSpace()
`Applies the black border.
d3d_color 0, 0, 0, 255
d3d_box 289, 49, 611, 371
`Sets the stage to be drawn.
d3d_color 235, 235, 235, 255
d3d_box 290, 50, 610, 370
`This loop takes the values for the board array to apply the color to the board.
`It also creates a series of 4 sqaures in the spot if there is no valid values.
for x = 0 to 31 step 1
for y = 0 to 31 step 1
`Determine whether the value is valid. 1=valid.
if board(x, y, 2) = 1
`Draw the box.
d3d_color rgbR(board(x, y, 1)),rgbG(board(x, y, 1)),rgbB(board(x, y, 1)), 255
d3d_box (290 + (x*10)), (50 + (y*10)), (300 + (x*10)), (60 + (y*10))
else
`Draws the four cubes in case there is no valid values.
`d3d_color 235, 235, 235, 255
`d3d_box (290 + (x*10)), (50 + (y*10)), (295 + (x*10)), (55 + (y*10))
`d3d_box (295 + (x*10)), (55 + (y*10)), (300 + (x*10)), (60 + (y*10))
d3d_color 135, 135, 135, 255
d3d_Box (295 + (x*10)), (50 + (y*10)), (300 + (x*10)), (55 + (y*10))
d3d_Box (290 + (x*10)), (55 + (y*10)), (295 + (x*10)), (60 + (y*10))
endif
next y
next x
`This loop generates white dots that make squares that seperates the locations where the pixels can be placed.
`d3d_color 255, 255, 255, 255
ink rgb(255, 255, 255), 0
lock pixels
for x = 1 to 31 step 1
for y = 1 to 160 step 1
xOne = 290 + ( x * 10 )
yOne = 49 + ( y * 2 )
xTwo = 289 + ( y * 2 )
yTwo = 50 + ( x * 10 )
`d3d_dot xOne, yOne
`d3d_dot xTwo, yTwo
dot xOne, yOne
dot xTwo, yTwo
next y
next x
unlock pixels
endFunction 0
`This draws and checks to see if you clicked the reset button.
`If you have, then it negated the array the colors are saved in.
function drawResetButton()
`Apply a black border.
D3D_Color 0, 0, 0, 255
d3d_box 289, 389, 341, 401
`The button itself.
d3d_color 165, 165, 165, 255
d3d_box 290, 390, 340, 400
`The text.
d3d_color 20, 20, 20, 255
d3d_startText
d3d_text 1, 315, 389, 1, "RESET"
d3d_endText
`If you click it, darkend the button and clear the array.
if mouseclick() = 1
if mouseX() > 290 and mouseX() < 340
if mouseY() > 390 and mouseY() < 400
d3d_color 0, 0, 0, 125
d3d_box 290, 390, 340, 400
for x = 0 to 31 step 1
for y = 0 to 31 step 1
`Invalidate the board without erasing the array.
board(x, y, 2) = 0
next y
next x
endif
endif
endif
endFunction 0
`Draws and checks to see if you clicked the save button.
`If you did, it darkens the button, and saves a file called "test.bmp" based off the preview of the picture on the left.
function drawSaveButton()
`Apply the black border.
D3D_Color 0, 0, 0, 255
d3d_box 349, 389, 451, 401
`Make the button itself.
d3d_color 165, 165, 165, 255
d3d_box 350, 390, 450, 400
`Make the text.
d3d_color 20, 20, 20, 255
d3d_startText
d3d_text 1, 400, 389, 1, "SAVE IMAGE"
d3d_endText
`if you click it, take a snapshot of the preview and save it.
if mouseclick() = 1
if mouseX() > 350 and mouseX() < 450
if mouseY() > 390 and mouseY() < 400
d3d_color 0, 0, 0, 125
d3d_box 350, 390, 450, 400
Get Image 1, 5, 255, 37, 287
Save Image "test.bmp", 1
endif
endif
endif
endFunction 0
`This renders the progress of the drawing in actual 32 x 32 to the left side of the screen.
Function DrawPreviewWindow()
`Sets the BG to black.
d3d_color 0, 0, 0, 255
d3d_box 5, 255, 37, 287
`Loops through each value to get the color values to print.
Lock Pixels
for x = 0 to 31 step 1
for y = 0 to 31 step 1
if board(x, y, 2) > 0
`d3d_color rgbR(board(x, y, 1)), rgbG(board(x, y, 1)), rgbB(board(x, y, 1)), 255
`d3d_dot 5+x, 255+y
dot 5+x, 255+y, board(x, y, 1)
endif
next y
next x
Unlock Pixels
endfunction 0
`This draws the hot key templates under the color sliders.
Function DrawTemplates()
d3d_color 0, 0, 0, 255
d3d_box 114, 149, 225, 161
`cycles through the array to draw each color in the template.
for x = 0 to 9 step 1
d3d_color rgbR(template(x)), rgbG(template(x)), rgbB(template(x)), 255
d3d_box (115 + (x*11)), 150, (125 + (x * 11)), 160
next x
endfunction 0
`This function checks for certain key combos to set and change to a template hot key.
Function SetTemplates(curCol)
`You must hold shift and a numaric value between 1 and 0 to set these hot keys, alloing for up to 10 presets.
`This is the setting if's block.
if KEYSTATE(42) > 0
if KEYSTATE(2) > 0
template(0) = curCol
endif
if KEYSTATE(3) > 0
template(1) = curCol
endif
if KEYSTATE(4) > 0
template(2) = curCol
endif
if KEYSTATE(5) > 0
template(3) = curCol
endif
if KEYSTATE(6) > 0
template(4) = curCol
endif
if KEYSTATE(7) > 0
template(5) = curCol
endif
if KEYSTATE(8) > 0
template(6) = curCol
endif
if KEYSTATE(9) > 0
template(7) = curCol
endif
if KEYSTATE(10) > 0
template(8) = curCol
endif
if KEYSTATE(11) > 0
template(9) = curCol
endif
endif
`This is the retrieval if's block.
if KEYSTATE(42) = 0
if KEYSTATE(2) > 0
curCol = template(0)
endif
if KEYSTATE(3) > 0
curCol = template(1)
endif
if KEYSTATE(4) > 0
curCol = template(2)
endif
if KEYSTATE(5) > 0
curCol = template(3)
endif
if KEYSTATE(6) > 0
curCol = template(4)
endif
if KEYSTATE(7) > 0
curCol = template(5)
endif
if KEYSTATE(8) > 0
curCol = template(6)
endif
if KEYSTATE(9) > 0
curCol = template(7)
endif
if KEYSTATE(10) > 0
curCol = template(8)
endif
if KEYSTATE(11) > 0
curCol = template(9)
endif
endif
endfunction curCol
