I applied wattywats idea and created a short test program that seems to work fine so far. Any suggestions to make the concept more efficient?
Rem Project: test13
Rem Created: Sunday, May 18, 2014
Rem ***** Main Source File *****
make object box 1, 20, 10, 10: color object 1,RGB(255,0,0): rem player object
make object box 2, 10, 10, 10: color object 2, RGB(192,0,0): rem player attack object
make object sphere 3, 60: hide object 3
numberofenemies = 35
for a = 10 to numberofenemies
make object sphere a, 20: set object wireframe a, 1: hide object a: rem collision boundary
make object box a + 100, 20, 10, 10: color object a + 100, RGB(192,255,0): rem enemy
make object box a + 200, 10, 10, 10: hide object a + 200: rem forward collision detection
make object box a + 300, 2, 2, 30: set object collision off a + 300: rem spear
glue object to limb a + 300, a + 100, 0: offset limb a + 300, 0, 10, 0, 0: rotate limb a + 300, 0, 0, -15, 0
make object cone a + 400, 10: set object collision off a + 400: rem spearhead
glue object to limb a + 400, a + 300, 0: offset limb a + 400, 0, 0, 0, 20: rotate limb a + 400, 0, 90, 0, 0
yrotate object a + 100, rnd(360): move object a + 100, rnd(300) + rnd(100)
set object collision off a + 100
dim updown(a)
next
sync on
do
REM CAMERA
position camera object position x(1), 350, object position z(1)
point camera object position x(1), 0, object position z(1)
REM PLAYER CONTROLS
position object 3, object position x(1), object position y(1), object position z(1)
if upkey() = 1
position object 2, object position x(1), object position y(1), object position z(1)
set object to object orientation 2, 1: move object 2, 15
if object collision (2, 0) < 10 or object collision (2, 0) > 10 + numberofenemies then move object 1, .5
endif
if downkey() = 1
position object 2, object position x(1), object position y(1), object position z(1)
set object to object orientation 2, 1: move object 2, -15
if object collision (2, 0) < 10 or object collision (2, 0) > 10 + numberofenemies then move object 1, -.5
endif
if leftkey() = 1 then turn object left 1, 1
if rightkey() = 1 then turn object right 1, 1
if spacekey() = 1
position object 2, object position x(1), object position y(1), object position z(1)
set object to object orientation 2, 1: move object 2, 15
else
position object 2, 0, -5000, 0
endif
REM ENEMY
for a = 10 to numberofenemies
REM ENEMY GETTING HIT
set object collision on a + 100
if object collision (2, a + 100) = 1
updown(a) = 1
endif
set object collision off a + 100
if updown(a) => 1 and updown(a) < 100
position object a + 100, object position x(a + 100), object position y(a + 100) + .5, object position z(a + 100)
move object a + 100, -.5
inc updown(a), 1
endif
if updown(a) => 100 and object position y(a + 100) => 0
position object a + 100, object position x(a + 100), object position y(a + 100) - .5, object position z(a + 100)
move object a + 100, -.5
inc updown(a), 1
endif
if updown(a) > 100 and object position y(a + 100) <= 0
position object a + 100, object position x(a + 100), 0, object position z(a + 100)
updown(a) = 0
endif
REM ENEMY MOVEMENT AND OVELAPPING AVOIDANCE
point object a + 100, object position x(1), object position y(1), object position z(1)
position object a, object position x(a + 100), object position y(a + 100), object position z(a + 100)
position object a + 200, object position x(a + 100), object position y(a + 100), object position z(a + 100)
set object to object orientation a + 200, a + 100: move object a + 200, 20
if object collision (a, 0) > 0
col = object collision (a, 0)
distancea = Abs(Sqrt((object position x(1) - object position x(a)) ^ 2 + (object position y(1) - object position y(a)) ^ 2 + (object position z(1) - object position z(a)) ^ 2))
distanceb = Abs(Sqrt((object position x(1) - object position x(col)) ^ 2 + (object position y(1) - object position y(col)) ^ 2 + (object position z(1) - object position z(col)) ^ 2))
endif
if object collision (a + 200, 0) <= 0 or object collision (a, 0) > 0 and distancea < distanceb and object collision (a, 1) = 0 and object collision (a + 200, 0) <= 0
if updown(a) = 0 then move object a + 100, .2
endif
REM ENEMY SPEAR ATTACK
set object collision on 3
if object collision(a, 3) = 1
offset limb a + 300, 0, 10, 0, 10
else
offset limb a + 300, 0, 10, 0, -10
endif
set object collision off 3
next
set cursor 0, 0: print "Use Arrow Keys to control the player and Spacebar to hit enemies"
sync
loop