Page 1 of 2
Multiple Charecters
Posted: Mon Feb 09, 2015 12:23 am
by pactace
I've looked around the forums hoping to find some answer to this question before I asked. I am trying to make a platformer with 4 alternate charecters with different stats such as speed and jump hieght. I need them two cicle at the press of a button do I make each of them a new set of of statistics such as
Code: Select all
player = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -700,
speed = 450,
flySpeed = 700,
state = "",
h = 32,
w = 32,
standing = false,
}
or can I do something less tedious
Re: Multiple Charecters
Posted: Mon Feb 09, 2015 4:46 am
by zorg
Literally just missed it:
viewtopic.php?f=4&t=2490
*unless you were asking about whether you really need to define each character's stats, which in my opinion would be a yes
Re: Multiple Charecters
Posted: Mon Feb 09, 2015 11:04 am
by s-ol
I cant imagine a different way of having different stats than having different stats, so I guess you'll need different stats
You could do this though:
Code: Select all
player = {
index = 1, -- index of currently selected player
x = 256, -- shared between chars
y = 127,
xvel=0,yvel=0,
jumpheight = {10, 64, -2, 19},
vel_multiplier= {1,1,1,4}
}
And then index those values that differ with player.index ofc.
Re: Multiple Charecters
Posted: Mon Feb 09, 2015 10:24 pm
by pactace
zorg wrote:Literally just missed it:
viewtopic.php?f=4&t=2490
*unless you were asking about whether you really need to define each character's stats, which in my opinion would be a yes
actually I did see that and I tried it in my game it didnt really work
Re: Multiple Charecters
Posted: Mon Feb 09, 2015 10:30 pm
by pactace
Sorry wasnt being very specific now that I know that Im going to need to make new stats and such (thank you by the way) How to I make it so when I press a button such as 1 I'll get player 1 and if I press 2 I'll get player two
Re: Multiple Charecters
Posted: Tue Feb 10, 2015 3:42 am
by pactace
Here a hypothisis but maybe this would work
Code: Select all
characters = {
player1
player2
player3
player4
}
player1 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player2 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player3 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player4 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
characters = Player
end
function love.keypressed(k)
if k == 1 then player = player1
elseif k == 2 then player = player2
elseif k == 3 then player = player3
elseif k == 4 then player = player4
end
end
thats just my guess
Re: Multiple Charecters
Posted: Tue Feb 10, 2015 8:18 am
by s-ol
pactace wrote:Here a hypothisis but maybe this would work
Code: Select all
characters = {
player1
player2
player3
player4
}
player1 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player2 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player3 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player4 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
characters = Player
end
function love.keypressed(k)
if k == 1 then player = player1
elseif k == 2 then player = player2
elseif k == 3 then player = player3
elseif k == 4 then player = player4
end
end
thats just my guess
That would almost work but doesnt make sense. You reassign The variable player and lose the list of players (that doesnt even work because they arent defined yet anyway)
Re: Multiple Charecters
Posted: Tue Feb 10, 2015 2:20 pm
by pactace
Can you improve the code cause I have no Idea what you just said
Re: Multiple Charecters
Posted: Tue Feb 10, 2015 3:00 pm
by s-ol
pactace wrote:Can you improve the code cause I have no Idea what you just said
I could but I won't. If I just give you working code you will never improve and come back with the next question in 5 minutes. You will need to learn and understand on your own, and it seems you have a lot of Lua and programming in general to learn.
I don't know if you have or not, but you should read programming in Lua (again) and then start with something smaller maybe.
And also: why ask "would this work?" You have a computer, go see for yourself.
Re: Multiple Charecters
Posted: Tue Feb 10, 2015 11:03 pm
by pactace
So something like this
Code: Select all
player1 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player2 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player3 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
player4 = {
x = 256,
y = 256,
x_vel = 0,
y_vel = 0,
jump_vel = -4000,
speed = 400,
flySpeed = 859,
state = "",
h = 55,
w = 45,
standing = false,
}
Player = player1
end
function love.keypressed(k)
if k == 1 then player = player1
elseif k == 2 then player = player2
elseif k == 3 then player = player3
elseif k == 4 then player = player4
end
end