11-14-2024, 11:02 PM
Hi Marcus,
click the image to zoom in
Sometimes, I wonder how you code every game efficiently using min() or max() functions.
This is a piece of code to animate a Santa Claus :
- cell sprite animation
- move santa from left to the right
- make santa jump up and down
Please advice me how to make the code efficient, perhaps using min() or max() functions ?
Thank you.
Note : the full code is on the attachement.
click the image to zoom in
Sometimes, I wonder how you code every game efficiently using min() or max() functions.
This is a piece of code to animate a Santa Claus :
- cell sprite animation
- move santa from left to the right
- make santa jump up and down
Please advice me how to make the code efficient, perhaps using min() or max() functions ?
Thank you.
Code:
'santa claus animation
'----------------------
'Cell Animation
draw image santa.run,santa.move,santa.jump,santa.cell
if santa.cell<11 then
santa.cell = santa.cell + dt*20
else
santa.cell = 0
endif
'Running Santa
if santa.move > 520 then
santa.move = -50
else
santa.move = santa.move + dt*50
endif
'Santa Position
if keydown(KEY_SPACE) then
santa.pos = 1 'santa position 0=stay 1=up 2=down
endif
if santa.pos=1 then
santa.jump = santa.jump - dt*100
elseif santa.pos=2 then
santa.jump = santa.jump + dt*100
else
santa.jump = 175
endif
if santa.jump <= 80 then
santa.pos = 2
elseif santa.jump >= 175 then
santa.pos = 0
endif