Getting a feel for different notation

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
OttoRobba
Party member
Posts: 104
Joined: Mon Jan 06, 2014 5:02 am
Location: Sao Paulo, Brazil

Getting a feel for different notation

Post by OttoRobba »

Hey fellas.

Testing out APIs and different notations - It got me thinking on how others see the situation and what is easier/more accessible.

Currently, in order to draw a circle and animate it's X property, this is what we do in LÖVE:

Code: Select all

local x = 100

love.draw = function()
  love.graphics.circle("fill", x, 200, 40)
end

love.update = function(dt)
  x = x+100*dt
end
It is simple and it works fine - but what if we tried something more "flixel-like" and have everything as objects?

Code: Select all

--below is the function that creates circles in the "new" notation, just to show how it works
newCircle = function(t)
  self = {}
  self.x = t.x or 0
  self.y = t.y or 0
  self.radius = t.radius or 0
  self[1] = t[1] or "fill"
  self.draw = function()
    love.graphics.circle(self[1], self.x, self.y, self.radius)
  end
  return self
end

--Creating our circle
ball = newCircle{x=100, y = 200, radius = 40, "fill"}

love.draw = function()
  --draw it!
  ball.draw()
end

love.update = function(dt)
  ball.x = ball.x+100*dt
end
To me, this feels great because I don't need to declare many variables beforehand - they are there by default.

How do you feel about this?

What would your ideal system be?



PS: Just for fun, how it would look in Moonscript:

Code: Select all

newCircle = (t) ->
	@ = {}
	@x = t.x or 0
	@y = t.y or 0
	@radius = t.radius or 0
	@draw = ->
		love.graphics.rectangle("fill", @x, @y, @radius)
	return @

ball = newCircle{x=:100, y:200,radius:40}

love.draw = ->
	ball.draw!

love.update = (dt) ->
	ball.x += 100*dt
PPS: I'm not proposing this as the new LÖVE default, merely brainstorming.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests