[Lope2D] Tutorial 0 - Introduction

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
ilgamer
Prole
Posts: 10
Joined: Fri Apr 12, 2013 5:55 am

[Lope2D] Tutorial 0 - Introduction

Post by ilgamer »

I am starting a series of tutorials of using Lope2D - a library which facilitate work with physical bodies in Love2D.

What is Lope2D?
Lope2D (Love2D Physics Engine) - Library (set of functions and other stuff) that makes it easier to work with physical bodies. It also makes your code much more clean.

Why Lope2D can be useful if I develop a game with gameplay based on physics.
To add one physical body in the game (using standard set of functions of Love2D), you would have to write 7-8 lines, and if needed to draw a sprite (plus one line):

Code: Select all

function love.load()
world = love.physics.newWorld(320,0,true)
love.physics.setMeter(32)

object = {}
object.image = love.graphics.newImage(“object.png”)
object.shape = love.physics.newRectangleShape(50, 50)
object.body = love.physics.newBody(world, 100, 100, “dynamic”)
object.fixture = love.physics.newFixture(object.body, object.shape, 100)
end

function love.update(dt)
world:update(dt)
end

function love.load()
love.graphics.draw(object.image, object.body:getX(), object.body:getY(), object.body:getAngle(), 1, 1, object.image:getWidth()/2, object.image:getHeight()/2)
end
First, you need to create the world, then the figure of the body. Connect them together using the fixture. Many activities have to make in order to add body, right?

To add the same dynamic body using Lope2D, you will need make like this:

Code: Select all

function love.load()
image_object = love.graphics.newImage("object.png")

object = lope_newDynamic(100, 100, "rectangle", 50, 50)
lope_setImage(object, image_object)
end

function love.update(dt)
lope_update(dt)
end

function love.draw()
lope_drawWorld()
end
You can see the difference. To add a body you don't need to create a world because it is created on the start of the game. We also used only one function rather three to add the body.

More details about adding physical bodies you will learn in the next tutorials.

How can I get it? How can I get started using Lope2D?

To use Lope2D, you need to download two files:
lope_core.lua
lope_graphics.lua


http://bitbucket.org/erlimoen/lope2d/src

After that you need to put them in the one folder with your "main.lua" file and add this code in its beginning:

Code: Select all

require "lope_core"
And that's it! You can make whatever you want.
Other tutorials soon...
Post Reply

Who is online

Users browsing this forum: slime and 7 guests