Hi guys, I am working on a map editor, and for some reason none of my sprites will draw. I've tried different things to no avail.
Here's the code:
Rem Project: Isometric Tile and Map Editor
Rem Created: Sunday, September 25, 2011
Rem ***** Main Source File *****
SET DISPLAY MODE 800, 600, 32
SYNC ON : SYNC RATE 60
DRAW SPRITES FIRST
// USER DEFINED TYPES
TYPE Image
img_num AS DWORD
img_marker AS STRING
img_filename AS STRING
ENDTYPE
TYPE MapElement
sprite_num AS DWORD
sprite_x AS INTEGER
sprite_y AS INTEGER
img_num AS DWORD
ENDTYPE
// SET GLOBAL VARIABLES:
GLOBAL load_image_pressed = 0
GLOBAL top_of_image_list = 0
GLOBAL currently_selected_image = -1
GLOBAL canvas_x = 0
GLOBAL canvax_y = 0
GLOBAL background_image AS DWORD
GLOBAL background_sprite AS DWORD
DIM image_list(0) AS Image // List of images
EMPTY ARRAY image_list(0)
DIM sprite_list(0) AS MapElement // List of sprites to be drawn on map
EMPTY ARRAY sprite_list(0)
// GET BACKGROUND IMAGE FOR EDITOR & SET UP TRANSPARENCY
SET IMAGE COLORKEY 255, 0, 255
background_image = Get_Free_Image()
LOAD IMAGE "media\editor_template.bmp", background_image
background_sprite = Get_Free_Sprite()
// OUR MAIN LOOP
DO
IF load_image_pressed = 1
Load_Image_Window()
GOTO end_of_loop
ENDIF
Normal_Window()
end_of_loop:
SYNC
LOOP
FUNCTION Get_Free_Image()
i = 1
REPEAT
i = i + 1
UNTIL IMAGE EXIST(i) = 0
ENDFUNCTION i
FUNCTION Get_Free_Sprite()
i = 1
REPEAT
i = i + 1
UNTIL IMAGE EXIST(i) = 0
ENDFUNCTION i
FUNCTION Load_Image_Window()
CLS RGB(0,0,0)
INK RGB(255,255,255),RGB(0,0,0)
ARRAY INSERT AT BOTTOM image_list(0)
max_items = ARRAY COUNT(image_list(0))
INPUT "Enter filename: ", image_list(max_items).img_filename
INPUT "Enter reference name: ", image_list(max_items).img_marker
image_list(max_items).img_num = Get_Free_Image()
LOAD IMAGE image_list(max_items).img_filename, image_list(max_items).img_num
load_image_pressed = 0
ENDFUNCTION
FUNCTION Normal_Window()
libp AS DWORD = 0
CLS RGB(200, 200, 200)
INK RGB(0,0,0),RGB(128,128,128)
//PASTE IMAGE background_image, 0, 0
SPRITE background_sprite, 0, 0, background_image
SET TEXT FONT "terminal" : SET TEXT SIZE 18 : SET TEXT TRANSPARENT
TEXT 0, 0, "MOUSE X,Y : "+Str$(MOUSEX())+","+Str$(MOUSEY())
TEXT 136, 582, "Currently selected image: "+Str$(currently_selected_image)
Draw_Canvas()
IF ARRAY COUNT(image_list(0)) > -1
Draw_Image_List()
ENDIF
libp = Text_Button(0, 22, "LOAD IMAGE")
IF libp = 1 THEN load_image_pressed = 1
ENDFUNCTION
FUNCTION Text_Button(x_pos AS DWORD, y_pos AS DWORD, txt AS STRING)
button_pressed = 0
text_width = TEXT WIDTH(txt)
text_height = TEXT HEIGHT(txt)
SET TEXT OPAQUE
TEXT x_pos,y_pos, txt
IF (MOUSEX() >= x_pos) AND (MOUSEX() <= x_pos+text_width)
IF (MOUSEY() >= y_pos) AND (MOUSEY() <= y_pos+text_height)
IF MOUSECLICK() = 1
INK RGB(0, 255,0),RGB(100,100,100)
TEXT x_pos,y_pos, txt
button_pressed = 1
ENDIF
ENDIF
ENDIF
ENDFUNCTION button_pressed
FUNCTION Draw_Image_List()
cur_y = 44
i = 0
visible_count = 0
max_items = ARRAY COUNT(image_list(0))
For i = top_of_image_list TO max_items
TEXT 0, cur_y, image_list(i).img_marker
//Check if list item is clicked on
IF (MOUSEX() >= 0) AND (MOUSEX() < 142)
IF (MOUSEY() >= cur_y) AND (MOUSEY() <= (cur_y+TEXT HEIGHT(image_list(i).img_marker)))
IF MOUSECLICK() = 1
//SET CLICKED ITEM TO CURRENTLY SELECTED ITEM AND ALLOW FOR PUTTING ON CANVAS
currently_selected_image = i
ENDIF
ENDIF
ENDIF
// Increase Y for next list item
cur_y = cur_y+TEXT HEIGHT(image_list(i).img_marker)
Next
ENDFUNCTION
FUNCTION Draw_Canvas()
max_sprites = ARRAY COUNT(sprite_list(0))
IF max_sprites > -1
FOR i = 0 TO max_sprites
SPRITE sprite_list(i).sprite_num, sprite_list(i).sprite_x, sprite_list(i).sprite_y, sprite_list(i).img_num
SHOW SPRITE sprite_list(i).sprite_num
NEXT
ENDIF
IF (MOUSEX() >= 135) AND (MOUSEX() <= 674)
IF (MOUSEY() >= 21) AND (MOUSEY() <= 579)
//TEXT 136, 582, "CANVAS X, Y: "
IF MOUSECLICK() = 1
// Place sprite at location
IF currently_selected_image > -1
ARRAY INSERT AT BOTTOM sprite_list(0)
sprite_list(ARRAY COUNT(sprite_list(0))).sprite_num = Get_Free_Sprite()
sprite_list(ARRAY COUNT(sprite_list(0))).sprite_x = MOUSEX()
sprite_list(ARRAY COUNT(sprite_list(0))).sprite_y = MOUSEY()
sprite_list(ARRAY COUNT(sprite_list(0))).img_num = image_list(currently_selected_image).img_num
SPRITE sprite_list(ARRAY COUNT(sprite_list(0))).sprite_num, sprite_list(ARRAY COUNT(sprite_list(0))).sprite_x, sprite_list(ARRAY COUNT(sprite_list(0))).sprite_y, image_list(currently_selected_image).img_num
ENDIF
ENDIF
IF MOUSECLICK() = 2
// Select sprite at location
ENDIF
ENDIF
ENDIF
ENDFUNCTION
And attached is the background image. Any help would be appreciated vastly.
Thanks!