Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Moving arrays  RSS feed

 
Alaric Mustoe
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i have 2 array's both defining separate lines of of enemies but how do i get them to move in the specific pattern right to the border, down then left to the border. But the second line of enemies isn't drawing. please help me
 
Knute Snortum
Sheriff
Posts: 3550
85
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At line 10 you have a for loop with nothing in it. Is that what you intended?
 
Fred Kleinschmidt
Bartender
Posts: 507
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You call setPosition() for enemies, but not for enemies1.
 
Liutauras Vilda
Marshal
Posts: 3820
200
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:You call setPosition() for enemies, but not for enemies1.
And all this, what Fred rightly mentioned comes from poorly chosen variable names. As there is no logical distinction between enemies and enemies1. Try to come up with something better. As blueEnemies, redEnemies, or something else a bit more meaningful from the game context.

Also you're not using conventional variable names within for loop. Would read better as i or j.

Other variables as barx, bary, barx1, barx2... also poorly chosen. If you haven't encountered problems on them yet, you will at some point.
 
Les Morgan
Rancher
Posts: 752
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alaric,

it also seems you are doing a lot of work here to get your armies to move. Each of your objects that are mobile should know how to move themselves, so you don't have to do the work, they do it, all you have to do is tell them. Your mobile objects need to keep track of where they are: (X, Y), how fast they move, MOVEMENT_RATE, and directions of movement--like LEFT, RIGHT, STRAIGHT, UP, DOWN, or whatever direction you choose, and the graphic object of the display object you are using, g. When you ask them to move, then all you need to is a very simple: MyObject.move(g, UP); or what ever an appropriate movement direction may be. This is going to become very important when you have multiple objects that you have moving on the screen--say a foot soldier, a mechanical transport, and etc.

Les
 
Les Morgan
Rancher
Posts: 752
17
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also load your sprites once, and access them from memory.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!