Hey people!

BlitzMax Forums/BlitzMax Beginners Area/Hey people!

cool, i'll look into that, thanks.

Well heres a 'alpha' verison of my first B-max game... (a simple breakout clone)

let me know if you find any bugs, i'm going to bed very tried. i believe theres some bugs with the level stuff ..

Rem

Breakout

9-23-07 - ??-??-??

End Rem

SuperStrict

Extern "win32" ' Crazy WinAPI stuff
	Function GetActiveWindow%()
	Function IsZoomed%(hwnd%)
End Extern

AppTitle = "Breakout"
Graphics 800,600
Global hWnd% = GetActiveWindow() ' Save current Window handle
enableMinimize( hwnd% )

Global paddleAdir:Int = 1, tempx:Int = 17, tempy:Int = 20, launch:Int, ball_padle_dif:Float, Brick:TBrick, check:TBrick, BRICKS_KILLED:Int = 0, LEVEL:Int = 1
SeedRnd MilliSecs()

SetBlend(ALPHABLEND)

'Tlist
Global BrickList:TList = CreateList()

'TEntity
Type TEntity
	Field x:Float
	Field y:Float
	Field a:Float = 1.0
EndType

'TPlayer type
Type TPlayer Extends TEntity
	Field Speed:Float

	Method Create()
		x = 20
		y = 530
		a = .5
		Speed = 6
		SetAlpha a
		DrawRect x,y,100,40
		SetAlpha 1.0
	End Method

	Method Update()
	
		If KeyDown(KEY_RIGHT)And x < 680
			x:+Speed
		End If
		If KeyDown(KEY_LEFT) And x > 0
			x:-Speed
		End If
		SetAlpha a
		DrawRect x,y,120,20
		SetAlpha 1.0
		
		If a > .99 paddleAdir = 0
		If a < .50 paddleAdir = 1
		If paddleAdir = 1
			a:+0.05
		Else
			a:-0.05
		EndIf
		

	EndMethod

EndType

'TBrick type
Type TBrick Extends TEntity

	Field HP:Int
	Field R:Int
	Field B:Int
	Field G:Int
	
	Method Create()
		HP = 1
		R = Rand(100,255)
		B = Rand(100,255)
		G = Rand(100,255)
		x = tempx
		y = tempy
		tempx:+70
		If tempx = 787 tempy:+20 tempx = 17
		SetAlpha a
		SetColor R,B,G
		DrawRect x,y,70,20
		SetColor 255,255,255
		SetAlpha 1.0
	End Method
	
	Method Update()
		SetColor R,B,G
		SetAlpha a
		If HP > 0 DrawRect x,y,70,20
		SetColor 255,255,255
		SetAlpha 1.0
	End Method
	
EndType

'TBall type
Type TBall Extends TEntity
	Field y_dir:Int
	Field x_dir:Int

	Method Create()
		x = player.x + 50
		y = 510
		SetAlpha a
		SetColor 0,0,255
		DrawOval x,y,20,20
		SetColor 255,255,255
		SetAlpha 1.0
	End Method
	
	Method Update()

		If KeyHit(KEY_SPACE) And launch = False
			launch = True
			y_dir = -10
		End If
		
		If launch = False 
			x = player.x + 50'Re-position ball to paddle
			y = 510
			y_dir = 0 ' 0 out direction controllers
			x_dir = 0
		End If
		If launch = True
			If y < 0 y_dir = 10
			If y > 540 launch = False
			If x > 780 x_dir = -10
			If x < 0 x_dir = 10
			
			If RectsOverlap(player.x,player.y,100,40,x,y,20,20)
				y_dir = -10
				x_dir = ball_padle_dif*6
			End If
			
			For check:TBrick = EachIn BrickList
				If RectsOverlap(check.x,check.y,60,7,ball.x,y,20,20)
					check.HP = 0
					y_dir = -10
					BrickList.Remove(check)
					BRICKS_KILLED:+1
				End If
				If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20)
					check.HP = 0
					y_dir = 10
					BrickList.Remove(check)
					BRICKS_KILLED:+1
				End If
				Rem
				SIDE COLLISIONS: BUGGED
				If RectsOverlap(check.x,check.y+7,10,13,x,y,20,20)
					check.HP = 0
					x_dir = -10
					BrickList.Remove(check)
				End If
				If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20)
					check.HP = 0
					x_dir = 10
				End If
				End Rem
			Next
		
			x:+x_dir
			y:+y_dir
		End If
		
		SetColor 0,0,255
		SetAlpha a
		DrawOval x,y,20,20
		SetColor 255,255,255
		SetAlpha 1.0
	End Method

EndType


AutoMidHandle True

Rem
MAIN PROGRAM ................
......................................................................
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
End Rem


Global NUMBER_OF_BRICKS:Int = 43'Number of bricks -- 11 per row.


Global player:TPlayer = New TPlayer
player.Create()
player.Speed = 10

Local i:Int
For i=0 To NUMBER_OF_BRICKS
	Brick:TBrick = New TBrick
	ListAddLast BrickList,Brick
	Brick.Create()
Next
i=0

Global ball:TBall = New TBall

ball.Create()
While Not AppTerminate() = True
	Cls
	ball_padle_dif = -(player.x+ 50 - ball.x) / 60
	
	player.Update()
	For check:TBrick = EachIn BrickList
		If check.HP > 0 check.Update()
	Next

	ball.Update()
	
	If BRICKS_KILLED = NUMBER_OF_BRICKS
		launch = False
		NUMBER_OF_BRICKS:+11
		BRICKS_KILLED = 0
		LEVEL:+1
		For i=0 To NUMBER_OF_BRICKS
			Brick:TBrick = New TBrick
			ListAddLast BrickList,Brick
			Brick.Create()
		Next
	End If
	
	DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL,0,0
	Flip
	
Wend
End

Function RectsOverlap%(x0:Int, y0:Int, w0:Int, h0:Int, x2:Int, y2:Int, w2:Int, h2:Int)
	If x0 > (x2 + w2) Or (x0 + w0) < x2 Then Return False
	If y0 > (y2 + h2) Or (y0 + h0) < y2 Then Return False
	Return True
End Function


Function enableMinimize(hWnd:Long)
' Adds the Minimize Button "_"
	Local tmp:Long = GetWindowLongA( hWnd, GWL_STYLE )
	tmp = tmp | WS_MINIMIZEBOX
	SetWindowLongA( hWnd, GWL_STYLE, tmp )
	DrawMenuBar( hWnd )
End Function