Anuncios Google

[LUA]Game Attack?

Hey  guys,

i managed to make an MENu,and Pausa Function and a Spirit which i can move in LUA(I use 16 Pictures to make the animations,4 right,4left,4attack right,4 attack left),but i cant make my 2D Player(Spirit) attack.......could someone give me an example script to make my Spirits move left and right AND attack left or right if pad:cross an direction == right/left? Couse i could make my Spirit move left and right(with Timer) but i cant make him Attack(got problems with the direction and the Attack animation....)so can someone post a exemple script or tell me how to do it ????

 

P.S. Im from Germany,so excuse my English and please answer in English oder German....

 

Thanks :DD


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.

Thanks

Thats what i wanna know!

Thanks for the help,now i got an Idea how to make it write,so thank you very much :D!

Hey:D

Hey,thanks for the help i understood what you wanted to teach me(like 70%),but i got an questions!

Here is my code:

Bild4 = Image.load("back/01.png")

font = Font.load("Geek a byte 2.ttf")
font:setPixelSizes(30,35)

red = Color.new(255,0,0)
light_blue = Color.new(0,180,255)
weiss = Color.new(255,255,255)

-- Player image
left = Image.load("sora/i1.png")
left2 = Image.load("sora/i2.png")
left3 = Image.load("sora/i3.png")
left4 = Image.load("sora/i4.png")

right = Image.load("sora/d1.png")
right2 = Image.load("sora/d2.png")
right3 = Image.load("sora/d3.png")
right4 = Image.load("sora/d4.png")

standright = Image.load("sora/s.png")

atkl = Image.load("sora/f.png")
atkl2 = Image.load("sora/f2.png")
atkl3 = Image.load("sora/f3.png")
atkl4 = Image.load("sora/f4.png")

atkr = Image.load("sora/a.png")
atkr2 = Image.load("sora/a2.png")
atkr3 = Image.load("sora/a3.png")
atkr4 = Image.load("sora/a4.png")

player = {}
player.x = 20
player.y = 200
player.img = standright
player.life = 100
playerdamage = 5
pright = 0
pleft  = 0

pause = 0
Wahl = 1
player.richtung = right

function mov()
if pad:right() and player.x > 1  and pause == 0 then
player.x = player.x +2
pright = pright + 1
end
 
if pad:left() and player.x > 440  and pause == 0 then
player.x = player.x -2
pleft = pleft + 1
end

function right()
if pright >= 0 and pright < 10 and pad:right() then
sprite = right
end
if pright >= 10 and pright < 20 and pad:right() then
sprite = right2
end
if pright >= 20 and pright < 30 and pad:right() then
sprite = right3
end
if pright >= 30 and pright < 40 and pad:right() then
sprite = right4
end
if pright >= 40 then
pright = 0
end
end

function left()
if pleft >= 0 and pleft < 10 and pad:left() then
sprite = left
end
if pleft >= 10 and pleft < 20 and pad:left() then
sprite = left
end
if pleft >= 20 and pleft < 30 and pad:left() then
sprite = left
end
if pleft >= 30 and pleft < 40 and pad:left() then
sprite = left
end
if pleft >= 40 then
pleft = 0
end
end

while true do  ----MAIN LOOP----
oldx = player.x
oldy = player.y

pad = Controls.read()
screen:clear()
screen:blit(0,0,Bild4,true)
screen:blit(player.x, player.y, player.img)

mov()
right()
left()

if pad:select() and oldpad:select() ~= pad:select() and pause == 1 then
pause = 0
end
if pad:start() and oldpad:start() ~= pad:start() and pause == 0 then
pause = 1
end

if pause == 1 then
screen:fillRect(184,64,190,150,light_blue)
screen:fontPrint(font,214,94,"PAUSE",red)
end

if Wahl == 1 and pause == 1 then
screen:fontPrint(font,199,124,"Weiter",red)
screen:fontPrint(font,199,154,"Hilfe",weiss)
screen:fontPrint(font,199,184,"Hauptmenue",weiss)
end
if Wahl == 2 and pause == 1 then
screen:fontPrint(font,199,124,"Weiter",weiss)
screen:fontPrint(font,199,154,"Hilfe",red)
screen:fontPrint(font,199,184,"Hauptmenue",weiss)
end
if Wahl == 3 and pause == 1 then
screen:fontPrint(font,199,124,"Weiter",weiss)
screen:fontPrint(font,199,154,"Hilfe",weiss)
screen:fontPrint(font,199,184,"Hauptmenue",red)
end

if pad:up() and oldpad:up() ~= pad:up() and pause == 1 and Wahl == 1 then
Wahl = 3
elseif pad:up() and oldpad:up() ~= pad:up() and pause == 1 and Wahl == 2 then
Wahl = 1
elseif pad:up() and oldpad:up() ~= pad:up() and pause == 1 and Wahl == 3 then
Wahl = 2
end

if pad:down() and oldpad:down() ~= pad:down() and pause == 1 and Wahl == 1 then
Wahl = 2
elseif pad:down() and oldpad:down() ~= pad:down() and pause == 1 and Wahl == 2 then
Wahl = 3
elseif pad:down() and oldpad:down() ~= pad:down() and pause == 1 and Wahl == 3 then
Wahl = 1
end

if pad:circle() and oldpad:circle() ~= pad:circle() or pad:cross() and oldpad:cross() ~= pad:cross() and pause == 1 and Wahl == 1 then
pause = 0
end
if pad:cross() and oldpad:cross() ~= pad:cross() and pause == 1 and Wahl == 2 then
dofile("hilfe.lua")
end
if pad:cross() and oldpad:cross() ~= pad:cross() and pause == 1 and Wahl == 3 then
dofile("script2.lua")
end

screen.flip()
oldpad = pad
screen.waitVblankStart()
end

 

I can move my Player in both direction...but i dont know how to make a attack function for those directions----thats my questions,how does a attack function looks(with 4 PICS) and how do i manage,that if my player looks left he attacks left and if he look right he attack right....how do i do tihis?

Imagen de DeViaNTe

-- try to avoid dofile's.

-- try to avoid dofile's. they're dangerous.

anywhere in your code, that appears something like: player.img = [image];
add that: player.textimage = "image";

And player.img will be for blitting, and player.textimage for kwnowing the direction.

Attack:
  if player.textimage == "left" then player.img = attckleft; player.textimage = "attackleft"; end

 do the same thing you did for the walking animation, but for attack animation.

 if trying to move, but animation is attacksomething, prevent moving.
 once attacksomething finishes, reset the sprite image to standdirection, and player re-gains controls of player.


Actualmente desarrollando nuestra web y UXCode : http://www.gcrew.es

Imagen de DeViaNTe

hello!

Glad to see people from other countries as well!

Well, you already have 16 pictures, 4+4+4+4, to make the animations. Let's prepare a new object, containing your spirit!

spirit = {
   name = "Myname",
   years = 20,
   exp = 1200,
   level = 20,
   attack = 20,
   stamina = 50,
   sprites = { 
     attack = { 
           image.load("attack1.png"),
           image.load("attack2.png"),
           image.load("attack3.png"),
           image.load("attack4.png")
     },
     moveleft = {
           image.load("left1.png"),
           image.load("left2.png"),
           image.load("left3.png"),
           image.load("lef4.png")
    },
    stayfront = {
         image.load("stayfront.png"),
    }
  },
  currentanimation = "stay",
  currentdirection = "front"
}

As you can see, the "object" is a table, containing various info about the player, and a field called sprites, that have subfields like "moveleft", "moveright". That "sprites" subfield contains the images of the movements, and they will be accessible thanks to two other fields, currentanimation + currentdirection.
To grab the current image in that range, we will use currentframe.
The range of images will be 1 <= current <= duration[anim].

Then, we need one function, that receives an animation, one direction, plus X and Y values to blit our player. Let's rock:

function blitplayer(x,y,anim,dir)
   if ( spirit.currentanimation ~= anim ) then
      spirit.currentanimation = anim;
      spirit.currentframe = 1;
      spirit.currentwait = 10;
   end
   if (
 spirit.currentdirection ~= dir ) then
       
spirit.currentdirection = dir;
      spirit.currentframe = 1;
      spirit.currentwait = 10;
  end

  local image_to_blit;

  image_to_blit = spirit.sprites[spirit.currentanimation..spirit.currentdirection][spirit.currentframe];
  -- image_to_blit, now contains the image WE WANT.

  spirit.currentwait = spirit.currentwait - spirit.currentspeed;
  if (spirit.currentwait < 0) then
     spirit.currentframe = spirit.currentframe + 1;
     if ( spirit.currentframe > #spirit.sprites[spirit.currentanimation..spirit.currentdirection] ) then
       spirit.currentframe = 1;
     end
     spirit.currentwait = 10;
  end
  
  -- Here goes your blitimage function, you blit image_to_blit in x and y.
end

 

With this function, you will blit the player, in the animation you decided, and the direction you decided. (Beware), the tables anim..direction must exist! So prepare all attack directions, and all move directions before using them.

spirit.currentspeed not involves the player movement, it is the frame change speed. If your player seems to be walking too slow, increase that speed.

--example of use:
x = 240;
y = 136;
dir = "down";
anim = "stay";
while true do
   -- pad:read..
   anim = "stay".
   if left then anim = "move"; dir = "left"; x = x -1; y = y; end
   if right then anim = "move"; dir = "right"; x = x + 1; y = y; end
   --... other directions.

   if cross then anim = "attack"; dir = dir; x=x; y=y; end
  --... other ... anims?
   
  -- and finally:
  blitsprite(anim,dir,x,y);
  screenflip()

end

Any question, just post!
   - DeV


Actualmente desarrollando nuestra web y UXCode : http://www.gcrew.es

????

If its a lot easier could you tell me what i should do to make my Spirit move left right AND attack left right?

Cant anyone help me?

Cant anyone help me?

hmmm

If saw this before,but its not for a 2D Game in TEKKEN Style.......

Imagen de Kenta15

Well thats a lot easier

Well thats a lot easier

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.