|
Post by Ranger1800 on May 5, 2004 0:53:00 GMT -5
It's me Branden once again, a couple of weeks ago i posted a message in the Demo Programs forum on a new shooter. We've thought up a name for the game we're calling it space adventure, where you take control of a pilot who works for an anti-alien orginization named Space Corp Pilots. We haven't gotten to the coding part yet so i was wondering if someone could post a small code example for a scrolling shooter the asteroid demo isn't the type of shooter we want, we want one kinda like space invaders or something related to that. So if anyone even Tom can post reply with a small code example, that would greatly apriciated.
Thanks
- Branden
|
|
|
Post by Tom Mulgrew on May 5, 2004 5:52:55 GMT -5
Sounds cool. A bit like Raiden 2 in space then? Here's very basic example that might be of some use. You can fly up the screen and shoot. (Although there's nothing to shoot at yet.) May or may not be useful :).. -Tom ' Note: Text mode also means sprite mode. ' Buffered means that the text and sprites aren't drawn ' until we call DrawText () TextMode (TEXT_BUFFERED) ' Sprite textures dim shipTex, rockTex, ballTex shipTex = LoadTexture ("data\F117.png") rockTex = LoadTexture ("data\asteroid.png") ballTex = LoadTexture ("data\ball.png") ' Animations dim explodeTex (ImageStripFrames ("data\explode.png") - 1) explodeTex = LoadMipmapImageStrip ("data\explode.png") ' 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, i for y = 0 to 19 for x = 0 to 9 read t (x)(y) next next ' setup tilemap SprSetTiles (t) ' Write tile array into tile map SprSetYRepeat (true) ' Tiles repeat vertically SprSetXRepeat (false) SprSetXSize (64) SprSetYSize (64) SprSetZOrder (100)
' Player sprite dim playerSprite playerSprite = NewSprite (shipTex) ' Use spaceship texture SprSetPos (320, 400) SprSetSize (50, 50)
dim lives, score: lives = 3 dim fireButtonDown ' Used to track the state of the fire button dim bulletSprites (200), bulletCount
while true while SyncTimer (15)
' Move background (the 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 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
' Update screen cls: locate 0, 0: print "Lives: ": for x = 1 to lives: print "|": next locate 30, 0: print "Score: " + score ' Draw screen DrawText () wend
|
|
|
Post by Ranger1800 on May 5, 2004 12:59:42 GMT -5
Hey Tom where do i put the enemy sprites in the code and how would i line them up like in Space Invaders and have them shoot, i guess me and my friends agreed to make the enemy sprites asteroids, heres a quick overview to make it sound more convincing. The alien ships have a protective asteroid covering that make them look like normal asteroids but when the alien's opponents get in range they can fire at their enemies, un-detected does that sound good? And we also want to add a menu to the game so the players can play around with options, thanks for your help it's nice to have an expert helping ;D
- Branden
|
|
|
Post by Tom Mulgrew on May 5, 2004 21:41:09 GMT -5
Hi, You probably need to save it into the Basic4GL programs folder, otherwise it won't be able to find the graphics and will complain. (Don't know why it would spit out a garbage error message though. It's supposed to say something meaningful...) Anyway, here's some more code to look at. Please keep in mind that I can't write your program for you (well I probably could... but you know what I mean.) These are just examples of ways to do things. You'll need to examine them, figure out how they work and change or extend them as necessary. I've put quite a few comments in to explain what the intention is. Good luck, -Tom TextMode (TEXT_BUFFERED)
'Rock textures dim rockTex rockTex = LoadTexture ("data\asteroid.png")
' Here we declare a structure. We put inside this structure ' all of the data that we want to store for an alien. ' Everything we need to keep the alien moving and shooting ' and doing whatever it needs to do. struc SAlien dim alive ' A true/false flag. When the alien is alive, we move it around and draw it. ' When it's dead, we hide it and don't move it. dim sprite ' This is the sprite that we use to draw the alien dim x#, y# ' This is the aliens position on the screen endstruc
' We need to declare some variables to store these aliens. ' Because we will have lots of them, it makes sense to use ' an array.
const MaxAliens = 100 ' The maximum number of aliens dim SAlien aliens (MaxAliens) ' An array of 100 aliens ' Now we need to initialise the aliens ' We want to: ' Set them to alive ' Give each one a sprite ' Lay them out in a grid pattern dim x, y, i i = 1 ' This is the current alien index for y = 1 to 10 for x = 1 to 10 ' Give the alien a sprite aliens (i).sprite = NewSprite (rockTex) ' Give it a position aliens (i).x# = x * 40 aliens (i).y# = y * 30 SprSetPos (aliens (i).x#, aliens (i).y#) ' Set it to alive aliens (i).alive = true i = i + 1 ' Get ready to setup the next alien next next
' Store the alien direction ' All aliens will move in the same direction, so they stay ' in formation. Therefore we only need to store the direction ' once. dim xd#, yd# xd# = 1 yd# = .1
' We will use a counter variable to count how far the aliens ' have moved. ' When they get far enough, we change direction. dim counter counter = 0
' Main game loop while true while SyncTimer (20) ' Timing synchronisation ' Move the aliens for i = 1 to maxAliens ' Only move the alien if it's 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 sprite BindSprite (aliens (i).sprite) SprSetPos (aliens (i).x#, aliens (i).y#) endif next ' Update the counter to see 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
|
|