The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
invaders
Posted by: david wheeler | February 27, 2011 @ 7:22am
BlitzBasic Code
[
Download
]
; PROJECT : spaceinvaders ; AUTHOR : david wheeler ; CREATED : 27/01/2011 ; EDITED : 27/02/2011 ; --------------------------------------------------------------------- OpenScreen 640,480,32,2 SetFPS 60 ScreenVsync On Mouse Off Global quit=False Global invaderimage1=1 Global invaderimage2=4 Global shipimage=60 Global numofinvaders=0 Global shipsprite=60 Global movem Global anim Global dropem Global tit global v Global changedir = 1 ; *** edit here and give a start direction; could be 1 or -1 Type tinvader image oldimage Status speed Xpos,Ypos animadd count EndType Type tship image xpos ypos speed status EndType Dim invaders(100) As tinvader Dim ship(1) As tship creategfx() setupwave() s$="Number of Invaders = " s$=s$+Str$(numofinvaders) ship(1).speed=2 Repeat Cls 0 v=ScanCode() Print s$ Print shipimage tick=tick+1 If tick>40 tick=0 tit=1 movem=1 EndIf control_Invaders() control_player() movem=0 drop=0 DrawAllSprites Sync Until quit=True function control_invaders() ;*** this is to check wether to change dir and drop or not For n=1 To numofinvaders If invaders(n).xpos+invaders(n).speed > 608 drop = 1 changedir = -1 ExitFor ElseIf invaders(n).xpos+invaders(n).speed < 0 drop = 1 changedir = 1 ExitFor Else drop = 0 EndIf Next ;*** end edit part For n=1 To numofinvaders If movem=1 invaders(n).xpos=invaders(n).xpos+(invaders(n).speed*changedir) ; <-- here: calculate xpos with the changdir ;*** if drop = 1 the we calculate the new ypos If drop = 1 invaders(n).ypos = invaders(n).ypos+16 EndIf ;*** end edit part tit=1 EndIf If tit=1 And invaders(n).count=0 Inc invaders(n).count invaders(n).image=invaders(n).animadd SpriteImage n,invaders(inv).image EndIf If tit=1 And invaders(n).count>30 invaders(n).count=0 tit=0 invaders(n).image=invaders(n).image-invaders(n).animadd SpriteImage n,invaders(inv).image EndIf If movem=0 invaders(n).image=1 EndIf PositionSprite n,invaders(n).xpos,invaders(n).ypos ;DrawSprite n Next endfunction Function control_player() Print v If v=203 ship(1).xpos=ship(1).xpos-ship(1).speed EndIf If v=205 ship(1).xpos=ship(1).xpos+ship(1).speed EndIf PositionSprite shipsprite,ship(1).xpos,ship(1).ypos If v=16 quit=True EndIf EndFunction Function creategfx() Restore gfx Invaderimage1=MakeImageFromData(13,10,32,20) Invaderimage2=MakeImageFromData(13,10,32,20) ;********************** Create Players Ship Sprite ************* ShipImage=MakeImageFromData(13,10,32,20) // This resource really should created dynamically CreateSprite shipsprite SpriteImage shipsprite,shipimage ship(1).image=shipimage ship(1).xpos=320 ship(1).ypos=400 EndFunction Function MakeImageFromData(DataWidth,DataHeight,PixelWidth,PixelHeight,ThisColour=$00ff00) oldsurface=GetSurface() ThisImage=NewImage(DataWidth,DataHeight) RenderToImage ThisIMage Ink ThisColour LockBuffer For y=0 To DataHeight-1 For x=0 To DataWidth-1 If ReadData()>0 Dot x,y EndIf Next x Next y UnLockBuffer RenderToImage oldsurface ScaleImage ThisImage,PixelWidth,PixelHeight,1 EndFunction ThisImage Function setupwave() offsety=30 inv=1 For y=1 To 10 For x=1 To 13 t=ReadData() If t>0 invaders(inv).xpos=offsetx invaders(inv).ypos=offsety invaders(inv).image=t invaders(inv).animadd=invaders(inv).image+1 invaders(inv).speed=8 CreateSprite inv SpriteImage inv,invaders(inv).image Inc inv Inc numofinvaders EndIf offsetx=offsetx+38 If x>11 offsety=offsety+15 offsetx=0 EndIf Next Next EndFunction gfx1: ;invader1 top row Image A Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,1,0,0,0,0,0,1,0,0,0,0 Data 1,0,0,1,0,0,0,1,0,0,1,0,0 Data 1,0,1,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,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Function dump() Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0 endfunction
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.46 / 8
248 Votes
http://codebin.yi.org/1144
page generated in 0.00 seconds