Page 1 of 1
Incorrect Formula
Posted: Fri Feb 08, 2013 3:15 am
by Orreven
I've been trying to recreate Block Breaker in PureBasic, as I am still relatively new, but I can't quite get this one formula to work. I tried to save about 140 lines of code with this one For loop, which is designed to assign Consecutive integer Values to a Two dimensional array. The reason I am not using an Enumeration loop, The number of constants (or variables) I would need to enumerate would be 144. I do not wish to code that. My code is
Code: Select all
For B.b=1 To 9
For A.b=1 To 16
BlockImage(A,B)=#Canvas_Main+((B-1)*16)+A
Debug BlockImage(A,B)
Debug A
Debug B
Delay(600)
Next A
Next B
I have correctly done the dimension earlier, #Canvas_Main is currently 78, but will increase as I add more buttons to the program.
What I have figured out that may be helpful to a solution: The value of BlockImage starts at 79, increases consecutively to 126, jumps to -127 (Incidentally at the same time as B hits 4), and increases consecutively to -33. There are no crashes until I try to use one of the variable containing a negative value as a gadget number. I also realize that I probably used too many ()'s, as I usually do, but I do that because of not wanting to be screwed up for lack of them. Help would be greatly appreciated, as I can not continue until this is fixed, and I can't figure out what is wrong for the life of me.
Re: Incorrect Formula
Posted: Fri Feb 08, 2013 3:42 am
by Zach
Maybe something to do with trying to assign a Gadget with a negative number, then?
If this is to generate gadget ID's, why not just use #PB_Any ?
Or stick to a positive number range
Maybe I'm way off base here (didn't explain a lot about what its supposed to actually do beside generate numbers) but are you trying to use Button Gadgets to display your bricks or something, and you need a negative to simulate X / Y movement? If so I think you are going about this all wrong.
Just hard for me to guess what you are trying to accomplish from this code.

Re: Incorrect Formula
Posted: Fri Feb 08, 2013 3:55 am
by Orreven
#PB_Any. Somehow I completely forgot about that. Thanks, this helps quite a bit. The way I'm trying to do this is by having every block in the game be an image Gadget, because I haven't learned about drawing to the screen (I did at some point, but nothing stuck), So I was making 144 Image Gadgets to make a 16*9 Grid of blocks for a sample game of block breaker. So far not much else can be said, so far the entire program is three menus and my attempt at making these image gadgets. Sorry I can't say anything else as of yet.
Re: Incorrect Formula
Posted: Fri Feb 08, 2013 8:25 am
by davido
The manual states that :
Byte .b 1 byte -128 to +127
Might not this be the problem.
You could try .w integers, perhaps?
Re: Incorrect Formula
Posted: Fri Feb 08, 2013 9:03 am
by BasicallyPure
Here is an example of 16 x 9 image gadgets on a window.
I hope there is something here you can use.
Code: Select all
; Blocks.pb
EnableExplicit
Define.i flags = #PB_Window_ScreenCentered | #PB_Window_SystemMenu
Define.i mainWin = OpenWindow(#PB_Any, 0, 0, 800, 600, "Blocks", flags)
If mainWin = 0 : MessageRequester("","Unable to open window") : End : EndIf
#winColor = $CDE5DD
SetWindowColor(mainWin,#winColor)
Define.i blockWidth = 40
Define.i blockHeight = 20
Dim BlockImage.i(16,9)
Macro DrawBlock(imageNumber, color_1, color_2)
; this macro will create an image that can be referenced with 'imageNumber'
; the image will be drawn with rounded corners and a gradient color fill
; using the colors 'color_1 and color_2'
Define.i imageNumber = CreateImage(#PB_Any, blockWidth, blockHeight, 24)
StartDrawing(ImageOutput(imageNumber))
Box(0, 0, blockWidth, blockHeight, #winColor)
DrawingMode(#PB_2DDrawing_Gradient)
FrontColor(color_1) : BackColor(color_2)
BoxedGradient(0, 0, blockWidth, blockHeight)
RoundBox(0, 0, blockWidth, blockHeight, 8, 8)
StopDrawing()
EndMacro
; make two images of different colors using the DrawBlock() macro
DrawBlock(block_1, $14204A, $1420DC)
DrawBlock(block_2, $042B87, $346FF4)
;
#Canvas_Main = 78
Define.i blockNumber = #Canvas_Main + 1
Define.i incX = blockWidth + 4
Define.i incY = blockHeight + 4
Define.i img_ID, A, B, x = 10, y = 10
; create and locate the image gadgets.
For B = 1 To 9
For A = 1 To 16
BlockImage(A,B) = blockNumber ; this is for future use to index image gadgets
If (A + B) & 1 ; alternate the image used for the image gadgets
img_ID = ImageID(block_1)
Else
img_ID = ImageID(block_2)
EndIf
ImageGadget(blockNumber, x, y, blockWidth, blockHeight, img_ID)
blockNumber + 1
x + incX
Next A
x = 10
y + incY
Next B
Repeat
Define.i event = WaitWindowEvent()
If event = #PB_Event_CloseWindow : Break
ElseIf event = #PB_Event_Gadget
Define.i baseNumber = EventGadget() - #Canvas_Main - 1
A = baseNumber % 16 + 1
B = baseNumber / 16 + 1
Debug " A= " + Str(A) + " B= " + Str(B) + " gadNumber= " + Str(BlockImage(A,B))
EndIf
ForEver
B.P.