locked
Question: LitDev-Extension (physics) RRS feed

  • Question

  • Sorry bothering again, but I don't get it. This is a little code piece. I just made boundaries, one paddle and a ball to play with.

    The paddle isn't at supposed starting-position and flies around somewhere else until it decides to go to it's starting position, and the ball ( click into graphicc window to drop one ) does not return from paddle. instead it looks like the ball hits from below and the paddle jumps up. What am I doing wrong:

    gwWidth = 480
    gwHeight = 600
    gwBorderWidth = 12
    
    padPosX = gwWidth * 0.5 - 40
    padPosY = gwHeight * 0.8
    
    LDPhysics.SetBoundaries(gwBorderWidth, gwWidth - gwBorderWidth, gwBorderWidth, gwHeight- gwBorderWidth)
    
    GraphicsWindow.Width = gwWidth
    GraphicsWindow.Height= gwHeight
    GraphicsWindow.Left = 220
    GraphicsWindow.Top = 140
    GraphicsWindow.BackgroundColor ="DarkSeaGreen"
    GraphicsWindow.BrushColor = "LightSteelBlue"
    GraphicsWindow.PenColor = "SteelBlue"
    GraphicsWindow.PenWidth = 2
    GraphicsWindow.Show()
    
    wall_left = Shapes.AddRectangle(gwBorderWidth,gwHeight - gwBorderWidth)
    Shapes.Move(wall_left, 0, gwBorderWidth)
    LDPhysics.AddFixedShape(wall_left, 1, 0)
    
    wall_right = Shapes.AddRectangle(gwBorderWidth, gwHeight - gwBorderWidth)
    Shapes.Move(wall_right, gwWidth-gwBorderWidth, gwBorderWidth)
    LDPhysics.AddFixedShape(wall_right, 1, 0)
    
    wall_top = Shapes.AddRectangle(gwWidth, gwBorderWidth)
    Shapes.Move(wall_top,0,0)
    LDPhysics.AddFixedShape(wall_top, 1, 0)
    
    points[0]["X"] = 8
    points[0]["Y"] = 0
    points[1]["X"] = 72
    points[1]["Y"] = 0
    points[2]["X"] = 80
    points[2]["Y"] = 8
    points[3]["X"] = 80
    points[3]["Y"] = 16
    points[4]["X"] = 72
    points[4]["Y"] = 24
    points[5]["X"] = 8
    points[5]["Y"] = 24
    points[6]["X"] = 0
    points[6]["Y"] = 16
    points[7]["X"] = 0
    points[7]["Y"] = 8
    
    GraphicsWindow.BrushColor = "Brown"
    GraphicsWindow.PenColor = "Maroon"
    
    paddle = LDShapes.AddPolygon(points)
    shapes.Move(paddle, padPosX, padPosY )
     
     LDPhysics.AddMovingShape(paddle,1,1,1)
     LDPhysics.SetPosition(paddle, padPosX, padPosY,0)
    LDPhysics.SetForce(paddle,1,1)
    GraphicsWindow.BrushColor = "LightRed"
    GraphicsWindow.PenColor = "Red"
    LDPhysics.DoTimestep()
    
    
    GraphicsWindow.MouseMove = onMouseMove
    GraphicsWindow.MouseDown = onMouseDown
    
    While GraphicsWindow.LastKey <> "Escape"
            
      LDPhysics.DoTimestep()
      LDPhysics.SetPosition(paddle, padPosX, padPosY, 0 )
       Program.Delay(20)
      endwhile Program.End() Sub onMouseMove padPosX = GraphicsWindow.MouseX If padPosX < gwBorderWidth + 40 Then padPosX = gwBorderWidth + 40 ElseIf padPosX > gwWidth - 40 - gwBorderWidth then padPosX = gwWidth - 40 - gwBorderWidth EndIf EndSub Sub onMouseDown ball = Shapes.AddEllipse(40,40) LDPhysics.AddMovingShape(ball, 1, 1, 1) LDPhysics.SetPosition(ball, padPosX, gwBorderWidth + 24, 0) EndSub

      And where do the balls go? are they deleted or still flying around in memory?

    Where can I get some suitable commands overview?

    Intellisense isn't really a help. Has anybody of those grown-ups ever tried to write a program with it?

    It's a pain in the... fingers and driving me nuts.  Especially if there's more than one extension and a few variables in memory and I've forgotten what the method was called that I need at the moment. It eats up too much time browsing all the commands and is slow and stucky.It informs on the right side about the currently typed method & params, but when it comes to type those parameters- that ...(thing?) decides to take a break and the stuff what is currently needed disappears! 

    What are those kids supposed to learn with it? How hard it was to write a program in the good old times? They don't care about the past - they are the future! Re-Editing some code (especially if using arrow keys to move) is almost impossible without getting a minor life-crisis and in the meantime I changed to notepad to write program-code! Is there a way to turn this nontellisense thingamagicky off and enable some kind of reverse command search or is there a suitable documentation?


    • Edited by Rene_Miner Tuesday, October 9, 2012 2:00 AM
    Tuesday, October 9, 2012 1:20 AM

Answers

  • For me, I just changed the paddle to a fixed shape and it still moved along the mouse because of LDPhysics.SetPosition and that did it.

    I am a 10 year old that loves math, games, and computers. "Everyone is potentially great, you just have to turn it into kinetic greatness."


    • Edited by Math Man Tuesday, October 9, 2012 2:12 AM
    • Marked as answer by Rene_Miner Tuesday, October 9, 2012 2:58 AM
    Tuesday, October 9, 2012 2:11 AM

All replies

  • I wrote a fairly detailed guide with the examples for the Box2D LDPhysics extension in the dll download.

    A pong type game isn't really that great for Box2D, think Angry Birds or Boxycraft.  If you move a shape by resetting its position no interaction will take place with the other shapes during the repositioning - see the discussion on teleporting in the guide.  The Box2D is really for limited interaction and let things interact with physics, like the games mentioned above, just apply the odd force or impulse here and there to start things off, like the pool demo.

    Also the balls falls to fast (so a delay in the game loop is required) and tunneling occurs (see Box2D documentation or the guide) LDPhysics.SetBullet.  The paddle has similar mass to the ball, so when the ball hits it at high speed it just pushes past, so a fixed shape would be better.

    Box2D is beyond most young children users, it requires some learning about physics, but that it the point really - learing about physics, forces, collisions etc.

    Modified version import CSP757

    Tuesday, October 9, 2012 1:56 AM
  • if i start a ball ( click on window ) it says Error-overflow!

    I took the LDPhysics-Methods out of the Mouse-Event-Handler. Now the ball is everywhere at the same time

    • Edited by Rene_Miner Tuesday, October 9, 2012 2:14 AM
    Tuesday, October 9, 2012 2:04 AM
  • For me, I just changed the paddle to a fixed shape and it still moved along the mouse because of LDPhysics.SetPosition and that did it.

    I am a 10 year old that loves math, games, and computers. "Everyone is potentially great, you just have to turn it into kinetic greatness."


    • Edited by Math Man Tuesday, October 9, 2012 2:12 AM
    • Marked as answer by Rene_Miner Tuesday, October 9, 2012 2:58 AM
    Tuesday, October 9, 2012 2:11 AM
  • Do the samples work?

    Where does this error appear?

    How do you create this error - I can't reproduce.  Just to be sure, perhaps use the standard LitDev.dll not the one for 32bit for the 3D testing in case there is something fundamentally wrong with this test version for 32 bit machines.

    Tuesday, October 9, 2012 2:24 AM
  • ah ok,  I still have the LD3D in use... this and the LitDev-extension-.dll files wear the same name. Might better change it then.
    But don't you see in your screenshot: there is more than one ball. On my screen too and I clicked the window only once.

    Where the other balls come from? Are these all those balls that ran during testing off the screen - came back from deep out of memory? :D


    • Edited by Rene_Miner Tuesday, October 9, 2012 2:48 AM
    Tuesday, October 9, 2012 2:44 AM
  • I took the LDPhysics-Methods out of the Mouse-Event-Handler. Now the ball is everywhere at the same time

    I don't understand?

    Sub onMouseDown
      ball = Shapes.AddEllipse(40,40)
      'LDPhysics.AddMovingShape(ball, 1, 1, 1)
      'LDPhysics.SetBullet(ball)
      'LDPhysics.SetPosition(ball, padPosX, gwBorderWidth + 24, 0)
    EndSub
    For me this just creates a ball that does nothing at the default top left coordinates?
    Tuesday, October 9, 2012 2:48 AM
  • The additional balls are because I clicked several times.  No the balls that miss the paddle just fall off the bottom and eventually out of the AABB for the Box2D engine - they are still in the SmallBasic memory but play not part - we should really remove them, but not a big deal.

    If it does work with the original LitDev extension, then that may be a clue to the 3D issues in 32 bit - I take the point about perhaps a completely new 3D extension with a different name - I just tagged it on the end of the main LitDev extension, but this was probably a mistake.

    Tuesday, October 9, 2012 2:53 AM
  • No, not completely. In the documentation it says its no good doing physics during events

    this is just the last few lines beginning from mainloop.

    While GraphicsWindow.LastKey <> "Escape"
            
      LDPhysics.DoTimestep()
      LDPhysics.SetPosition(paddle, padPosX, padPosY, 0 )
     Program.Delay(20)
     if fromMouse=1
       LDPhysics.AddMovingShape(ball, 1, 1, 1)
       LDPhysics.SetPosition(ball, padPosX, gwBorderWidth + 24, 0)
       fromMouse = 0
       
    EndIf
     
    endwhile
    
    Program.End()
    
    Sub onMouseMove
      padPosX = GraphicsWindow.MouseX
      If padPosX < gwBorderWidth + 40 Then
        padPosX = gwBorderWidth + 40
      ElseIf padPosX > gwWidth - 40 - gwBorderWidth then
        padPosX = gwWidth - 40 - gwBorderWidth
      EndIf
     
    EndSub
    
    Sub onMouseDown
     ball = Shapes.AddEllipse(40,40)
     fromMouse = 1
    EndSub
    
      
    But thanks to Math Man. a fixed shape solves the problem. I supposed that a FIXED shape is fixed and cannot be moved

    Tuesday, October 9, 2012 2:55 AM
  • You are right best to not use LDPhysics in the event since they are handled by SmallBasic on new threads and can clash with the main thread.

    I assumed you were using the modified code I posted where I also set the paddle to a fixed shape and added the bullet attribute.

    Does this work with the 3D dll?

    • Edited by litdev Tuesday, October 9, 2012 3:00 AM
    Tuesday, October 9, 2012 3:00 AM
  • No, the modified code brought up that overflow. But I just replaced the dll and now is no overflow. You don't want me to change it back again and try again?
    Tuesday, October 9, 2012 3:06 AM
  • No thanks, but this gives me hope that there is a simple configuration setting error in the 32 bit 3D stuff (which I couldn't detect or test on my 64 bit PC).
    Tuesday, October 9, 2012 3:17 AM
  • A Pong game can be easily made using vanilla Small Basic, look into velocity if you are interested on making a ball bounce of walls.
    • Edited by Mainchip Tuesday, October 9, 2012 4:50 PM
    Tuesday, October 9, 2012 4:50 PM
  • no, i don't want to create a pong-game. I'm just testing capabilities and what I can co with all these extensions. I want to learn more about certain behaviour and see what's possible, testing, tampering around..., playing Try'n'Error...

    When I got an idea for a real game or program, I want to know how to use all this stuff and what to use.

    It's like so: I had no internet-access for about 5 years because I live in a very small hamlet (?) in the back of beyond inbetween the mountains - so there was no cable-connection and no usb-web-stick possible either because of the mountains around. But now I've got a fast wired-internet-connection.  :)

    I came to Small Basic last week, and just start to learn how to use it. I like it because it's not that overwhelming bunch of unclear stuff like vb.net - that's why I was still stuck to good old VB 6.0. But I was missing a few little things in it, so I tried to google and find out how to extend sb with some useful functions... that's how I came here to this forum in the first place.

    Please write me someone a XOR()-function! 

    Edit:

    I tried myself at the spring-problem-challenge ( that sticky-thread in the forum ) - surely I won't use LDPhysics, but in the first steps (I was just up to create a mousepointer) I experience that there's some problem with them shapes. They both are set to the same location but they seperate on mouse moves.

    See Example: WLT029

    There's no way to attach regular shapes to each other? Might be a suggestion for LDShapes...Attach()


    • Edited by Rene_Miner Tuesday, October 9, 2012 6:24 PM
    Tuesday, October 9, 2012 5:07 PM