如何在Lua中使对象从上到下移动?

如何在Lua中使对象从上到下移动?,lua,position,drawing,Lua,Position,Drawing,在我正在做的一个游戏中,有一个正方形,游戏在里面进行。我希望生成的圆从顶部开始向下移动到底部。在原始程序中,它们从左向右移动。我该怎么办?我不知道如何让它从顶部开始向下移动,而不是从左侧开始向右移动 这是原始代码(我知道太多了,对不起)。我想帮助一个朋友 --Made by Joms or /u/jomy582 --Please credit me if using this in a battle. spawntimer = 0 timerspawn = 0 storedtime = Tim

在我正在做的一个游戏中,有一个正方形,游戏在里面进行。我希望生成的圆从顶部开始向下移动到底部。在原始程序中,它们从左向右移动。我该怎么办?我不知道如何让它从顶部开始向下移动,而不是从左侧开始向右移动

这是原始代码(我知道太多了,对不起)。我想帮助一个朋友

--Made by Joms or /u/jomy582
--Please credit me if using this in a battle.

spawntimer = 0
timerspawn = 0
storedtime = Time.time

bullets = {}
bulletsbig = {}
bulletswarn = {}
dir = 1
bigheight = {33, 98}

function Update()
  spawntimer = spawntimer + (Time.dt*Time.mult)
  timerspawn = timerspawn + (Time.dt*Time.mult)

  --normal bullets
  --change the number in the if statement to make them spawn more frequently/less frequently
  --EX: spawntimer > 0.2 spawns them pretty fast
  --EX2: spawntimer > 1 spawns them pretty slow
  --Make sure to change the subtraction method in the if statement
  if spawntimer > 0.16 then
    spawntimer = spawntimer-0.16
    local bullet = CreateProjectile("bullet", -Arena.width/2, math.random(-Arena.height/2, Arena.height/2))
    bullet.SetVar("deadly", true)
    table.insert(bullets, bullet)
  end

  --warning. spawns a warning every 5 seconds
  --You could change it, but that may cause some bugs
  if timerspawn > 2.2 then
    timerspawn = timerspawn-2.2
    dir = math.random(1,2)
    local bulletwarn = CreateProjectile("warning", 0, Arena.height/2 - bigheight[dir])
    bulletwarn.SetVar("warningtimer", 0)
    bulletwarn.SetVar("soundtimer", 0)
    bulletwarn.SetVar("animtimer", 0)
    bulletwarn.SetVar("anim", 1)
    table.insert(bulletswarn, bulletwarn)
  end

  --controlling normal bullets
  --a simple method that moves the bullets 1 pixel each frame
  --you can change it by editing the bullet.move
  --EX: bullet.Move(5*Time.mult, 0) moves the bullets 5 pixels each frame
  for i=1, #bullets do
    local bullet = bullets[i]
    if bullet.isactive then
      bullet.Move(2*Time.mult, 0)
      if bullet.y > -Arena.height/2 then
        bullet.Remove()
      end
    end
  end

  --controlling warning timer
  --a method that controls the warning timer
  for i=1, #bulletswarn do
    local bullet = bulletswarn[i]
    if bullet.isactive then
      local warningtimer = bullet.GetVar("warningtimer") + (Time.mult*Time.dt)
      local soundtimer = bullet.GetVar("soundtimer") + (Time.mult*Time.dt)
      local animtimer = bullet.GetVar("animtimer") + (Time.mult*Time.dt)
      local bulletSprite = bullet.sprite
      local anim = bullet.GetVar("anim")

      --flashing colors
      --change the animtimer > TIME where time is how often you want the warning to blink
      --warnings last for 3 seconds. Can change that as well
      --to get different colors, find the rgb value of the color you want and insert them below
      if animtimer > 0.08 then
        animtimer = animtimer-0.08
        if anim == 1 then
          local r = 0 --put Red value here
          local g = 0 --put Green value here
          local b = 169 --put Blue value here
          bulletSprite.color = {r/255, g/255, b/255} -- changes the color to whatever you'd like. Uses RGB.
          bullet.SetVar("anim", 2)
        elseif anim == 2 then
          local r = 0 --put Red value here
          local g = 0 --put Green value here
          local b = 255 --put Blue value here
          bulletSprite.color = {r/255, g/255, b/255} -- changes the color to whatever you'd like. Uses RGB.
          bullet.SetVar("anim", 1)
        end
      end

      --plays a timer evert 10 frames for 3 seconds.
      --change the soundname to change the sound
      --change the soundtimer > 0.16 to change how often it plays
      --can change how long it lasts as well by changing the less than statement
      if soundtimer > 0.10 then
        soundtimer = soundtimer-0.10
        Audio.PlaySound("alarm")
      end

      --this controls when to spawn the bullets
      --change the statement to change how long the warning timer is
      if warningtimer > 2 then
        warningtimer = warningtimer-2
        Audio.PlaySound("shoot")
        local bullet1 = CreateProjectile("leftbigbullet", Arena.width/2+30, Arena.height/2 - bigheight[dir]) --where to spawn them
        bullet1.SetVar("speed", -4) --how fast
        bullet1.SetVar("deadly", true)
        local bullet2 = CreateProjectile("rightbigbullet", -Arena.width/2-30, Arena.height/2 - bigheight[dir]) --where to spawn them
        bullet2.SetVar("speed", 4) --how fast
        bullet2.SetVar("deadly", true)
        table.insert(bulletsbig, bullet1)
        table.insert(bulletsbig, bullet2)
        bullet.Remove()
      end

      bullet.SetVar("warningtimer", warningtimer)
      bullet.SetVar("animtimer", animtimer)
      bullet.SetVar("soundtimer", soundtimer)
    end
  end

  --controlling big bullets
  --this method controls the big bullets
  for i=1, #bulletsbig do
    local bullet = bulletsbig[i]
    if bullet.isactive then
      local speed = bullet.GetVar("speed")
      bullet.SendToBottom()
      bullet.Move(speed*Time.mult, 0)
      if bullet.absx > 700 or bullet.absx < -70 then
        bullet.Remove()
      end
    end
  end

end

function OnHit(bullet)
    if(bullet.getVar("deadly")) then
    Player.Hurt(3)
    end
end
——由Joms或/u/jomy582制作
--如果在战斗中使用这个,请相信我。
产卵计时器=0
timerspawn=0
storedtime=Time.Time
子弹={}
bulletsbig={}
bulletswarn={}
dir=1
bigheight={33,98}
函数更新()
spawntimer=spawntimer+(Time.dt*Time.mult)
timerspawn=timerspawn+(Time.dt*Time.mult)
--普通子弹
--更改if语句中的数字,使它们生成的频率更高/更低
--EX:spawntimer>0.2生成它们的速度非常快
--EX2:spawntimer>1生成它们的速度非常慢
--确保更改if语句中的减法方法
如果spawntimer>0.16,则
spawntimer=spawntimer-0.16
本地bullet=CreateSproject(“bullet”,-Arena.width/2,数学随机(-Arena.height/2,Arena.height/2))
bullet.SetVar(“致命”,正确)
表.插入(项目符号,项目符号)
结束
--警告。每5秒产生一个警告
--您可以更改它,但这可能会导致一些错误
如果timerspawn>2.2,则
timerspawn=timerspawn-2.2
dir=数学随机(1,2)
本地bulletwarn=CreateSprojects(“警告”,0,Arena.height/2-bighight[dir])
bulletwarn.SetVar(“warningtimer”,0)
bulletwarn.SetVar(“声音计时器”,0)
bulletwarn.SetVar(“animtimer”,0)
bulletwarn.SetVar(“动画”,1)
表.插入(bulletswarn、bulletswarn)
结束
--控制普通子弹
--一种简单的方法,每帧将项目符号移动1个像素
--您可以通过编辑bullet.move来更改它
--例如:bullet.Move(5*Time.mult,0)将项目符号每帧移动5个像素
对于i=1,#子弹可以
局部项目符号=项目符号[i]
如果bullet.i是活动的,那么
子弹移动(2*Time.mult,0)
如果bullet.y>-Arena.height/2,则
bullet.Remove()
结束
结束
结束
--控制报警定时器
--控制警告计时器的方法
当i=1时,#bulletswarn do
局部项目符号=项目符号[i]
如果bullet.i是活动的,那么
本地warningtimer=bullet.GetVar(“warningtimer”)+(Time.mult*Time.dt)
本地soundtimer=bullet.GetVar(“soundtimer”)+(Time.mult*Time.dt)
本地animtimer=bullet.GetVar(“animtimer”)+(Time.mult*Time.dt)
本地bulletSprite=bullet.sprite
本地动画=bullet.GetVar(“动画”)
--闪烁的颜色
--更改animtimer>TIME,其中TIME是您希望警告闪烁的频率
--警告持续3秒钟。也可以改变这一点
--要获得不同的颜色,请找到所需颜色的rgb值并将其插入下面
如果animtimer>0.08,则
animtimer=animtimer-0.08
如果anim==1,则
本地r=0——将红色值放在这里
本地g=0——将绿色值放在这里
本地b=169——将蓝色值放在这里
bulletSprite.color={r/255,g/255,b/255}——将颜色更改为您想要的任何颜色。使用RGB。
bullet.SetVar(“动画”,2)
elseif anim==2然后
本地r=0——将红色值放在这里
本地g=0——将绿色值放在这里
本地b=255——将蓝色值放在此处
bulletSprite.color={r/255,g/255,b/255}——将颜色更改为您想要的任何颜色。使用RGB。
bullet.SetVar(“动画”,1)
结束
结束
--每10帧播放一次计时器,持续3秒。
--更改soundname以更改声音
--更改soundtimer>0.16以更改播放频率
--也可以通过更改小于语句来更改它的持续时间
如果soundtimer>0.10,则
soundtimer=soundtimer-0.10
音频播放声音(“报警”)
结束
--这控制何时生成子弹
--更改语句以更改警告计时器的持续时间
如果警告时间>2,则
警告计时器=警告计时器-2
音频播放声音(“拍摄”)
本地bullet1=createSprojects(“leftbigbullet”,Arena.width/2+30,Arena.height/2-bigheight[dir])——在哪里生成它们
bullet1.SetVar(“速度”,-4)——多快
bullet1.SetVar(“致命”,正确)
本地bullet2=createSprojects(“rightbigbullet”,-Arena.width/2-30,Arena.height/2-bigheight[dir])——在哪里生成它们
bullet2.SetVar(“速度”,4)——多快
bullet2.SetVar(“致命”,正确)
表.插入(公告B、公告1)
表.插入(公告B、公告2)
bullet.Remove()
结束
bullet.SetVar(“warningtimer”,warningtimer)
bullet.SetVar(“animtimer”,animtimer)
bullet.SetVar(“soundtimer”,soundtimer)
结束
结束
--控制大子弹
--这种方法控制大子弹
对于i=1,#bulletsbig do
局部项目符号=项目符号BIG[i]
如果bullet.i是活动的,那么
本地速度=bullet.GetVar(“速度”)
bullet.SendToBottom()
子弹移动(速度*Time.mult,0)
如果bullet.absx>700或bullet.absx<-70,则
bullet.Remove()
结束
结束
结束
结束
函数OnHit(bullet)
如果(bullet.getVar(“致命”)),那么
球员受伤(3)
结束
结束

不确定您要找的是什么。这是一个数学问题还是一个编程问题?bullet.Move的参数是什么?也许它们是x和y方向的速度,你只需要交换它们。你只需要交换投射物的x,y绳索,交换
竞技场。宽度
竞技场。高度
这是一个机械人的问题。