|
Post by Ranger1800 on May 10, 2004 22:17:44 GMT -5
Okay my Space Adventure game is complete, i tried to run it and i get an error saying reDIMED variable and the error lies in this line here dim alienSprite and i didn't repeat this line in any other part of the program can someone help me? oh and one other thing i tried different array names and i still got the same message.
|
|
|
Post by Pizzasgood on May 11, 2004 16:56:33 GMT -5
You probably already checked this, but if it's in a subroutine or loop (including the main 'while' loop that all the instructions are in) that would mess it up. Other than that I have no ideas unless I can see the actual code.
|
|
|
Post by Ranger1800 on May 11, 2004 22:54:05 GMT -5
Alright here it is. ' Space Adventure version 1 ' HUD and Enemy coding: Branden Finch ' Sounds and Visuals: Fadi Hasan ' Start the sprite mode TextMode (Text_Buffered)
' Sprite textures dim shipTex, rockTex, ballTex shipTex = LoadTexture ("data\F117.png") rockTex = LoadTexture ("data\asteroid.png") ballTex = LoadTexture ("data\ball.png") struc SAlien dim alive dim sprite dim x#, y# endstruc
const MaxAliens = 100 dim SAlien aliens (MaxAliens) ' Animations ' Fadi's area /////////////////
' Tile textures dim tileTex (ImageStripFrames ("data\spacetiles.png") - 1) tileTex = LoadMipMapImageStrip ("data\spacetiles.png")
' Cavern tile textures dim cavernTex (ImageStripFrames ("data\caverntiles.png") - 1) cavernTex = LoadMipmapImageStrip ("data\caverntiles.png")
' Setup tile map dim tileMap, t(9)(19) tileMap = NewTileMap (tileTex) data 2,2,3,1,2,1,1,3,2,3 data 3,3,2,3,2,3,2,3,2,2 data 3,1,2,3,3,4,3,2,3,3 data 2,1,4,2,5,3,3,1,2,1 data 2,3,2,3,3,1,2,3,3,3 data 2,2,2,1,2,2,3,1,3,2 data 3,1,3,1,2,2,2,2,1,3 data 2,1,2,4,1,3,2,3,2,3 data 2,2,3,2,1,2,2,3,3,1 data 1,2,1,3,3,3,3,2,3,2 data 2,1,3,1,1,2,4,1,2,1 data 5,1,2,1,2,1,1,2,3,3 data 3,2,1,3,1,3,1,3,1,1 data 3,1,2,4,2,2,2,2,3,3 data 1,3,2,3,2,1,1,2,2,2 data 2,1,1,1,3,3,1,1,3,2 data 1,2,2,3,1,1,3,3,1,1 data 3,1,3,2,3,3,5,1,2,3 data 3,3,2,3,3,3,1,3,2,2 data 1,4,2,3,2,2,1,2,3,3 data 2,2,1,1,1,2,3,3,1,1
' Load tiles into array dim x, y for y = 0 to 19 for x = 0 to 9 read t (x)(y) next next
' Setup tilemap SprSetTiles (t) SprSetYRepeat (true) SprSetXRepeat (false) SprSetXSize (64) SprSetYSize (64) SprSetZOrder (100)
' Player sprite dim playerSprite playerSprite = NewSprite (shipTex) SprSetPos (320, 400) SprSetSize (50, 50) dim lives, score: lives = 3 dim fireButtonDown
dim i i = 1 for y = 1 to 10 for x = 1 to 10 ' Give aliens a sprite dim alienSprite alienSprite = NewSprite (rockTex) ' Postion the aliens near the top of the screen SprSetPos (30, 40) ' Set aliens alive aliens (i).alive = true i = i + 1 next next
' Store the alien direction dim xd#, yd# xd# = 1 yd# = .1
dim counter counter = 0 ' Main loop while true while SyncTimer (20) ' Move the aliens for i = 1 to maxAliens ' Only move the alien if it's not alive if aliens (i).alive then ' Update the alien's position aliens (i).x# = aliens (i).x# + xd# aliens (i).y# = aliens (i).y# + yd# ' Reposition the aliens BindSprite (aliens (i).sprite) SprSetPos (aliens (i).x#, aliens (i).y#) endif next ' Update the counter, to check if the aliens need to change direction counter = counter + 1 if counter > 200 then ' Reverse direction xd# = -xd# ' Reset the counter counter = 0 endif wend
DrawText () wend
dim bulletSprites (200), bulletCount while true
while SyncTimer (15) ' Move background (tileMap) downwards BindSprite (tileMap) SprSetY (sprY () + 1) ' Move sprites AnimateSprites () ' Move player BindSprite (playerSprite) if ScanKeyDown (Vk_Left) then SprSetX (SprX () - 3) endif if ScanKeyDown (Vk_Right) then SprSetX (SprX () + 3) endif if ScanKeyDown (Vk_Up) then SprSetY (SprY () - 3) endif if ScanKeyDown (Vk_Down) then SprSetY (SprY () + 3) endif ' Stop player from going off the screen if SprLeft () < 0 then SprSetX (SprXSize () / 2) endif if SprRight () > SpriteAreaWidth () then SprSetX (SpriteAreaWidth () - SprXSize () / 2) endif if SprTop () < 0 then SprSetY (SprYSize () / 2) endif if SprBottom () > SpriteAreaHeight () then SprSetY (SpriteAreaHeight () - SprYSize () / 2) endif ' Make bullets when player hits space if ScanKeyDown (Vk_Space) and not fireButtonDown then ' Make a new bullet bulletCount = bulletCount + 1 bulletSprites (bulletCount) = NewSprite (ballTex) SprSetsize (20, 20) SprSetPos (SprPos (playerSprite) + vec2 (0, -20)) SprSetYVel (-7) endif fireButtonDown = ScanKeyDown (Vk_Space) ' Delete any bullets that go off the screen i = 1 while i <= bulletCount BindSprite (bulletSprites (i)) if SprBottom () < 0 then DeleteSprite (bulletSprites (i)) bulletSprites (i) = bulletSprites (bulletCount) bulletCount = bulletCount - 1 else i = i + 1 endif wend wend ' Display the player info cls: locate 0, 0: print "Lives: ": for x = 1 to lives: print "3": next locate 30, 0: print "Score: " + score
' Draw Screen DrawText () wend
|
|
|
Post by Pizzasgood on May 12, 2004 17:35:15 GMT -5
Here's your problem:
dim i i = 1 for y = 1 to 10 for x = 1 to 10
' Give aliens a sprite dim alienSprite alienSprite = NewSprite (rockTex)
You have 'dim alienSprite' inside of two 'for' loops. If you dim it before the loops, it should work.
|
|
|
Post by Tom Mulgrew on May 13, 2004 20:22:35 GMT -5
' Give aliens a sprite dim alienSprite alienSprite = NewSprite (rockTex)
Problem is, this won't work properly whether the dim alienSprite is inside or outside of the loop.
What you're looking for is:
for y = 1 to 10 for x = 1 to 10
' Give aliens a sprite aliens(i).sprite = NewSprite (rockTex)
What NewSprite () does is it creates a sprite, and returns a handle (a number that corresponds to the sprite). NewSprite () gets called 100 times to create 100 sprites, and therefore return 100 handles (numbers) to control them.
The code was trying to store 100 handles in 1 variable!
You'll also notice that the code has 2 main loops! There are two "while true ... wend" sections. You need to re-organise them into 1 main loop, containing all the code.
Otherwise the program gets to the first main loop, and just keeps running it (it's an "infinite loop"), without ever getting to the code in the second one.
-Tom
|
|
|
Post by Ranger1800 on May 13, 2004 23:24:38 GMT -5
Okay i fixed the problem, but the background nor the player sprite isn't moving when i press the movement key for the player a the shoot key isn't working either and i put everything in that you provided for me and re-made the code did a little bit of tweaking. And also only one enemy is showing up on the screen whats gives
- Branden
|
|