画移动球体
来源:互联网 发布:linux 路由表怎么看 编辑:程序博客网 时间:2024/04/30 03:35
移动球体,包括下落加速度设定和移动设定,有碰撞效果
function love.load()
love.physics.setMeter(64) --the height of a meter our worlds will be 64px
world = love.physics.newWorld(0, 9.81*64, true) --create a world for the bodies to exist in with horizontal gravity of 0 and vertical gravity of 9.81
size = 650
object = {}
--create ground
object.ground = {}
object.ground.body = love.physics.newBody(world,size/2,size - 50/2)
object.ground.sharp = love.physics.newRectangleShape(size,50)
--attach the sharp to the body
object.ground.fixture = love.physics.newFixture(object.ground.body,object.ground.sharp)
--create a ball
object.ball = {}
--place the body in the center of the world and make it dynamic, so it can move around
object.ball.body = love.physics.newBody(world,size/2,size/2,"dynamic")
--create a circle
object.ball.sharp = love.physics.newCircleShape(20)
--attache the shape the body
object.ball.fixture = love.physics.newFixture(object.ball.body,object.ball.sharp,1)
object.ball.fixture:setRestitution(0,9)
--let's create a couple blocks to play around with
object.block1 = {}
object.block1.body = love.physics.newBody(world, 200, 550, "dynamic")
object.block1.shape = love.physics.newRectangleShape(0, 0, 50, 100)
object.block1.fixture = love.physics.newFixture(object.block1.body, object.block1.shape, 5) -- A higher density gives it more mass.
object.block2 = {}
object.block2.body = love.physics.newBody(world, 200, 400, "dynamic")
object.block2.shape = love.physics.newRectangleShape(0, 0, 100, 50)
object.block2.fixture = love.physics.newFixture(object.block2.body, object.block2.shape, 2)
--set the background color to a nice blue
love.graphics.setBackgroundColor(104, 136, 248)
--set the window dimensions to 650 by 650 with no fullscreen, vsync on, and no antialiasing
love.graphics.setMode(650, 650, false, true, 0)
end
function love.update(dt)
--this puts the world into motion
world:update(dt)
--press the right arrow key to push the ball to the right
if love.keyboard.isDown("right") then
object.ball.body:applyForce(400,0)
elseif love.keyboard.isDown("left") then
object.ball.body:applyForce(-400,0)
--press the up arrow key to set the ball in the air
elseif love.keyboard.isDown("up") then
object.ball.body:setPosition(size/2,size/2)
end
end
function love.draw()
-- set the drawing color to green for the ground
love.graphics.setColor(72, 160, 14)
-- draw a "filled in" polygon using the ground's coordinates
--love.graphics.polygon("fill", object.ground.body:getWorldPoints(object.ground.sharp:getPoints()))
--自己测试polygon的点算法,行Ч?
love.graphics.polygon("fill", 0,650,0,600,650,600,650,650)
love.graphics.setColor(193, 47, 14) --set the drawing color to red for the ball
love.graphics.circle("fill", object.ball.body:getX(), object.ball.body:getY(), object.ball.sharp:getRadius())
love.graphics.setColor(50, 50, 50) -- set the drawing color to grey for the blocks
love.graphics.polygon("fill", object.block1.body:getWorldPoints(object.block1.shape:getPoints()))
love.graphics.polygon("fill", object.block2.body:getWorldPoints(object.block2.shape:getPoints()))
end
function love.keypressed(key)
end
- 画移动球体
- 画球体
- Android OpenGL ES 画球体
- OpenGL---实例 球体 画圆锥
- Three.JS 发光球体,材质纹理,缩放移动动画,教程
- 玻璃球体
- 绘制球体
- 球体问题
- 球体问题
- CSS 球体
- CSS3D--球体
- 发射球体和销毁球体
- 【Matlab微代码】画一个透明的三维球体并在里面显示一个矢量箭头
- Matlab 在同一个坐标系下画颜色不相同的多个球体
- 球体重量测试
- Sphere球体节点
- 2002 计算球体积
- 纹理模拟球体漫反射
- 开启VMlog后,通话无法录音,而普通录音可以。关闭VMlog后,通话正常录音,而普通录音可以。
- 听说谷歌秘密开发Xphone手机
- 学习FFmpeg API – 解码视频
- CString的两种LoadString
- XCode如何设置预编译宏
- 画移动球体
- 查询转换——谓语前推(3)!
- 谈《走出软件作坊》
- Salesmen LA4256 Seoul2008
- 插入排序算法
- hdu 2090
- windows IE 访问linux 下FTP服务
- 怎样招聘程序员
- 关于vs2005、vs2008和vs2010项目互转的总结