Page 1 of 2

Pokemon

Posted: Fri May 11, 2012 2:19 am
by jradich
Ok so what I decided to make was a very simple version of the Pokemon battle system. There's no AI at the moment, and there is certainly a lot to be implemented, but I think it's a good start. Enjoy!
And excuse inappropriate names.

Re: Pokemon

Posted: Fri May 11, 2012 9:22 am
by Roland_Yonaba
This is definitely not a good start.
I looked at it, and found many code repetitions. That is not how classes work.
Besides, you are using a fairly simple class system.Then take full advantage of it.

Note that yours classes (Twattle and Vagikarp) have exactly the same methods, but you repeated them. I expect when you'll next have to add new species, you will rewrite down the same stuff, and it will result in a extremely long source code.

Why not move all methods (draw, fight, level up, faint) into the basePoke class ? And then instanciate Vagikarp and Twattle ?

Code: Select all

class "BasePoke" {
	hp=100, name="Base",user=true,enemy=false,level=1,attacking=false,attackname='fap'
}
function BasePoke:__init(hp,name,user,enemy,level,attacking,attackname)--Sets how you would name a custom pokemon
  --etc
end


function BasePoke:draw()
  --etc
end
function BasePoke:fight()
  --etc
end

function BasePoke:levelup()
  --etc
end

function BasePoke:faint()
  --etc
end

Vagikarp=BasePoke:new(100,"Vagikarp",true,false,1,false,'fap')
Twattle=BasePoke:new(100,"Twattle",false,true,1,false,'fap')
And that's it. Then you should be able to use Twattle:draw(), Vagikarp:levelup(), etc...the same way than before.
Don't forget to consider that inside methods, you can call other methods, just use self.
Example:

Code: Select all

function BasePoke:fight()
	if fight==true then
        --etc etc
	end
	self:levelup()
	--etc etc
end

Re: Pokemon

Posted: Fri May 11, 2012 10:55 am
by jradich
Roland_Yonaba wrote:This is definitely not a good start.
I looked at it, and found many code repetitions. That is not how classes work.
Besides, you are using a fairly simple class system.Then take full advantage of it.

Note that yours classes (Twattle and Vagikarp) have exactly the same methods, but you repeated them. I expect when you'll next have to add new species, you will rewrite down the same stuff, and it will result in a extremely long source code.

Why not move all methods (draw, fight, level up, faint) into the basePoke class ? And then instanciate Vagikarp and Twattle ?

Code: Select all

class "BasePoke" {
	hp=100, name="Base",user=true,enemy=false,level=1,attacking=false,attackname='fap'
}
function BasePoke:__init(hp,name,user,enemy,level,attacking,attackname)--Sets how you would name a custom pokemon
  --etc
end


function BasePoke:draw()
  --etc
end
function BasePoke:fight()
  --etc
end

function BasePoke:levelup()
  --etc
end

function BasePoke:faint()
  --etc
end

Vagikarp=BasePoke:new(100,"Vagikarp",true,false,1,false,'fap')
Twattle=BasePoke:new(100,"Twattle",false,true,1,false,'fap')
And that's it. Then you should be able to use Twattle:draw(), Vagikarp:levelup(), etc...the same way than before.
Don't forget to consider that inside methods, you can call other methods, just use self.
Example:

Code: Select all

function BasePoke:fight()
	if fight==true then
        --etc etc
	end
	self:levelup()
	--etc etc
end
Thanks
Changed it.
love pokemon.love
(2.5 KiB) Downloaded 398 times

Re: Pokemon

Posted: Sat May 12, 2012 12:41 am
by rokit boy
jradich wrote:
Roland_Yonaba wrote:This is definitely not a good start.
I looked at it, and found many code repetitions. That is not how classes work.
Besides, you are using a fairly simple class system.Then take full advantage of it.

Note that yours classes (Twattle and Vagikarp) have exactly the same methods, but you repeated them. I expect when you'll next have to add new species, you will rewrite down the same stuff, and it will result in a extremely long source code.

Why not move all methods (draw, fight, level up, faint) into the basePoke class ? And then instanciate Vagikarp and Twattle ?

Code: Select all

class "BasePoke" {
	hp=100, name="Base",user=true,enemy=false,level=1,attacking=false,attackname='fap'
}
function BasePoke:__init(hp,name,user,enemy,level,attacking,attackname)--Sets how you would name a custom pokemon
  --etc
end


function BasePoke:draw()
  --etc
end
function BasePoke:fight()
  --etc
end

function BasePoke:levelup()
  --etc
end

function BasePoke:faint()
  --etc
end

Vagikarp=BasePoke:new(100,"Vagikarp",true,false,1,false,'fap')
Twattle=BasePoke:new(100,"Twattle",false,true,1,false,'fap')
And that's it. Then you should be able to use Twattle:draw(), Vagikarp:levelup(), etc...the same way than before.
Don't forget to consider that inside methods, you can call other methods, just use self.
Example:

Code: Select all

function BasePoke:fight()
	if fight==true then
        --etc etc
	end
	self:levelup()
	--etc etc
end
Thanks
Changed it.
love pokemon.love
addthat to SYS post.

Re: Pokemon

Posted: Sat May 12, 2012 12:45 am
by jradich
rokit boy wrote: addthat to SYS post.
Already did.

Re: Pokemon

Posted: Mon May 14, 2012 11:52 am
by misstr87
Some good basic advice there for beginners.
Thanks.

And hope the pokemon project continues :megagrin:

Re: Pokemon

Posted: Wed May 16, 2012 2:00 am
by jradich
love pokemon.zip
(4.78 KiB) Downloaded 324 times
New Update. Pictures are now possible, and there are multiple attacks.

Re: Pokemon

Posted: Wed May 16, 2012 9:12 am
by Roland_Yonaba
I haven't run it yet, I just took a look at the code. Looks nicer than before.

Re: Pokemon

Posted: Wed May 16, 2012 11:44 pm
by jradich
Roland_Yonaba wrote:I haven't run it yet, I just took a look at the code. Looks nicer than before.
Thanks.
Oh and also, making pokemon is incredibly easy. Just write:

Code: Select all

YourPoke=BasePoke:new(hp,name,user,enemy,level,attackname1,attackname2,pic)

And call "YourPoke:fight()" and "YourPoke:draw()" in the proper functions. Remember, though, there are only two attacks, though new attacks are easy, too.

Re: Pokemon

Posted: Mon May 21, 2012 11:40 pm
by jradich
love pokemon.love
(20.17 KiB) Downloaded 573 times
Shameless bump, because of progress.