04-30-2005, 05:52 PM
I am working on a little paint program for a game (so i can make my own sprites without bloading, bsaving or having 10 miles worth of DATA etc). I got almost everything to work exept the saving and loading, i am doing it a n00b way i know by diming the whole screen as an array but it is the only way i can think of.
I made it in freeBASIC.
the image that i load gets cut in half diagnolly and switched around. what do i do oh gurus of programming wisdom.
I made it in freeBASIC.
Code:
'set mouse
DECLARE SUB loadpic (screensave%(),pname$)
DECLARE SUB save (screensave%(),x1,y1, x2, y2, pname$)
DECLARE FUNCTION resetscreen(screensave%(), x1, y1, x2, y2)
CONST LEFTBUTTON = 1 ' sets so left mouse button works
CONST MIDDLEBUTTON = 4 ' sets so middle mouse button works
CONST RIGHTBUTTON = 2 ' sets so right mouse button works
CONST SHOWMOUSE = 1 ' sets so mouse arrow is visible
CONST HIDEMOUSE = 0 ' sets so mouse arrow is visible
DIM currentx AS INTEGER
DIM currenty AS INTEGER
DIM mousebuttons AS INTEGER
SCREEN 13
x1 = 0
y1 = 0
INPUT "Enter the maximum x co-ordinate"; x2
INPUT "Enter the maximum y co-ordinate"; y2
DIM screensave% (x2, y2)
FOR i = 0 TO x2
FOR s = 0 TO y2
screensave% (i, s) = 15
NEXT
NEXT
ClS
LINE (x1,y1)-(x2, y2), 15, BF
colour = 0
DO
k$ = InKey$
GETMOUSE currentx, currenty, ,mousebuttons
LINE (310,10)-(320, 20), colour, BF
LINE (x1, x1)- (x2, y2), 15, B
IF mousebuttons = LEFTBUTTON AND currenty >= y1 AND currenty <= y2 AND currentx >= x1 AND currentx <= x2 THEN
LINE (currentx, currenty)-(currentx + zoom, currenty + zoom), colour, BF
screensave%(currentx, currenty) = colour
END IF
IF k$ = "+" AND colour < 15 OR k$ = "=" AND colour < 15 THEN colour = colour + 1
IF k$ = "-" AND colour > 0 THEN colour = colour - 1
IF k$ = "s" THEN
pname$ = "test.azi"
CALL save (screensave%(),x1,y1, x2, y2, pname$)
END IF
IF k$ = "c" THEN CALL resetscreen(screensave%(), x1, y1, x2, y2)
IF k$ = "l" THEN
pname$ = "test.azi"
CALL loadpic (screensave%(), pname$)
END IF
LOOP UNTIL k$ = CHR$(27)
' this should load a image
SUB loadpic (screensave%(),pname$)
OPEN pname$ FOR INPUT AS #1
INPUT #1, x
INPUT #1, y
FOR y1 = 1 TO y
FOR x1 = 1 TO x
INPUT #1, clr
PSET (x1, y1), clr
screensave%(x1, y1) = clr
NEXT
NEXT
END SUB
' this should save the screen
SUB save (screensave%(),x1,y1, x2, y2, pname$)
OPEN pname$ FOR OUTPUT AS #1
PRINT #1, x2
PRINT #1, y2
FOR y3 = y1 TO y2
FOR x3 = x1 TO x2
PRINT #1, screensave% (x3,y3)
NEXT
NEXT
END SUB
' this should reset the screen
FUNCTION resetscreen(screensave%(), x1, y1, x2, y2)
LINE (x1,y1)-(x2, y2), 15, BF
FOR x = x1 TO x2
FOR y = y1 TO y2
screensave%(x,y) = 15
NEXT
NEXT
END FUNCTION
the image that i load gets cut in half diagnolly and switched around. what do i do oh gurus of programming wisdom.