Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
That 3d thing
#62
(05-31-2024, 09:00 PM)Marcus Wrote: Here's step 6. ...

STEP 6. What if the enemy can shoot you ?

click image to zoom in
   
Enemy shoots randomly, the bullet goes at the same direction as the enemy movement.

click image to zoom in
   
When the enemy moves toward you, they begin to shoot you.
Question : 
    How to use collision detection function when the enemy's bullet hit you at certain area ?
    Mine is still error ....  Sad

You may answer when you have free time, don't worry, it's not urgent  Big Grin

Code:
'----------------
' INITIALIZATION
'----------------
...
constant ENEMY_BULLET_ID    = 8
vEnemyBulletImage = loadimage("assets6/enemy_bullet.png",4,1)
...


'-----------
' GAME LOOP
'-----------
EA_Run()


'-----------
' FUNCTIONS
'-----------
function CreatePumpkinEnemy(x, y, z)
    enemy = EA_Object()
    enemy.id = PUMPKIN_ID
    ...
    enemy.Update = function(dt)
        .stimer = max(.stimer - dt, 0)
        if .stimer = 0
            .stimer = 0.5
            EA_AddObject(CreateEnemyBullet(
                    ENEMY_BULLET_ID,
                    vEnemyBulletImage,
                    .X() + .DX()*0.2, .Y() - 0.3 + .DY()*0.2, .Z() + .DZ()*0.2,
                    .DX()*4, .DY()*4, .DZ()*4))
        endif       
    ...
    endfunc
    ...
endfunc


function CreateEnemyBullet(id, img, x, y, z, dx, dy, dz)
    b = EA_Object()
    b.id = id
    b.SetPos(x, y, z)
    b.SetSprite(img, 0, false)
    b.SetHeight(height(img)/64)
    b.SetRadius(0.5*width(img)/64)
    b.dx = dx
    b.dy = dy
    b.dz = dz
    b.numCels = cels(img)
    b.cel = 0
    b.Update = function(dt)
        if .numCels > 1
            .cel = (.cel + dt*30)%.numCels
            .SetCel(int(.cel))
        endif
        res = .Move(.dx*dt, .dy*dt, .dz*dt, 0)
        if res.any
            EA_RemoveObject(this)
        else
            'Error collision detection enemy bullet and player
            'if .CollidesWith(PLAYER_ID)
            '    EA_RemoveObject(PLAYER_ID)    'remove player
            'endif
        endif
    endfunc

    return b
endfunc


Attached Files
.zip   test6.zip (Size: 51.11 KB / Downloads: 4)
Reply


Messages In This Thread
That 3d thing - by Marcus - 04-20-2024, 11:34 PM
RE: That 3d thing - by johnno56 - 04-21-2024, 02:06 AM
RE: That 3d thing - by Marcus - 04-21-2024, 07:58 AM
RE: That 3d thing - by 1micha.elok - 04-21-2024, 09:46 AM
RE: That 3d thing - by johnno56 - 04-21-2024, 10:15 AM
RE: That 3d thing - by Marcus - 04-21-2024, 10:54 AM
RE: That 3d thing - by johnno56 - 04-21-2024, 12:19 PM
RE: That 3d thing - by Marcus - 04-27-2024, 02:32 PM
RE: That 3d thing - by 1micha.elok - 04-28-2024, 12:25 AM
RE: That 3d thing - by Marcus - 04-28-2024, 12:05 PM
RE: That 3d thing - by 1micha.elok - 04-29-2024, 12:34 AM
RE: That 3d thing - by johnno56 - 04-27-2024, 07:02 PM
RE: That 3d thing - by Marcus - 04-29-2024, 04:30 PM
RE: That 3d thing - by johnno56 - 04-29-2024, 07:54 PM
RE: That 3d thing - by 1micha.elok - 04-30-2024, 02:32 AM
RE: That 3d thing - by Marcus - 05-19-2024, 04:18 PM
RE: That 3d thing - by aliensoldier - 05-19-2024, 09:03 PM
RE: That 3d thing - by Marcus - 05-20-2024, 03:32 PM
RE: That 3d thing - by johnno56 - 05-20-2024, 08:02 PM
RE: That 3d thing - by Marcus - 05-23-2024, 06:42 PM
RE: That 3d thing - by johnno56 - 05-23-2024, 07:51 PM
RE: That 3d thing - by Marcus - 05-23-2024, 08:29 PM
RE: That 3d thing - by Marcus - 05-23-2024, 08:38 PM
RE: That 3d thing - by johnno56 - 05-23-2024, 11:37 PM
RE: That 3d thing - by Marcus - 05-24-2024, 05:04 AM
RE: That 3d thing - by johnno56 - 05-24-2024, 08:12 AM
RE: That 3d thing - by Marcus - 05-24-2024, 10:06 AM
RE: That 3d thing - by Marcus - 05-24-2024, 06:15 PM
RE: That 3d thing - by 1micha.elok - 05-25-2024, 05:26 AM
RE: That 3d thing - by johnno56 - 05-24-2024, 07:58 PM
RE: That 3d thing - by Marcus - 05-25-2024, 11:51 AM
RE: That 3d thing - by johnno56 - 05-26-2024, 02:37 AM
RE: That 3d thing - by aliensoldier - 05-26-2024, 03:36 PM
RE: That 3d thing - by Marcus - 05-26-2024, 05:14 PM
RE: That 3d thing - by aliensoldier - 05-26-2024, 08:52 PM
RE: That 3d thing - by Marcus - 05-27-2024, 06:30 PM
RE: That 3d thing - by 1micha.elok - 05-28-2024, 05:02 AM
RE: That 3d thing - by Marcus - 05-28-2024, 05:14 AM
RE: That 3d thing - by johnno56 - 05-27-2024, 07:59 PM
RE: That 3d thing - by Marcus - 05-28-2024, 05:58 PM
RE: That 3d thing - by 1micha.elok - 05-29-2024, 04:55 AM
RE: That 3d thing - by Marcus - 05-29-2024, 05:33 AM
RE: That 3d thing - by 1micha.elok - 05-29-2024, 12:10 PM
RE: That 3d thing - by Marcus - 05-29-2024, 02:05 PM
RE: That 3d thing - by Marcus - 05-29-2024, 05:15 PM
RE: That 3d thing - by Marcus - 05-29-2024, 06:46 PM
RE: That 3d thing - by 1micha.elok - 05-30-2024, 10:52 AM
RE: That 3d thing - by Marcus - 05-30-2024, 04:28 PM
RE: That 3d thing - by johnno56 - 05-29-2024, 08:08 PM
RE: That 3d thing - by Marcus - 05-29-2024, 08:27 PM
RE: That 3d thing - by Marcus - 05-30-2024, 05:55 PM
RE: That 3d thing - by johnno56 - 05-30-2024, 07:43 PM
RE: That 3d thing - by 1micha.elok - 05-31-2024, 02:11 AM
RE: That 3d thing - by johnno56 - 05-31-2024, 08:24 AM
RE: That 3d thing - by Marcus - 05-31-2024, 09:00 PM
RE: That 3d thing - by 1micha.elok - 06-01-2024, 06:56 AM
RE: That 3d thing - by Marcus - 06-01-2024, 08:10 AM
RE: That 3d thing - by 1micha.elok - 06-05-2024, 08:57 AM
RE: That 3d thing - by Marcus - 06-01-2024, 12:05 PM
RE: That 3d thing - by johnno56 - 06-01-2024, 12:34 PM
RE: That 3d thing - by Marcus - 06-01-2024, 01:35 PM
RE: That 3d thing - by 1micha.elok - 06-05-2024, 05:07 AM
RE: That 3d thing - by Marcus - 06-05-2024, 05:40 PM
RE: That 3d thing - by 1micha.elok - 06-06-2024, 12:37 AM
RE: That 3d thing - by 1micha.elok - 06-07-2024, 11:43 AM
RE: That 3d thing - by johnno56 - 06-07-2024, 10:41 PM
RE: That 3d thing - by 1micha.elok - 06-11-2024, 01:59 AM
RE: That 3d thing - by Marcus - 06-15-2024, 08:27 AM
RE: That 3d thing - by 1micha.elok - 06-16-2024, 10:57 AM
RE: That 3d thing - by johnno56 - 06-15-2024, 10:23 AM
RE: That 3d thing - by kevin - 06-15-2024, 01:33 PM
RE: That 3d thing - by Marcus - 06-25-2024, 05:35 PM
RE: That 3d thing - by johnno56 - 06-25-2024, 08:26 PM
RE: That 3d thing - by 1micha.elok - 06-28-2024, 12:12 AM
RE: That 3d thing - by Marcus - 06-30-2024, 12:38 PM
RE: That 3d thing - by 1micha.elok - 07-02-2024, 11:04 AM

Forum Jump:


Users browsing this thread: 25 Guest(s)