Show Posts
|
|
Pages: [1] 2
|
|
3
|
Game Development / Game Play & Game Design / Re: Help for my enemy chase
|
on: 2006-09-27 09: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-27 00: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??!!!!!
|
|
|
|
|
7
|
Java Game APIs & Engines / Java 2D / What is better for animation?
|
on: 2006-09-24 15: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] 
|
|
|
|
|
8
|
Java Game APIs & Engines / Java 2D / Re: Little Problem with player movement
|
on: 2006-09-23 22: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
|
|
|
|
|
12
|
Java Game APIs & Engines / Java 2D / Re: I want to create a mirror of the image
|
on: 2006-09-18 11: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  )
|
|
|
|
|
13
|
Java Game APIs & Engines / Java 2D / I want to create a mirror of the image
|
on: 2006-09-18 09: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();
transform.setToTranslation(x,y);
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 20: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 16: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 10: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!
|
|
|
|
|
18
|
Java Game APIs & Engines / Java 2D / Enemy Movement strategy
|
on: 2006-09-12 20: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!
|
|
|
|
|
20
|
Java Game APIs & Engines / Java 2D / Little Problem with player movement
|
on: 2006-09-12 16: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 20: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.htmI'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??
|
|
|
|
|
23
|
Game Development / Newbie & Debugging Questions / enemy movement
|
on: 2006-09-08 18: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();
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) { } } |
|
|
|
|
|
24
|
Java Game APIs & Engines / Java 2D / Ghost movement on pacman game
|
on: 2006-09-07 16: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 11: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  ) 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-06 00: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.javaThe 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 19: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: dx = 1; dy = 0; d = 0; break;
case 1: dx = 0; dy = 1; d = 1; break;
case 2: dx = -1; dy = 0; d = 2; break;
case 3: 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?  ? 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?
|
|
|
|
|
30
|
Game Development / Newbie & Debugging Questions / Re: Enemy movement
|
on: 2006-08-01 11: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?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|