Howdy, Stranger!

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

Vec2 polygon?

edited September 2014 in Questions Posts: 17

Hello, I have never used vector graphics in Codea before and want to make a game similar to Elite (1984) but 2d and much more simple. The only problem is that I have no clue how to use vector graphics. If anyone could give me a quick example of a vec2 polygon that has basic physics like gravity and collisions, I would be very thankful. (Yes, the polygon is for the station.)


  • IgnatzIgnatz Mod
    Posts: 5,396

    @MichaelWeedmark - I would start by modelling very simple circle and rectangle shapes, to get a feeling for the physics.

    Then you can map a set of (x,y) points to fit around the outline of your station [centred on (0,0) in the middle of the station], and use the physics polygon function with those points, to create a physics object that resembles the shape of your station.

    While an example will help, I think it's better to grasp the basic concepts first, otherwise you will find much of the code puzzling. (In particular, the physics demo app included with Codea has a lot of code that isn't needed in most cases, and it confused me for months).

    I've written an ebook on Codea which explains how physics works, which you can find here.

  • @Ignatz Thank you very much, that ebook is very well done.

  • IgnatzIgnatz Mod
    edited September 2014 Posts: 5,396

    Also, here is a step by step project on basic physics (make sure you copy it into its separate tabs, if you don't know the trick, ask)

  • Unfortunately, I do not know the trick, unless it is to past into project.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Press the Add New Project button until until it gives you the option to paste into project, and use that. It should split the code up for you.

  • Got it.

  • dave1707dave1707 Mod
    Posts: 7,809

    @MichaelWeedmark Here an example with a polygon and a circle.

    displayMode(FULLSCREEN) function setup() c1 = physics.body(POLYGON,vec2(0,0),vec2(50,0),vec2(50,50),vec2(0,50)) c1.x=WIDTH/2 c1.y=900 c1.gravityScale=1 c2 = physics.body(CIRCLE,50) c2.x=WIDTH/2 c2.y=600 c2.gravityScale=0 end function draw() background(30, 30, 30, 25) stroke(255) strokeWidth(2) pushMatrix() translate(c1.x,c1.y) rotate(c1.angle) line(0,0,50,0) line(50,0,50,50) line(50,50,0,50) line(0,50,0,0) popMatrix() ellipse(c2.x,c2.y,100) end
  • @dave1707 Thank you very much.

  • Posts: 1,326

    Hi @MichaelWeedmark,

    Started a similar thread to you some time ago Elite... as I have always been interested in the game then and the later incarnations. Got a lot of help and managed to do most of what I needed but not pulled it all together. On my to do list. I'll see how you progress and help where I can



Sign In or Register to comment.