05-30-2024, 10:52 AM
(05-29-2024, 06:46 PM)Marcus Wrote: Here you go, tutorial step 5, about really simple moving sprites....
Question on Example 5
Each time new tutorial is released, it's more and more interesting. I like it
I would like to run different scenarios of the pumpkins before and after touching the ground.
Before Touching The Ground
click image to zoom in
After Touching The Ground
click image to zoom in
Could you please advice me how to do those scenarios ? I have tried to code, but it's failed.
Code:
'----------------
' INITIALIZATION
'----------------
...
'load game assets (pumpkin, map, player)
visible vPumpkinImage1 = loadimage("assets5/pumpkin1.png", 4, 1)
visible vPumpkinImage2 = loadimage("assets5/pumpkin2.png", 4, 1)
..
foreach f in flags
select f.flag
...
case "pumpkin"
o = CreatePumpkinEnemy(f.x, -10, f.z)
EA_AddObject(o)
endsel
next
...
'-----------
' GAME LOOP
'-----------
EA_Run()
'-----------
' FUNCTIONS
'-----------
...
function CreatePumpkinEnemy(x, y, z)
enemy = EA_Object()
'--------------------------------------------------
'It's intended to have different Pumpkin Image
'before touch the ground and after touch the ground
'but it seems failed :(
if enemy.Y()<0
enemy.SetSprite(vPumpkinImage1, 0, true)
enemy.SetHeight(height(vPumpkinImage1)/64)
enemy.SetRadius(0.5*width(vPumpkinImage1)/64)
elseif enemy.Y()>=0
enemy.SetSprite(vPumpkinImage2, 0, true)
enemy.SetHeight(height(vPumpkinImage2)/64)
enemy.SetRadius(0.5*width(vPumpkinImage2)/64)
endif
'--------------------------------------------------
enemy.SetPos(x, y, z)
enemy.SetYaw(rad(rnd(360)))
enemy.cel = 0
enemy.Update = function(dt)
.cel = (.cel + dt*8)%4
.SetCel(int(.cel))
'--------------------------------------------------------------
'It's intended to give different gravity or speed for each enemy
'but it seems failed :(
objs = .SectorObjects()
if objs and sizeof(objs)
for i = 0 to sizeof(objs) - 1
gravity = rnd(0,1)*dt
next
endif
'---------------------------------------------------------------
res = .Move(.DX()*0.75*dt, gravity, .DZ()*0.75*dt, 0)
if res.w 'wall
.SetYaw(rad(deg(atan2(res.dx, res.dz)) - 90 + rnd()*180))
endif
endfunc
return enemy
endfunc