Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Play & Game Design / Re: The base of an entity system on: 2012-04-23 01:49:08
Alright, I appreciate all the posts you've guys have made. You helped me alot as in this if my first time making an entity system. I'm sorry I guess I didn't know you guys didn't have the same definition as me, but anyways what would a good way be to this for a 2D game. I'm trying to handle movement, collision, level, stats. Every "Entity" should have them. So would I would have an Entity class that would contain all the entities, such as player, npcs/monsters and then each of them would have there own classes? How would this look?
2  Game Development / Game Play & Game Design / Re: The base of an entity system on: 2012-04-23 00:00:17
Could you write me a simple example? I'm having a hard time understanding.
3  Game Development / Game Play & Game Design / Re: The base of an entity system on: 2012-04-22 23:23:08
This is what I've got so far.

GameWorld.java
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  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
package com.akrillix.client;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class GameWorld extends JPanel implements ActionListener {

   Player Player;
   Monster Monster;
   MapLoader Map;
   Timer time;

   public GameWorld() throws Exception {
      Player = new Player(100,100);
      Monster = new Monster(250,250);
      Map = new MapLoader("testMap");
      addKeyListener(new AL());
      setFocusable(true);
      time = new Timer(5, this);
      time.start();
   }

   public void actionPerformed(ActionEvent e) {
      Player.move();
      Monster.randomWalkRight();
      repaint();
   }

   public void paint(Graphics g) {
      super.paint(g);
      Graphics2D g2d = (Graphics2D) g;
      Map.paint(g);
      g2d.drawImage(Player.getImage(), Player.getX(), Player.getY(), null);
      g2d.setColor(Color.GREEN);
      g2d.drawString(Player.playerName, Player.getX(), Player.getY());
      g2d.drawImage(Monster.getImage(), Monster.getX(), Monster.getY(), null);
      g2d.setColor(Color.YELLOW);
      g2d.drawString(Monster.monsterName, Monster.getX() - 17, Monster.getY());
   }

   private class AL extends KeyAdapter {
      public void keyReleased(KeyEvent e) {
         Player.keyReleased(e);
      }

      public void keyPressed(KeyEvent e) {
         Player.keyPressed(e);
      }
   }
}


Monster.java
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  
31  
32  
33  
34  
35  
package com.akrillix.client;

import java.awt.Image;

import javax.swing.ImageIcon;

public class Monster {
   Image jelly;
   int x, y;
   String monsterName = "Purple Jelly";
   
   public Monster(int x, int y) {
      ImageIcon i = new ImageIcon("src/jelly.png");
      jelly = i.getImage();
      this.x = x;
      this.y = y;
   }
   public int getX(){
      return x;
   }
   public int getY(){
      return y;
   }
   public Image getImage(){
      return jelly;
   }
   public String getMonsterName() {
      return monsterName;
   }
   public void randomWalkRight() {
      if(this.x < 700) {
         this.x += 2;
      }
   }
}


Player.java
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  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
package com.akrillix.client;

import java.awt.Image;
import com.akrillix.*;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;

public class Player {
   int x, y, dx, dy, speed;
   boolean alive;
   MapLoader Map;
   GameWorld GameWorld;
   String playerName = "Admin";
   Image player;
   
   public Player(int x, int y) {
      ImageIcon i = new ImageIcon("src/player.png");
      player = i.getImage();
      this.x = x;
      this.y = y;
      speed = 3;
   }
   public void move (){
      x = x + dx;
      y = y + dy;
      if (x > 800 - 32) {
         try {
            Map = new MapLoader("testMap2");
         } catch (Exception e) {
            e.printStackTrace();
         }
         x = 5;
      }
      if(x < 1) {
         try {
            Map = new MapLoader("testMap");
         } catch (Exception e) {
            e.printStackTrace();
         }
         x = 800 - 33;
      }
   }
   public int getX(){
      return x;
   }
   public int getY(){
      return y;
   }
   public Image getImage(){
      return player;
   }
   public String getPlayerName() {
      return playerName;
   }
   public void keyPressed(KeyEvent e){
      int key = e.getKeyCode();
      if (key == KeyEvent.VK_LEFT) {
         dx = -speed;
         dy = 0;
      }
      if (key == KeyEvent.VK_RIGHT) {
         dx = speed;
         dy = 0;
      }
      if (key == KeyEvent.VK_UP) {
         dy = -speed;
         dx = 0;
      }
      if (key == KeyEvent.VK_DOWN) {
         dy = speed;
         dx = 0;
      }  
      if (key == KeyEvent.VK_SHIFT) {
         speed = 4;
      }
      if (key == KeyEvent.VK_F1 ) {
         
      }
      if (key == KeyEvent.VK_F2 ) {
         //Map.drawGrid = false;
      }
   }
   public void keyReleased(KeyEvent e){
      int key = e.getKeyCode();
      if (key == KeyEvent.VK_LEFT) {
         dx = 0;
      }
      if (key == KeyEvent.VK_RIGHT) {
         dx = 0;
      }
      if (key == KeyEvent.VK_UP) {
         dy = 0;
      }
      if (key == KeyEvent.VK_DOWN) {
         dy = 0;
      }
      if (key == KeyEvent.VK_SHIFT) {
         speed = 3;
      }
   }
}


Entity.java - Does nothing, still don't know what to do.
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  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
package com.akrillix.client;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class Entity {
   int x;
   int y;
   int dx;
   int dy;
   HashMap<Long,ArrayList<Entity>> dataByComponent;
   SpriteSheetLoader sprite;
   Rectangle me = new Rectangle();
   Rectangle him = new Rectangle();
   
   public Entity(String sheetName, int x, int y, int rows, int columns) {
      try {
         this.sprite = new SpriteSheetLoader(sheetName, 32, 32, rows, columns);
         this.x = x;
         this.y = y;
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
   
   public void move() {
      x += dx;
      y += dy;
   }
   
   public void setHorizontalMovement(int dx) {
      this.dx = dx;
   }
   
   public void setVerticalMovement(int dy) {
      this.dy = dy;
   }
   
   public int getHorizontalMovement() {
      return dx;
   }
   
   public int getVerticalMovement() {
      return dy;
   }
}


Other two classes are SpriteSheetLoader and MapLoader.
4  Game Development / Game Play & Game Design / Re: The base of an entity system on: 2012-04-22 22:53:52
HashMap<Int, ArrayList<Entity>> entityListMap = new HashMap<Int, ArrayList<Entity>>();

As you've noticed I've been trying to make my first entity system. I just still have a few questions.

Int would be the Entity id
And Entity would be every Entity alives data?
5  Game Development / Game Play & Game Design / Re: The base of an entity system on: 2012-04-22 22:33:30
Will someone teach me how to use the HashMap array please?
6  Game Development / Game Play & Game Design / Re: The base of an entity system on: 2012-04-22 00:13:01
I'm just a little confused on how to use the HashMapArray.
7  Game Development / Game Play & Game Design / Re: The base of an entity system on: 2012-04-21 04:13:52
Could someone give me an example of one?
8  Game Development / Game Play & Game Design / Re: The base of an entity system on: 2012-04-20 17:10:13
Quote
It depends.  There are no silver bullets in computer science.  So it depends on what your skills are like, what you want to do, etc. etc.
Yeah, I understand that. I mean how should an efficient base look like.

Quote
Try to find things in common between your entities.
Their x and y coordinates?
A draw and update method?
A move method?
How about getX, getY methods?
Or you could also handle their sprites here. Animation...
If all your entities have health, why not put it here? (I wouldn't do that, I have lots of entities that are neither drawn nor have health, so I leave that for extended classes)

Ok, really I kind of figured that. I should have been more clear, I was in a hurry last night typing that.
So how should I go about IDing them? I noticed some people used a HashMap array I guess, never used one before. But is that how I would id them?

Like,
1  
2  
3  
public int getEntityX(int ID) {
return ID.x;
{


Quote
If you don't have any idea what an entity system should look like, why are you looking to write one?  Most libraries factor out common patterns that the creator is already familiar with.  If you just want to use an entity system, grab an existing implementation like Entreri

I'm trying to write one so I can learn about them now. I don't want to use any external libraries.
9  Game Development / Game Play & Game Design / The base of an entity system on: 2012-04-20 02:58:39
Hey, I've been trying to think of ways to make an entity system. I have never made one so I'm not quite sure whats efficient or not. Honestly, I don't know how the class would look. So if someone could help me out with the base of one, thanks.
10  Java Game APIs & Engines / Java 2D / Re: Loading a sprite sheet on: 2012-04-19 18:12:17
I'm still doing my best at learning, thanks for all the help.
11  Java Game APIs & Engines / Java 2D / Re: Loading a sprite sheet on: 2012-04-19 03:40:10
Thanks alex. That was it. What a silly 45 minute mistake =/.
12  Java Game APIs & Engines / Java 2D / Re: Loading a sprite sheet on: 2012-04-19 03:33:10
Loading the sprite sheet.
1  
BufferedImage spriteSheet = ImageIO.read(new File("src/spriteSheet.png"));  


What do you mean by a loader?
13  Java Game APIs & Engines / Java 2D / Loading a sprite sheet on: 2012-04-19 03:19:32
Alright so I'm having a little bit of trouble getting my sprite sheet loader to work.

1  
SSL = new SpriteSheetLoader(32, 32, 5//rows, 1//columns);


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  
31  
32  
33  
package com.akrillix.client;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class SpriteSheetLoader {
   BufferedImage spriteSheet = ImageIO.read(new File("src/spriteSheet.png"));  
   
   int width;
   int height;
   int rows;
   int columns;
   BufferedImage[] sprites = new BufferedImage[rows * columns];
   
   public SpriteSheetLoader(int width, int height, int rows, int columns) throws IOException {
      this.width = width;
      this.height = height;
      this.rows = rows;
      this.columns = columns;
     
      for(int i = 0; i < rows; i++) {
         for(int j = 0; j < columns; j++) {
            sprites[(i * columns) + j] = spriteSheet.getSubimage(i * width, j * height, width, height);
         }
      }
   }
   public void paint(Graphics g) {
      //g.drawImage(sprites[1], 100, 100, null);
   }
}


The error.

1  
2  
3  
4  
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
   at com.akrillix.client.SpriteSheetLoader.<init>(SpriteSheetLoader.java:26)
   at com.akrillix.client.GameWorld.<init>(GameWorld.java:25)
   at com.akrillix.client.Launcher.main(Launcher.java:12)


This is my sprite sheet.
14  Java Game APIs & Engines / Java 2D / Tilemap question on: 2012-04-14 05:12:03
Alright, so instead of hard coding my map into my code. I want to load it from a text file.

Wasn't too sure how to go about this, haven't done much file i/o. Thanks if you help.

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  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
package com.akrillix;

import java.awt.Graphics;
import com.akrillix.*;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;

public class Map {
   private final int TILE_SIZE = 32;
   private Image grass, dirt, water;
   public static boolean drawGrid = false;
   public static int[][] map = {
         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 0 },
         { 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 0 },
         { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 0 },
         { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };

   public Map() {
      grass = new ImageIcon("src/grass.png").getImage();
      dirt = new ImageIcon("src/dirt.png").getImage();
      water = new ImageIcon("src/water.png").getImage();
   }

   public void paint(Graphics g) {
      for (int across = 0; across < 25; across++) {
         for (int down = 0; down < 18; down++) {
            if (map[across][down] == 1) {
               g.drawImage(dirt, across * TILE_SIZE, down * TILE_SIZE,
                     null);
            } else if (map[across][down] == 0)
               g.drawImage(grass, across * TILE_SIZE, down * TILE_SIZE,
                     null);
            if (map[across][down] == 2) {
               g.drawImage(water, across * TILE_SIZE, down * TILE_SIZE,
                     null);
            }
            if (drawGrid) {
               g.drawRect(across * TILE_SIZE, down * TILE_SIZE, TILE_SIZE,
                     TILE_SIZE);
            }
         }
      }
   }
}
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (56 views)
2014-10-14 00:39:48

TehJavaDev (55 views)
2014-10-14 00:35:47

TehJavaDev (46 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!