Ultimate Amiga

Network Boards => AMOS Language Discussion => AMOS Factory => AMOS The Creator Forum => Topic started by: BooBoo on October 23, 2008, 10:46:03 AM

Title: Anim Problems
Post by: BooBoo on October 23, 2008, 10:46:03 AM
HI again  ;) Im trying to debug this simple script.

Key press "a" = Fire
Joy Left & Right

Quote from: Debug Code
A=1
B=2
Cls 0
 Screen Open 0,320,256,32,LOWERS
 Load Iff "dh1:japan2.iff",1
Double Buffer
10 Load "dh1:Sprite/ryu2.abk"
Get Sprite Palette
Do
If Jright(1) Then Wait 5 : B=B+1 : A=A+5 : If B>5 Then B=2
If Jleft(1) Then Wait 5 : B=B-1 : A=A-5 : If B<2 Then B=5
If Inkey$="a" Then Goto LIGHTPUNCH :
Bob 1,A,100,B
Loop
End
Rem********************************************************************
LIGHTPUNCH:
Load "dh1:sprite/Light-punch.abk"
Channel 1 To Bob 1
Bob 1,A,100,B
Anim 1,"(1,3)(2,3)(3,3)"
Z=1
Do
If Inkey$="a" Then Z=1
Anim On
Z=Z+1
If Z=200 Then Anim Off : Z=0 : Goto 10
Loop
Return

The problem is that at certain points on the screen if I press "a" to puch the Bob jumps up for a second but this only happends with the Anim command if I animated the Bob without Anim this doesnt happen. - Do I need to clear memory? before loading in the new Bob? It only happend with the Anim command.
Title: Re: Anim Problems
Post by: SamuraiCrow on October 23, 2008, 05:24:39 PM
Generally you're supposed to put all of your Bobs in one bank and then load it at startup.  You can change the Bob image with the last parameter of the Bob command.

Also, as common practice in the industry is to use structured programming, try to avoid using Goto until you're sure that there isn't another way to do it.  You can always restructure your code using Goto later on when you're sure there is a part of your code that is too slow but if you don't know how to write structured code you may never get to that point.  As Donald Knuth once said, "Premature optimization is the root of all evil."  That means write it readable first and then optimize it later.

Make use of the indenter button on the editor and, if it isn't present on Amos the Creator, get AmosPro from the downloads section of this website and use it from there.
Title: Re: Anim Problems
Post by: BooBoo on October 23, 2008, 07:55:34 PM
Well GOTO is a very simple command but I only wrote this as a simple example to help debug this problem ive writen a much larger code and was tidying up the Animation routines and found this problem.


:The reason Im using more than one Bank is because I plan on haveing such a large amount of Sprites
Title: Re: Anim Problems
Post by: SamuraiCrow on October 23, 2008, 10:15:20 PM
Here's an example of how it's usually done:

Code: [Select]
dim statetable(5,5)
call stateinit: rem assumes this proc is defined elsewhere
rem it should initialize the statetable array
global plystate,plyx,plyy
iff load "background.iff"
load "playerbobs.abk"
load "soundeffects.abk",5
double buffer
get sprite palette
do
  wait vbl
  screen swap
  on plystate+1 gosub state1, state2, state3, state4, state5
loop

rem first state
state1:
  rem assumes plystate is the same number as the
  rem bob image number to be displayed
  Bob 1,plyx,plyy,plystate
  rem transition to the next state according to the table
  plystate = statetable[1,joy(1)]
  inc plyx
return
state2:
  Bob 1,plyx,plyy,plystate
  plystate = statetable[2,joy(1)]
  sam play 1,1:  rem assumes this sound effect exists
return
...

Note that the state table can get quite large if you have special hidden moves in them.  Note also, that the array that contains the state table should be square (equal rows and columns) so that the current state being passed in will have a corresponding state coming out.

I've left a lot up to you to define in the example but it should get you started.