Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
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 4148 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:
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.

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  

EgonOlsen (1314 views)
2018-06-10 19:43:48

EgonOlsen (1179 views)
2018-06-10 19:43:44

EgonOlsen (917 views)
2018-06-10 19:43:20

DesertCoockie (1318 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1338 views)
2018-04-24 18:14:32

ivj94 (2080 views)
2018-03-24 14:47:39

ivj94 (1231 views)
2018-03-24 14:46:31

ivj94 (2230 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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‑
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!