Neatening Types.
BlitzPlus Forums/BlitzPlus Programming/Neatening Types.
| ||
Just been getting my source code to display my bitmap files in the right clocations, got that working but it appears to be longer than it should be. Any suggestions for shortening the source code?, or do I have to do it this way: AppTitle "BreakIn! (beta)" Local ScreenWidth = 180 Local ScreenHeight = 182 Graphics ScreenWidth,ScreenHeight,32,2 Type Pad Field X Field Y End Type PadFileName = LoadImage("Pad.bmp") Pad.Pad = New Pad Pad\X = 135 Pad\Y = 67 Type Ball Field X Field Y End Type BallFileName = LoadImage("Ball.bmp") Ball.Ball = New Ball Ball\X = 127 Ball\Y = 90 Type WideScreen Field X Field Y End Type WSFileName = LoadImage("WideScreen.bmp") WideScreen.WideScreen = New WideScreen WideScreen\X = 0 WideScreen\Y = 0 WideScreen.WideScreen = New WideScreen WideScreen\X = 167 WideScreen\Y = 0 Type Box Field X Field Y End Type BoxFileName = LoadImage("Box.bmp") Box.Box = New Box Box\X = 45 Box\Y = 15 Box.Box = New Box Box\X = 45 Box\Y = 30 Box.Box = New Box Box\X = 45 Box\Y = 45 Box.Box = New Box Box\X = 45 Box\Y = 60 Box.Box = New Box Box\X = 45 Box\Y = 75 Box.Box = New Box Box\X = 45 Box\Y = 90 Box.Box = New Box Box\X = 45 Box\Y = 105 Box.Box = New Box Box\X = 45 Box\Y = 120 Box.Box = New Box Box\X = 45 Box\Y = 135 Box.Box = New Box Box\X = 45 Box\Y = 150 Box.Box = New Box Box\X = 60 Box\Y = 15 Box.Box = New Box Box\X = 60 Box\Y = 30 Box.Box = New Box Box\X = 60 Box\Y = 45 Box.Box = New Box Box\X = 60 Box\Y = 60 Box.Box = New Box Box\X = 60 Box\Y = 75 Box.Box = New Box Box\X = 60 Box\Y = 90 Box.Box = New Box Box\X = 60 Box\Y = 105 Box.Box = New Box Box\X = 60 Box\Y = 120 Box.Box = New Box Box\X = 60 Box\Y = 135 Box.Box = New Box Box\X = 60 Box\Y = 150 MaskImage WSFileName,250,250,250 MaskImage BoxFileName,250,250,250 MaskImage PadFileName,250,250,250 MaskImage BallFileName,250,250,250 ClsColor 250,250,250 SetBuffer BackBuffer() While Not KeyDown(1) Cls For WideScreen.WideScreen = Each WideScreen DrawImage WSFileName,WideScreen\Y,WideScreen\X Next For Box.Box = Each Box DrawImage BFilename,Box\Y,Box\X Next DrawImage PFileName,Pad\Y,Pad\X DrawImage BallFileName,Ball\Y,Ball\X Flip Wend End I know it's abit long. :\ |
| ||
PS: Please ignore any errors as they have now been fixed. |
| ||
Look up these commands: Data & Restore Use those to store coordinates and read them.. then you only need one x.x = new x thing inside a For/Next or something.. that'd shorten your code a LOT. IE: ; Creates 3 Type entries with x and y coordinates from DATA statements Type test Field tx Field ty End Type Restore stuff Read num_coords ; Read amount of coords in DATA statements (3) For q = 1 To num_coords Read x ; Read X coord (10,20,30) Read y ; Read Y coord (20,30,40) t.test = New test ; Put into type t\tx = x t\ty = y Next .stuff Data 3 ; x1 y1 x2 y2 x3 y3 Data 10,20,20,30,30,40 Tracer |
| ||
If there is an obvious pattern, as in this case, then you don't need data.For x = 45 To 60 Step 15 For y = 15 To 150 Step 15 box.box = New box box\x = x box\y = y Next Next |
| ||
hehe, you're right.. i didn't even look at his code really :) i just saw a poopload of box things :) Tracer |
| ||
You should also try using functions. |
| ||
Change this:Type Pad Field X Field Y End Typeto this Type Pad Field X,Y End Type |
| ||
Masterbeaker, Theres no difference to either coding pattern and tbh I prefer the broken form for readability for larger types Skully |
| ||
Yep, agree with Skully. I always do: if bla1 = bla2 bla2 = bla1 endif instead of: if bla1 = bla2 then bla2 = bla1 or worse.. i've seen: if bla1 = bla2 bla2 = bla1 brr... for example, better readability is what i do that for mostly. :) For the rest it's the exact same thing. I never use Gosub/Return or Goto's either. Same reason. Boxing all the stuff into Functions is just more readable IMHO, especially in giant source codes. Tracer |
| ||
Tracer, I would never write any of those statements -- none of them do anything! (if a and b are the same then make b and a the same too) ;-) |
| ||
lol Tracer |