Changeset 1370


Ignore:
Timestamp:
May 12, 2012, 1:51:46 PM (9 years ago)
Author:
sam
Message:

orbital: the snake is now destructible.

Location:
trunk/orbital
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/orbital.cpp

    r1368 r1370  
    113113    }
    114114
    115     m_snakes.Push(new Snake(3));
    116     Ticker::Ref(m_snakes.Last());
    117     m_snakes.Push(new Snake(8));
    118     Ticker::Ref(m_snakes.Last());
    119     m_snakes.Push(new Snake(25));
     115    //m_snakes.Push(new Snake(3));
     116    //Ticker::Ref(m_snakes.Last());
     117    //m_snakes.Push(new Snake(8));
     118    //Ticker::Ref(m_snakes.Last());
     119    m_snakes.Push(new Snake(33));
    120120    Ticker::Ref(m_snakes.Last());
    121121
  • trunk/orbital/snake.h

    r1368 r1370  
    5555
    5656        m_steer += 2.f * seconds;
    57         float test = sinf(m_steer) * 100.f + 20.f;
     57
     58        /* Destruction test */
     59        if (m_nodes.Count() >= 3 && m_steer > 30
     60             && (int)m_steer / 6 != (int)(m_steer - 2.f * seconds) / 6)
     61        {
     62            int todelete = (int)RandF(m_nodes.Count() - 2);
     63            m_nodes[todelete + 1].m1 += m_nodes[todelete].m1;
     64            m_nodes.Remove(todelete);
     65            m_nodes[todelete + 1].m1 += m_nodes[todelete].m1;
     66            m_nodes.Remove(todelete);
     67        }
     68
     69        float test = sinf(m_steer) * 100.f + 30.f;
    5870        m_rotation *= quat::rotate(seconds * test, vec3(0, 1, 0));
    5971
     
    6577        {
    6678            /* The current node is dragged by the previous one */
    67             vec3 newdelta = m_nodes[i].m1 - deltapos;
    68             if (dot(newdelta, newdelta) > 12.f * 12.f)
    69                 newdelta = 12.f * normalize(newdelta);
    70             deltapos = newdelta + deltapos - m_nodes[i].m1;
    71             m_nodes[i].m1 = newdelta;
     79            vec3 new_delta = m_nodes[i].m1 - deltapos;
     80            float new_distance = length(new_delta);
     81            if (new_distance > 12.f)
     82            {
     83                new_delta /= new_distance;
     84                new_distance = std::max(12.f, new_distance - seconds * 80.f);
     85                new_delta *= new_distance;
     86            }
     87            deltapos = new_delta + deltapos - m_nodes[i].m1;
     88            m_nodes[i].m1 = new_delta;
    7289
    7390            /* If the current node is not the tail, rotate */
Note: See TracChangeset for help on using the changeset viewer.