Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
That 3d thing
#61
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
Reply
#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
#63
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.
Reply
#64
(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
Reply
#65
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".
Reply
#66
Nicely done... the only problem I had was that I ran out of bullets... lol
Logic is the beginning of wisdom.
Reply
#67
(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
Reply
#68
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.

Reply
#69
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!
Logic is the beginning of wisdom.
Reply
#70
This looks amazing Marcus. Not one of my favourite genres to be honest, but technically there is so much to admire.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)