Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (604)
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] 2
1  Game Development / Game Play & Game Design / Re: I don't use an "elapsed time" for enemy/player movement. it's an error? on: 2006-10-03 09:14:28
How I can know If  my game runs at a fixed frame rate and if it is 30..40 etc fps?
2  Java Game APIs & Engines / Java 2D / take a sprite image from a "sprite sheet" on: 2006-09-30 17:46:47
Hi guys, I've a question:

I was looking this link:  http://sprites.fireball20xl.com/nintendo/mario/smw2/smw2badguys.gif

it's possible to acquire directly my sprites images from a sprite sheet like that?
If yes, how I can do? I've to specify the (x,y) coordinates and the width,height of the single image?
3  Game Development / Game Play & Game Design / Re: Help for my enemy chase on: 2006-09-27 07:59:49
I was thinking to give a priority when I check (x < or > player X) & (y < or > playerY)

like this:

1  
2  
3  
4  
if(Math.abs(x-px) > Math.abs(y-py)
than check (x < or > player X)
else
check (y < or > playerY)


but it's still imperfect
any ideas?
4  Game Development / Game Play & Game Design / Help for my enemy chase on: 2006-09-26 22:52:50
Hi, I've an enemy that chase my player on maze tile game.
I've implemented the bresenham algorithm, it draw a rect from the enemy to the player, if this rect collides with a tile, enemy can't see the player and false is returned, otherwise it can see and true is returned.

The bresenham algorithm work fine, but I've a problem on my chase method:

px and py are player's coordinates
x and y are enemy's coordinates
validLocation return true if my enemy can walk in that direction:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
private void chase(float px, float py)
    {
        if(x < px && validLocation(x + velocità,y))
            EAST;
        else if(x > px && validLocation(x - velocità,y))
            WEST;
        else if(y < py && validLocation(x,y + velocità))
            SOUTH;
        else if(y > py && validLocation(x,y - velocità))
            NOTH;  
       
        super.incremen();
    }


obviously this method isn't correct, for example, when I've this situation:



my ghost enemy goes to EAST, but when x > px ot goes to WEST

how I've to change the controls??

please, any suggestion??!!!!!
5  Game Development / Game Play & Game Design / Re: Problem with kev's spaceinvaders on: 2006-09-25 15:41:12
Thanks very much! now it run  Grin
6  Game Development / Game Play & Game Design / Problem with kev's spaceinvaders on: 2006-09-25 13:50:57
Hi, I've created a simple gui that call the game class of spaceInvaders game http://www.cokeandcode.com/info/showsrc/showsrc.php?src=../spaceinvaders/org/newdawn/spaceinvaders/Game.java

The problem is that I can't play the game, it doesn't reply at any key events:

this is the code from my gui where I call game:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void actionPerformed(ActionEvent e)
            {  
            Object src = e.getSource();                          
           
             if( src.equals(start) )
                {
                frameOwner.dispose();
               
                Game game = new Game();      
                g.gameLoop();
                }


start is a JButton, and frameOwner is the JFrame of the GUI
7  Java Game APIs & Engines / Java 2D / What is better for animation? on: 2006-09-24 13:56:37
Hi, I would create an animation with some frames for my game entities.

Is better to create

an Array of images
or
a single image that will contain all frames and then call methods
[CODE]
g.setClip((int)x,(int)y,image.getWidth(null) / numFrames,image.getHeight(null));         
g.drawImage(image,(int)x - frameCorrente * image.getWidth(null) / numFrames,(int)y,null);
[/CODE]

 Huh Huh
8  Java Game APIs & Engines / Java 2D / Re: Little Problem with player movement on: 2006-09-23 20:39:27
I had just understood this concept!!


also in this image I have to move the sprite to allow the movement to right, but in this case I've to remove y pixel.


My question was:

How I can determine if  I've to add or remove pixels!

I was thinking to verify where I'm trying to move, for ex: NORTH
then I check if my right superior angle of my sprite can move on this direction, I remove x pixels
else I add pixels
9  Java Game APIs & Engines / Java 2D / Re: Little Problem with player movement on: 2006-09-23 18:14:04
Little problem!!

If my player is on this case:



how I can determine that my player  was moving downward if now my direction is EST?

without this information I can't understand if add or remove pixel
10  Game Development / Game Play & Game Design / I don't use an "elapsed time" for enemy/player movement. it's an error? on: 2006-09-22 11:16:21
Hi, I've seen many game that use elapsed time to update the movement for player/enemies.
ex: 

move(long elapsedTime)

My game call move method from gameloop and entity change their position without using "elapsedTime".

Is this an error or I'm doing right?
11  Java Game APIs & Engines / Java 2D / Re: I want to create a mirror of the image on: 2006-09-18 09:42:45
why don't you use multiple images - as far as I know AffineTransform isn't hardware accalerated every time

Two images ghostleft.png and ghostright.png ??
12  Java Game APIs & Engines / Java 2D / Re: I want to create a mirror of the image on: 2006-09-18 09:31:13
the problem isn't AffineTransform!

if my character moving left, then it face left correctly!!

I've a problem when my character moving up or down, it always has "right face" 'cause my default image have "right face".
What I want is:
if my character move up or down, it keep the last  "direction face"  (if it was left, then left face .... if it was right, then right face)

I hope you understand me (english isn't my mother language  Tongue)
13  Java Game APIs & Engines / Java 2D / I want to create a mirror of the image on: 2006-09-18 07:52:27
Hi, I want  to create a mirror image effect: when the character is moving left it face left, when is moving right it face right.

The character can move also up and down, but I want only this kind of effect: left and right.
So, if my character have face left and it move up/down, it continues with face left
if the character hava face right and it move up/down, it continues with face right

this is the code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public void draw(Graphics2D g) {
         AffineTransform transform = new AffineTransform();        

            // translate the sprite
            transform.setToTranslation(x,y);

            // if the sprite is moving left, flip the image
            if (dir == dir.WEST) {
                transform.scale(-1, 1);
                transform.translate(-sprite.getWidth(), 0);
            }            
          g.drawImage(sprite.image,transform,null);          
   }


The problem is: 'cause my default image have face right, if it move left, it change to face left, but if it move up/down/right, it change to face right.

for example: character is moving left, it change to face left.. then, character is moving up/down, it change to face right.

How I can resolve this problem??
14  Game Development / Game Play & Game Design / Re: My maze game design on: 2006-09-15 18:19:35
thanks kev, but interface (as we talked) at the end isn't the good implementation cause chaseMovement and RandomMovement have differents references...

So I was thinking:  'cause random movement is the common method of  slippyEnemy and chaseEnemy, I'll implement an Enemy class that extends Entity.. this class will contains the random movement .. then i'll implements slippyEnemy and chaseEnemy that extends Enemy
Question: is better to create  two inner subclasses of Enemy???

15  Game Development / Game Play & Game Design / My maze game design on: 2006-09-15 14:04:53
Hi guys, I want explain my game design, I would appreciate any kind of comments and suggestion.

The game is a tile-map maze, with a logic similar to Pac-man:

-player
-various typologies of enemies
-bonus

I've implemented the following classes:

- the map class (contain the images of the tiles and a method called cantMove
                                that check if a particular location on the map is blocked)
- the sprite class  (contain a sprite to be displayed on the screen. don't  contains state information)
- the entity class (represents any element that appears in the game, setX().. setY().. setDirection etc..)
- the player class extends entity (is the entity that represents the player, it have also a method to check if  it collides with another entity).

for my bonus and enemies class I've littles doubts:

Bonus class:
I've three types of bonus:
  - A random positive bonus that casually appears in the map and it assigns a positive score
  - A random negative bonus that casually appears in the map and it assigns a negative score
  - A fixed bonus that player have to acquire to pass to the second level
What's is the best way to implement bonus? I was thinking to create Bonus class extends Entity
and then create 3 subclasses (randomPos, randomNeg,Dollar)... it's ok???

Enemy class:
I've two types of enemies:
  - An enemy that moves Randomly
  - An enemy that chase the player if possible, otherwise it moves randomly
So, I've implemented one enemy class that extends Entity.
I've also a Movement class with two methods: Random and Chase, if enemy type is 1 I call exclusively
Random method, otherwise, if enemy type is 2, first I call chase method and eventully Random method.
Movement class uses the "cantMove" method from map class.

I'm not sure about this last implementation (enemy, movement class).. what do you think about it?

16  Java Game APIs & Engines / Java 2D / Re: Enemy Movement strategy on: 2006-09-15 08:58:52
Ok, so: this is my chasePlayer method where I implement bresenham Algorithm

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  
public boolean chasePlayer(Map map, float startX, float startY, float endX, float endY)
    {
        p1 = new Point((int)startX, (int)startY);
        p2 = new Point((int)endX, (int)endY);
       
        boolean steep = (Math.abs(p2.y - p1.y) > Math.abs(p2.x - p1.x));
       
        if (steep)
        {
            p1 = new Point((int)startY, (int)startX);
            p2 = new Point((int)endY, (int)endX);
        }
     
        if (p1.x > p2.x)
        {
            Point temp = p1;
            p1 = p2;
            p2 = temp;
            temp = null;              
        }
       
        int deltax = p2.x - p1.x;
        int deltay = Math.abs(p2.y - p1.y);
        int error = 0;
        int ystep;
        int y = p1.y;
     
        if (p1.y < p2.y)
            ystep = 1;    
        else
            ystep = -1;
       
        for (int x = p1.x; x <= p2.x; x++)
        {
            if (steep)
            {
                if(map.cantMove(y / map.TILE_SIZE,x / map.TILE_SIZE))
                    return false;
            }
            else
            {
                if(map.cantMove(x / map.TILE_SIZE,y / map.TILE_SIZE))
                    return false;
            }                
            error = error + deltay;
            if (2*error >= deltax)
            {
                 y = y + ystep;
                 error = error - deltax;
            }
        }
       
        return true;
    }


the method return false if there is a blocked tile betwen player and enemy.

The chasePlayer is located in the "movement" class (that contain also randomMovement method).
The enemy class call chasePlayer;
if the value is false, then it call randomMovement, otherwise I verify
the x,y coordinate of enemy and player to determine the direction

Any suggestion or comment are appreciated!
17  Java Game APIs & Engines / Java 2D / Re: Enemy Movement strategy on: 2006-09-13 17:46:31
nobody has implemented this technique??

perhaps another algorithm can be "bresenham algorithm".. but, it's a right implementation for this problem?
18  Java Game APIs & Engines / Java 2D / Enemy Movement strategy on: 2006-09-12 18:27:37
Hi guys, I've created Random movement for my enemies on a tilemap.
Now I want that some enemies can "see" the player and therefore follow it.

For this reason I make a straight line from my enemy to my player.
The line can
hits obstacles (blocked tiles) so enemy can't see the player and implement random movement
don't hits obstacles so enemy can see the player and follow it.

to trace the straight line I've  thought this code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
float startX, startY, endX, endY
float p, xp, yp;

startX = enemy.getX();
startY = enemy.getY();
endX = player.getX();
endY = player.getY();

p = ((float) endY - startY) / (endX - startX);

        for (x=startX; x<=endX; x++)
        {
            xp = x;
            yp = startY + (x - startX) * p;
            map.canMove(xp / map.TILE_SIZE, yp / map.TILE_SIZE);
        }


this code can trace only lines where x is positive.

you can suggest me any other solution??

I think there can be something better!
19  Java Game APIs & Engines / Java 2D / Re: Little Problem with player movement on: 2006-09-12 16:27:38
so, when I move my player I check if the new location is accessible or blocked.
if it's blocked I check if the image's center can move in that direction.
if yes I'll add the amount of pixel necessary to move the player in the desidered direction.
20  Java Game APIs & Engines / Java 2D / Little Problem with player movement on: 2006-09-12 14:34:37
Hi, my game is a maze with tiles, their dimension is 32*32 pix.

'cause my player sprite is 32*32.. when I move it I've some problem to pass through the corridors
if the sprite is not perfectly positioned.

How I can resolve this drawback using 32*32 images size??
21  Game Development / Newbie & Debugging Questions / a* algorithm path finding on: 2006-09-10 18:35:32
Hi, I've implemented a class of Enemies (enemygood) with random movement.
Now I want to implement a new class of Enemies (enemyhunter) that chase the player with an A* algorithm:
http://www.policyalmanac.org/games/aStarTutorial.htm

I've writed the Node class, it represent a single node from the map, on this class I've:

- The x coordinate of the node
- The y coordinate of the node
- The cost of the node
- The precedent node

Now, I want to know if it's correct to write the rest of A* algorithm  in a new class (for example AI class)
or I can write it into the enemyhunter class??
22  Game Development / Newbie & Debugging Questions / Re: enemy movement on: 2006-09-09 15:22:05
Ok Thanks!!

So i'll write the first option!
23  Game Development / Newbie & Debugging Questions / enemy movement on: 2006-09-08 16:30:23
It's better let the movement to be handled by our Enemies class, like this:

Game class
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  
public class Game()
{
    ............
    public class loop()
    {
              enemy.move(delta);
    }
}
[/CODE]

Enemy class
[CODE]
public class Enemy()
{
     public void move(long delta)
     {
          oldX = this.getX();
          oldY= this.getY();

          //movement

          this.setX(........);
          this.setY(........);
     }
}


or put some control on the loop in the main class like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class Game
{
     .......
     public void loop()
     {
            oldX = enemy.getX();
            oldY = enemy.getY();
            enemy.move(delta,oldX,oldY);
            enemy.setX(......);
            enemy.setY(......);
     }
}


Enemy class:

1  
2  
3  
4  
5  
6  
7  
public class Enemy
{
      public class move(long delta,float x,float y)
      {
                //movement
      }
}
24  Java Game APIs & Engines / Java 2D / Ghost movement on pacman game on: 2006-09-07 14:58:35
Hi, I'm doing a maze game like pacman and I'm writing the ghost class.

My question is: if I want that ghosts moves to the player direction what I've to do?
My solution is

a - compare the x and y values of ghosts and player
      if(ghost.x > player.x) OVEST movement else EST
      if(ghost.y > player.y) NORD movemente else SUD
      and add this directions into preferredDir list

b - check all the possible directions of movement  EST(x+1,y), OVEST(x-1,y), SUD(x,y+1), NORD(x,y-1)
     and add this directions into  possibleDir list

c - I compare the preferredDir list with possibleDir and
     no match - i'll choose a casual direction from possibleDir
     1 match - i'll choose this direction
     2 match - i'll choose a casual direction from preferredDir

It's correct??


25  Game Development / Newbie & Debugging Questions / Re: Animation Class on: 2006-09-06 09:00:04
that methods were taken from "new Riders developing java game".... I don't use threads so my methods don't have "synchronized" (forgive me the mistake  Wink)

Now I've a small doubt:  the SpriteStore class have a

[CODE]public Sprite getSprite(String ref)[/CODE]
that return a Sprite and ref  is the reference to the image to use for the sprite

The  addFrame method from Animation class is:

[CODE] public void addFrame(Image image,long duration) [/CODE]

so, if I extends Animation from Sprite I've to modify addFrame, it's correct??
26  Game Development / Newbie & Debugging Questions / Animation Class on: 2006-09-05 22:43:25
Hi, I'm writng my first maze game.

I've based my project from the http://www.cokeandcode.com tutorials (spaceinvaders and tilemaps)

So, I've a Game class, Sprite, SpriteStore, Entity,Enemy,Player and Bonus

Now I want to create an animation (like cartoons) for Entity and bonus objects;  I think that a good idea is to create a class like the Animation class from "new riders java game developers" book.
The Animation class will extends the sprite class and contain this methods:

1  
public synchronized void addFrame(Image image,long duration)

Adds an image to the animation with the specified duration (time to display the image).

1  
public synchronized void start()

Starts this animation over from the beginning.

1  
public synchronized void update(long elapsedTime)

Updates this animation's current image (frame), if neccesary.

1  
public synchronized Sprite getImage()

Gets this Animation's current image. Returns null if this animation has no images.

The sprite class is the original class from Spaceinvaders tutorial http://www.cokeandcode.com/info/showsrc/showsrc.php?src=../spaceinvaders/org/newdawn/spaceinvaders/Sprite.java

The constructor of Animation is:
[CODE] public Animation(ArrayList frames, long totalDuration) [/CODE]

so, in the Sprite class I've add an empty constructor

What do you think?? it's a good idea??

27  Game Development / Newbie & Debugging Questions / Re: Enemy movement on: 2006-08-06 17:13:48
Hi, I've founded this code from the game Taleban vs Robot

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  
class Fish extends SJGSprite
{
   
   
    public void move()
        {
            if(count == 0)
            {
                int i = d;
                do
                    switch((int)(4D * Math.random()))
                    {
                    case 0: // '\0'
                        dx = 1;
                        dy = 0;
                        d = 0;
                        break;

                    case 1: // '\001'
                        dx = 0;
                        dy = 1;
                        d = 1;
                        break;

                    case 2: // '\002'
                        dx = -1;
                        dy = 0;
                        d = 2;
                        break;

                    case 3: // '\003'
                        dx = 0;
                        dy = -1;
                        d = 3;
                        break;
                    }
                while(!maze.canMove(this, getX() + dx, getY() + dy) || Math.random() > 0.10000000000000001D && d != i);
            }


the maze.canMove method is:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
public boolean canMove(SJGSprite sjgsprite, double d1, double d2)
    {
        double d3 = sjgsprite.getWidth();
        double d4 = sjgsprite.getHeight();
        double d5 = d1 - d3 / 2D;
        double d6 = d2 - d4 / 2D;
        for(int i = Math.max((int)Math.floor(d5 / (double)blockWidth), 0); i <= Math.min((int)Math.floor(((d5 + d3) - 1.0D) / (double)blockWidth), width - 1); i++)
        {
            for(int j = Math.max((int)Math.floor(d6 / (double)blockHeight), 0); j <= Math.min((int)Math.floor(((d6 + d4) - 1.0D) / (double)blockHeight), height - 1); j++)
                if(maze[i][j].isSolid())
                    return false;

        }

        return true;
    }

 
what does mean this line code?Huh?

1  
for(int j = Math.max((int)Math.floor(d6 / (double)blockHeight), 0); j <= Math.min((int)Math.floor(((d6 + d4) - 1.0D) / (double)blockHeight), height - 1); j++)



What do you think about this code??
Anyone know something better?
28  Game Development / Newbie & Debugging Questions / Re: Enemy movement on: 2006-08-04 16:09:37
ok, thanks
29  Game Development / Newbie & Debugging Questions / Re: Enemy movement on: 2006-08-02 10:45:20
I know how move the player
I'm interested on the movement of enemy  Sad
I want to move it on all possible directions.

nobody has done a maze game with tilemap??
30  Game Development / Newbie & Debugging Questions / Re: Enemy movement on: 2006-08-01 09:11:28
1  
2  
3  
4  
5  
....
......
.........
}
move(direction);


Bad bad code.

If he cannot move in any direction, your game locks up in an infinite loop.


So, why anybody don't post others code's examples?

I've a class TileMap that contains the data for a tile-based map, including Sprites..
with methods that gets width and height of the map,
getTile, setTile, addSprite, getSprite and
public boolean canMove(int x, int y) where I check if there is a blocked tile or not.

In the class ResourceManager I've the
void updateCreature(Creature creature, long elapsedTime)
where I calculate new value of x and y position

In the class Enemy I've the move method.

So, the control if a tile is blocked or not (with public boolean canMove(int x, int y) method)
it must have done in the enemy class or in the ResourceManager class?
Pages: [1] 2
 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (27 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (96 views)
2014-12-08 04:46:31

JscottyBieshaar (56 views)
2014-12-05 12:39:02

SHC (72 views)
2014-12-03 16:27:13

CopyableCougar4 (74 views)
2014-11-29 21:32:03

toopeicgaming1999 (134 views)
2014-11-26 15:22:04

toopeicgaming1999 (125 views)
2014-11-26 15:20:36

toopeicgaming1999 (35 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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