Hey, just bought blitzmax, i'm liking the look of the IDE, i'm a Blitz3D user, i'd like to get started learning the language, any suggestions? tips? starter assignments, welcomes? for me?
Hey people!
BlitzMax Forums/BlitzMax Beginners Area/Hey people! Woah, i'm having problems already ..
Edit:
"BlitzMax now features a set of pre-defined keycode constants with different numerical values to previous Blitzes. See the Key Codes section of the documentation (under Module Reference) for details. In particular, if you use the common "Repeat [... ] Until KeyHit (1)" to detect the Esc key, change it to KeyHit (KEY_ESCAPE). The value 1 now relates to a left mouse button press, so don't wear out your Esc key in confusion and frustration..."
Graphics 400,300 While Not KeyHit(1) Wend End
Edit:
"BlitzMax now features a set of pre-defined keycode constants with different numerical values to previous Blitzes. See the Key Codes section of the documentation (under Module Reference) for details. In particular, if you use the common "Repeat [... ] Until KeyHit (1)" to detect the Esc key, change it to KeyHit (KEY_ESCAPE). The value 1 now relates to a left mouse button press, so don't wear out your Esc key in confusion and frustration..."
Download BLide
www.blide.org
Oh and hi.
www.blide.org
Oh and hi.
wow my heads spinning with all this module stuff
If you have MaxGUI check
The MaxGUI Beginner Tutorial Series
For Bmax check this
Beginners guide to BlitzMax
and this
Learning 2D Game Programming With BlitzMax
and for extra OOP check this
Learning Object-Oriented Programming in Blitzmax
plus any other of the tutorials which take your fancy.
<EDIT> Oh.. and this Orientation guide for existing Blitz users
The MaxGUI Beginner Tutorial Series
For Bmax check this
Beginners guide to BlitzMax
and this
Learning 2D Game Programming With BlitzMax
and for extra OOP check this
Learning Object-Oriented Programming in Blitzmax
plus any other of the tutorials which take your fancy.
<EDIT> Oh.. and this Orientation guide for existing Blitz users
why doesnt the close button on the window work? and where did that minimize button go?
why doesnt the close button on the window work?
Check AppTerminate command.
and where did that minimize button go?
Search using 'Minimize' for a few other posts asking the same.
You can try Minimize / Maximize buttons
in the Code Archives although it's Windows only.
Isnt the begginers guide to Bmax 1.12?
Possibly as it's dated 2005 but 99.9% of it is still valid unless you think otherwise.
It probably OK, It would be Auto GC.
Was that before auto Handle was scrapped?
@YahFree,
Start Every program with
"SuperStrict"
Was that before auto Handle was scrapped?
@YahFree,
Start Every program with
"SuperStrict"
whats that do? seems like it would make my life miserible as i'm thinking it means that its very strict and won't compile unless everything is absolutely perfect..
Yep, which is better than having it compile and havin to debug it later if you've done something wrong.
It makes sure you declare all your variables and their types before usage, this results in faster code and less errors.
that makes me happy, pretty much the whole b-max source (not the IDE) is included and much of it is coded in b-max, so it looks like it can get very controling and complicated like c++ ect, but can also remain simple and easy.
You can dowload the code for the IDE as well if you want to, its open sorce, but as I said before DL BLide
Edit: ahhh it wants me to declare 'local' picky picky...
^
ahaha, i cant find the compile button help! :D (create EXE)
There is no way to *not* create an exe. Every time you "build" or "build and run" an EXE is created/overwritten. Just find the folder you put your source code in, and there will be the EXE.
Lol... I'm a blitz3d user and I felt a strong urge to finally buy blitzmax during the last couple of days, but this thread scared me off :)
I'm afraid I'm gonna end up just like that...
I'm afraid I'm gonna end up just like that...
hah, i like it, i suggest going for it, so far i'm liking it, its just completely different, still getting used to it
Lol... I'm a blitz3d user and I felt a strong urge to finally buy blitzmax during the last couple of days, but this thread scared me off :)
I used to be a b3d user, but I I'd never go back now, BMax is faster, more flexible, and generally gives you a warm fuzzy feeling inside.
its telling me i cant convert this into a object on the ListAddlast line..
any ideas? i'm trying to add a type to a list through a method, i thought this was possible?
Global BrickList:TList = CreateList() '.... '.... 'TBrick type Type TBrick Field HP:Int Field x:Int Field y:Int Method Create() Local tempx:Int HP = 1 ListAddLast BrickList,TBrick For check:TBrick = EachIn BrickList tempx = check.x Next x = tempx + 30 SetColor Rand(100,255),Rand(100,255),Rand(100,255) DrawRect x,y,30,20 SetColor 255,255,255 End Method EndType
any ideas? i'm trying to add a type to a list through a method, i thought this was possible?
TBrick is the type, not an instance of the type. In a Method Self is the instance.
Also, you can't have a Create Method. It's pointless. Methods are nothing but functions which work on a type instance, and you don't have an instance when you create. Ergo, there is no way to call a method. It needs to be a function.
Thirdly, you're not actually creating anything at all. You don't New TBrick which is how you get an instance.
Fourthly, there's no point making the bricklist global, it belongs to the TBrick type.
Fifth, people weren't kidding when they said to use Superstrict. It would have pointed out many of the errors for you.
Try something more like this ( untested because you can't call SetColor without calling Graphics and I'm not sure why you're looping through a list and drawing a rectangle only when the brick is created )
Also, you can't have a Create Method. It's pointless. Methods are nothing but functions which work on a type instance, and you don't have an instance when you create. Ergo, there is no way to call a method. It needs to be a function.
Thirdly, you're not actually creating anything at all. You don't New TBrick which is how you get an instance.
Fourthly, there's no point making the bricklist global, it belongs to the TBrick type.
Fifth, people weren't kidding when they said to use Superstrict. It would have pointed out many of the errors for you.
Try something more like this ( untested because you can't call SetColor without calling Graphics and I'm not sure why you're looping through a list and drawing a rectangle only when the brick is created )
SuperStrict '.... '.... 'TBrick type Type TBrick Global BrickList:TList=New TList Field HP:Int Field x:Int Field y:Int Function Create() Local Brick:TBrick=New TBrick Local tempx:Int Brick.HP = 1 BrickList.AddLast(Brick) For Local check:TBrick = EachIn BrickList tempx = check.x Next Brick.x = tempx + 30 SetColor Rand(100,255),Rand(100,255),Rand(100,255) DrawRect Brick.x,Brick.y,30,20 SetColor 255,255,255 End Function EndType
well, the create method is for setting up everything, and yes i have super-strict on thats why i'm getting all these errors.
at the moment i'm trying to figure out why the bricks are not spreading out like they should:
i'm liking this easy interaction thing with DLL's, also how did B-max get all the Win32 constants? with B3d you had to set the constants up yourself.
edit: also liking this realtime alpha as you can see above.
at the moment i'm trying to figure out why the bricks are not spreading out like they should:
Rem Breakout 9-23-07 - ??-??-?? End Rem SuperStrict Extern "win32" ' Crazy WinAPI stuff Function GetActiveWindow%() Function IsZoomed%(hwnd%) End Extern Graphics 800,600 Global hWnd% = GetActiveWindow() ' Save current Window handle Global paddleAdir:Int = 1 enableMinimize( hwnd% ) SetBlend(ALPHABLEND) 'Tlist Global BrickList:TList = CreateList() 'TPlayer type Type TPlayer Field x:Int Field y:Int Field a:Float Method Create() x = 20 y = 530 a = .5 SetAlpha a DrawRect x,y,100,40 SetAlpha 1.0 End Method Method Update() If KeyDown(KEY_RIGHT)And x < 680 x:+6 End If If KeyDown(KEY_LEFT) And x > 0 x:-6 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 Field HP:Int Field x:Int Field y:Int Field R:Int Field B:Int Field G:Int Method Create() Local tempx:Int Local check:TBrick HP = 1 R = Rand(100,255) B = Rand(100,255) G = Rand(100,255) For check:TBrick = EachIn BrickList tempx = check.x Next x = tempx + 30 SetColor R,B,G DrawRect x,20,30,20 SetColor 255,255,255 End Method Method Update() SetColor R,B,G DrawRect x,20,30,20 SetColor 255,255,255 End Method EndType 'TBall type Type TBall 'Method Create EndType AutoMidHandle True Rem MAIN PROGRAM ................ ...................................................................... End Rem Local check:TBrick Local player:TPlayer = New TPlayer player.Create() Local i:Int For i=0 To 10 Local Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Next While Not AppTerminate() = True Cls player.Update() For check:TBrick = EachIn BrickList check.Update() Next DrawText "Player X,Y,A = "+player.x+","+player.y+","+player.a,0,0 Flip Wend End 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
i'm liking this easy interaction thing with DLL's, also how did B-max get all the Win32 constants? with B3d you had to set the constants up yourself.
edit: also liking this realtime alpha as you can see above.
Ok, Something that is going to seem totaly pointless to you at this point. If you Extend TBrick, then you wont want TBricks creation and setup to be in the same function. (Dont ask why, just trust me you dont), so..
Ive Changed Create() to return the New Brick, this doesnt slow the program down at all. And you are not obliged to allocate it to any thing, but if you ever want to, then its there.
Ive moved all the setup of a new brick to the Method setup.
Why?
Well now if you ever extend Tbrick, you can call TBrick setup, which you wouldnt be able to do if it was in the same function as the New command.
EDit: Sorry did realise you'd posted again, this is directed at your post before last. but after Gabs
SuperStrict '.... '.... 'TBrick type Type TBrick Global BrickList:TList=New TList Field HP:Int Field x:Int Field y:Int Method New() BrickList.AddLast(Self) End Method Method Setup:Tbrick() Local tempx:Int Self.HP = 1 For Local check:TBrick = EachIn BrickList tempx = check.x Next Self.x = tempx + 30 SetColor Rand(100,255),Rand(100,255),Rand(100,255) DrawRect Self.x,Self.y,30,20 SetColor 255,255,255 Return Self End Method Function Create:TBrick() Return New TBrick.Setup() End Function EndTypeIve moved adding the brick to the lits to the New Method, this is just a style prefferance.
Ive Changed Create() to return the New Brick, this doesnt slow the program down at all. And you are not obliged to allocate it to any thing, but if you ever want to, then its there.
Ive moved all the setup of a new brick to the Method setup.
Why?
Well now if you ever extend Tbrick, you can call TBrick setup, which you wouldnt be able to do if it was in the same function as the New command.
EDit: Sorry did realise you'd posted again, this is directed at your post before last. but after Gabs
wow, blitzmax types are extremely more complex then blitz3d types, but so much more flexible..
can someone show me how to set the app title? it keeps giving me errors... from a simple: AppTitle "Hello"
-.-
what does b-max have in terms of rectangular area collision? need somthing like B3D's RectsOverlap()
heres the source up to now..
hmm thinking about coding a fancy moving star BG like the star-pong example in the samples...
heres the source up to now..
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 SeedRnd MilliSecs() SetBlend(ALPHABLEND) 'Tlist Global BrickList:TList = CreateList() 'TEntity Type TEntity Field x:Int Field y:Int Field a:Float = 1.0 EndType 'TPlayer type Type TPlayer Extends TEntity Method Create() x = 20 y = 530 a = .5 SetAlpha a DrawRect x,y,100,40 SetAlpha 1.0 End Method Method Update() If KeyDown(KEY_RIGHT)And x < 680 x:+6 End If If KeyDown(KEY_LEFT) And x > 0 x:-6 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 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 = -6 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 = 6 If y > 540 launch = False 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 Const NUMBER_OF_BRICKS:Int = 20'Number of bricks Local check:TBrick Global player:TPlayer = New TPlayer player.Create() Local i:Int For i=0 To NUMBER_OF_BRICKS Local Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Next Global ball:TBall = New TBall ball.Create() While Not AppTerminate() = True Cls player.Update() For check:TBrick = EachIn BrickList check.Update() Next ball.Update() DrawText launch,0,0'"Player X,Y,A = "+player.x+","+player.y+","+player.a,0,0 Flip Wend End 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
hmm thinking about coding a fancy moving star BG like the star-pong example in the samples...
thanks, just what i'm looking for, seems to work ok:
i'll add x-axis directional deflection when i get back (IE if it hits the paddle at a far left spot it will fly off more to the left.)
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 SeedRnd MilliSecs() SetBlend(ALPHABLEND) 'Tlist Global BrickList:TList = CreateList() 'TEntity Type TEntity Field x:Int Field y:Int Field a:Float = 1.0 EndType 'TPlayer type Type TPlayer Extends TEntity Method Create() x = 20 y = 530 a = .5 SetAlpha a DrawRect x,y,100,40 SetAlpha 1.0 End Method Method Update() If KeyDown(KEY_RIGHT)And x < 680 x:+6 End If If KeyDown(KEY_LEFT) And x > 0 x:-6 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 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 = -6 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 = 6 If y > 540 launch = False If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -6 End If 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 Const NUMBER_OF_BRICKS:Int = 20'Number of bricks Local check:TBrick Global player:TPlayer = New TPlayer player.Create() Local i:Int For i=0 To NUMBER_OF_BRICKS Local Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Next Global ball:TBall = New TBall ball.Create() While Not AppTerminate() = True Cls player.Update() For check:TBrick = EachIn BrickList check.Update() Next ball.Update() DrawText launch,0,0'"Player X,Y,A = "+player.x+","+player.y+","+player.a,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
i'll add x-axis directional deflection when i get back (IE if it hits the paddle at a far left spot it will fly off more to the left.)
how do i delete somthing off a list: run the example below and try to hit a brick above another brick, you'll see my problem; it still thinks its alive.
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 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 Method Create() x = 20 y = 530 a = .5 SetAlpha a DrawRect x,y,100,40 SetAlpha 1.0 End Method Method Update() If KeyDown(KEY_RIGHT)And x < 680 x:+6 End If If KeyDown(KEY_LEFT) And x > 0 x:-6 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 = -6 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 = 6 If y > 540 launch = False If x > 780 x_dir = -6 If x < 0 x_dir = 6 If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -6 x_dir = ball_padle_dif*6 End If For check:TBrick = EachIn BrickList If RectsOverlap(check.x,check.y,70,20,ball.x,ball.y,20,20) check.HP = 0 y_dir = 6 End If 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 Const NUMBER_OF_BRICKS:Int = 20'Number of bricks Global player:TPlayer = New TPlayer player.Create() Local i:Int For i=0 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Next 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 check.Update() Next ball.Update() DrawText ball_padle_dif,0,0'"Player X,Y,A = "+player.x+","+player.y+","+player.a,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
check for all caps line:
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 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 Method Create() x = 20 y = 530 a = .5 SetAlpha a DrawRect x,y,100,40 SetAlpha 1.0 End Method Method Update() If KeyDown(KEY_RIGHT)And x < 680 x:+6 End If If KeyDown(KEY_LEFT) And x > 0 x:-6 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 = -6 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 = 6 If y > 540 launch = False If x > 780 x_dir = -6 If x < 0 x_dir = 6 If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -6 x_dir = ball_padle_dif*6 End If For check:TBrick = EachIn BrickList If RectsOverlap(check.x,check.y,70,20,ball.x,ball.y,20,20) check.HP = 0 y_dir = 6 BRICKLIST.REMOVE(CHECK) End If 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 Const NUMBER_OF_BRICKS:Int = 20'Number of bricks Global player:TPlayer = New TPlayer player.Create() Local i:Int For i=0 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Next 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 check.Update() Next ball.Update() DrawText ball_padle_dif,0,0'"Player X,Y,A = "+player.x+","+player.y+","+player.a,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
Ahh, so a TList is a type to keep track of other types, and it has its own methods ect, should i worry about creating to many TBricks? as i'm going to be adding/removing them alot and the TBrick part isnt going to move..
No. Add as many as you want. Althoug it might get quite slow if excesive large number of instances are stored in it. The reason is that it has to go through the list to find the one it needs to remove. Do a little research on "tlink" it is more eficient and depending on how you use it, might make your game quite a bit faster. But for a game like that you probably won't notice any difference any way.
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 ..
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
you don't need to keep track of how many brick you have created because Tlist keep track of how many instances of your bricks are stored. you can access it with BrickList.count()
thanks.
try this one out, i'm having some problems it seems like some bricks i hit give me double points, that means i finish the level faster then i'm suppost to and i get extra bricks laid under the new ones..
try this one out, i'm having some problems it seems like some bricks i hit give me double points, that means i finish the level faster then i'm suppost to and i get extra bricks laid under the new ones..
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 = 30, 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 Type TSpeedEntity Extends TEntity Field Speed:Float End Type 'TPlayer type Type TPlayer Extends TSpeedEntity 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 TSpeedEntity Field y_dir:Int Field x_dir:Int Method Create() x = player.x + 50 y = 510 Speed = 10 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 = Speed If y > 540 launch = False If x > 780 x_dir = -Speed If x < 0 x_dir = Speed If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -Speed x_dir = ball_padle_dif*(Speed-2) 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 = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20) check.HP = 0 y_dir = Speed 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 = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = Speed 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=1 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 tempx = 17 tempy = 30 ball.Speed:+2 For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Next End If DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL+" BricksKilled: "+BRICKS_KILLED+"/"+NUMBER_OF_BRICKS,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
the collition handleing is not being delt logically. at certain instances you are attempting to remove the same object more than once. by the same token you are increasing your accumulator for tiles removed more than once. I have solved it in my computer but I will only post it if you can't figure it out.
well i'm stumped. so if you can i'd apperciate it :).
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 = 30, 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 Type TSpeedEntity Extends TEntity Field Speed:Float End Type 'TPlayer type Type TPlayer Extends TSpeedEntity 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 TSpeedEntity Field y_dir:Int Field x_dir:Int Method Create() x = player.x + 50 y = 510 Speed = 10 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 = Speed If y > 540 launch = False If x > 780 x_dir = -Speed If x < 0 x_dir = Speed If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -Speed x_dir = ball_padle_dif*(Speed-2) End If For check:TBrick = EachIn BrickList Local COLLIDED:Int = False '************************************** If RectsOverlap(check.x,check.y,60,7,ball.x,y,20,20) check.HP = 0 y_dir = -Speed COLLIDED = True '***************************************** End If If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20) check.HP = 0 y_dir = Speed COLLIDED = True '******************************************** End If If COLLIDED '******************************************* 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 = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = Speed 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=1 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 tempx = 17 tempy = 30 ball.Speed:+2 For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Next End If DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL+" BricksKilled: "+BRICKS_KILLED+"/"+NUMBER_OF_BRICKS,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
thanks!
its starting to look like a game(added score, gameover screen, pumping up ball speeds per level ect..):
its starting to look like a game(added score, gameover screen, pumping up ball speeds per level ect..):
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 = 30, launch:Int, ball_padle_dif:Float, Brick:TBrick, check:TBrick, BRICKS_KILLED:Int = 0, LEVEL:Int = 1, SCORE:Int =0 SeedRnd MilliSecs() SetBlend(ALPHABLEND) 'Tlist Global BrickList:TList = CreateList() 'TEntity Type TEntity Field x:Float Field y:Float Field a:Float = 1.0 EndType Type TSpeedEntity Extends TEntity Field Speed:Float End Type 'TPlayer type Type TPlayer Extends TSpeedEntity 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 TSpeedEntity Field y_dir:Int Field x_dir:Int Field LIFES:Int Method Create() x = player.x + 50 y = 510 Speed = 10 LIFES = 3 Local i:Int SetAlpha a SetColor 0,0,255 DrawOval x,y,20,20 For i = 1 To LIFES DrawOval 500+(i*20),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method Method Update() Local i:Int 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 = Speed If y > 540 launch = False LIFES:-1 If x > 780 x_dir = -Speed If x < 0 x_dir = Speed If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -Speed x_dir = ball_padle_dif*(Speed-2) End If For check:TBrick = EachIn BrickList Local COLLIDED:Int = False '************************************** If RectsOverlap(check.x,check.y,60,7,ball.x,y,20,20) check.HP = 0 y_dir = -Speed COLLIDED = True '***************************************** End If If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20) check.HP = 0 y_dir = Speed COLLIDED = True '******************************************** End If If COLLIDED '******************************************* BrickList.Remove(check) '************************************ BRICKS_KILLED:+1 '******************************************* SCORE:+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 = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = Speed End If End Rem Next x:+x_dir y:+y_dir End If SetColor 0,0,255 SetAlpha a DrawOval x,y,20,20 For i=1 To LIFES DrawOval 500+(i*26),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method EndType AutoMidHandle True Rem MAIN PROGRAM ................ ...................................................................... . . . . . . . . . . . . . . . . . End Rem Global NUMBER_OF_BRICKS:Int = 44'Number of bricks -- 11 per row. Global player:TPlayer = New TPlayer player.Create() player.Speed = 10 Local i:Int For i=1 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 tempx = 17 tempy = 30 ball.Speed:+2 For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Next End If If ball.LIFES < 0 GameOver() End If DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL+" SCORE: "+SCORE+" Balls Left: "+ball.LIFES+"/4",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 Function GameOver() Local i:Int NUMBER_OF_BRICKS = 44 BRICKS_KILLED = 0 launch = False tempy = 30 tempx = 17 ball.Speed = 10 ball.LIFES = 3 For check:TBrick = EachIn BrickList BrickList.Remove(check) Next For i = 1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast(BrickList,Brick) Brick.Create() Next While Not KeyHit(KEY_SPACE) Cls If AppTerminate() End DrawText "YOU LOSE!!! press Space to start a new game!",200,300 Flip Wend End Function
All you need to do is add some proper timing so it doesn't play faster or slower depending what your refresh or performance is, and you have the foundations for a decent breakout game. Very cool.
proper timing? explain.
FPS / update time difference dependant update logic
Check this thread here for a demo that's about as easy as it gets. I'm using that method for a game I'm working on:
http://www.blitzbasic.com/Community/posts.php?topic=71030
http://www.blitzbasic.com/Community/posts.php?topic=71030
hmm, interesting, i'm not sure i get it completely, i think i'll return to that later, i'v switched all the RBG bricks to images, i'm trying to create a break effect, using the brick image itself (when colliding with the ball) this is what i have so far..
(Put these images in the same dir.)
wall1.png

wall2.png

never done any sort of special effect seqence creation before, should i try to make a animated image strip with image 1 being the brick and the rest being animation of it blowing up maybe? or should i go with a different direction all together?
(Put these images in the same dir.)
wall1.png

wall2.png

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% ) 'Initalization area.. Global paddleAdir:Int = 1, tempx:Int = 17, tempy:Int = 30, launch:Int, ball_padle_dif:Float, Brick:TBrick, check:TBrick, BRICKS_KILLED:Int = 0, LEVEL:Int = 1, SCORE:Int =0 SeedRnd MilliSecs() SetBlend(ALPHABLEND) Global wall1:TImage=LoadImage("wall1.png"), wall2:TImage=LoadImage("wall2.png") 'Tlist Global BrickList:TList = CreateList() 'TEntity Type TEntity Field x:Float Field y:Float Field a:Float = 1.0 EndType Type TSpeedEntity Extends TEntity Field Speed:Float End Type 'TPlayer type Type TPlayer Extends TSpeedEntity Method Create() x = 20 y = 530 a = .5 Speed = 8 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 image:TImage Method Create() image = wall1 HP = 1 x = tempx y = tempy tempx:+70 If tempx = 787 tempy:+20 tempx = 17 SetAlpha a DrawImage image,x,y SetAlpha 1.0 End Method Method Update() SetAlpha a If HP > 0 DrawImage image,x,y SetAlpha 1.0 End Method EndType 'TBall type Type TBall Extends TSpeedEntity Field y_dir:Int Field x_dir:Int Field LIFES:Int Method Create() x = player.x + 50 y = 510 Speed = 10 LIFES = 3 Local i:Int SetAlpha a SetColor 0,0,255 DrawOval x,y,20,20 For i = 1 To LIFES DrawOval 500+(i*20),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method Method Update() Local i:Int 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 = Speed If y > 540 launch = False 'LIFES:-1 If x > 780 x_dir = -Speed If x < 0 x_dir = Speed If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -Speed x_dir = ball_padle_dif*(Speed-2) End If For check:TBrick = EachIn BrickList Local COLLIDED:Int = False If RectsOverlap(check.x,check.y,60,7,ball.x,y,20,20) check.HP = 0 y_dir = -Speed COLLIDED = True End If If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20) check.HP = 0 y_dir = Speed COLLIDED = True End If If COLLIDED BrickList.Remove(check) BRICKS_KILLED:+1 SCORE:+1 Play_EXP_EFFECT() End If Rem SIDE COLLISIONS: BUGGED If RectsOverlap(check.x,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = Speed End If End Rem Next x:+x_dir y:+y_dir End If SetColor 0,0,255 SetAlpha a DrawOval x,y,20,20 For i=1 To LIFES DrawOval 500+(i*26),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method EndType AutoMidHandle True Rem MAIN PROGRAM ................ ...................................................................... . . . . . . . . . . . . . . . . . End Rem Global NUMBER_OF_BRICKS:Int = 44'Number of bricks -- 11 per row. Global player:TPlayer = New TPlayer player.Create() player.Speed = 10 Local i:Int For i=1 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 tempx = 17 tempy = 30 ball.Speed:+1 For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Brick.image = wall2 Next End If If ball.LIFES < 0 GameOver() End If DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL+" -- SCORE: "+SCORE,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 Function GameOver() Local i:Int NUMBER_OF_BRICKS = 44 BRICKS_KILLED = 0 launch = False tempy = 30 tempx = 17 ball.Speed = 10 ball.LIFES = 3 SCORE = 0 For check:TBrick = EachIn BrickList BrickList.Remove(check) Next For i = 1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast(BrickList,Brick) Brick.Create() Next While Not KeyHit(KEY_SPACE) Cls If AppTerminate() End DrawText "YOU LOSE!!! press Space to start a new game!",200,300 Flip Wend End Function Function Play_EXP_Effect() Local i:Int SetScale .2,.2 For i=0 To 30 SetScale .2+(i*.01),.2+(i*.01) DrawImage Brick.image,ball.x,ball.y Next SetScale 1.0,1.0 End Function
never done any sort of special effect seqence creation before, should i try to make a animated image strip with image 1 being the brick and the rest being animation of it blowing up maybe? or should i go with a different direction all together?
trying to anim image route, giving me errors, what am i doing wrong(testing the animation)
wall1_break.png:
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% ) 'Initalization area.. Global paddleAdir:Int = 1, tempx:Int = 17, tempy:Int = 30, launch:Int, ball_padle_dif:Float, Brick:TBrick, check:TBrick, BRICKS_KILLED:Int = 0, LEVEL:Int = 1, SCORE:Int =0 SeedRnd MilliSecs() SetBlend(ALPHABLEND) Global wall1:TImage=LoadImage("wall1.png"), wall2:TImage=LoadImage("wall2.png"), wall1_break:TImage=LoadAnimImage("wall1-break.png",100,50,0,5) 'Tlist Global BrickList:TList = CreateList() 'TEntity Type TEntity Field x:Float Field y:Float Field a:Float = 1.0 EndType Type TSpeedEntity Extends TEntity Field Speed:Float End Type 'TPlayer type Type TPlayer Extends TSpeedEntity Method Create() x = 20 y = 530 a = .5 Speed = 8 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 image:TImage Method Create() image = wall1 HP = 1 x = tempx y = tempy tempx:+70 If tempx = 787 tempy:+20 tempx = 17 SetAlpha a DrawImage image,x,y SetAlpha 1.0 End Method Method Update() SetAlpha a If HP > 0 DrawImage image,x,y SetAlpha 1.0 End Method EndType 'TBall type Type TBall Extends TSpeedEntity Field y_dir:Int Field x_dir:Int Field LIFES:Int Method Create() x = player.x + 50 y = 510 Speed = 10 LIFES = 3 Local i:Int SetAlpha a SetColor 0,0,255 DrawOval x,y,20,20 For i = 1 To LIFES DrawOval 500+(i*20),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method Method Update() Local i:Int 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 = Speed If y > 540 launch = False 'LIFES:-1 If x > 780 x_dir = -Speed If x < 0 x_dir = Speed If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -Speed x_dir = ball_padle_dif*(Speed-2) End If For check:TBrick = EachIn BrickList Local COLLIDED:Int = False If RectsOverlap(check.x,check.y,60,7,ball.x,y,20,20) check.HP = 0 y_dir = -Speed COLLIDED = True End If If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20) check.HP = 0 y_dir = Speed COLLIDED = True End If If COLLIDED BrickList.Remove(check) BRICKS_KILLED:+1 SCORE:+1 Play_EXP_EFFECT() End If Rem SIDE COLLISIONS: BUGGED If RectsOverlap(check.x,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = Speed End If End Rem Next x:+x_dir y:+y_dir End If SetColor 0,0,255 SetAlpha a DrawOval x,y,20,20 For i=1 To LIFES DrawOval 500+(i*26),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method EndType AutoMidHandle True Rem MAIN PROGRAM ................ ...................................................................... . . . . . . . . . . . . . . . . . End Rem Global NUMBER_OF_BRICKS:Int = 44'Number of bricks -- 11 per row. Global player:TPlayer = New TPlayer player.Create() player.Speed = 10 Local i:Int For i=1 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 tempx = 17 tempy = 30 ball.Speed:+1 For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Brick.image = wall2 Next End If If ball.LIFES < 0 GameOver() End If DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL+" -- SCORE: "+SCORE,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 Function GameOver() Local i:Int NUMBER_OF_BRICKS = 44 BRICKS_KILLED = 0 launch = False tempy = 30 tempx = 17 ball.Speed = 10 ball.LIFES = 3 SCORE = 0 For check:TBrick = EachIn BrickList BrickList.Remove(check) Next For i = 1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast(BrickList,Brick) Brick.Create() Next While Not KeyHit(KEY_SPACE) Cls If AppTerminate() End DrawText "YOU LOSE!!! press Space to start a new game!",200,300 Flip Wend End Function Function Play_EXP_EFFECT() Local i:Int For i=0 To 5 DrawImage wall1_break,ball.x,ball.y,i Delay 100 Next End Function
wall1_break.png:
animation is a bit tricky. first you need to find a way to display each frame long enough for the player to notice it. But it has to be done with out stopping the game play. it is like when you are able to move the paddle while the ball is in motion.
what you are doing is drawing all of the frames in the back page piling each other with in one cycle(one cycle is when you completed all your calculations and drawings and flip the page). When you flip it, the mess/stack is displayed with in the one cycle making it almost too fast for the eye to perceive. you need to display each frame of animation at least several cycles.
I suggest you create a type for the explosion. create it when a tile is collided. and delete it when the animation is completed. if you think you are going to have more than one explosion at a time, create a list to store them and work it like you work the tile list. you can create a counter with in the explosion type that would decrease every cycle and when it reaches 0 display the next frame. and then reasign the counter repeat that until all of the frames are displayed. then delete it. I can easily create one for you but I think you should give it a try first. I will be here if you need some help.
lear how to use "loadanimimage"
this is an example of how it works using your image
I don't know if your image is really a png I think is a bmp.
what you are doing is drawing all of the frames in the back page piling each other with in one cycle(one cycle is when you completed all your calculations and drawings and flip the page). When you flip it, the mess/stack is displayed with in the one cycle making it almost too fast for the eye to perceive. you need to display each frame of animation at least several cycles.
I suggest you create a type for the explosion. create it when a tile is collided. and delete it when the animation is completed. if you think you are going to have more than one explosion at a time, create a list to store them and work it like you work the tile list. you can create a counter with in the explosion type that would decrease every cycle and when it reaches 0 display the next frame. and then reasign the counter repeat that until all of the frames are displayed. then delete it. I can easily create one for you but I think you should give it a try first. I will be here if you need some help.
lear how to use "loadanimimage"
this is an example of how it works using your image
Strict Graphics 800,600 Local image:timage = LoadAnimImage("wall1_break.png",100,50,0,6) If image = Null Notify "animation not found" Local counter:Int =20 Local index:Int = 0 SetClsColor(100,100,0) Repeat Cls counter = (counter +1) Mod 10 If Not counter index = (index+1) Mod 6 DrawText "Press (esc) to exit",100,0 DrawImage(image,100,100,index) Flip() Until KeyDown(key_escape)
I don't know if your image is really a png I think is a bmp.
its a png... your example doesnt work? is that intentional?
it works I tried it before posting it
make shure you save it first where you have the image saved.
<edit>
I said that because when I tried to save it to my computer it said it was a bmp. I had to convert it back to png after copying to my harddrive.
make shure you save it first where you have the image saved.
<edit>
I said that because when I tried to save it to my computer it said it was a bmp. I had to convert it back to png after copying to my harddrive.
EDIT: Nevermind, spell mistake on the image directory.
any ideas why this is not working correctly? am i on the right track?
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% ) 'Initalization area.. Global paddleAdir:Int = 1, tempx:Int = 17, tempy:Int = 30, launch:Int, ball_padle_dif:Float, Brick:TBrick, check:TBrick, BRICKS_KILLED:Int = 0, LEVEL:Int = 1, SCORE:Int =0,killed:TExplosion SeedRnd MilliSecs() SetBlend(ALPHABLEND) Global wall1:TImage=LoadImage("wall1.png"), wall2:TImage=LoadImage("wall2.png"), wall1_break:TImage=LoadAnimImage("wall1-break.png",100,50,0,6) 'Tlist Global BrickList:TList = CreateList(), ExplosionList:TList = CreateList() 'TEntity Type TEntity Field x:Float Field y:Float Field a:Float = 1.0 EndType Type TSpeedEntity Extends TEntity Field Speed:Float End Type 'TPlayer type Type TPlayer Extends TSpeedEntity Method Create() x = 20 y = 530 a = .5 Speed = 8 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 image:TImage Method Create() image = wall1 HP = 1 x = tempx y = tempy tempx:+70 If tempx = 787 tempy:+20 tempx = 17 SetAlpha a DrawImage image,x,y SetAlpha 1.0 End Method Method Update() SetAlpha a If HP > 0 DrawImage image,x,y SetAlpha 1.0 End Method EndType 'TBall type Type TBall Extends TSpeedEntity Field y_dir:Int Field x_dir:Int Field LIFES:Int Method Create() x = player.x + 50 y = 510 Speed = 10 LIFES = 3 Local i:Int SetAlpha a SetColor 0,0,255 DrawOval x,y,20,20 For i = 1 To LIFES DrawOval 500+(i*20),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method Method Update() Local i:Int 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 = Speed If y > 540 launch = False 'LIFES:-1 If x > 780 x_dir = -Speed If x < 0 x_dir = Speed If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -Speed x_dir = ball_padle_dif*(Speed-2) End If For check:TBrick = EachIn BrickList Local COLLIDED:Int = False If RectsOverlap(check.x,check.y,60,7,ball.x,y,20,20) check.HP = 0 y_dir = -Speed COLLIDED = True End If If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20) check.HP = 0 y_dir = Speed COLLIDED = True End If If COLLIDED BrickList.Remove(check) BRICKS_KILLED:+1 SCORE:+1 killed:TExplosion = New TExplosion ListAddLast ExplosionList,killed killed.CreateEXP(check.x,check.y,wall1_break) End If Rem SIDE COLLISIONS: BUGGED If RectsOverlap(check.x,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = Speed End If End Rem Next x:+x_dir y:+y_dir End If SetColor 0,0,255 SetAlpha a DrawOval x,y,20,20 For i=1 To LIFES DrawOval 500+(i*26),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method EndType Type TExplosion Extends TEntity Field FrameTimer:Float Field Current_Frame:Int Field Image:TImage Method CreateEXP(Brick_x:Int,Brick_y:Int,Brick_image:TImage) x=Brick_x-10 y=Brick_y-15 FrameTimer = 20 Image = Brick_image End Method Method UpdateEXPs() FrameTimer:+0.001 If FrameTimer = Ceil(FrameTimer) Current_Frame = Current_Frame + 1 If FrameTimer > 6.0 Current_Frame = 0 FrameTimer = 0 DrawImage Image,x,y,Current_Frame End Method End Type AutoMidHandle True Rem MAIN PROGRAM ................ ...................................................................... . . . . . . . . . . . . . . . . . End Rem Global NUMBER_OF_BRICKS:Int = 44'Number of bricks -- 11 per row. Global player:TPlayer = New TPlayer player.Create() player.Speed = 10 Local i:Int Local all:TExplosion For i=1 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 tempx = 17 tempy = 30 ball.Speed:+1 For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Brick.image = wall2 Next End If For all:TExplosion = EachIn ExplosionList all.UpdateEXPs() Next If ball.LIFES < 0 GameOver() End If DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL+" -- SCORE: "+SCORE,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 Function GameOver() Local i:Int NUMBER_OF_BRICKS = 44 BRICKS_KILLED = 0 launch = False tempy = 30 tempx = 17 ball.Speed = 10 ball.LIFES = 3 SCORE = 0 For check:TBrick = EachIn BrickList BrickList.Remove(check) Next For i = 1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast(BrickList,Brick) Brick.Create() Next While Not KeyHit(KEY_SPACE) Cls If AppTerminate() End DrawText "YOU LOSE!!! press Space to start a new game!",200,300 Flip Wend End Function
ahh i saw how the old one didnt work, but why doesnt this new one work? it looks good as far as logic..
same images above (wall1.png,wall2.png,wall1-break.png)
same images above (wall1.png,wall2.png,wall1-break.png)
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% ) 'Initalization area.. Global paddleAdir:Int = 1, tempx:Int = 17, tempy:Int = 30, launch:Int, ball_padle_dif:Float, Brick:TBrick, check:TBrick, BRICKS_KILLED:Int = 0, LEVEL:Int = 1, SCORE:Int =0,killed:TExplosion SeedRnd MilliSecs() SetBlend(ALPHABLEND) Global wall1:TImage=LoadImage("wall1.png"), wall2:TImage=LoadImage("wall2.png"), wall1_break:TImage=LoadAnimImage("wall1-break.png",100,50,0,6) 'Tlist Global BrickList:TList = CreateList(), ExplosionList:TList = CreateList() 'TEntity Type TEntity Field x:Float Field y:Float Field a:Float = 1.0 EndType Type TSpeedEntity Extends TEntity Field Speed:Float End Type 'TPlayer type Type TPlayer Extends TSpeedEntity Method Create() x = 20 y = 530 a = .5 Speed = 8 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 image:TImage Method Create() image = wall1 HP = 1 x = tempx y = tempy tempx:+70 If tempx = 787 tempy:+20 tempx = 17 SetAlpha a DrawImage image,x,y SetAlpha 1.0 End Method Method Update() SetAlpha a If HP > 0 DrawImage image,x,y SetAlpha 1.0 End Method EndType 'TBall type Type TBall Extends TSpeedEntity Field y_dir:Int Field x_dir:Int Field LIFES:Int Method Create() x = player.x + 50 y = 510 Speed = 10 LIFES = 3 Local i:Int SetAlpha a SetColor 0,0,255 DrawOval x,y,20,20 For i = 1 To LIFES DrawOval 500+(i*20),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method Method Update() Local i:Int 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 = Speed If y > 540 launch = False 'LIFES:-1 If x > 780 x_dir = -Speed If x < 0 x_dir = Speed If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -Speed x_dir = ball_padle_dif*(Speed-2) End If For check:TBrick = EachIn BrickList Local COLLIDED:Int = False If RectsOverlap(check.x,check.y,60,7,ball.x,y,20,20) check.HP = 0 y_dir = -Speed COLLIDED = True End If If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20) check.HP = 0 y_dir = Speed COLLIDED = True End If If COLLIDED BrickList.Remove(check) BRICKS_KILLED:+1 SCORE:+1 killed:TExplosion = New TExplosion ListAddLast ExplosionList,killed killed.CreateEXP(check.x,check.y,wall1_break) End If Rem SIDE COLLISIONS: BUGGED If RectsOverlap(check.x,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = Speed End If End Rem Next x:+x_dir y:+y_dir End If SetColor 0,0,255 SetAlpha a DrawOval x,y,20,20 For i=1 To LIFES DrawOval 500+(i*26),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method EndType Type TExplosion Extends TEntity Field FrameTimer:Float Field Current_Frame:Int Field Image:TImage Method CreateEXP(Brick_x:Int,Brick_y:Int,Brick_image:TImage) x=Brick_x-10 y=Brick_y-15 FrameTimer = 1.0 Image = Brick_image End Method Method UpdateEXPs() Select FrameTimer Case 1.0 Current_Frame = 0 Case 2.0 Current_Frame = 1 Case 3.0 Current_Frame = 2 Case 4.0 Current_Frame = 3 Case 5.0 Current_Frame = 4 Case 6.0 Current_Frame = 5 End Select DrawImage Image,x,y,Current_Frame FrameTimer:+0.1 End Method End Type AutoMidHandle True Rem MAIN PROGRAM ................ ...................................................................... . . . . . . . . . . . . . . . . . End Rem Global NUMBER_OF_BRICKS:Int = 44'Number of bricks -- 11 per row. Global player:TPlayer = New TPlayer player.Create() player.Speed = 10 Local i:Int Local all:TExplosion For i=1 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 tempx = 17 tempy = 30 ball.Speed:+1 For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Brick.image = wall2 Next End If For all:TExplosion = EachIn ExplosionList all.UpdateEXPs() Next If ball.LIFES < 0 GameOver() End If DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL+" -- SCORE: "+SCORE,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 Function GameOver() Local i:Int NUMBER_OF_BRICKS = 44 BRICKS_KILLED = 0 launch = False tempy = 30 tempx = 17 ball.Speed = 10 ball.LIFES = 3 SCORE = 0 For check:TBrick = EachIn BrickList BrickList.Remove(check) Next For i = 1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast(BrickList,Brick) Brick.Create() Next While Not KeyHit(KEY_SPACE) Cls If AppTerminate() End DrawText "YOU LOSE!!! press Space to start a new game!",200,300 Flip Wend End Function
did you rename wall1_break.png?
anyway here it is rename that file if you need to.
anyway here it is rename that file if you need to.
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% ) 'Initalization area.. Global paddleAdir:Int = 1, tempx:Int = 17, tempy:Int = 30, launch:Int, ball_padle_dif:Float, Brick:TBrick, check:TBrick, BRICKS_KILLED:Int = 0, LEVEL:Int = 1, SCORE:Int =0,killed:TExplosion SeedRnd MilliSecs() SetBlend(ALPHABLEND) Global wall1:TImage=LoadImage("wall1.png"), wall2:TImage=LoadImage("wall2.png"), wall1_break:TImage=LoadAnimImage("wall1_break.png",100,50,0,6) 'Tlist Global BrickList:TList = CreateList(), ExplosionList:TList = CreateList() 'TEntity Type TEntity Field x:Float Field y:Float Field a:Float = 1.0 EndType Type TSpeedEntity Extends TEntity Field Speed:Float End Type 'TPlayer type Type TPlayer Extends TSpeedEntity Method Create() x = 20 y = 530 a = .5 Speed = 8 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 image:TImage Method Create() image = wall1 HP = 1 x = tempx y = tempy tempx:+70 If tempx = 787 tempy:+20 tempx = 17 SetAlpha a DrawImage image,x,y SetAlpha 1.0 End Method Method Update() SetAlpha a If HP > 0 DrawImage image,x,y SetAlpha 1.0 End Method EndType 'TBall type Type TBall Extends TSpeedEntity Field y_dir:Int Field x_dir:Int Field LIFES:Int Method Create() x = player.x + 50 y = 510 Speed = 10 LIFES = 3 Local i:Int SetAlpha a SetColor 0,0,255 DrawOval x,y,20,20 For i = 1 To LIFES DrawOval 500+(i*20),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method Method Update() Local i:Int 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 = Speed If y > 540 launch = False 'LIFES:-1 If x > 780 x_dir = -Speed If x < 0 x_dir = Speed If RectsOverlap(player.x,player.y,100,40,x,y,20,20) y_dir = -Speed x_dir = ball_padle_dif*(Speed-2) End If For check:TBrick = EachIn BrickList Local COLLIDED:Int = False If RectsOverlap(check.x,check.y,60,7,ball.x,y,20,20) check.HP = 0 y_dir = -Speed COLLIDED = True End If If RectsOverlap(check.x,check.y+13,60,7,x,y,20,20) check.HP = 0 y_dir = Speed COLLIDED = True End If If COLLIDED BrickList.Remove(check) BRICKS_KILLED:+1 SCORE:+1 killed:TExplosion = New TExplosion ListAddLast ExplosionList,killed killed.CreateEXP(check.x,check.y,wall1_break) End If Rem SIDE COLLISIONS: BUGGED If RectsOverlap(check.x,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = -Speed BrickList.Remove(check) End If If RectsOverlap(check.x+50,check.y+7,10,13,x,y,20,20) check.HP = 0 x_dir = Speed End If End Rem Next x:+x_dir y:+y_dir End If SetColor 0,0,255 SetAlpha a DrawOval x,y,20,20 For i=1 To LIFES DrawOval 500+(i*26),570,20,20 Next SetColor 255,255,255 SetAlpha 1.0 End Method EndType Type TExplosion Extends TEntity Field FrameTimer:Float Field Current_Frame:Int Field Image:TImage Method CreateEXP(Brick_x:Int,Brick_y:Int,Brick_image:TImage) Current_Frame =0 x=Brick_x-10 y=Brick_y-15 FrameTimer = 0'****************************************************** Image = Brick_image End Method Method UpdateEXPs() If frametimer < 6.0 Current_Frame = FrameTimer'you realize you can also use frametimer as current_frame. DrawImage Image,x,y,Current_Frame Else ListRemove(explosionlist,Self)' just another way of doing explosionlist.remove(self) EndIf FrameTimer:+0.1 End Method End Type AutoMidHandle True Rem MAIN PROGRAM ................ ...................................................................... . . . . . . . . . . . . . . . . . End Rem Global NUMBER_OF_BRICKS:Int = 44'Number of bricks -- 11 per row. Global player:TPlayer = New TPlayer player.Create() player.Speed = 10 Local i:Int Local all:TExplosion For i=1 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 If explosionlist.count() = 0 '*********************************** launch = False NUMBER_OF_BRICKS:+11 BRICKS_KILLED = 0 LEVEL:+1 tempx = 17 tempy = 30 ball.Speed:+1 For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Brick.image = wall2 Next EndIf '************************************************************ End If For all:TExplosion = EachIn ExplosionList all.UpdateEXPs() Next If ball.LIFES < 0 GameOver() End If DrawText "[SPACE]=Launch, [<-] & [->]=Movement --- LEVEL: "+LEVEL+" -- SCORE: "+SCORE,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 Function GameOver() Local i:Int NUMBER_OF_BRICKS = 44 BRICKS_KILLED = 0 launch = False tempy = 30 tempx = 17 ball.Speed = 10 ball.LIFES = 3 SCORE = 0 For check:TBrick = EachIn BrickList BrickList.Remove(check) Next For i = 1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast(BrickList,Brick) Brick.Create() Next While Not KeyHit(KEY_SPACE) Cls If AppTerminate() End DrawText "YOU LOSE!!! press Space to start a new game!",200,300 Flip Wend End Function
wow.... that looks awsome... thanks, i should be finished with it soon.
Alright its finished, i don't plan to make it very great, just made some photoshop images, added some more gameplay, dressed it up, made a main menu, so now its done.
thanks for all the help, i think i have a basic understanding on how max works vs. b3d..
now i'm gonna try to make a platformer...
thanks for all the help, i think i have a basic understanding on how max works vs. b3d..
now i'm gonna try to make a platformer...
reading this again, some mentioned its possible to reduce the creation process:
is this sort of thing possible? i'm having a horrible time trying to get it working, should i stop and go back to my 1 line more creation process or is this possible? and should i use it vs the other way for good practice or ?
Global player:TPlayer . . . . . . Method Create:TPlayer() Local t:TPlayer = New TPlayer Return t End Method . . . . player.Create()
is this sort of thing possible? i'm having a horrible time trying to get it working, should i stop and go back to my 1 line more creation process or is this possible? and should i use it vs the other way for good practice or ?
It needs to be a function. Methods work on instances of objects.
It was me,
I stopped posting advice, because it became clear that you were going to treat Bmax Types as slightly better b3d types, and not as contained objects.
That is, things like this
So I felt it better to not post, because it was just a matter of opinion, and
1) Your stuff was working
2) When you ignored it the first time, I felt that you probably didnt really understand why I was saying it, and I know I couldnt expain it any better
Type aType Global List:Tlist= New TList Method New() BrickList.AddLast(Self) End Method Function Create:aType() Return New AType.Allocate() End Function Method Allocate:aType() allocate stuff End Method End TypeThe reason becomes clear when you come to extend this type, because then you have access to The super.allocation (I called it setup last time
I stopped posting advice, because it became clear that you were going to treat Bmax Types as slightly better b3d types, and not as contained objects.
That is, things like this
For i=1 To NUMBER_OF_BRICKS Brick:TBrick = New TBrick ListAddLast BrickList,Brick Brick.Create() Nextwould not have been in open/main code, and listadd would be inside TBrick.new() and Create would contaied the new. And the Draw commands would have been in AType.Draw etc.
So I felt it better to not post, because it was just a matter of opinion, and
1) Your stuff was working
2) When you ignored it the first time, I felt that you probably didnt really understand why I was saying it, and I know I couldnt expain it any better
yea, i really don't understand it much better then a b3d type, OOP is new to me.. i'll look into it.