Pokemon

Show off your games, demos and other (playable) creations.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Pokemon

Post 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.
User avatar
jradich
Party member
Posts: 100
Joined: Mon Dec 12, 2011 8:44 pm

Re: Pokemon

Post 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...
Losing a friend's trust is the fastest way to lose a friend, forever. FOREVER!
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Pokemon

Post 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
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Pokemon

Post 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...
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Pokemon

Post by coffee »

Roland_Yonaba wrote: Think that should be enough...
Image
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Pokemon

Post by Roland_Yonaba »

@coffee: Oh, come on... I'm not criticizing...
Just want to help ! :P
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Pokemon

Post 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.
User avatar
jradich
Party member
Posts: 100
Joined: Mon Dec 12, 2011 8:44 pm

Re: Pokemon

Post by jradich »

Ahhh Roland! Much credit will go to you in my code.
Losing a friend's trust is the fastest way to lose a friend, forever. FOREVER!
Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests