Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Moving array of objects  RSS feed

 
Alaric Mustoe
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Please I need help SOS
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if(x == x +20)
This condition will never be true.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!