Anybody familiar with blitzplus?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Jale
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Fri Nov 22, 2013 7:05 am

Anybody familiar with blitzplus?

Post by Jale »

I have a problem, sort of.
To a some degree I understand how types work, but the problem comes when I try to do this:

Code: Select all


New Type
  Field Xpos
  Field Ypos
  Field .....
  .
  .
  .
End Type

For some_number = 0 to 3
  type_pointer.Type = New Type
  type_pointer\Xpos = blahblah
  type_pointer\Ypos = blahblah
Next


For type_pointer.Type = Each Type
pHandle = Handle(type_pointer) 
 
;Handle takes an address of the pointer (previous/next) and stores it in a specific number from 1 to infinity    ;when it is destroyed it cannot be reused again, handle of that pointer = 0

 If type_pointer\Xpos = blehbleh
     For type_pointer.Type = Each Type
        type_pointer\Xpos = blohbloh
     Next
 End if

type_pointer = Object.Type(pHandle)

 If type_pointer\Ypos = blehbleh
     For type_pointer.Type = Each Type
        type_pointer\Ypos = blohbloh
     Next
 End if

type_pointer = Object.Type(pHandle)

;Object.Type(pointer_handle) is taking a handle from a pointer and returns an object or pointer if you wish, of that "Type"
;I'm returning an object to a type_pointer of a first For/Each loop 
;I did this because pointer gets to the last object/pointer in Type once it loops through nested For/Each loop

Next
This code is basically saying if any object from "Type"(or "Class") has such and such parameters, or such and such X position Then set such and such parameters for every object of that "Type". E.G. if "this" block hits the ground then every other block should "stop" too.

The problem is that it is only applied to the last created object, every Check, or If statement gets applied to the last pointer, so I can't check for every object just the last one, which works properly. So basically all blocks of that "Type" will stop only if last created block (within the Type) stops, so If statements are not including other blocks in their conditions (I think so, I'm not sure)

Now, I know that there is thing called inheritance, composition and stuff, but it is all relatively new to me...
It is still so vague...
Jale
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Fri Nov 22, 2013 7:05 am

Re: Anybody familiar with blitzplus?

Post by Jale »

I "fixed" it. :oops:
The problem existed in collision function (btw I had a problem with horizontal collision).
Every shape is made of many other blocks that have same speed of falling down and their side "delta" movement
Click here to see the hidden message (It might contain spoilers)
Plus, I added nested Type in another so

Code: Select all

Type Tetris
	Field speed
	Field delta_r
	Field delta_l
	Field block.Tetblock
End Type


Type Tetblock
	Field Xpos
	Field Ypos
End Type


shape.Tetris = New Tetris
shape\speed = 5
shape\delta_r = 20
shape\delta_l = 20
For b = 1 To nBlock	
	shape\block.Tetblock = New Tetblock
	shape\block\Xpos = 200 + b*20 ;a simple shape >> horizontal shape with 3 blocks
	shape\block\Ypos = 40 
Next

But
The loop, that checks parameters of every block of "a" particular shape, ended on last block and then it stopped because it was the last object(block.Tetblock) created within the "shape.Tetris" Type, and on top of that I didn't have any condition that would stop the loop immediately after any of the created blocks touched solid surface so it just continued.
It was that delta value that I had to bring to 0, but I had no condition that would say stop and wait until something is done:
Click here to see the hidden message (It might contain spoilers)

Code: Select all

Function CheckCollision_Left(shape.Tetris,block.Tetblock)

	For lx = 0 To 4 ; don't mind the for loops they are for something else
	
	Select True
	Case position(x_pos(shape\block\Xpos - 20),y_pos(shape\block\Ypos) - lx) = 1 Or shape\block\Xpos = 140
			shape\delta_l = 0
		Default
			Select True 
				Case KeyDown(RightArrow)  ;<<<<<<<<<< Here
					shape\delta_l = 20
			End Select
	End Select
	
	Next
	
End Function



Function CheckCollision_Right(shape.Tetris,block.Tetblock)

	For rx = 0 To 4
	
	Select True 
	Case position(x_pos(shape\block\Xpos + 20),y_pos(shape\block\Ypos) - rx) = 1 Or shape\block\Xpos = 460
			shape\delta_r = 0
		Default
			Select True 
				Case KeyDown(LeftArrow)  ;<<<<<<<<<< Here
					shape\delta_r = 20
			End Select
	End Select
	
	Next
	
End Function
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Anybody familiar with blitzplus?

Post by dandymcgee »

Thanks for posting the answer. I hate when people say "Nvm, fixed." then carry on leaving the future Googlers baffled. 8-)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Jale
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 3
Joined: Fri Nov 22, 2013 7:05 am

Re: Anybody familiar with blitzplus?

Post by Jale »

dandymcgee wrote:Thanks for posting the answer. I hate when people say "Nvm, fixed." then carry on leaving the future Googlers baffled. 8-)
The problem was easier to solve viewed from a different point of view, but I thought it was something else, I thought it was much more than that, but now, at least I'm 100% sure that I know how Types and pointers work in BB comparing to some other languages. Because it made me search for the answer much deeply and widely.

Okay, okay, one last touch, I just added a piece that says to shift "current" pointer to a last pointer in pointer loop when that "current" satisfies the particular condition, so it just stops movement when any pointer satisfies the condition.

Code: Select all

	For lx = 0 To 4
	shape\delta_l = 20
	Select True
	Case position(x_pos(shape\block\Xpos - 20),y_pos(shape\block\Ypos) - lx) = 1 Or shape\block\Xpos = 140
		shape\delta_l = 0
			
		shape\block.Tetblock = Last Tetblock ;<<<<<<<<<<< Here
		lx = 5 ;<<< Also if you have an additional for-loop like I do make sure it ends here as well
	End Select
Post Reply