Page 1 of 1

Issue using Hardon Collider

Posted: Thu Feb 16, 2017 9:57 pm
by destinyschilde
I am having this silly issue with my collisions. I chose this library HC to detect collisions, but there's not a lot of actual examples of it in use anywhere that i can find in order to reverse engineer. Has anyone used this library?
this is what my code looks like:

Code: Select all

require "AnimatedSprite"
HC = require 'hardoncollider'
Polygon = require 'hardoncollider.polygon' --Including the file
diag = 0
collide = false
x = 400
y = 400

function love.load()

    love.graphics.setDefaultFilter("nearest", "nearest")
    player = GetInstance ("player.lua")
    level = GetInstance ("level.lua")
    subject = GetInstance ("subject.lua")
    beam = GetInstance ("beam.lua")
    emitter = HC.circle(400,300,20)
    poly = HC.polygon(10,35, 40,50, 70,35, 40,20)
    poly:moveTo(x+25,y+80)
end

function love.update(dt)
    love.mouse.setVisible(false)
    UpdateInstance(player, dt)
    UpdateInstance(level, dt)
    UpdateInstance(beam, dt)
    UpdateInstance(subject, dt)  
    poly:moveTo(x+25,y+80)
   
    for shape, delta in pairs(HC.collisions(poly)) do 
        collide=true
    end

    if collide == false then
    if(love.keyboard.areDown('s','a')) then
        y=y+dt+0.83
        x=x-dt-1.7
        player.curr_anim = player.sprite.animations_names[4]
        diag = 1
        frozen=false
    elseif(love.keyboard.areDown('s','d')) then
        y=y+dt+0.83
        x=x+dt+1.7
        player.curr_anim = player.sprite.animations_names[10]
        diag=2
    elseif(love.keyboard.areDown('w','a')) then
        y=y-dt-0.83
        x=x-dt-1.7
        player.curr_anim = player.sprite.animations_names[6]
        diag=3
    elseif(love.keyboard.areDown('w','d')) then
        y=y-dt-0.83
        x=x+dt+1.7
        player.curr_anim = player.sprite.animations_names[8]
        diag=4
    elseif(love.keyboard.isDown('w')) then
        y=y-dt-1.6
        player.curr_anim = player.sprite.animations_names[7]
        diag=0
    elseif(love.keyboard.isDown('a')) then
        x=x-dt-1.6
        player.curr_anim = player.sprite.animations_names[5]
    elseif(love.keyboard.isDown('s')) then
        y=y+dt+1.6
        diag=0
        player.curr_anim = player.sprite.animations_names[3]
    elseif(love.keyboard.isDown('d')) then
        x=x+dt+1.6
        player.curr_anim = player.sprite.animations_names[9]
    end
    end
end

now obviously, when the shapes collide it turns this boolean off breaking my movement code. but i cant seem to figure out any other way to have my stuff stop moving when it collides. This is an amateurish problem to be having, but i'm pretty new to love2d. I'm not using tile-maps or anything like that, i'm just trying to effect collision between these two shapes. What am i missing?

Re: Issue using Hardon Collider

Posted: Tue Feb 21, 2017 10:42 am
by D0NM
man ))) look at my signature
and dl our open source Zabuyaki.
Recently I migrated from BUMP to HC.

Hope it'll help u with your HC issue.

Re: Issue using Hardon Collider

Posted: Wed Mar 15, 2017 3:31 am
by destinyschilde
im still trying to find the actual collision code in there. :( it seems like my problem is something to do with the fundamental logic behind collisions or maybe even booleans. either way i'm still pretty screwed with this. i even cleaned up my movement code a lot and still no luck. Im only just starting out here.

Re: Issue using Hardon Collider

Posted: Wed Mar 15, 2017 3:42 am
by destinyschilde
here's my now more legible code that still doesn't work:

Code: Select all

local baton = require 'baton'
love.joystick.loadGamepadMappings('gamecontrollerdb.txt')
HC = require 'hardoncollider'
x = 400
y = 300

local controls = {
  left = {'key:left', 'axis:leftx-', 'button:dpleft'},
  right = {'key:right', 'axis:leftx+', 'button:dpright'},
  up = {'key:up', 'axis:lefty-', 'button:dpup'},
  down = {'key:down', 'axis:lefty+', 'button:dpdown'},
  primary = {'sc:x', 'button:a'},
  secondary = {'sc:z', 'button:x'},
}

input = baton.new(controls, love.joystick.getJoysticks()[1])

function love.load()
    love.graphics.setDefaultFilter("nearest", "nearest")
    player = GetInstance ("player.lua")
    collide = false
    polyy = HC.polygon(10,35, 40,50, 70,35, 40,20)
    poly = HC.polygon(10,35, 40,50, 70,35, 40,20)
    speed= 1.6
end

function love.update(dt)
  input:update()
  UpdateInstance(player, dt)
  poly:moveTo(x+25,y+80)
  x = x + speed * input:get 'right'
  x = x - speed * input:get 'left'
  y = y + speed * input:get 'down'
  y = y - speed * input:get 'up'

    for shape, delta in pairs(HC.collisions(poly)) do
        collide = true
    end

    if collide==true then
        speed = speed*-1
    end


end

function love.draw()

  DrawInstance (player, x, y)
  love.graphics.print(tostring(input:getActiveDevice()))
  polyy:draw('fill')
  poly:draw('fill')
end

Its detecting collision( the shapes are in pairs ) but i dont know how to make it work after...

Re: Issue using Hardon Collider

Posted: Sun Apr 16, 2017 5:30 am
by destinyschilde
THAnK yOU YOUR CODE SAVED MY LIFE <3

Re: Issue using Hardon Collider

Posted: Mon Apr 17, 2017 4:11 am
by D0NM
destinyschilde wrote: Sun Apr 16, 2017 5:30 am THAnK yOU YOUR CODE SAVED MY LIFE <3
NP :nyu: