I used the TileMap for the bricks. I just cleared the cell when it was hit.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!). https://deluxepixel.com
Thank you sinistersoft. I am almost getting where I want to go with bricks in a table. Right now I am assigning the bricks (sprites) to another table then I should be able to do stage:removeChild(bricks[l][c]). If I can't get it then I will explore the TileMap.
for l =1, 6do
level[l]={}
bricks[l]={}for c =1, 15do
level[l][c]=1
bricks[l][c]=nilendend
B
local bx, by =0, 0for l =1, 6do
bx =0for c =1, 15doif level[l][c]==1thenlocal r = Pixel.new(0x00ff00, 0.75, brickwidth - 5, brickheight - 5)
r:setAnchorPoint(0.5, 0.5)
r:setPosition(bx, by)
bricks[l][c]= r
stage:addChild(r)end
bx = bx + brickwidth
end
by = by + brickheight
end
THE COLLISIONS
-- BRICKS COLLISIONlocal c =math.floor(myball:getX()/ brickwidth) + 1local l =math.floor(myball:getY()/ brickheight) + 1if c >=1and c <=15and l >=1and l <= #level thenif level[l][c]==1then
level[l][c]=0print(l..","..c)-- if bricks[l][c] ~= nil then
stage:removeChild(bricks[l][c])-- end
ballspeedy = - ballspeedy
end
end</pre>
The code isn't optimized or anything, I am not a gideros guru yet! Have fun!
> Newcomers roadmap: from where to start learning Gideros "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
hi apollo14, I don't think that would work because sprites position are stored in a two dimension array (x, y) in my case line, column. It may work with a pair but I am not that far yet into lua.
Thank you for the shorten lua code, I will use it from now on.
Just off the top of my head maybe you could just use another table called "bricks" to store pointers to your brick Pixel objects..
bricks ={}
level ={}for r =1, 6dolocal l ={}local b ={}for c =1, 15do
l[#l + 1]=1
b[#b + 1]=nil-- add empty pointer to bricks rowend
level[#level + 1]= l
bricks[#bricks + 1]= b -- save bricks rowendlocal bx, by =0, 0for l =1, 6do
bx =0for c =1, 15doif level[l][c]==1thenlocal r = Pixel.new(0x00ff00, 0.75, brickwidth, brickheight)
r:setAnchorPoint(0.5, 0.5)
r:setPosition(bx, by)
stage:addChild(r)
bricks[l][c]= r -- add the brickend
bx = bx + brickwidth
end
by = by + brickheight
endlocal c =math.floor(myball:getX()/ brickwidth) + 1local l =math.floor(myball:getY()/ brickheight) + 1if c >=1and c <=15and l >=1and l <= #level thenif level[l][c]==1then
ballspeedy = - ballspeedy
level[l][c]=0
bricks[l][c]:removeFromParent()-- remove brck from stage
bricks[l][c]=nil-- remove brick from bricksend
Note: I didn't test that at all but it should work.. just scream out if it doesn't
thank you antix, I already got my brick game working. I am learning gideros making simple demo apps.
Your code looks kind of what I have: a brick table + a level table. Then I was able to remove a brick, at a given position in the level, upon collision.
Anyway your code is very helpful.
Now I am learning the basics of tilemaps with gideros.
@antix you seem to be quite a good of a developer indeed! you know that gideros lacks tutorials. So far I have learnt the basics that is: bitmaps (scale, position, ...) + moving a sprite with the keyboard + tables with my pong demo (collisions) + tilemaps.
Right now I am on a plateformer demo (physics).
I am trying to get the best practices as well (using macros, ...) and I may do youtube tutorials, but I am not there quite yet.
Comments
https://deluxepixel.com
A
B
THE COLLISIONS
The code isn't optimized or anything, I am not a gideros guru yet!
Have fun!
Likes: SinisterSoft, pie
Likes: SinisterSoft
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Thank you for the shorten lua code, I will use it from now on.
Have fun you all.
Your code looks kind of what I have: a brick table + a level table. Then I was able to remove a brick, at a given position in the level, upon collision.
Anyway your code is very helpful.
Now I am learning the basics of tilemaps with gideros.
PS: you should show some code in your devblog
Have fun!
Likes: antix
Likes: SinisterSoft
Right now I am on a plateformer demo (physics).
I am trying to get the best practices as well (using macros, ...) and I may do youtube tutorials, but I am not there quite yet.
See you gideros boy and the others gideros fans!
Likes: SinisterSoft