Hi Blitzer.
Da bin ich mal wieder. Ich habe gestern beschlossen mich mal wieder richtig in BlitzBasic einzuüben.Und als erstes habe ich mir einen breakout clon vorgenommen. Da sowas komplizierter ist als es aussieht habe ich mir gedacht, es kann nicht schaden eine Abgespeckte Version dem Blitzforum Code Archiv zur verfügung zu stellen. Es ist ein kleingehaltener Code und die Grafik ist Manuell erstellt. Copy & Paste muss ja klappen. Trotzdem ist es Spielbar und es gibt 5 Levels+ Testlevel. Den Levelwechsel habe ich jetzt schnell eingebaut und die game over Sache + level Switch vllt ein wenig umständlich gelöst.
Die Arbeit mit dem Dokumentieren habe ich mir dieses mal gespart, beim letzten geposteten Code wurde mir klar wie undankbar und unfreundlich hier viele sind. Ich verschwende deshalb meine Zeit damit nicht.
Jeder der es gebrauchen kann dem wünsche ich viel Spaß damit.
Hier der Code :
Bewegen des Pads erfolgt über die Maus.
Vergebt mir WaitTimer, aber für den schnellen gebrauch als fps Begrenzung reicht es.
Mit Space könnt ihr ein wenig Cheaten. Der Ball geht dann ohne abtitschen durch die Blöcke durch.
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN]
Const screen_width = 1024 Const screen_height = 768
Graphics screen_width,screen_height,32,1
SeedRnd(MilliSecs())
Global ball_image Global balken_image Global background_image
Dim block_image(20)
For i = 0 To 19 block_image(i) = CreateImage(50,20) Next
Gosub CreateImages
font = LoadFont("Comic Sans MS",30,1) SetFont font
Global balken_width = ImageWidth(balken_image), balken_height = ImageHeight(balken_image) Global ball_x#,ball_y# Global ball_xwinkel#,ball_ywinkel# Global y_check, x_check Global balken_x, balken_y Global game_score Global game_over = 0 Global game_level = 1 Global mod_value Global next_level = 1 Global game_life = 3 Global game_timer = CreateTimer(80)
Gosub SetTypes
SetBuffer BackBuffer() CreateLevel(game_level,game_score)
Repeat Cls WaitTimer(game_timer)
If game_life<1 FlushKeys() Repeat Cls WaitTimer(game_timer) Text screen_width/2, screen_height/2,"LOOOSSSSSEEEER, geh weg!!",1,1 Flip Until GetKey()<>0 End ElseIf ball_y=>screen_height-20 ball_x#=screen_width/2 ball_y# =screen_height/2 ball_xwinkel#=1 ball_ywinkel#=1
FlushKeys() Repeat Cls WaitTimer(game_timer) Text screen_width/2, screen_height/2,"Sowas, noch ein Versuch!!",1,1 Flip Until GetKey()<>0
game_life = game_life-1 EndIf
If BlocksExist()=0 next_level= 1 EndIf
If next_level game_level = game_level+1 CreateLevel(game_level,game_score) next_level = 0 EndIf
ball_x = ball_x+ball_xwinkel ball_y = ball_y+ball_ywinkel
For i = 0 To 5 CreatePixel(ball_x+5,ball_y+5,Rnd(-.5,.5),Rnd(-.5,.5),RGB(255,0,0),60) CreatePixel(ball_x+5,ball_y+5,Rnd(-.7,.7),Rnd(-.7,.7),RGB(255,255,0),30) Next
x_check = (ball_x=>screen_width-20) Or (ball_x<=0) y_check = (ball_y=>screen_height-20) Or (ball_y<=0)
If x_check ball_xwinkel = 0-ball_xwinkel EndIf
If y_check ball_ywinkel = 0-ball_ywinkel EndIf
balken_x = MouseX() balken_y = screen_height-(balken_height+50)
MoveMouse balken_x, balken_y
If balken_x=>(screen_width-balken_width)-10 balken_x = (screen_width-balken_width)-10 EndIf
If balken_x<=10 balken_x = 10 EndIf
If ImagesOverlap(ball_image,ball_x,ball_y,balken_image,balken_x,balken_y) ball_ywinkel = 0-ball_ywinkel ball_xwinkel = (-(balken_width/2)+(ball_x-balken_x))/10 EndIf
If ball_ywinkel>0 If ball_ywinkel<=3 ball_ywinkel = 3 EndIf ElseIf ball_ywinkel>-3 ball_ywinkel = -3 EndIf
If ball_xwinkel>0 If ball_xwinkel<=1 ball_xwinkel = 1 EndIf ElseIf ball_xwinkel>-1 ball_xwinkel = -1 EndIf
If game_score>0 If game_score Mod mod_value = 0 CreateMessage(0,screen_height/2,"SCORE: "+game_score) game_score = game_score+20 mod_value = mod_value*2 EndIf EndIf
DrawImage background_image,0,0 DrawImage ball_image,ball_x,ball_y DrawImage balken_image, balken_x, balken_y
CheckColli() DrawBlocks() DrawPixels() DrawMessage()
Color 255,255,255 Text 0,0,"SCORE: "+game_score
Text screen_width-200,0,"LIFES: "+game_life
Flip Until KeyHit(1) End
.SetTypes
Type message Field x,y Field txt$ End Type
Type block Field x,y Field width,height Field block_image End Type
Type pixel Field x#,y# Field farbe Field xspeed#,yspeed# Field life_time End Type
Return
.CreateImages
ball_image = CreateImage(10,10) balken_image = CreateImage(150,20) background_image = CreateImage(1024,768)
SetBuffer ImageBuffer(balken_image) Color 0,255,0 Rect 0,0,ImageWidth(balken_image),ImageHeight(balken_image)
For i = 0 To 8 Color 0,100+(i*(155/8)),0 Rect 0+i,0+i,ImageWidth(balken_image)-(i*2),ImageHeight(balken_image)-(i*2),0 Next
SetBuffer ImageBuffer(background_image) stepsize# = ImageHeight(background_image)/255.0
For i = 0 To 255 Color 0,10,i Rect 0,i*stepsize,ImageWidth(background_image),stepsize+1 Next
For i = 0 To 500 Color 200,200,200 Plot Rnd(0,ImageWidth(background_image)),Rnd(0,ImageHeight(background_image)/5) Next
SetBuffer ImageBuffer(block_image(1)) Color 255,255,0 Rect 0,0,ImageWidth(block_image(1)),ImageHeight(block_image(1))
For i = 0 To 3 Color 155+(i*(100/3)),155+(i*(100/3)),0 Rect i,i,ImageWidth(block_image(1))-(i*2),ImageHeight(block_image(1))-(i*2),0 Next
SetBuffer ImageBuffer(block_image(2)) Color 255,0,255 Rect 0,0,ImageWidth(block_image(2)),ImageHeight(block_image(2))
For i = 0 To 3 Color 155+(i*(100/3)),0,155+(i*(100/3)) Rect i,i,ImageWidth(block_image(2))-(i*2),ImageHeight(block_image(2))-(i*2),0 Next
SetBuffer ImageBuffer(ball_image)
Color 255,0,0 Oval 0,0,ImageWidth(ball_image), ImageHeight(ball_image)
Return
Function CreatePixel(x#,y#,xspeed#,yspeed#,farbe,life_time=100) pixel.pixel = New pixel pixel\x = x pixel\y = y pixel\xspeed = xspeed pixel\yspeed = yspeed pixel\life_time = life_time pixel\farbe = farbe End Function
Function DrawPixels() LockBuffer BackBuffer() For this.pixel = Each pixel If this\life_time<=0 Delete this Else If this\x>0 And this\x<screen_width-1 If this\y>0 And this\y<screen_height-2 WritePixelFast(this\x,this\y,this\farbe,BackBuffer()) this\x = this\x+this\xspeed this\y = this\y+this\yspeed EndIf EndIf this\life_time = this\life_time-1 EndIf Next UnlockBuffer BackBuffer() End Function
Function CreateBlock(x,y,block_image) block.block = New block block\x = x block\y = y block\block_image = block_image block\width = ImageWidth(block\block_image) block\height = ImageHeight(block\block_image) End Function
Function BlocksExist() Local temp_num = 0
For this.block = Each block temp_num = temp_num+1 Next
Return temp_num End Function
Function DrawBlocks() For this.block = Each block DrawImage this\block_image,this\x,this\y Next End Function
Function CheckColli() For this.block = Each block If ImagesOverlap(ball_image,ball_x,ball_y,this\block_image,this\x,this\y) If KeyDown(57) = 0 ball_xwinkel = (-(this\width/2)+(ball_x-this\x))/4 ball_ywinkel = (-(this\height/2)+(ball_y-this\y))/5 EndIf For i = 0 To 100 CreatePixel(this\x+(this\width/2),this\y+(this\height/2),Rnd(-2,2),Rnd(-2,2),RGB(255,0,0),100) CreatePixel(this\x+(this\width/2),this\y+(this\height/2),Rnd(-1,1),Rnd(-1,1),RGB(255,255,0),80) CreatePixel(this\x+(this\width/2),this\y+(this\height/2),Rnd(-0.5,0.5),Rnd(-0.5,0.5),RGB(255,255,255),40) Next game_score = game_score+10 Delete this Exit EndIf Next End Function
Function CreateMessage(x,y,txt$) message.message = New message message\x = x-StringWidth(txt) message\y = y message\txt = txt End Function
Function DrawMessage() For this.message = Each message If this\x=>screen_width Delete this Else Color 255,0,0 Text this\x, this\y, this\txt this\x = this\x+5 this\y = this\y+Sin(this\x)*2 EndIf Next End Function
Function RGB(r,g,b) Return a*$1000000 + r*$10000 + g*$100 + b End Function
Function CreateLevel(level_num,temp_score = 0) Local stopper = 0
Delete Each pixel Delete Each block Delete Each message
ball_x#=screen_width/2 ball_y# =screen_height/2 ball_xwinkel#=1 ball_ywinkel#=1 game_score = temp_score next_level = 0 game_over = 0 mod_value = game_score+200
Select level_num
Case -1 For x = 0 To (screen_width/50) For y = 0 To (screen_height/20)-10 CreateBlock(x*50,100+y*20,block_image(Rand(1,2))) Next Next Case 1
For x = 0 To (screen_width/50)-5 For y = 0 To 1 CreateBlock(100+x*50,100+y*20,block_image(Rand(1,2))) Next Next
Case 2 For x = 0 To (screen_width/50)-5 Step 2 For y = 0 To 10 Step 2 CreateBlock(100+x*50,100+y*20,block_image(Rand(1,2))) Next Next Case 3 For x = 0 To (screen_width/50)-5 For y = 0 To 15 stopper = 1-stopper If stopper CreateBlock(100+x*50,100+y*20,block_image(Rand(1,2))) EndIf Next Next Case 4 For x = 0 To (screen_width/50)-8 For y = 0 To x*2 CreateBlock(100+x*50,100+y*20,block_image(Rand(1,2))) Next Next Case 5 For x = 5 To (screen_width/50)-10 For y = 0 To 15 CreateBlock(100+x*50,100+y*20,block_image(Rand(1,2))) Next Next Default FlushKeys() Repeat Cls WaitTimer(game_timer) Text screen_width/2, screen_height/2,"Alle Levels geschafft. Gewonnen!!!!",1,1 For i = 0 To 60 CreatePixel(Rnd(10,screen_width-10),Rnd(10,screen_height-10),Rnd(-2,2),Rnd(-2,2),RGB(Rnd(0,255),100,Rnd(0,255)),100) Next DrawPixels() Flip Until GetKey()<>0 End End Select
FlushKeys()
Repeat Cls
WaitTimer(game_timer)
Color 255,0,0 Text screen_width/2, screen_height/2, "LEVEL "+level_num,1,1
Color 0,255,0 Text screen_width/2, screen_height/2+50,"Press enter",1,1
For i = 0 To 10 CreatePixel(Rnd(10,screen_width-10),Rnd(10,screen_height-10),Rnd(-2,2),Rnd(-2,2),RGB(Rnd(0,255),100,0),100) Next
DrawPixels()
Flip Until KeyHit(57) Or KeyHit(28)
Delete Each pixel CreateMEssage(0,screen_height/2,"<<Level "+level_num+">>") FlushKeys() End Function
Mfg Suco, viel Spaß beim Programmieren.
|