Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Chipmunks Engine Tester
- mousepos = { x= 240, y =136 }
- --os.luadevsplash();
- os.autofps(120);
- chipmunk.init();
- sp = chipmunk.space.new();
- chipmunk.space.resizestatichash(sp, 22.0, 500.0);
- chipmunk.space.resizeactivehash(sp, 22.0, 500.0);
- chipmunk.space.gravity(sp,0.0, -100.0);
- mouse = chipmunk.cursor.new(sp);
- -- crear margenes:
- body = chipmunk.space.staticbody(sp);
- forma = chipmunk.shape.newsegment( body , 0.0 ,0.0, 479.0, 0.0, 0.0);
- chipmunk.shape.elasticity(forma,1.0);
- chipmunk.shape.friction(forma,1.0);
- chipmunk.space.addstaticshape(sp,forma);
- forma = chipmunk.shape.newsegment( body , 0.0 ,0.0, 0.0, 272.0, 0.0);
- chipmunk.shape.elasticity(forma,1.0);
- chipmunk.shape.friction(forma,1.0);
- chipmunk.space.addstaticshape(sp,forma);
- forma = chipmunk.shape.newsegment( body , 479.0 ,0.0, 479.0, 272.0, 0.0);
- chipmunk.shape.elasticity(forma,1.0);
- chipmunk.shape.friction(forma,1.0);
- chipmunk.space.addstaticshape(sp,forma);
- forma = chipmunk.shape.newsegment( body , 0.0 ,272.0, 479.0, 272.0, 0.0);
- chipmunk.shape.elasticity(forma,1.0);
- chipmunk.shape.friction(forma,1.0);
- chipmunk.space.addstaticshape(sp,forma);
- forma = chipmunk.shape.newsegment( body , 100.0 ,100.0, 200.0, 200.0, 0.0);
- chipmunk.shape.elasticity(forma,2.0);
- chipmunk.shape.friction(forma,1.0);
- chipmunk.space.addstaticshape(sp,forma);
- vertices = { { -10.0, -10.0 }, { -10.0 , 10.0 }, { 10.0, 10.0 }, { 10.0 , -10.0 } }
- for i=0,10 do
- for j = 0, i do
- cuerpo = chipmunk.body.new( 1.0 , chipmunk.moment.polygon( 1.0 , vertices ) );
- chipmunk.body.position(cuerpo,240.0 + j*20.0 - i*10.0, 300.0 - i*20.0);
- chipmunk.space.addbody(sp,cuerpo);
- forma = chipmunk.shape.newpoly(cuerpo, vertices);
- chipmunk.shape.elasticity(forma,0.0);
- chipmunk.shape.friction(forma,0.8);
- chipmunk.space.addshape(sp,forma);
- end
- end
- cuerpo = chipmunk.body.new( 10.0 , chipmunk.moment.circle( 10.0 , 0.0, 15.0 ) );
- chipmunk.body.position(cuerpo,240.0 , 15.0);
- chipmunk.space.addbody(sp,cuerpo);
- forma = chipmunk.shape.newcircle(cuerpo, 15.0);
- chipmunk.shape.elasticity(forma,0.0);
- chipmunk.shape.friction(forma,0.9);
- chipmunk.space.addshape(sp,forma);
- --os.chipmunksplash();
- while true do
- chipmunk.space.step(sp, 2/60);
- screen.print(10,10,"Chipmunk DEMO at "..screen.fps().."fps - "..os.cpu().." mhz");
- --screen.print(10,25,"R para coger objetos. Cruz/Triangulo/Redonda/Cuadrado\ncambiar gravedad. Cursor: "..mousepos.x.." "..mousepos.y);
- chipmunk.space.wiredraw(sp);
- draw.line(mousepos.x,mousepos.y-3,mousepos.x,mousepos.y+4,color.new(255,250,250));
- draw.line(mousepos.x-3,mousepos.y,mousepos.x+4,mousepos.y,color.new(255,250,250));
- screen.flip();
- controls.read();
- --[[if controls.left() then mousepos.x = mousepos.x - 3; end
- if controls.right() then mousepos.x = mousepos.x + 3; end
- if controls.up() then mousepos.y = mousepos.y -3; end
- if controls.down() then mousepos.y = mousepos.y + 3; end]]
- if math.abs(controls.analogx())>20 then mousepos.x = mousepos.x + controls.analogx()/30 end
- if math.abs(controls.analogy())>20 then mousepos.y = mousepos.y + controls.analogy()/20 end
- chipmunk.cursor.move(mouse,mousepos.x,272-mousepos.y);
- if controls.r() then
- cuerpo = chipmunk.space.pointqueryfirst_body(sp, mousepos.x, 272 - mousepos.y);
- if cuerpo then
- local px, py = chipmunk.body.position(cuerpo);
- mousepos.x = px; mousepos.y = 272.0-py;
- end
- chipmunk.cursor.grab(mouse,mousepos.x,272.0-mousepos.y);
- end
- if controls.release("r") then chipmunk.cursor.release(mouse); end
- if controls.press("triangle") then chipmunk.space.gravity(sp,0.0,100.0); end
- if controls.press("l") then chipmunk.space.gravity(sp,0.0,0); end
- if controls.press("square") then chipmunk.space.gravity(sp,-100.0,0.0); end
- if controls.press("cross") then chipmunk.space.gravity(sp,0.0,-100.0); end
- if controls.press("circle") then chipmunk.space.gravity(sp,100.0,0.0); end
- if controls.press("select") then a() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement