Page 1 of 1

Help with melee attacks

Posted: Sat Apr 18, 2015 12:46 pm
by slavian
Hi all, is there any example of the melee attack from a mathematical point, without using of Physics engine, etc.
Thank you.

Upd added the project.
At the moment, that's such nonsense. Prompt how to better implement the melee attack.
Ps, a lot of code collected from various sources something himself already did. I'm just starting to learn Lua.

Re: Help with melee attacks

Posted: Sat Apr 18, 2015 12:50 pm
by Nixola
We'll need a bit more of your code to help you with that

Re: Help with melee attacks

Posted: Sat Apr 18, 2015 1:20 pm
by slavian
Use AdvTiled to create the world

Code: Select all

function game.load()
	tileSize = 32  -
	loadMap(1, 15, 8)
end

function loadMap(level, ox, oy)
	map = loader.load("map_"..level..".tmx")  
	mapw = map.width*tileSize-800
        maph = map.height*tileSize-600	
	createPlayer(ox,oy)  

end

function exec( s )
    return loadstring( 'return ' .. s )()
end

function Actors.new(name, x, y, w, h)
	local a = objLayer:newObject(name, actor, x, y, w, h)
	a.dir = 1
	a.hv = 0
	a.vv = 0
	a.coll = {left=false, top=false, right=false, down=false, player=false}
	return a
end

function checkObj(a,b)
	if a.x+a.width>b.x and a.x<b.x+b.width and a.y+a.height>b.y and a.y<b.y+b.height then return true end
end
function Actors.update(dt)
	for i,v in ipairs(objLayer.objects) do if not v.properties.static then
		v.coll.top, v.coll.down, v.coll.right, v.coll.left = false, false, false, false
end
  function createPlayer(ox,oy)
	                player = Actors.new("player", ox*tileSize, oy*tileSize, 31, 55)
   end
function game.update(dt)
Actors.update(dt)
   end
function game.draw()
       gr.push()
       map:autoDrawRange(cx, cy, 0, 0)
       map:draw()
       gr.pop()
 end
Showed pieces of code responsible for creating the character and check on touch

Re: Help with melee attacks

Posted: Sat Apr 18, 2015 3:37 pm
by Jeeper
I would really recommend you dropping ATL, it is very outdated and no longer maintained. Use STI instead: viewtopic.php?f=5&t=76983

Re: Help with melee attacks

Posted: Sat Apr 18, 2015 4:23 pm
by slavian
well, you're most likely right. I hope not to have to redo everything)

Re: Help with melee attacks

Posted: Sat Apr 18, 2015 5:33 pm
by slavian
A little digging in the STI. I realized that while arranges ATL.

Re: Help with melee attacks

Posted: Sun Apr 19, 2015 8:15 am
by slavian
okay, though Papuan code, but it works. Made the attack, the creation of an actor in pleer.x and player.y + 1 to the size of a 1-tile and life of 0.5 seconds. And also delay before the attack 0.5 seconds.