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 (575)
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 3 4
1  Game Development / Newbie & Debugging Questions / Re: Referencing Files within Src on: 2013-04-11 07:40:43
yer I tried that just before you posted and it still wouldn't work, then the solution hit me:

such a fail mistake, replaced "." with "/" and now it finds the file.

probably couldn't find the file, because I was POINTING IT AT A NON-EXISTENT FILE :\

noob.
2  Game Development / Newbie & Debugging Questions / Referencing Files within Src on: 2013-04-11 07:07:29
Trying to initialise an image object using the following:

1  
land = new Image("com.westloar.testing1/assets/land.jpg");


land.jpg is in the following file structure:

testing1/src/com.westloar.testing1/com.westloar.testing1.assets

I realise this is such a noob question but I can't seem to work out why it can't find the image :|
3  Game Development / Newbie & Debugging Questions / Vector Drawing? on: 2013-01-28 09:49:32
I have imported the following Vec2 class into my project:

http://www.johnloomis.org/ece538/notes/java1/Vec2.java.html

I'm currently playing with the use of vectors as I am new to them.

I can't seem to get the vector to draw using the Vec2.draw() method unless it is left in it's constructed default position (0,0).

This is my code:

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  
public class Avatar extends Sprite
{
    protected int hitPoints;
    protected int attackTime = 100; //ms
    protected int strength;
    protected boolean isAttack = false;
    Vec2 normal = new Vec2(posX, posY);

    public Avatar (int x, int y, int w, int h, int s, int hp, int str){
    super(w/2, h/2, w, h, s);
    hitPoints = hp;
    strength = str;
    }
    public void moveLeft()
    {posX-=step;}

    public void moveRight()
    {posX+=step;}

    public void moveUp()
    {posY-=step;}

    public void moveDown()
    {posY+=step;}

    public void attack(){
        if(isAttack)
        {isAttack = false;}
        else
        isAttack = true;
        System.out.println(normal.length());
    }

    public void isHit(int str){
        hitPoints-=str;
        if(hitPoints<= 0){
            this.dead();
        }//endif
    }

    public void dead(){
        //called when player hp <=0
    }
@Override
public void drawSprite(Graphics g){
   
        if(isAttack){
        g.setColor(Color.blue);
        g.fillOval(posX - 10, posY - 10, 30, 30);
        g.setColor(Color.black);
       
       }
        if(isActive()){
        g.setColor(Color.orange);
        g.fillOval(posX, posY, 10, 10);
        g.setColor(Color.black);
        }
         normal.draw(g);
}

}


I have checked its length with a print line and it returns two every time but does not draw to the canvas, I called its draw() method last to ensure it is drawn last (on top), but that doesn't seem to make a difference.

Any help would be much appreciated Smiley
4  Game Development / Game Mechanics / Re: Heuristic Path Finding on: 2013-01-25 14:26:15
I have simplified the path finding to make it easier for me to code as this is my first from scratch project.

So using my pathfinding method the enemy object would be constrained to one of the 8 directions.

All I really want at the moment is to get a rudimentry pathfinding algorithm working so that the enemies move towards the player character with roughly the shortest path on every call of enemy.update().

So does my pseudo code look like it would achieve that?
5  Game Development / Game Mechanics / Re: Heuristic Path Finding on: 2013-01-25 14:14:25
That's what I thought I just needed some clarification, here's some pseudo code of my thinking so far:

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  
private double dx;
private double dy;
private float distance;
private float smallDistance = 1000.0f;
ArrayList moveList = new ArrayList;

Point currentPos = new Point;
Point move = new Point;

Point nw = new Point;
Point n = new Point;
//... create points for each direction

currentPos.setX(enemy.posX);
currentPos.setY(enemy.posY);

nw = (currentPos.translate(-step,-step))
n = (currentPos.translate(0,-step))
//...set values for each direction.


moveList.add(nw);
moveList.add(n);
//...add all directions to list

for(i=0; i < moveList.size(); i++){
dx= (player.getX() - moveList[i].getX();
dy= (player.getY() - moveList[i].getY();

distance = sqrt((dx*dx) + (dy*dy));

if(distance < smallDistance){
smallDistance = distance; //if current point has shortest distance from Player set smallDistance = distance
move.setLocation(moveList[i]); //set the final move position to current point
}//endif
}//end for
6  Game Development / Game Mechanics / Re: Heuristic Path Finding on: 2013-01-25 12:53:36
It's less that I need an understanding of path finding and more the implementation of it in Java.

I'd really appreciate being pointed to a article about using vectors in Java.
7  Game Development / Game Mechanics / Re: Heuristic Path Finding on: 2013-01-25 11:38:06
Read a little more into it and I'm going to use pythagoras to calculate the difference between points, thanks for the help Smiley
8  Game Development / Game Mechanics / Re: Heuristic Path Finding on: 2013-01-25 10:51:01
Having never really used vectors before, could you point me to a good resource?
9  Game Development / Game Mechanics / Heuristic Path Finding on: 2013-01-25 10:35:43
My game is a top down 2d twin stick hack n slash.

I have an enemy object that I want to continuously move towards the player object. I figured a simplified version of Heuristic pathfinding would be the best way to do this whereby every time enemy.update() is called the following happens:

 
  • Create a point for each of the cardinal directions (N, NE, E...etc) around the enemy object at a distance of one Step(predefined movement amount in pixels) away from the enemy object
  • Loop through these and check which point would make the enemy object closer to the PC
  • Move the enemy object in that direction

My thoughts on how to do this are to create an ArrayList containing the possible movement directions then subtract the elements from the player position in turn to give the distance from the player, then select the smallest distance as the direction the object moves.

In terms of implementation I am not sure whether to use points or vectors. I have done a little research and found nothing that implies I can use mathematical operators on points, is this possible? And if not should I use vectors and can someone point me to a resource on how to implement this?

Thanks in advance Smiley
10  Game Development / Game Mechanics / Re: Point Indexing on: 2013-01-13 01:28:56
Essentially the pc swings a sword in 180 degree arc infront of himself and I want to check which enemy mobs i.e. the points are in said arc.

I would imagine there could be 10 - 20 mobs on the screen at a time.

I'm not so hot with my maths so wasn't sure if I would have to do some calculations based ona circle and then work out if the mobs were in the top half of the circle i.e. within the sword swing or if there is maths that allows you to just work with semicircles.

I figured that you would have to at some level query all the points on screen to discover if they were in the circle, so the max points in a query would be the same as the number of points on screen.

The max number of queries per frame is like to be very small as it will be limited by the amouint of times the pc can swing, possibly 1 a second or less.
11  Game Development / Game Mechanics / Re: Point Indexing on: 2013-01-12 19:16:04
The code you posted is essentially my algorithm, I don't think I explained with enough clarity in my first post.

The question I was asking is should I filter the points that definitely could not be within the semi-circle i.e. have a distance from the origin of the circle bigger than it's radius and then run the algorithm on the points that could be in the circle.

OR

Is it more efficient to just iterate through all points with the algorithm?


Also I realise that the better method would be to use radians (I don't understand these yet), but would the following work to determine whether a point within the circle is in the top semicircle or bottom semicircle:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
A = Answer
P = Point (x,y)
C = Circle Origin (x,y)

P = (P - C)
C = (C - C)

A = (C - P)

If A is -ve then P lies within the top half of the circle.

If A is +ve then P lies within the bottom half of the circle.


This is obviously not in Java, it is more of a mental exercise.
12  Game Development / Game Mechanics / Point Indexing on: 2013-01-12 16:43:36
I have the algorithm for determining whether a specific point is within the area of a semi-circle, but which is the more efficient way of determining whether multiple points lay within that area:

a) Running through each of the points and discounting those that couldn't possibly be within the circle i.e. are much further away from the origin of the circle than the length of radius or diameter. Then creating an index or array of the points that could be within the circle and running the algorithm.

OR

b) Just running the algorithm on all points
13  Game Development / Newbie & Debugging Questions / Re: java 7 issue on: 2012-06-04 09:52:34
not sure how it could be infected before it exists? Or will it infect it as it's installing?

I don't believe it could be a conflict as there are no traces of java left on this machine
14  Game Development / Newbie & Debugging Questions / Re: java 7 issue on: 2012-06-03 10:16:15
Ok thanks, scanned my computer and it seems clean as well, I've been having issues with Java for a while, I thought I'd try and sort it out, kinda wish I hadn't now Tongue
15  Game Development / Newbie & Debugging Questions / Re: java 7 issue on: 2012-06-03 09:41:37
wow so no one on the internet knows a solution?
16  Game Development / Newbie & Debugging Questions / java 7 issue on: 2012-06-02 21:34:15
I know this is probably not the right place for it, but anyhow:

I have a problem with java, though up to date, it says I need to update my plugin, it is enabled in my browser and apparently up to date.

So I uninstalled java RE and attempted to re-install, I get an error message:

Java has found a problem with a file:

fx -runtime.exe

And it won't install because of this, help!?
17  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-20 21:58:33
thanks, that's really helpful for when I figure out what the hell is going on with the boomerang inexplicably starting from the wrong position and travelling in the wrong direction.

I'm going to try using floats for my co-ordinates and see if that makes any difference.
18  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-18 18:14:26
well for now just a diagonal line, at the moment a lot of the code is place holder while I get everything together, the issue is the code isn't working properly.

The boomerang is supposed to calculate its path from the centre of the player (I think I know why it doesn't do that) towards the position of the mouse pointer when boomerang.fire() is called.

If you check the diagram (if you can call it that Tongue) above it shows that when mouse pointer is up and to the right of the player not only does the boomerang start above and to the left of the player (wrong) it then travels diagonally downwards(wrong), whereas it is supposed to travel diagonally upwards to the right i.e. towards the position of the mouse pointer.
19  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-18 17:54:13
Yer, I totally get that, I am a noob at Java, but I have read a couple of books and while that was a while ago I have retained some of the knowledge, I just can't get my head around the behaviour of the boomerang and how using floats as opposed to Points will change that?
20  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-18 10:26:03
Ok, so I've added the code you suggested, I'll code in the calculation of the Y path when I've fixed the problem that my boomerang travels diagonally downwards, any suggestions especially as changing the operator like so:

From:

1  
boomPath[i+1] = new Point((boomPath[i].x - nodeLength), (boomPath[i].y - nodeLength));


To:

1  
boomPath[i+1] = new Point((boomPath[i].x + nodeLength), (boomPath[i].y + nodeLength));


makes no difference whatsoever!?
21  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-18 01:12:00
you know when you're really tired and you say things that are silly because you are really tired and say silly things that are silly.

Yes, I have done that, of course I need a different Y value worked out from the angle of the mouse pointer relative to the X perpendicular (also still tired so that may sound like crap, but again I know what I mean Tongue)

I'm glad you've brought that to my attention, but the main problem still remains, what the hell is going on!?
22  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-17 23:49:52
If I want to calculate a path with a 1:1 ratio i.e:



(I realise that triangle does not have a 1:1 ratio)

surely the X and Y would need to be the same.

Also, why does my boomerang travel on a path diagonally downwards whether I add or subtract nodeLength, surely, even if my game logic, so to speak, is flawed, changing whether the value is added or subtracted should change the vertical direction of the path?
23  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-17 23:26:30
nodeLength is essentially the distance between each node, may be confusingly named, but I know what I mean and ultimately that's all that matters as this is a one man project Tongue

what I think I'm doing is:

The next node is at the X position of the current node - the nodeLength and at the Y postion...etc.
24  Game Development / Newbie & Debugging Questions / Re: Raycasting on: 2012-05-17 23:19:30
I have nothing to add to this post except for this, gouessej:

BOOM TRIPLE WORD SCORE!
25  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-17 23:15:48
Ok so Orangy Tang here's a rough approximation of what currently happens when you throw the boomerang:



The green line is the path that the boomerang takes, the red cross is the mouse pointer position at time of throwing the boomerang.

I have tried subtracting the nodeLength from the X and Y co-ord (line 67) as I having read up on Java's co-ord system, it seems to use a system by which 0,0 is the top left of the screen. Confusingly whether I add or subtract nodeLength the boomerang still takes a downwards diagonal path.
26  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-17 23:08:04
Yes but before

1  
boomPath[i+1] = nextPoint;


nextPoint is calculated for every iteration:

1  
nextPoint.setLocation((boomPath[i].x - nodeLength), (boomPath[i].y - nodeLength));
27  Game Development / Newbie & Debugging Questions / Re: A co-ordinate problem. on: 2012-05-16 14:40:07
how so?
28  Game Development / Newbie & Debugging Questions / A co-ordinate problem. on: 2012-05-16 09:49:46
OK so this may be a long a complicated problem, I have made a Boomerang class (yes it's that guy) that determines the boomerangs start point by getting the X,Y position of the player and then modifying these co-ords so the boomerang will appear from the centre of the player.

First problem: It doesn't, it appears significantly higher and to the left of the player.

The class then creates the path of the boomerang and stores it in a point array and every time the sprite is updated moves it to the next point in the array.

Second problem: Although it does move in a straight, diagonal line, it moves vertically down from the start point, even though the path is calculated by adding X,Y positions to the last "node" of the path.

I will post the class and see if you can make head or tails of where the problem is coming from, part of me thinks that it may be using points to store the X,Y co-ords, as these use Java's co-ordinate system and points aren't used throughout the rest of the code. I wanted someone else's opinion before I rewrite the class or the rest of the engine to use or not to use points.

Here's the 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  
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  
public class Boomerang extends Sprite
{
    private static double DURATION = 0.5;  // secs
    // total time to cycle through all the images
    private int period;    // in ms; the game's animation period
    private BricksManager brickMan;
   
    private int speed; //used to calculate how many nodes to create along the
                       //boomerangs path.
    protected int locx, locy;
    private Boolean isVisible;
    private JumperSprite rat;
    private Point startPoint = new Point();
    private Point nextPoint = new Point();
    private int nodeLength;
    private int nodes = 0;
    private Point[] boomPath;
   
public Boomerang (int x, int y, BricksManager bm, ImagesLoader imsLd, int p, String name, JumperSprite js)
{
super(x, y, 30, 32, imsLd, "Boomerang");
 
locx = x;
locy = y;
super.setImage(name);
speed = 3;
period = p;
isVisible = false;
rat = js;
boomPath = new Point[20];
    }

public void fire(){
    int x;
    int y;
    int ratx = rat.getXPosn();
    int raty = rat.getYPosn();
    System.out.println("ratx:" + ratx);
    System.out.println("raty:" + raty);
   
    Point endp = new Point();
    int midx = rat.getWidth()/2; //get the mid point of rat' sprite
    //System.out.println("midx:" + midx);
    int midy = rat.getHeight()/2;
    //System.out.println("midy:" + midy);
    startPoint.setLocation((ratx + midx), (raty - midy));
    //set the start of boomPath to the mid
    //positions.
    //System.out.print("startPoint original" +startPoint);
    boomPath[0] = startPoint;
   
    PointerInfo MousePosn = MouseInfo.getPointerInfo();
   
    endp = MousePosn.getLocation();
   
    nodeLength = (int) (startPoint.distance(endp)/(20-speed));
    //System.out.println();
    //System.out.println("nodeLength:" + nodeLength);
    //cut the distance into equal segments to increment boomPath
   
    for(int i = 0; i<(20- speed); i++){   //add points to boomPoint using nodeLength increments
        //System.out.println();
        //System.out.println("boomPath[0].x:" + boomPath[0].x);
        //System.out.println();
        //System.out.println(i + 1);
       
        nextPoint.setLocation((boomPath[i].x - nodeLength), (boomPath[i].y - nodeLength));
       
        boomPath[i+1] = nextPoint;
       
       
        //System.out.println();
        //System.out.println("boompath[" + i + "]:" + boomPath[i]);    
       
    } //end of for loop
   
    isVisible = true;
   
           
  }//end of fire()

public boolean isVisible(){
    return this.isVisible;
}

public void update() {
   if(isVisible){
       if(nodes < boomPath.length){
       locx = boomPath[nodes].x;
       
       //System.out.println("boomPath[" + nodes + "]" + "locx:" + locx);
       locy = boomPath[nodes].y;
       //System.out.println("boomPath[" + nodes + "]" + "locx:" + locy);
       nodes ++;
        }
       }
    }//end of update()
   


}//end of Boomerang


Cheers for any help you can give me Smiley
29  Game Development / Newbie & Debugging Questions / Re: Addition using Point objects on: 2012-04-28 11:34:10
SOLVED!

Point.x returns the x value as an int.

also, I'M AN IDIOT.
30  Game Development / Newbie & Debugging Questions / Re: Addition using Point objects on: 2012-04-28 11:30:28
which was my first solution but point.getX() returns a double so you can't add an int to it
Pages: [1] 2 3 4
 

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 (33 views)
2014-10-17 03:59:02

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

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

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

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

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

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

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

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

BurntPizza (74 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!