Discord
Login
Community
DARK THEME

how to make objects chase after mouse

I'm trying to make a zombie game but when trying to make the zombie chase after the player (right now its the mouse) but it seems it doesn't want to move, is there any problem with the code. :)

init = function() zombie1 = new zombie zom = 7 player_x = 0 player_y = 0 end

update = function() player_x = mouse.x player_y = mouse.y zombie1.move(1)

end

draw = function() screen.clear zombie1.display() end

zombie = class enemy_x = 0 enemy_y = 0 constructor = function(x,y) this.x = 1 this.y = 0 end move = function(speed) for i=1 to 10 if player_x > this.x then this.x += speed end if player_x < this.x then this.x -= speed end end end display = function() screen.fillRect(enenmy_x,enemy_y,10,10,"rgb(255,255,255)") end end

//end

Fixed a bit of the code but the problem is still there

;init = function() zombie1 = new zombie zom = 7 player_x = 0 player_y = 0 end

update = function() player_x = mouse.x player_y = mouse.y zombie1.move()

end

draw = function() screen.clear zombie1.display() end

zombie = class enemy_x = 0 enemy_y = 0 constructor = function(x,y) this.x = x this.y = y end move = function() for i=1 to 10 if player_x > this.x then this.x = this.x + 1 elsif player_x < this.x then this.x = this.x + 1 end end end display = function() screen.fillRect(enenmy_x,enemy_y,10,10,"rgb(255,255,255)") end end

3 times the character next to key 1 - then the string of characters will not be modified.

init = function() 
  zombie1 = new zombie()
  zom = 7 
  player_x = 0 
  player_y = 0 
end

update = function() 
  player_x = mouse.x 
  player_y = mouse.y 
  zombie1.move()

end

draw = function()
  screen.clear()
  zombie1.display()
end

zombie = class
  enemy_x = 0
  enemy_y = 0
  constructor = function(x,y) 
    this.x = x 
    this.y = y 
  end 
  move = function() 
    for i=1 to 10 
      if player_x > this.x then 
        this.x = this.x + 1 
      elsif player_x < this.x then 
          this.x = this.x - 1 
        end 
    end 
  end 
  display = function() 
    screen.fillRect( this.x,this.y,10,10,"rgb(255,255,255)") 
  end 
end

Thank you, I'm kinda new to this.

you still there DanMan97

What do you mean by that @bober890

But yeah great job for someone new to microstudios welcome!

Yeah I’m still here, I’m just busy with school and taking care of chickens

DanMan97: how do you code walking?

Nice yeah school gets annoying sometimes when you want to finish coding And for mrPancake97 you don’t you animate it

@Kaish ok thanks for replying! :)

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community