Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX spawning enemies  (Read 3598 times)
0 Members and 1 Guest are viewing this topic.
Offline vastrolorde

Junior Devvie





« Posted 2014-06-29 15:33:43 »

What is a good way to spawn a wave of enemies in a gradual way. And if there are multiple enemies moving in  row, and they bounce off the side, how to make it so that they all have the same trajectorie.
Offline PandaMoniumHUN

JGO Coder


Medals: 32
Exp: 3 years


White-bearded OGL wizard


« Reply #1 - Posted 2014-06-29 15:54:48 »

Spawn your enemies with a specific X and Y offset based on your loop's index.
So for example:
1  
2  
3  
4  
5  
6  
7  
int amountOfEnemies = 15;
int enemiesInARow = 5;
int xOffset = 15;
int yOffset = 15;
for(int i = 0; i < amountOfEnemies; i++){
   spawnEnemy(i*xOffset, i+1/enemiesInARow*yOffset);
}

This will spawn 3 rows of enemies, with 5 enemies in each row.
Every enemy will be offset with the xOffset and yOffset based on the for loop's index variable.
I just wrote this off the top of my head, hopefully I didn't make any mistakes.

To move a wave of enemies in the same direction all the time (I hope that this is what you meant) you just have to change the direction of all your enemies in the wave if you change the direction of a single enemy. This means that you would need some way of grouping together your wave of enemies.

My Blog | Jumpbutton Studio - INOP Programmer
Can't stress enough: Don't start game development until you haven't got the basics of programming down! Pointing
Offline vastrolorde

Junior Devvie





« Reply #2 - Posted 2014-06-29 16:39:47 »

Well almost but not quite. I want the enemy rows act like a snake. If the first bounces off the wall then the 2nd one will continue until it bounces and then the 3rd continues until it bounces and so on.

Atm i have the line of enemies, they all move with the same direction, from their point of view, so it like a straight line falling down and flipping itself.

*Edited*
Fixed it, instead of having yOffset depend on the amount of enemies, i made it depend on the velocity vector. Now all of the enemies move like i want. but im getting a problem where the distance between them isnt always constant. after some bounces some of the get left behind a bit.
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (13 views)
2017-11-21 16:21:00

xxMrPHDxx (10 views)
2017-11-21 16:14:31

xxMrPHDxx (10 views)
2017-11-21 16:10:57

Ecumene (113 views)
2017-09-30 02:57:34

theagentd (148 views)
2017-09-26 18:23:31

cybrmynd (246 views)
2017-08-02 12:28:51

cybrmynd (242 views)
2017-08-02 12:19:43

cybrmynd (242 views)
2017-08-02 12:18:09

Sralse (257 views)
2017-07-25 17:13:48

Archive (875 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!