Skip to content

Instantly share code, notes, and snippets.

@videlais
Last active April 10, 2018 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save videlais/090658b4d8bf13694658ddd01c182df2 to your computer and use it in GitHub Desktop.
Save videlais/090658b4d8bf13694658ddd01c182df2 to your computer and use it in GitHub Desktop.
Updated player.lua with physics
-- Create a player table
player = {}
-- Create a width (for later drawing)
player.width = 20
-- Create a height (for later drawing)
player.height = 20
-- Create a new physics body in the world and make it "dynamic"
-- The new coordinates will be where the 'body' is going forward.
-- Any time (like for drawing) the x,y is needed use getX() and getY()
player.body = love.physics.newBody( world, 100, 100, "dynamic" )
-- Make a rectangle shape with:
-- Starting at 100, 100 (player.body:getX() and player.body:getY() )
-- a width of player.width
-- a height of player.height
player.shape = love.physics.newRectangleShape(player.body:getX(), player.body:getY(), player.width, player.height)
-- Attach the shape to the body
player.fixture = love.physics.newFixture(player.body, player.shape, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment