10-21-2005, 10:37 AM
well im having problems with a space invaders clone im making. The .bas runs like a charm but once I compile it into a .exe i get a "subscript out or range". I know many people have posted these types of problems, and I am suspecting it has to do something with my arrays :???: But anyways here is the code
o yeah there is some extra lines of code because im still working on the game :roll:
o yeah there is some extra lines of code because im still working on the game :roll:
Code:
DECLARE SUB InitPaletteData (FileName$, PaletteArray&())
DECLARE SUB HARloadPut (FileName$, Array() AS INTEGER)
DECLARE SUB ChangePalette (PaletteArray&())
DEFINT A-Z
DIM MyArray(200) AS INTEGER
DIM MyArraym(200) AS INTEGER
SCREEN 13
'$DYNAMIC
'Load standard palette.
REDIM StandardPal&(1 TO 1)
CALL InitPaletteData("C:\GRADIENT.PAL", StandardPal&())
CALL ChangePalette(StandardPal&())
HARloadPut "c:\jelly.PUT", MyArray()
HARloadPut "c:\jellym.PUT", MyArraym()
player.x% = 142
player.y% = 180
PUT (player.x%, player.y%), MyArray, PSET
DO
WAIT &H3DA, 8
a$ = INKEY$
IF x = 100 THEN direction$ = "down"
IF y = 20 THEN direction$ = "right"
IF x = 0 AND y = 0 THEN direction$ = "left"
IF x = 0 AND y = 20 THEN direction$ = "up"
IF direction$ = "left" THEN x = x + 1
IF direction$ = "down" THEN y = y + 1
IF direction$ = "right" THEN x = x - 1
IF direction$ = "up" THEN y = y - 1
PUT (x, y), MyArray, PSET
PUT (x + 30, y), MyArray, PSET
PUT (x + 60, y), MyArray, PSET
PUT (x + 90, y), MyArray, PSET
PUT (x + 120, y), MyArray, PSET
PUT (x, y + 30), MyArray, PSET
PUT (x + 30, y + 30), MyArray, PSET
PUT (x + 60, y + 30), MyArray, PSET
PUT (x + 90, y + 30), MyArray, PSET
PUT (x + 120, y + 30), MyArray, PSET
PUT (x, y + 60), MyArray, PSET
PUT (x + 30, y + 60), MyArray, PSET
PUT (x + 60, y + 60), MyArray, PSET
PUT (x + 90, y + 60), MyArray, PSET
PUT (x + 120, y + 60), MyArray, PSET
pixelcolortop% = POINT(y, y)
IF player.x% = 0 THEN player.x% = 0 ELSE IF a$ = CHR$(0) + CHR$(75) THEN player.x% = player.x% - 1: PUT (player.x%, player.y%), MyArray, PSET
IF player.x% = 298 THEN player.x% = 298 ELSE IF a$ = CHR$(0) + CHR$(77) THEN player.x% = player.x% + 1: PUT (player.x%, player.y%), MyArray, PSET
FOR a% = 1 TO level%
LOCATE 23, 1: PRINT x, y
LOCATE 22, 1: PRINT playerx, playery
LOCATE 23, 6: PRINT pixelcolortop%
NEXT a%
LOOP
SUB ChangePalette (PaletteArray&())
'Break down all 256 colours into their RGB values.
DIM RGBval(0 TO 255, 0 TO 2)
FOR n = 0 TO 255
c& = PaletteArray&(n)
b = c& \ 65536: c& = c& - b * 65536
g = c& \ 256: c& = c& - g * 256
r = c&
RGBval(n, 0) = r
RGBval(n, 1) = g
RGBval(n, 2) = b
NEXT n
'Write colours directly to the video card.
WAIT &H3DA, &H8, &H8: WAIT &H3DA, &H8
FOR n = 0 TO 255
OUT &H3C8, n 'Select attribute.
OUT &H3C9, RGBval(n, 0) 'Write red.
OUT &H3C9, RGBval(n, 1) 'Write green.
OUT &H3C9, RGBval(n, 2) 'Write blue.
NEXT n
END SUB
SUB HARloadPut (FileName$, Array() AS INTEGER)
l& = 0
FF = FREEFILE
OPEN FileName$ FOR BINARY AS #FF
l& = LOF(FF)
CLOSE #FF
Ints = (l& - 7) \ 2
'$DYNAMIC
REDIM Array(Ints) AS INTEGER
DEF SEG = VARSEG(Array(0))
BLOAD FileName$, 0
DEF SEG
END SUB
'* InitPaletteData() subroutine:
'* Initializes a long integer array with palette colour data - this must be
'* done before changing palettes with the PALETTE USING statement. The
'* calling value of FileName$ dictates whether the data should be read
'* directly from a palette file or from DATA statements (see below).
'*
'* Parameters:
'* FileName$ - The name of the palette file to load. This must include
'* the path to the file if it does not reside in the
'* current directory. If FileName$ is an empty string (""),
'* palette data is read from DATA statements.
'* PaletteArray&() - Dynamic, long integer array to hold palette data.
'*
'* Note: Before calling InitPaletteData() to initialize a palette from DATA
'* statements, use an appropriate RESTORE statement to ensure the
'* correct DATA statements are read.
'*
SUB InitPaletteData (FileName$, PaletteArray&())
'Size array to hold all 256 colours.
REDIM PaletteArray&(0 TO 255)
IF FileName$ <> "" THEN
'*** Read palette data from file ***
FileNo = FREEFILE
OPEN FileName$ FOR BINARY AS #FileNo
FOR n = 0 TO 255
GET #FileNo, , colour&
PaletteArray&(n) = colour&
NEXT n
CLOSE #FileNo
ELSE
'*** Read palette data from DATA statements ***
FOR n = 0 TO 255
READ colour&
PaletteArray&(n) = colour&
NEXT n
END IF
END SUB