Jump to content

I'm writing a little game in Java...

- - - - -

  • Please log in to reply
6 replies to this topic

#1
ikoniq

ikoniq

    Newbie

  • Members
  • PipPip
  • 11 posts
This is my first big project in Java, I've been with the help of advisors and artists so far, and now I'm coming to this forum for help. The game is in the form of an applet. When I tell it to run the applet in NetBeans, it doesn't run. It comes up with a gray box and sits there. My code is attached to this post in the form of a ZIP file containing the NetBeans project files, sources, etc.

[ATTACH]3866[/ATTACH]

Attached Files



#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
You have

update(g);

as last line in the paint method. that update does this (ctrl-click it in netbeans):

public void update(Graphics g) {

        if (isShowing()) {

            if (! (peer instanceof LightweightPeer)) {

                g.clearRect(0, 0, width, height);

            }

            paint(g);

        }

    }


So you have your paint method calling update, which calls paint() in there, which will again call update, paint, update, paint, ... stackoverflowerror.
Just remove that last line of update(g);

Instead, as I think it's double buffering you're attempting there, add this line as last line:

g.drawImage(bg, 0, 0, null);



If you read this before i'm awake again (going to bed now), the app can't find your images. Set your color to black and you'll see it gets painted.
(images are searched at tanks/build/classes/ but they aren't placed there upon compiling/running.
Manually copying them there works.

#3
ikoniq

ikoniq

    Newbie

  • Members
  • PipPip
  • 11 posts

wim DC said:

You have

update(g);

as last line in the paint method. that update does this (ctrl-click it in netbeans):

public void update(Graphics g) {

        if (isShowing()) {

            if (! (peer instanceof LightweightPeer)) {

                g.clearRect(0, 0, width, height);

            }

            paint(g);

        }

    }


So you have your paint method calling update, which calls paint() in there, which will again call update, paint, update, paint, ... stackoverflowerror.
Just remove that last line of update(g);

Instead, as I think it's double buffering you're attempting there, add this line as last line:

g.drawImage(bg, 0, 0, null);



If you read this before i'm awake again (going to bed now), the app can't find your images. Set your color to black and you'll see it gets painted.
(images are searched at tanks/build/classes/ but they aren't placed there upon compiling/running.
Manually copying them there works.


Thank you, that's fixed a first problem, but now another couple of problems come up. Now, for some odd reason, when it draws the tank moving, it doesn't erase the previous tank that it draws. Another issue is that when the game starts and the first shot is fired, the game crashes.

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

Quote

Now, for some odd reason, when it draws the tank moving, it doesn't erase the previous tank that it draws.
It's only for the tank, because for the planes you first redraw the background, so the previous planes get "overdrawn". For the tank, who stands below the scene that doesn't happen.
You can just paint the tank higher so it's on the ground so it will be overdrawn aswell, also looks more normal. (paint it at y-position 436) Or else before you paint everything, paint a big white square over everything.

Quote

Another issue is that when the game starts and the first shot is fired, the game crashes.
You have i instead of j there (collisiondetection()) :

for(int j = 0; [B][SIZE="5"]i[/SIZE][/B] < npc.length; j++){



#5
ikoniq

ikoniq

    Newbie

  • Members
  • PipPip
  • 11 posts
Well, that fixes those issues. Now, however, for some reason whenever anything happens, usually an object of the class EnemyBomb crosses the line of p1.xPos, it drops the lives to a negative number and the game is over. I'm not entirely sure why this happens.

[ATTACH]3867[/ATTACH]

Attached is the current code with all the changes I've made so far.

Attached Files


Edited by ikoniq, 17 May 2011 - 07:11 AM.


#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
you if-statement in the 2nd for-loop from collisiondetection is wrong.
This is correct:

if(p1.xPos <= ebomb[i].xPos - ebomb[i].width

                    && p1.xPos + p1.width >= ebomb[i].xPos

                    && p1.yPos <= ebomb[i].yPos + ebomb[i].height

                    && p1.yPos + p1.height >= ebomb[i].yPos)



#7
ikoniq

ikoniq

    Newbie

  • Members
  • PipPip
  • 11 posts

wim DC said:

you if-statement in the 2nd for-loop from collisiondetection is wrong.
This is correct:

if(p1.xPos <= ebomb[i].xPos - ebomb[i].width

                    && p1.xPos + p1.width >= ebomb[i].xPos

                    && p1.yPos <= ebomb[i].yPos + ebomb[i].height

                    && p1.yPos + p1.height >= ebomb[i].yPos)


All right, that's good. Now then, all I'm waiting on (at the moment) is for the graphics to be done. If you notice any more bugs in the code, feel free to tell me, I've been looking for a place like this to have people openly check through my code as they please without having to worry about it getting stolen (I'm not sure why one would want to steal this...but I've seen stupider things being stolen.) Again, thank you for all your help.

Also, I'd like to make it a standalone application, if I could get some help with that. I've been working with applets, now I'd like to make it not browser-dependent.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users