Discord
Login
Community
DARK THEME

Map collision

ok so, before posting this, i saw other posts about this and didn't understanded, well, atleast i understanded how to convert the normal coordinates to the map coordinates but now, how do i make the player collide with the things? and also, how do i sync the map coordinates to the normal ones. Here, let me explain:

here's the game i made to test:https://microstudio.dev/i/menzis/hmm/

my objective was to see if the map coordinates are synced and... they aren't, the left red ball was supposed to be on the coordinates 6,9, the upper one was supposed to be 11,11 and the right bottom one was supposed to be 16,6; How do i sync the map?(and how to i make collisions also :p)

forgot to say that you can see the coords with shift

init = function()
  // Setup Quick Engine
  Quick.init()
  Quick.gravity = 0
  Quick.friction = 50
  
  // Create a map object and a player
  map = Quick.addMap("map",0,0,300,200)
  player = new Player(-50,50,map)
end

update = function()
  Quick.update()
  player.update()
end

draw = function()
  screen.clear()
  Quick.draw()
end

Player = class
  constructor = function(x, y, map)
    // Construct the player object
    this.x = x
    this.y = y
    this.s = 1
    this.cur_lvl = map
    this.obj = Quick.addSprite("player",x,y,16,16)
  end
  
  update = function()
    // Creates variables to keep track of collisions
    local upcol = Quick.mapCellAt(this.cur_lvl,this.x,this.y + 6)
    local downcol = Quick.mapCellAt(this.cur_lvl,this.x,this.y - 6)
    local leftcol = Quick.mapCellAt(this.cur_lvl,this.x - 6,this.y)
    local rightcol = Quick.mapCellAt(this.cur_lvl,this.x + 6,this.y)
    
    // Check if key is pressed and space is free, then move
    if keyboard.LEFT and not leftcol then this.x -= this.s 
    elsif keyboard.RIGHT and not rightcol then this.x += this.s end
    if keyboard.UP and not upcol then this.y += this.s 
    elsif keyboard.DOWN and not downcol then this.y -= this.s end
      
    // Finally apply input to Quick-Object
    this.obj.x = this.x
    this.obj.y = this.y
  end
end

If you want to use it, import the library Quick Engine into your project, and you should have a dynamic collision code for maps pretty much.

Hmmmmm, based on how i don't understand a thing that's happening here, it's going to be better if i leave this for now and learn some more code lol

Yea he said his code was bad and yours better already why are you insisting so much? (btw we are speaking portuguese but that doesn't matter since it's a common mistake)

Tá de boa man, inglês realmente não é muito um problema pra mim pq eu sou meio fluente msm e tbm na mensagem em cima eu tava respondendo a mina q tava respondendo sua msg de forma bem grossa mas agr eu vi q ela deletou, n tava falando q vc tá insistindo n kkkkkkkkkkk

Eu entendi um pouco como o microscript funciona mas essas colisões de mapa aí é bem complicado, eu vou aprender outras coisas daí eu volto pra cá

Eu fiquei interessado nesse microscript orientado a objetos, como q ativa ele? Eu acho que vai ficar muito mais fácil pra mim se eu começar a usar isso e também mto obrigado por tá me ajudado até agr man vc é incrível 🤝

You two look like two kids fighting over a candy, such a useless fight seriously, let's stop this already goddamn

vi sim, alias, tem algum botao ou algo assim pra ativar o microscript orientado????????

Acho q topo mas eu não tenho insta ent vai ser difícil nos comunicarmos, tem alguma ideia de como a gente pode se comunicar???

Q tal discord?

opa, foi mal tava ocupado com outras coisas, ainda posso entrar?

Post a reply

Progress

Status

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