Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Chipmunks Engine Tester
- mousepos = { x= 17, y =136 }
- mouse2pos = { x= 470, 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, 0.0); --gravedad 0
- mouse = chipmunk.cursor.new(sp);
- -- crear margenes:
- body = chipmunk.space.staticbody(sp);
- forma = chipmunk.shape.newsegment( body , 0.0 ,1.0, 479.0, 1.0, 0.0);
- chipmunk.shape.elasticity(forma,1.0);
- chipmunk.shape.friction(forma,0.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,0.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,0.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,0.0);
- chipmunk.space.addstaticshape(sp,forma);
- vertices = { { -10, -10 }, { -10 , 35 }, { 2, 35 }, { 2 , -10 } }
- p1 = chipmunk.body.new( 1.0 ,chipmunk.moment.polygon( 1.0 , vertices ) );
- chipmunk.body.position(p1,mousepos.x,mousepos.y);
- chipmunk.space.addbody(sp,p1);
- forma1 = chipmunk.shape.newpoly(p1, vertices);
- chipmunk.shape.elasticity(forma1,1.0);
- chipmunk.shape.friction(forma1,0.5);
- chipmunk.space.addshape(sp,forma1);
- p2 = chipmunk.body.new( 1.0 , chipmunk.moment.polygon( 1.0 , vertices ) );
- chipmunk.body.position(p2,mouse2pos.x,mouse2pos.y);
- chipmunk.space.addbody(sp,p2);
- forma2 = chipmunk.shape.newpoly(p2, vertices);
- chipmunk.shape.elasticity(forma2,0.5);
- chipmunk.shape.friction(forma2,0.5);
- chipmunk.space.addshape(sp,forma2);
- ball = chipmunk.body.new( 10.0 , chipmunk.moment.circle( 10.0 , 0.0, 15.0 ) );
- chipmunk.body.position(ball,240 ,136);
- chipmunk.space.addbody(sp,ball);
- forma = chipmunk.shape.newcircle(ball, 6.0);
- chipmunk.shape.elasticity(forma,0.5);
- chipmunk.shape.friction(forma,0.5);
- chipmunk.space.addshape(sp,forma);
- --os.chipmunksplash();
- while true do
- chipmunk.space.step(sp, 2/60);
- screen.print(10,10,"Chipmunk PONG 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);
- screen.flip();
- controls.read();
- if controls.triangle() then mouse2pos.y = mouse2pos.y -3.5; end
- if controls.cross() then mouse2pos.y = mouse2pos.y + 3.5; end
- if controls.up() then mousepos.y = mousepos.y -3.5; end
- if controls.down() then mousepos.y = mousepos.y + 3.5; end
- if mousepos.y<0 then mousepos.y=0 end
- if mouse2pos.y<0 then mouse2pos.y=0 end
- if mousepos.y>272 then mousepos.y=272 end
- if mouse2pos.y>272 then mouse2pos.y=272 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
- chipmunk.body.position(p1,mousepos.x ,272.0-mousepos.y);
- chipmunk.body.position(p2,mouse2pos.x ,272.0-mouse2pos.y);
- --[[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