Ultimate Amiga

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Making Enemys in Rows?  (Read 3474 times)

0 Members and 2 Guests are viewing this topic.

Amiga Forever

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 11
  • Generic Amiga User
Making Enemys in Rows?
« on: May 24, 2015, 02:55:05 PM »

I have try to make into rows of Enemys like 3 in rows with 3 in colums by changing Code like Bob B,i*4,B*35+y,2  somethings like that

I am making Space invader to start with it and take from there.



Logged

Sidewinder

  • Forum Mod
  • A600
  • *****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • http://www.liquido2.com/
Re: Making Enemys in Rows?
« Reply #1 on: May 24, 2015, 05:07:54 PM »

Is this not working correctly?  I didn't see a question in the post.  But it looks like it should work with I as the column and B as the row with Y as a vertical offset.
Logged
- Sidewinder

Amiga Forever

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 11
  • Generic Amiga User
Re: Making Enemys in Rows?
« Reply #2 on: May 24, 2015, 07:25:32 PM »

Is this not working correctly?  Not working correctly because I am trying do 3 in rows which is BOB B,B*35,B,2 work fine but when I change the code to 3 in rows and columns....it didn't look right as it like had Aliens like this

A= Aliens
======

A
   A
      A

.....so frustrations

What I am trying to do is like this

A A A
A A A
A A A

« Last Edit: May 24, 2015, 07:34:20 PM by Amiga Forever »
Logged

Sidewinder

  • Forum Mod
  • A600
  • *****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • http://www.liquido2.com/
Re: Making Enemys in Rows?
« Reply #3 on: May 24, 2015, 07:59:04 PM »

Oh, right.  That makes sense now.  Here is the loop code you have in your editor snapshot:

Code: [Select]
For B=0 To 2
   Bob B,I,B*35+Y,2
   I=I+_DIR
Next

I think the reason you are seeing this diagonal layout is because I is being incremented on each iteration of the loop.  So it moves the Bob over to the right every time B changes and moves it down a row.  If you want to keep only one loop you'll have to add more Bob commands in the loop in order to generate all the columns for a row at once:

Code: [Select]
For B=0 To 2
   Bob B*3,I,B*35+Y,2
   Bob B*3+1,I+_DIR,B*35+Y,2
   Bob B*3+2,I+2*_DIR,B*35+Y,2
Next

Or, you could use two loops if that is clearer:

Code: [Select]
X=10
Y=10
I=0
For ROW=0 To 2
   For COLUMN=0 To 2
      Bob I,COLUMN*35+X,ROW*35+Y,2
      I=I+1
   Next COLUMN
Next ROW
   
« Last Edit: May 24, 2015, 08:42:08 PM by Sidewinder »
Logged
- Sidewinder

Amiga Forever

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 11
  • Generic Amiga User
Re: Making Enemys in Rows?
« Reply #4 on: May 24, 2015, 09:55:39 PM »

Quote
Or, you could use two loops if that is clearer:

Code: [Select]
X=10
Y=10
I=0
For ROW=0 To 2
   For COLUMN=0 To 2
      Bob I,COLUMN*35+X,ROW*35+Y,2
      I=I+1
   Next COLUMN
Next ROW

Thank you and that did show 3 rows and columns Aliens :-)  However when I move all of them by increasing the X to move Aliens right then it just show one Aliens moving the screen like what I done this
Code: [Select]
For ROW=0 To 2
   For CO=0 To 2
      Bob I,CO*35+X,ROW*35+Y,2
      X=X+_Dir
   Next CO
Next ROW

Why does it show just one Aliens on the screen when I move to the left as when should be all Aliens moving!?
Logged

Sidewinder

  • Forum Mod
  • A600
  • *****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • http://www.liquido2.com/
Re: Making Enemys in Rows?
« Reply #5 on: May 24, 2015, 11:15:18 PM »

The simple reason is that I never changes in the loop.  So if I is set to 0 before the loop, then only bob 0 will move--9 times.

The easiest way to fix it is to add an I=I+1 after the X=X+_DIR:

Code: [Select]
I=0
For ROW=0 To 2
   For CO=0 To 2
      Bob I,CO*35+X,ROW*35+Y,2
      X=X+_DIR
      I=I+1
   Next CO
Next ROW

As a side note, once you get this working, you will probably want to unroll these loops.  Looping like this is actually quite a bit slower than it looks.  Consider that for each FOR/NEXT loop, at a minimum an extra load, test, add, store and branch instruction must be executed on each iteration...that is 5 extra instructions.  So in the above case, that's 5*9=35 extra instructions just to move the bobs each frame.  That would be fine for design and debugging, but when you're looking to increase performance, loop unrolling is a good place to start.
Logged
- Sidewinder

xboxisfinished

  • A600
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 205
  • Generic Amiga User
    • gamemakermagazine.com
Re: Making Enemys in Rows?
« Reply #6 on: May 24, 2015, 11:44:06 PM »

The simple reason is that I never changes in the loop.  So if I is set to 0 before the loop, then only bob 0 will move--9 times.

The easiest way to fix it is to add an I=I+1 after the X=X+_DIR:

Code: [Select]
I=0
For ROW=0 To 2
   For CO=0 To 2
      Bob I,CO*35+X,ROW*35+Y,2
      X=X+_DIR
      I=I+1
   Next CO
Next ROW

As a side note, once you get this working, you will probably want to unroll these loops.  Looping like this is actually quite a bit slower than it looks.  Consider that for each FOR/NEXT loop, at a minimum an extra load, test, add, store and branch instruction must be executed on each iteration...that is 5 extra instructions.  So in the above case, that's 5*9=35 extra instructions just to move the bobs each frame.  That would be fine for design and debugging, but when you're looking to increase performance, loop unrolling is a good place to start.

Of course that would have being irrelevant had said classic Amiga was running at 3 Ghz Quad processor with 8 GB of RAM :D
Logged

Sidewinder

  • Forum Mod
  • A600
  • *****
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • http://www.liquido2.com/
Re: Making Enemys in Rows?
« Reply #7 on: May 25, 2015, 01:37:58 AM »

Quote
Of course that would have being irrelevant had said classic Amiga was running at 3 Ghz Quad processor with 8 GB of RAM :D

Well, even with billions of cycles per second, it's not irrelevant to save cycles when you can, but your point is taken.  It wouldn't be as big of a deal on modern hardware as it is on classic Amiga hardware.  But loop unrolling is a common optimization, and any modern compiler worth anything will automatically unroll loops like this.  Unfortunately, AMOS, even compiled AMOS, does not, thus it's up to the programmer to code smarter.  And also, the actual savings will be even greater because unrolling the loops will turn many of the command arguments into constants, which will speed things up even further.
Logged
- Sidewinder
Pages: [1]   Go Up
 

TinyPortal 2.2.2 © 2005-2022