programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Moving array of objects

Ranch Hand
Posts: 34
• Number of slices to send:
Optional 'thank-you' note:
so I have an array
and have defined Entity
and also said enemy
can you help me to move these 2 lines of enemies over to the right 10 down 10 then over to the left 10 and then down 10 in that chronological order

Bartender
Posts: 1845
10
• Number of slices to send:
Optional 'thank-you' note:
Well do you have any ideas?

I can see code in there where you loop through an array. That would be a start.

How would you affect the position of the "enemy" entities?

Alaric Mustoe
Ranch Hand
Posts: 34
• Number of slices to send:
Optional 'thank-you' note:

Stefan Evans wrote:Well do you have any ideas?

I can see code in there where you loop through an array. That would be a start.

How would you affect the position of the "enemy" entities?

Well I have a move method such as
for(int c =0;c<3;c++){
x = x+10;
etc

Alaric Mustoe
Ranch Hand
Posts: 34
• Number of slices to send:
Optional 'thank-you' note:

Stefan Evans
Bartender
Posts: 1845
10
• Number of slices to send:
Optional 'thank-you' note:
Hmmm.
Ok, we've got some code there. But that is just x's and y's. I presume that they relate to location somehow.
But what does "c" refer to?
Can you explain what this code is meant to do using PseudoCode - i.e english?

Something along the lines of:
if (the enemy just moved to the right) then (move the enemy down)

Alaric Mustoe
Ranch Hand
Posts: 34
• Number of slices to send:
Optional 'thank-you' note:
so
if(boolean is set to true)
then move to the right this many times
then move down
then move left
then move down and loop
x is referring to entity class which defines entity x position and same with the y

Bartender
Posts: 2236
63
• Number of slices to send:
Optional 'thank-you' note:
if(x == x +20)
This condition will never be true.

Bartender
Posts: 10780
71
• Number of slices to send:
Optional 'thank-you' note:

Alaric Mustoe wrote:so
if(boolean is set to true)...

No, you're still trying to program it.

Describe the problem to us; don't tell us how you want to solve it - because that clearly isn't working.

Something along the lines that you did earlier: "Can you help me to move these 2 lines of enemies over to the right 10 down 10 then over to the left 10 and then down 10".

But we need to know ALL the rules before we can help you much.
If you already have a formal explanation of the game written out, show it to us - and if not, I suggest you start on it before you write one more line of code.

Also, a few questions:
1. If your battlefield is restricted, what do you want to happen if the rightmost enemy in the line can't move right 10?
2. You also appear to have some obstacles. How to they affect your line movement?

Winston

Saloon Keeper
Posts: 10782
86
• Number of slices to send:
Optional 'thank-you' note:
When you move to the right (or left, or up, or down) what back fills the places vacated by the pieces that are moved?
What happens if the location you are about to move to is already occupied?
What happens when you get to the edge of the playing area and can't move?