Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
L÷VE for Lua Game Programming

You're reading from   L÷VE for Lua Game Programming If you want to create 2D games for Windows, Linux, and OS X, this guide to the L?ñVE framework is a must. Written for hobbyists and professionals, it will help you leverage Lua for fast and easy game development.

Arrow left icon
Product type Paperback
Published in Sep 2013
Publisher Packt
ISBN-13 9781782161608
Length 106 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
AKINLAJA DAMILARE JOSHUA AKINLAJA DAMILARE JOSHUA
Author Profile Icon AKINLAJA DAMILARE JOSHUA
AKINLAJA DAMILARE JOSHUA
Arrow right icon
View More author details
Toc

A player character


The player character will be doing simple things such as killing the enemy, jumping, and walking towards the left or right, making it spawn, and also colliding with the platform.

---set the player's collider box left, Right and height spaces

playerCollideboxL = 8

playerCollideboxR = 8

playerCollideboxY = 4

The player spawn function binds the collider with the player's left, right, and height space parameters. Our player is size 32:

function PlayerSpawn(x,y)

   local left = x + playerCollideboxL
   local right = 32 
   local height = 32 - playerCollideboxY
  1. Create a table to hold all the player's necessary properties:

    player = {} 
    player.name="player"
    
    ---player left
    player.l=x
    
    --player bottom space
    
    player.t=y+playerCollideboxY
    
    --player right space
    
    player.w=right
    
    --player height
    player.h=height
    --current layer's velocity (vY) in the Y axis
    player.vY=0
    --player's current direction
    
    player.dir=1
  2. Add player to bump, so the player can collide too:

    bump.add(player)
    
    --where...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime