Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  
  Tower Defence waves loading  (Read 274 times)
0 Members and 1 Guest are viewing this topic.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Posted 2013-08-13 18:24:01 »

Hey guys!

Since I'm not the first guy in history to program a Tower Defence, I thought I might ask you how you solved this, or would have solved it:

Loading waves in a reusable manner. I really don't want to have to reload a file, or reprocess anything really. I'd like to be able to load and process the data, and then use it several times.

What I thought I'd do, was to interpret some simple simple text-document that feeds a Queue of creeps. This Queue will then be used to grab a Creep, and insert it into the world - thus, creating a wave of Creeps.

There's a problem here, though. I can't modify the original Queue, because that would ruin any playthroughs of the same level. I only want to have a single loading screen.

So.. how would you solve this? 

Offline PaidGEEK

Senior Member


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« Reply #1 - Posted 2013-08-13 18:38:22 »

How about randomized spawns? Make a spawner helper class with variables like: enemy types, spawn delay, max enemies spawned etc. Logic behind that is self-explanatory and those values can vary over time and/or wave.

Improvisational programmer.
Offline GNecro1
« Reply #2 - Posted 2013-08-13 19:06:36 »

int wave = 1;

void spawn1(Idk idk){
idk.spawnEnemy(4);
}
void spawn2(Idk idk){
idk.spawnEnemy(6)
}


ArrayList<Enemy> enemys = new ArrayList<Enemy>();
void spawnEnemy(int size){
for(int i = 0; i<size;i++;){

enemys.add(new Enemy(idk,idk,idk,idk,))

}
}

void check(){
if(enemy.isEmpty()){
swich(wave)
case1:
spawn1(Idk);
case2:
spawn2(idk)
}
}

and so one do you get it Huh


Java freak! Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grunnt

JGO Wizard


Medals: 70
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #3 - Posted 2013-08-13 19:34:16 »

I've never made a tower defence game, but I do have some idea on how to do this.

A good and easy way to load and save data from java is using the json format, which is text based so you can edit the text files outside the game. Reading and writing is typically done using a library, for example Google offers gson, which is an easy to use one.

Now for the data you would need to save. I would create a simple Java class Wave containing the basic information about a wave, e.g. number of creeps of a certain type and the interval between creeps appearing. For example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
public class Wave {

   int numberOfCreeps;
   int creepType;
   float intervalBetweenCreeps;

   public int getNumberOfCreeps() {
      return numberOfCreeps;
   }

   public void setNumberOfCreeps(int numberOfCreeps) {
      this.numberOfCreeps = numberOfCreeps;
   }

   public int getCreepType() {
      return creepType;
   }

   public void setCreepType(int creepType) {
      this.creepType = creepType;
   }

   public float getIntervalBetweenCreeps() {
      return intervalBetweenCreeps;
   }

   public void setIntervalBetweenCreeps(float intervalBetweenCreeps) {
      this.intervalBetweenCreeps = intervalBetweenCreeps;
   }
}


A text file containing a List of Waves would then look like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
[
   {
      "numberOfCreeps":10,
      "creepType":1,
      "intervalBetweenCreeps":0.25
   },
   {
      "numberOfCreeps":10,
      "creepType":1,
      "intervalBetweenCreeps":0.25
   }
]


You can read this from disk by reading a simple text file in the the json format, and converting it into a Java object through the use of gson.

Anyway, this is how I would probably get started.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!