Git Product home page Git Product logo

naga's Introduction

Naga [WIP]

A framework for Love2D, heavily inspired by DragonRuby.

Features

  • A single tick function that replaces load, update, and draw
  • Live-reload on file save (currently only reloads main.lua)
  • An in-game console that you can use to inspect / manipulate state
  • Configureable resolution with optional pixel-perfect mode
  • Full access to the Love2D engine and it's ecosystem

Installation

To install, run git submodule add https://github.com/rameshvarun/naga.git naga in the same directory as your main.lua.

local naga = require "naga"

Examples

Space Shooter Example

local naga = require "naga" -- Load naga
local vec, color, util = naga.vec, naga.color, naga.util -- Shortcuts

function naga.tick(args)
  color(0, 0, 0.1):clear() -- Background color of game
  naga.music("assets/music.ogg", 0.5) -- Looping background music

  -- Create 50 randomly positioned stars on screen
  local stars = args.state:init("stars", function ()
    return util.map(util.range(50), function ()
      return { pos = vec.random(vec(1280, 720)), depth = love.math.random() }
    end)
  end)

  -- Move stars with wraparound and draw
  for _, star in ipairs(stars) do
    star.pos.y = (star.pos.y + star.depth) % (720 + 24)
    naga.sprite("assets/star.png", star.pos, {
      origin = vec(0.5, 1), color = color(1, 1, 1, star.depth) })
  end

  -- Lasers that move upwards when fired
  local lasers = args.state:get("lasers", {})
  for _, laser in ipairs(lasers) do
    laser:translate(0, -20)
    naga.sprite("assets/laser.png", laser, { origin = vec(0.5, 0.5) })
  end

  -- Create a ship that is moved with the arrow keys
  local ship = args.state:get("ship", vec(1280 / 2, 720 / 2))
  ship:translate(args.keys.arrows * 10) -- Move ship by arrow keys vector
  ship:clamp(vec(0, 0), vec(1280, 720)) -- Clamp ship on screen
  naga.sprite("assets/ship.png", ship, { origin = vec(0.5, 0.5) }) -- Draw ship

  -- Shoot lasers with space.
  if args.keys.pressed.space then
    table.insert(lasers, ship:translated(0, -40))
    naga.sound("assets/laser.ogg")
  end
end

Platformer Example

local naga = require "naga"
local vec = naga.vec

local map = naga.tilemap.parse [[
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000330000000000
00000000000000000000
11111111111111111111
22222222222222222222
22222222222222222222
22222222222222222222
]]

function naga.tick(args)
  -- Draw the background.
  naga.sprite("assets/background.png", vec(0, -250))
  naga.sprite("assets/background.png", vec(1024, -250))

  -- Draw the level.
  naga.tilemap.draw(map, 64, {"assets/grass-top.png", "assets/dirt.png", "assets/block.png"})

  -- Draw the character.
  naga.sprite("assets/character.png", vec(100, 7 * 64 + 16), {origin = vec(0.5, 0.5)})
end

naga's People

Contributors

rameshvarun avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.