PÄSSION: object-oriented LÖVE

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by kikito »

Last night I implemented the first version of stackable states on MiddleClass.

I'm sure it's buggy - haven't done proper testing yet. But if anyone feels adventurous... the new code is on the SVN.

I'll try to do some testing during this week.

I haven't given up on implementing some sort of observation pattern - just putted it on the backburner, the stackable states sounded more fun to program :)

By the way , I accept suggestions on this matter. I'm specially interested on the "registration" interface. This is what I have in mind right now. Please let me know what you guys think - function names, structure, etc.

Code: Select all

Player = passion.actor.subclass('Player')
function Player:startListening()
  self:listen('keypress', 'a', self.goLeft)
  self:listen('keypress', 'd', self.goRight)
  self:listen('mousepress', 'l', self.setTarget)
end
function Player:stopListening()
  self:ignore('keypress', 'a')
  self:ignore('keypress', 'd')
  self:ignore('mousepress', 'l')
end
function Player:goLeft()
  print('left')
end
function Player:goRight()
  print('right')
end
function Player:setTarget(x,y)
  print('My target is :' .. x .. ', ' .. y)
end
Oh and I forgot to answer to this one the other day:
By the way, have you thought about saving&loading, and sending over networks? You want this too to be simple and by storing userdata in the tables, this might not be possible.
I have thought a bit about object serialization, and networking (I consider them two different problems, by the way). But PÄSSION 1.0 will not have them, but they are not discarded from future versions. If they do, serialization will come first, since it seems an order of magnitude easier to implement than networking.
When I write def I mean function.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by bartbes »

kikito wrote: since it seems an order of magnitude easier to implement than networking.
<subliminal>LUBE</subliminal>
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by kikito »

bartbes wrote:<subliminal>LUBE</subliminal>
:D Even with LUBE, it's still going to be an elephant, at least if I'm to implement it properly (preemtion, "local" and "remote" functions and states...)

What about the listen() and ignore() stuff? Do you think it could be simplified more than that, and still be used the same way?
Last edited by bartbes on Mon Feb 15, 2010 8:15 pm, edited 1 time in total.
Reason: LUBE HAS NO UMLAUT!
When I write def I mean function.
blenderer
Prole
Posts: 16
Joined: Fri Feb 12, 2010 1:19 am

Re: PÄSSION: object-oriented LÖVE

Post by blenderer »

Hi Kikito, and thanks for writing an amazing/helpful library. I having a problem with middleclass and I am not understanding why it is happening.

here is my code:

Code: Select all

require 'MiddleClass.lua'

function love.load()
	npc = class("npc")
	function npc:initialize(name)
		self.name = name
	end
	
	boss = class('boss', npc)
	function boss:initialize(name, hp)
		super.initialize(self, name)
		self.hp = hp
	end
	
	bowser = boss:new('Bowser', 799)
	deckard = npc:new('Deckard Cain')

end
 
function love.update(dt)

end
 
function love.draw()
	love.graphics.print("Boss name = " .. bowser.name, 400, 300)
	love.graphics.print("Boss level = " .. bowser.level, 400, 320)
	love.graphics.print("npc name = " .. deckard.name, 400, 340)
end
This is creating an error for me on:

Code: Select all

super.initialize(self, name)
Its probably something very elementary, so thanks in advance for the help.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by kikito »

Hi blenderer,

Just so you know, this forum is for PÄSSION-related stuff. (PÄSSION is a different library built on top of MiddleClass). There's a different post for MiddleClass itself. It would have been "more organized" if you had posted your question there.

I've looked at your code and on a first glance it looks ok (well, you are not respecting the naming conventions ;) but it should work anyway).

Could you tell us the error message you are getting?
When I write def I mean function.
User avatar
Deecodeuh
Citizen
Posts: 70
Joined: Tue Dec 15, 2009 3:18 am
Location: Michigan, USA

Re: PÄSSION: object-oriented LÖVE

Post by Deecodeuh »

Oh man.. :( Looking at this source code.. I can't make sense of any of it. I really need help learning all of this. Where do I start? What do I have to read?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by kikito »

Hi Deecodeuh,

I'll tell you what you can "ignore" first.

It is quite probable that you are not interested in implementing your own way to do classes on Lua, you can safely ignore these two:
  • passion/MiddleClass.lua
  • passion/MindState.lua
It is also quite possible that you don't want to implement your own GUI (windows, buttons), so it is safe for you to ignore everything on the UI directory:
  • passion/gui/*
This will leave a bunch of stuff out of the way.

The graphics directory is where I put drawing-related functions that I find useful - for example, rounded corner rectangles and automatic drawing of shapes. I might add new stuff there today (for creating/drawing quads). For the files on these directories, you should just learn the function names and their parameters; you don't need to browse their code.
  • passion/graphics/*
This leaves you with passion/Core.lua and passion/actors/*. These are the most critical parts in PÄSSION. Again, you should be just fine if you are able to read the method names and parameters; you only need to look at the method code if you are really curious.

Warning - some of the stuff in passion.Core and in actors/* is still changing. Notably, I still haven't made "invisible" and "frozen" actor states, and I have to change the way callbacks (keypress, mousedown, etc) hare handled in passion.Core.

I hope this helps you. If you have specific questions, ask away!
When I write def I mean function.
User avatar
Deecodeuh
Citizen
Posts: 70
Joined: Tue Dec 15, 2009 3:18 am
Location: Michigan, USA

Re: PÄSSION: object-oriented LÖVE

Post by Deecodeuh »

Thank you for your help. :) Late last night, I noticed the wiki entry for MiddleClass, and that helped a lot.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by kikito »

Deecodeuh wrote:Thank you for your help. :) Late last night, I noticed the wiki entry for MiddleClass, and that helped a lot.
There's one for MiddleClass and another one for MindState.

Making a wiki entry for PÄSSION is also on my TO-DO list. But I've got to clear up some areas first, on that same list :)
When I write def I mean function.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: PÄSSION: object-oriented LÖVE

Post by kikito »

PÄSSION 0.6.2rc1 is here!

It has been some time since I did not update this thread. In the meantime, development has continued. You can blame the lack of forum updates on work, holidays, and then this guy and this other guy.

Last time Osuf suggested two improvements: stackable states and an observer pattern. Both are done now.
  • Regarding stackable states, I've even made some documentation about them.
  • I've implemented a little messaging system called Beholder (Observer was too boring). Quick sneak peek:

Code: Select all

MyActor = class('MyActor', passion.Actor)
function MyActor:initialize()
  super.initialize(self)
  self:observe('keypressed_up',    'goUp')
  self:observe('keypressed_down', function(obj) obj.y = obj.y + 1 end)
end
function MyActor:goUp()
  self.y = self.y - 1
end
function MyActor:destroy()
  self:stopObserving('keypressed_up')
  self:stopObserving('keypressed_down')
end
Notice that it is possible to specify either a function or a method name for the callback. The callbacks admit parameters (mousepressed_l will give you the x and y coords, for example)

'keypressed_up' and 'keypressed_down' are events triggered by PÄSSION, but it is possible to trigger them from code by invoking:

Code: Select all

Beholder.trigger('keypressed_up')
It is also possible to create custom messages - for example, on a multiplayer game, one could create an event called 'player_won', passing the winning player as a parameter:

Code: Select all

Player = class('Player') -- Player is a regular class (not an actor)
Player:implements(Beholder) -- This includes "observe" and "stopObserving" on regular classes. passion.Actor includes it by default.
function Player:initialize(name)
  super.initialize(self)
  self.name = name
  self:observe('player_won', 'someoneWon')
end

function Player:someoneWon(someone)
  if(someone==self) then
    print(self.name .. ' : yahooo!')
  else
    print(self.name .. ': buaaaah!')
  end
end

frank = Player:new('frank')
peter = Player:new('peter')
ann = Player:new('ann')

Beholder.trigger('player_won', ann) -- ann will smile, peter and frank will cry
In additon to these changes, I've:
  • Removed the hasBody / hasImage stuff. There's a proper subclass now, called ActorWithBody, that handles actors with bodies. HasImage was too trivial, so I've just scrapped it.
  • I've chanded all passion:methods to passion.methods, so it looks more like love now.
  • I've added utility functions here and there. passion:dumpTable(t) will output the contents of a table on the console. There's also a function for drawing shapes (passion.graphics.drawShape) that it is used by ActorWithBody:drawShapes, a very useful debug function. And there are others, mostly on passion_util.lua.
  • I've re-organized the code in modules: audio, fonts, graphics, gui, oop and timer. Hopefully this will make the library easier to understand on a first glance.
  • By the way, timer functions are the other big addition. Check this out:

Code: Select all

MyActor = class('MyActor', passion.Actor)
function MyActor:initialize()
  super.initialize(self)
  self:after(3, function(obj) print('This will be printed 3 seconds after the object creation') end)
  self:every(4, 'shout', 'wooho!') -- prints 'Periodic call - wooho!' every 4 seconds
  self:every(5, 'shout', 'yeehoo!') -- prints 'Periodic call - yeehoo!' every 5 seconds
end
function MyActor:shout(phrase)
  print('Periodic call - ' .. phrase)
end
The 'after' and 'every' functions allow you to invoke methods (by name) or functions, with optional parameters.

Finally, I've updated all the samples on this thread to the latest version of PÄSSION. I've replaced the old versions on their respective entries, but for comfort I'm also attaching them here (except the piano one, which is too big - you might find it here).

What comes next?
  • Well, I certainly want to include more gui elements.
  • I'm also planning to make an 'interpolator', based on the timer implementation that I've got now. This will allow the creation of "fade in/fade out" effects (like the ones Jasoko and others alked about not long ago) easily, not only on images, but on every lua object (i.e. sounds). I'll be "inspiring myself" on jquery's animate function.
  • I'll try to create a passion.audio.play method that handles the duplication the source automatically so we can hear the same sound more than once.
  • I still have to delucidate a way to handle the new camera-like functions of love properly.
  • And, documentation :). I keep delaying this one, but sooner or later I will have to start writing tutorials about PÄSSION.
  • I'm making a space game that uses all the new stuff. I've got a ship that shoots stuff, with different cannons. I'll publish it once I get it done to the "Asteroids" level.
Sorry for the long post. Comments / Questions are welcomed - and encouraged!
Attachments
p3v2.love
PÄSSION Physics Platformer - Shows input handling
(32.95 KiB) Downloaded 113 times
passionavalanche.love
Avalanche of PÄSSION - Simple physics demo
(39.06 KiB) Downloaded 104 times
pgdv2.love
PÄSSION GUI Demo v2 - Buttons, Pannels and labels
(30.86 KiB) Downloaded 123 times
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest