Page 2 of 2

Re: Pokemon

Posted: Tue May 22, 2012 8:45 am
by Roland_Yonaba

Code: Select all

function love.draw()--Draws the pokemon
	--
   Vagikarp:draw()
   Fapdos:draw()
   Bitchachu:draw()
   Thunderfapper:draw()
   Maurice:draw()
   Kyle:draw()
   Twattle:draw()
   Trosh:draw()
   Saso:draw()
   Lawnboy:draw()
   Fluttershy:draw()
   Pinkie:draw()
   Rainbow:draw()
   Luna:draw()
end
That's redundancy.
You can simply register all species created within your Base in a specific field, and attach some custom draw(), update() methods to it.
Then call that Base in the 'main.lua' and use these methods inside löve update, draw, ... callbacks.

Re: Pokemon

Posted: Tue May 22, 2012 8:42 pm
by jradich
Roland_Yonaba wrote: That's redundancy.
You can simply register all species created within your Base in a specific field, and attach some custom draw(), update() methods to it.
Then call that Base in the 'main.lua' and use these methods inside löve update, draw, ... callbacks.
I'm not quite sure how this could be done...

Re: Pokemon

Posted: Wed May 23, 2012 8:10 am
by Roland_Yonaba
Fairly simple. Inside your PokeBase file definition, you can store each new species created within a local table, or the Base class itself.

Code: Select all

class "BasePoke" {...} -- Class definition
BasePoke.species = {} -- new field to keep track of all species created

local function register(...)
 for k,poke in ipairs(arg) do table.insert(BasePoke.species,poke) end
end

function BasePoke:update()
   for k,poke in ipairs(self.species) do poke:update() end
end

function BasePoke:draw() -- Goes the same way  end

-- Rest of BasePoke class definition

-- Creates an register all species
Vagikarp = BasePoke:new(...)
Twattle = BasePoke:new(...)
Fapdos = BasePoke:new(...)
...
register(Vagikarp, Twattle, Fapdos...)
Then inside the main file:

Code: Select all

function love.update()
BasePoke:update() -- will iterate over the collection BasePoke.species and update each one
end

function love.load()
BasePoke:draw() -- will iterate over the collection BasePoke.species and update each one
end

...etc
Note that to make it more elegant, you can tweak BasePoke.__init function, so that it will register the new entity autmatically.
The local register function will not be needed anymore. Not tested, but should work.

Code: Select all

function BasePoke:__init(...)
-- same as before
table.insert(BasePoke.species,self)
end

Re: Pokemon

Posted: Tue May 29, 2012 11:04 am
by Roland_Yonaba
Hi,
As a response to thispost...
Lots of things need to be improved, in terms of coding style, using tricks you can reuse next.

About 'battle.lua'

I won't discuss how you implemented it, indeed you might agree the code inside battle:update() in quite redundant...
Why not store all the possible actions inside a local table,indexing them with their proper name, and pairing them with a cost representing the attack value ?

Code: Select all

local allAttacks  = { ['shout'] = 35, ['flutter'] = 20, ['kick'] = 25,...}
function battle:update(dt)
...
   for attackName,cost in ipairs(allAttacks) do
       user.attack[n] = (user.attackname[n]==attackName and cost)
       ennemy.attack[p] = (ennemy.attackname[p]==attackName and cost)
   end
...
end

About item.lua
I am pretty sure that your items list will grow... To easily loop through the item collection (for updating, or any purpose,...) maybe you might to consider using the same technique you used to iterate through your list of pokemon species ( record each new initiated from the "item" class in a local register)

About player.lua
Actually, why not making this a regular class ? I was expecting that, but you may have your own reasons. Just an idea.

About pokemon.lua
I do know if you have experience some running speed issues, but if so, you might want to consider avoiding making useless checks each loop inside your functions.
- Inside BasePoke:draw(), why checking each loop if pics exists ? Maybe check this once, on game start.
- Still inside BasePoke:draw(), when nesting love.graphics.newImage with love.graphics.draw, you create a new image every frame...This is kinda ugly...Just create all images you need on game start,assert them to variables then pass them to love.graphics.draw.
- Inside BasePoke:update(), the way you set levels is...redundant. Convert the string lvel to a number, that should do the same:

Code: Select all

self.level = tonumber(level)
Think that should be enough...

Re: Pokemon

Posted: Tue May 29, 2012 12:58 pm
by coffee
Roland_Yonaba wrote: Think that should be enough...
Image

Re: Pokemon

Posted: Tue May 29, 2012 2:14 pm
by Roland_Yonaba
@coffee: Oh, come on... I'm not criticizing...
Just want to help ! :P

Re: Pokemon

Posted: Tue May 29, 2012 3:45 pm
by coffee
Roland_Yonaba wrote:@coffee: Oh, come on... I'm not criticizing...
Just want to help ! :P
Yeah, I know and you do well. Checking his code I agree that several things need to be improved. However my humorous touch was just to point how jradich should be feeling after read all your remarks. But he will for sure be happy again after done some refactoring.

Re: Pokemon

Posted: Tue May 29, 2012 9:10 pm
by jradich
Ahhh Roland! Much credit will go to you in my code.