Author Topic: [HELP] Unstable program speed  (Read 2962 times)

0 Members and 1 Guest are viewing this topic.

Offline Omar Chehab

  • LV2 Member (Next: 40)
  • **
  • Posts: 30
  • Rating: +0/-0
    • View Profile
[HELP] Unstable program speed
« on: June 12, 2015, 05:19:54 pm »
Hello, I have a problem with program speed. When the program is processing a lot of things the game slows down, and when everything settles down it goes fast again.

You can see it in the movement here:

As you can see the character dashes when the animation goes from 9 to 5, and this is probably because of the way i designed my program.  You can see the code over here:


-Something to note is, most of the features like jump and duck were before i decided to add animations but i didnt change them. so you can ignore them. i need help in either finding a new method to organize my sprites and to load them when needed, or to fix my problem of maintaining a constant program speed.
Code: [Select]
.MK Omar Chehab
sub(INIT)
Repeat getKey(15)
sub(MOVEMENT)
sub(ACTION)
sub(RENDER)
End



Lbl MOVEMENT
  ..If TIRED then RECOVER
{L1+4}++
  If {L1+3}>128
    {L1+3}++
  End
  ..If no ANIMATION STATE is going on then
  If {L1+3}=0
  0->{L1+2}
    ..DUCK
    If getKey(1)
      ..Set ANIMATION to DUCK
      3->{L1+2}
    End
    ..LEFT
    If getKey(2) and ({L1+2}=0)
      ..Decrement X POSITION
      {L1+0}--
      sub(aWALK)
    End
    ..RIGHT
    If getKey(3) and ({L1+2}=0)
      ..Increment X POSITION
      {L1+0}++
      sub(aWALK)
    End
    ..JUMP
    If getKey(4) and ({L1+1}=56)
      ..Set ANIMATION to JUMP
      4->{L1+2}
      ..Set ANIMATION STATE to UPWARDS
      1->{L1+3}
    End
    ..IDLE
    If {L1+2}>=0 and ({L1+2}<=4)
      sub(aIDLE)
    End
  End
  ..GRAVITY
  If {L1+2}=4 or ({L1+2}=5)
         ..LEFT
      If getKey(2)
        {L1}--
    End
    ..RIGHT
    If getKey(3)
        {L1}++
    End
      If {L1+1}=56 and ({L1+3}=2)
      ..Set ANIMATION to RECOVER
          11->{L1+2}
        ..Set ANIMATION STATE to RECOVER for 15 ticks
        ~15->{L1+3}
    End
    ..Peak
    If {L1+1}=34
        ..Set ANIMATION to FALLING
      5->{L1+2}
        ..Set ANIMATION STATE to DOWNWARDS
        2->{L1+3}
    End
      ..If ANIMATION STATE is UPWARDS
      If {L1+3}=1
        ..Increment height
      {L1+1}--
    End
    If {L1+3}=2
        ..Decrement height
        {L1+1}++
    End
  End
Return



Lbl ACTION
   
Return



Lbl RENDER
  Text(0,0,{L1+2}>Dec
  ..Sum all sprite sizes up till the selected sprite
  0->D
  For(C,0,{L1+2})
    (({GDB1+(C-1*2))*({GDB1+(C-1*2+1)))+D->D
  End
  ..Loop for height of sprite
  0->C
  ({GDB1+({L1+2}*2+1)})->B
  While B>0
      B--
    ..Loop for width of sprite
    For(A,0,({GDB1+({L1+2}*2)})-1)
      Pt-On(A*8+{L1},~B*8+{L1+1},C*16+Pic0+(D*16))
      Pt-On(A*8+{L1},~B*8+{L1+1},C*16+Pic0+8+(D*16))^^r
      C++
    End
  End
  DispGraphClrDraw^^r^^r
Return



Lbl aIDLE
  If {L1+4}=128
    0->{L1+4}
  End
  If {L1+4}<16
    0->{L1+2}
  ElseIf {L1+4}<32
    1->{L1+2}
  ElseIf {L1+4}<64
    2->{L1+2}
  ElseIf {L1+4}<96
    3->{L1+2}
  ElseIf {L1+4}<128
    4->{L1+2}
  End
Return



Lbl aWALK
  If {L1+4}=128
    0->{L1+4}
  End
  If {L1+4}<16
    5->{L1+2}
  ElseIf {L1+4}<32
    6->{L1+2}
  ElseIf {L1+4}<64
    7->{L1+2}
  ElseIf {L1+4}<96
    8->{L1+2}
  ElseIf {L1+4}<128
    9->{L1+2}
  End
Return

Lbl INIT
  0->{L1+0}.. X POSITION
  56->{L1+1}.. Y POSITION
  0->{L1+2}.. ANIMATION
  0->{L1+3}.. ANIMATION STATE
  0->{L1+4}.. ANIMATION CLOCK

*Hexadecimal Sprites into Pic0 and their sizes x,y into GDB1*

Return

Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: [HELP] Unstable program speed
« Reply #1 on: June 25, 2015, 04:25:28 pm »
You could try using timer interrupts to set a frame limit.
If you like my work: why not give me an internet?