• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Moving array of objects

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2235
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if(x == x +20)
This condition will never be true.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 8566
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic