Anuncios Google

Otra vez, molestando en Lua Dev.(Solucionado)

Bueno, po fín, logre darle limite a mis objetos, logre darles el move que queria, pero, al objeto porteria, quiero que se mueva de arriba hacia abajo y de abajo hacia arriba, el problema esque solo se mueva de arriba hacia abajo, y, ahi se queda :(.

 

Para que me entiendan:

Ahorita con este code, solo baja de arriba abajo, pero yp quiero que cuando baje de arriba a abajo tambien suba y asi todo el juego.

function moveball(ball)
if ball.dir=="r" then 
	ball.x=ball.x+ball.vel
elseif ball.dir=="l" then 
	ball.x=ball.x-ball.vel
elseif ball.dir=="u" then 
	ball.y=ball.y-ball.vel
elseif ball.dir=="d" then 
	ball.y=ball.y+ball.vel
end
if ball.dir=="r" and ball.x>=ball.x2+1 then
	ball.dir="l"
end
if ball.dir=="l" and ball.x<=ball.x1-1 then
	ball.dir="r"
end
if ball.dir=="d" and ball.y>=ball.y2+1 then
	ball.dir="u"
end
if ball.dir=="u" and ball.y<=ball.y1-1 then
	ball.dir="d"
end
end


Anuncios Google

Opciones de visualización de comentarios

Seleccione la forma que prefiera para mostrar los comentarios y haga clic en «Guardar las opciones» para activar los cambios.
Imagen de NauTiluS1

Lee bien lo que te digo

Mira no asignaste un valor en "y" y tampoco en "y2" si tu objeto esta en x y y 0 pues en y2 pon el limite hasta donde quieres que vaya por ejemplo a la 272 osea el final de la pantalla bajara de 0 a 272 entonces cuando baje a 272 subira a 0 y así sucesivamente

porteria = {img = image.load("porterias/porteria1.png"),x1=0,y1=0,x=0,y=0,x2=0,y2=0,dir="d",velocidad=2}

Follow me twitter nautilus1_jmccu!!
Sony, ya a nadie le interesa tus UMD si alguien compra una psp es por nosotros los coders. Madura y has un FW que haga la diferencia y anime a las personas en comprar un PSP

Imagen de barney77

mmm...

mmm... pues ahora he asignado a Y=0 y Y2=272, y sigue igual.

De todos modos ahora pruebo con otra cosas que se me ha ocurrido.

Gracias.

EDITO: Aquí te dejo el code por si lo quieres checar ;).

--Nivel 1
bola1 = {img = image.load("bolas/bola1.png"),x=436,y=136}
porteria = {img = image.load("porterias/porteria1.png"),x1=0,y1=0,x=0,y=0,x2=0,y2=272,dir="d",vel=2}
function mover(porteria)
if porteria.dir=="u" then 
	porteria.y=porteria.y-porteria.vel
elseif porteria.dir=="d" then 
	porteria.y=porteria.y+porteria.vel
end
if porteria.dir=="d" and porteria.y>=porteria.y2+1 then
	porteria.dir="u"
end
if porteria.dir=="u" and porteria.y<=porteria.y1-1 then
	porteria.dir="d"
end
end
 
while true do
controls.read()
porteria.img:blit(porteria.x,porteria.y)
porteria.h=porteria.img:height()
bola1.img:blit(bola1.x,bola1.y)
if controls.up() then
	bola1.y=bola1.y-2
end
if controls.down() then
	bola1.y=bola1.y+2
end
if porteria.x<0 then
	porteria.x=0
elseif porteria.x+80>480 then
	porteria.x=480-80
end
 
if porteria.y<0 then
	porteria.y=0
elseif porteria.y+44>272 then
	porteria.y=272-44
end
if bola1.x<0 then
	bola1.x=0
elseif bola1.x+50>480 then
	bola1.x=480-50
end
 
if bola1.y<0 then
	bola1.y=0
elseif bola1.y+50>272 then
	bola1.y=272-50
end
if controls.press("circle") then 
	causaerror()
end
mover(porteria)
screen.flip()
end

Si se moviera sería raro,

Si se moviera sería raro, pones la x2 y la y2 0.

Imagen de barney77

??

??, pero yo quiero que semueva de arriba abajo y de abajo a aarriba durante todo el tiempo, y, no entiendo para que es la X? si no la voy a usar, y Y2 está en 272.

Prueba mi función, dentro del

Prueba mi función, dentro del while solo pon: mover(porteria)

Imagen de barney77

Eso mismo

Eso mismo hise, mira:

--Nivel 1
bola1 = {img = image.load("bolas/bola1.png"),x=436,y=136}
porteria = {img = image.load("porterias/porteria1.png"),x1=0,y1=0,x=0,y=0,x2=0,y2=272,dir="d",vel=2}
function mover(porteria)
if porteria.dir=="u" then 
	porteria.y=porteria.y-porteria.vel
elseif porteria.dir=="d" then 
	porteria.y=porteria.y+porteria.vel
end
if porteria.dir=="d" and porteria.y>=porteria.y2+1 then
	porteria.dir="u"
end
if porteria.dir=="u" and porteria.y<=porteria.y1-1 then
	porteria.dir="d"
end
end
 
while true do
controls.read()
porteria.img:blit(porteria.x,porteria.y)
porteria.h=porteria.img:height()
bola1.img:blit(bola1.x,bola1.y)
if controls.up() then
	bola1.y=bola1.y-2
end
if controls.down() then
	bola1.y=bola1.y+2
end
if porteria.x<0 then
	porteria.x=0
elseif porteria.x+80>480 then
	porteria.x=480-80
end
 
if porteria.y<0 then
	porteria.y=0
elseif porteria.y+44>272 then
	porteria.y=272-44
end
if bola1.x<0 then
	bola1.x=0
elseif bola1.x+50>480 then
	bola1.x=480-50
end
 
if bola1.y<0 then
	bola1.y=0
elseif bola1.y+50>272 then
	bola1.y=272-50
end
if controls.press("circle") then 
	causaerror()
end
mover(porteria)
screen.flip()
end

Y solo baja y ya no sube. :S

Pruebalo así:   --Nivel

Pruebalo así:

 

--Nivel 1
bola1 = {img = image.load("bolas/bola1.png"),x=436,y=136}
porteria = {img = image.load("porterias/porteria1.png"),x1=0,y1=0,x=0,y=0,x2=0,y2=272,dir="d"}
 
function move(object,vel)
if object.dir=="r" then 
	object.x=object.x+vel
elseif object.dir=="l" then 
	object.x=object.x-vel
elseif object.dir=="u" then 
	object.y=object.y-vel
elseif object.dir=="d" then 
	object.y=object.y+vel
end
if object.dir=="r" and object.x>=object.x2+1 then
	object.dir="l"
end
if object.dir=="l" and object.x<=object.x1-1 then
	object.dir="r"
end
if object.dir=="d" and object.y>=object.y2+1 then
	object.dir="u"
end
if object.dir=="u" and object.y<=object.y1-1 then
	object.dir="d"
end
end
 
while true do
controls.read()
porteria.img:blit(porteria.x,porteria.y)
bola1.img:blit(bola1.x,bola1.y)
 
move(porteria,5)
 
if controls.press("circle") then 
	causaerror()
end
screen.flip()
end

 

Imagen de barney77

Tío !

Tío !, sos un crack, ahora veo porque te llaman Master Xerpi, muchas gracias.

Jeje no es para tanto xD si

Jeje no es para tanto xD si quieres cambiar la velocidad solo cambia el 5 ->move(porteria,5) si quieres que vaya mas lento ponle 2 o 3

Prueba con eso: function

Prueba con eso:

function moveball(ball)
if ball.dir=="r" then 
	ball.x=ball.x+ball.vel
elseif ball.dir=="l" then 
	ball.x=ball.x-ball.vel
elseif ball.dir=="u" then 
	ball.y=ball.y-ball.vel
elseif ball.dir=="d" then 
	ball.y=ball.y+ball.vel
end
if ball.dir=="r" and ball.x>=ball.x2+1 then
	ball.dir="l"
end
if ball.dir=="l" and ball.x<=ball.x1-1 then
	ball.dir="r"
end
if ball.dir=="d" and ball.y>=ball.y2+1 then
	ball.dir="u"
end
if ball.dir=="u" and ball.y<=ball.y1-1 then
	ball.dir="d"
end
end

Imagen de barney77

Ahora

Ahora pruebo.

EDITO: Sigue totalmente igual D:, hise lo que dijo Nau, pues al prinicipio se quedaba estancado en la cordenada 0, pero ahora, hace lo mismo, baja de arriba hacia abajo y ahi se queda D:.

Imagen de Kenta15

OFFTOPIC

Una pregunta tu tienes varios usuarios con barney verdad??

Imagen de barney77

No, solo me cambio el

No, solo me cambio el nombre de vez en cuando.

Opciones de visualización de comentarios

Seleccione la forma que prefiera para mostrar los comentarios y haga clic en «Guardar las opciones» para activar los cambios.