NaaLaa
That 3d thing - Printable Version

+- NaaLaa (https://www.naalaa.com/forum)
+-- Forum: NaaLaa (https://www.naalaa.com/forum/forum-1.html)
+--- Forum: NaaLaa 7 Code (https://www.naalaa.com/forum/forum-4.html)
+--- Thread: That 3d thing (/thread-124.html)

Pages: 1 2 3 4 5 6 7 8


RE: That 3d thing - 1micha.elok - 06-05-2024

THE STARGATE
           
Click each image to zoom in

I am thinking to give some different visual effects of weapons in each image ...
Just give me 1-2 days to try before waving a white flag ....

Yes, the stargate will be released soon this week !!!

Big Grin Big Grin Big Grin


RE: That 3d thing - 1micha.elok - 06-05-2024

(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



RE: That 3d thing - Marcus - 06-05-2024

Can't check the code right now. But if you are in the enemy bullet's Update function, just call "if .CollidesWith(vPlayer)", if your player is in a visible variable named vPlayer.


RE: That 3d thing - 1micha.elok - 06-06-2024

(06-05-2024, 05:40 PM)Marcus Wrote: Can't check the code right now. But if you are in the enemy bullet's Update function, just call "if .CollidesWith(vPlayer)", if your player is in a visible variable named vPlayer.

Thank you, now it's working ! 
 .CollidesWith(vPlayer) is working perfectly  Big Grin

       
click each image to zoom-in

Code:
function CreateEnemyBullet(id, img, x, y, z, dx, dy, dz)
    ...
    b.Update = function(dt)
        ...
        if res.any
            EA_RemoveObject(this)
        else
            'collision detection enemy's bullet and player
            if .CollidesWith(vPlayer)
                set color 255,0,0,200
                draw rect 0,0,width(primary),height(primary),1
                redraw
                fwait 10
            endif
        endif
    endfunc

    return b
endfunc



RE: That 3d thing - 1micha.elok - 06-07-2024

THE STARGATE is released now !
https://naalaa.com/forum/thread-140.html

It was developed based on Marcus' tutorial on 3D Thing and discussions in this thread "That 3d thing".


RE: That 3d thing - johnno56 - 06-07-2024

Nicely done... the only problem I had was that I ran out of bullets... lol


RE: That 3d thing - 1micha.elok - 06-11-2024

(06-07-2024, 10:41 PM)johnno56 Wrote: Nicely done... the only problem I had was that I ran out of bullets... lol

I should put a puzzle in the game to solve and return bullets as your reward so that you may reload your weapon with more bullets and powers ... let me think about it.... perhaps in the next sequel .... The Stargate II

Big Grin Big Grin Big Grin


RE: That 3d thing - Marcus - 06-15-2024

I'm done with the code for the final part of this tutorial, but now I have lots of confusing text to write. Uploaded a video to youtube.




RE: That 3d thing - johnno56 - 06-15-2024

Aww, man! They shoot back? Multiple keys? You mean we have to "remember" where all the locked doors are; search for keys; collect treasure AND fight off a bunch of "possessed" pumpkins?? COOL... sounds like fun!


RE: That 3d thing - kevin - 06-15-2024

This looks amazing Marcus. Not one of my favourite genres to be honest, but technically there is so much to admire.