Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to code efficiently
#1
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.

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   
Note : the full code is on the attachement.


Attached Files
.zip   Snow2024.zip (Size: 118.43 KB / Downloads: 6)
Reply


Messages In This Thread
How to code efficiently - by 1micha.elok - 11-14-2024, 11:02 PM
RE: How to code efficiently - by johnno56 - 11-15-2024, 06:27 AM
RE: How to code efficiently - by 1micha.elok - 11-16-2024, 05:04 AM
RE: How to code efficiently - by Marcus - 11-16-2024, 10:25 AM
RE: How to code efficiently - by 1micha.elok - 11-17-2024, 09:31 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)