Ping Pong DX - Page 2 - Gideros Forum

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Ping Pong DX

2»

• Member
Please note that I went through some gideros brick game code on github, but he/she wasn't using table + he/she was using box2d which I am not at yet.
• Maintainer
I used the TileMap for the bricks. I just cleared the cell when it was hit.
• Member
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.
• Member
edited March 25
cool that worked:
A
 ```for l = 1, 6 do level[l] = {} bricks[l] = {} for c = 1, 15 do level[l][c] = 1 bricks[l][c] = nil end end```

B
 ```local bx, by = 0, 0 for l = 1, 6 do bx = 0 for c = 1, 15 do if level[l][c] == 1 then local 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 COLLISION local c = math.floor(myball:getX() / brickwidth) + 1 local l = math.floor(myball:getY() / brickheight) + 1 if c >= 1 and c <= 15 and l >= 1 and l <= #level then if level[l][c] == 1 then level[l][c] = 0 print(l..","..c) -- if bricks[l][c] ~= nil then stage:removeChild(bricks[l][c]) -- end ballspeedy = - ballspeedy end end```

The code isn't optimized or anything, I am not a gideros guru yet!
Have fun!

Likes: SinisterSoft, pie

+1 -1 (+2 / -0 ) Share on Facebook
• Member
edited March 26
if I understood correctly (sorry if I didn't), you can combine 'getChildAt' and 'removeChildAt' methods
 `stage:getChildAt(l):removeChildAt(c)`
p. s. btw you can shorten lua code with Gideros' mutation operators
 ```--ballspeedy = - ballspeedy ballspeedy-=ballspeedy --bx = bx + brickwidth bx+=brickwidth```

Likes: SinisterSoft

> 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)﻿
+1 -1 (+1 / -0 ) Share on Facebook
• Member
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.

Have fun you all.
• Member
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, 6 do local l = {} local b = {} for c = 1, 15 do l[#l + 1] = 1 b[#b + 1] = nil -- add empty pointer to bricks row end level[#level + 1] = l bricks[#bricks + 1] = b -- save bricks row end   local bx, by = 0, 0 for l = 1, 6 do bx = 0 for c = 1, 15 do if level[l][c] == 1 then local 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 brick   end bx = bx + brickwidth end by = by + brickheight end   local c = math.floor(myball:getX() / brickwidth) + 1 local l = math.floor(myball:getY() / brickheight) + 1 if c >= 1 and c <= 15 and l >= 1 and l <= #level then if level[l][c] == 1 then ballspeedy = - ballspeedy level[l][c] = 0   bricks[l][c]:removeFromParent() -- remove brck from stage bricks[l][c] = nil -- remove brick from bricks end```
Note: I didn't test that at all but it should work.. just scream out if it doesn't
• Member
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.

Now I am learning the basics of tilemaps with gideros.

PS: you should show some code in your devblog

Have fun!

Likes: antix

+1 -1 (+1 / -0 ) Share on Facebook
• Member
@MoKaLux Thanks, yes I should have more code in my devblog.. mostly it's a rant about my daily life currently

Likes: SinisterSoft

+1 -1 (+1 / -0 ) Share on Facebook
• Member
@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.

See you gideros boy and the others gideros fans!

Likes: SinisterSoft

+1 -1 (+1 / -0 ) Share on Facebook