How to call one class in the principal main?.
I do a code for the bullet using OOP and i tried to call the class of bullet in the principal main but is doesn't worked, and i want really know how to do it
Link of my game: https://microstudio.io/rianstar/ghosthunt/
THANKS FOR THE HELP <33333333333
ghost file
ghostINIT = function()
ghost = object end
ghost.speed = 2
ghost.facing = 1
ghost.x = 0
ghost.y = 0
ghost.width = 8
ghost.height = 8
ghost.dash = 0
ghost.cooldown = 0
ghost.dash_active = false
ghost.bullets = []
end
ghostCooldown = function()
if (ghost.dash == 0) and ( ghost.cooldown > 0) then
ghost.cooldown -= 1
end
end
ghostDash = function( isMoving )
if (ghost.dash_active) and (ghost.cooldown == 0) then
if isMoving then
if ghost.dash == 0 then
ghost.dash = 60
end
end
if ghost.dash > 0 then
ghost.dash -=1
if ghost.dash == 0 then
ghost.cooldown = 120
end
end
end
return ghost.dash > 0
end
ghostUPDATE = function()
local isMoving = false
if keyboard.release.B then
ghost.dash_active = not ghost.dash_active
end
if keyboard.RIGHT then
ghost.facing = 1
ghost.x += ghost.speed + ghostDash(true) * ghost.speed
isMoving = true
end
if keyboard.LEFT then
ghost.facing = -1
ghost.x -= ghost.speed + ghostDash(true) * ghost.speed
isMoving = true
end
if keyboard.DOWN then
ghost.y -= ghost.speed + ghostDash(true) * ghost.speed
isMoving = true
end
if keyboard.UP then
ghost.y += ghost.speed + ghostDash(true) * ghost.speed
isMoving = true
end
if not isMoving then
ghostDash(false)
end
ghostCooldown()
if keyboard.SPACE then
ghost.bullets.push( new Shot( ghost ))
bb =new Shot( ghost )
end
print("bullets="+ghost.bullets.length)
for i = ghost.bullets.length -1 to 0 by -1
local b = ghost.bullets[i]
print(b.active)
b.update()
if b.active == false then
ghost.bullets.removeElement(b)
end
end
end
main file
init = function()
//maneira porca de fzr coordenadas no mapakkkk
x = 0
y = 0
//isso e pra chamar a funcao do player
//uma tecnica pra nn deixar o codigo mt longo
ghostINIT()
touchKeys.arrows = not system.input.keyboard
touchKeys.keys = ["X","B"]
menuINIT()
end
update = function()
menuUPDATE()
//isso e pra chamar a funcao de update
ghostUPDATE()
if keyboard.B then
ghostDash()
ghostCooldown()
end
//maneira tenebrosa q eu fiz o limite do mapa
//se o codigo de um segundo atras me da medo
//imagine o de 1hr atras kskskskssk
ghost.x = limitmap(ghost.x, -152, 152)
ghost.y = limitmap(ghost.y, -80, 80)
touchKeys.update()
end
draw = function()
screen.fillRect(x,y, 450, 200, "rgb(0,0,0)")
screen.drawMap("level1_red",x,y, 350, 200)
//isso de setDrawScale pra poder desenhar as escalas
//dependendo de pra onde o personagem esteja virado
screen.setDrawScale(ghost.facing, 1)
screen.drawSprite("ghost", ghost.x, ghost.y, 16, 16)
for b in ghost.bullets
b.draw()
end
screen.setDrawScale(1,1)
touchKeys.draw()
menuDRAW()
end
Shot file
Shot = class
constructor = function( source )
this.x = source.x
this.y = source.y
this.width = 12
this.height = 12
this.facing = source.facing
this.step = 0
this.dist = 0
this.active = true
end
update = function()
if this.active then
this.step += 1
if this.dist > 1000 then
this.active = false
end
this.dist += 30
this.x += 30 * this.facing
end
end
draw = function()
if this.active then
screen.drawSprite("gshot", this.x, this.y, 12, 12)
end
end
end