hello,
i found alot game tutorial about the game tutorial..
but i cant totally understand wat they post.. lolz...
so may i ask got some source code for me to do some revision?
if can better that game is using mouse to play..
Thank you very much
Need help in my final project - java 2d game
Page 1 of 18 Replies - 1901 Views - Last Post: 28 July 2009 - 09:40 PM
Replies To: Need help in my final project - java 2d game
#2
Re: Need help in my final project - java 2d game
Posted 23 July 2009 - 11:12 PM
im no pyschic but ur gonna fail this one
#3
Re: Need help in my final project - java 2d game
Posted 24 July 2009 - 02:13 AM
Hi fakuatlong
Giving you source code would not help you at all, it is highly unlikely that it would be what you are looking for, and if you decided to change it you wouldn't know where to start. Especially because you couldn't understand some beginners tutorials.
Your best bet if you are at school is to talk to your teacher and explain that your having problems, maybe he can point you in the right direction, or explain in more detail what it is you are trying to achieve so that we can be of more help to you.
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Please post like this:
Thank you for helping us helping you.
Giving you source code would not help you at all, it is highly unlikely that it would be what you are looking for, and if you decided to change it you wouldn't know where to start. Especially because you couldn't understand some beginners tutorials.
Your best bet if you are at school is to talk to your teacher and explain that your having problems, maybe he can point you in the right direction, or explain in more detail what it is you are trying to achieve so that we can be of more help to you.
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Please post like this:
Thank you for helping us helping you.
#4
Re: Need help in my final project - java 2d game
Posted 27 July 2009 - 06:09 AM
I'm so sorry... please forgive my stupid question...
i should ask my problem 1 by 1... lolz...
1st question... how to i change my mouse cursor with image?
here is my code..
when i run the program it doesn't work... it didnt show the image on the frame... izzit i do something mistake??
2nd question... how to i delete or remove the image from the game?
izzit using the dispose() function?
Thank you very much
i should ask my problem 1 by 1... lolz...
1st question... how to i change my mouse cursor with image?
here is my code..
Image cursorImage = Toolkit.getDefaultToolkit().getImage("number1.gif");
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point( 0, 0), "" );
setCursor( blankCursor );
when i run the program it doesn't work... it didnt show the image on the frame... izzit i do something mistake??
2nd question... how to i delete or remove the image from the game?
izzit using the dispose() function?
Thank you very much
#5
Re: Need help in my final project - java 2d game
Posted 27 July 2009 - 07:52 AM
#6
Re: Need help in my final project - java 2d game
Posted 27 July 2009 - 11:11 AM
there are some complete examples for basic java games
here is one I found using google:
Java Game Source Code
here is one I found using google:
Java Game Source Code
#7
Re: Need help in my final project - java 2d game
Posted 28 July 2009 - 04:59 AM
bobjob, on 27 Jul, 2009 - 10:11 AM, said:
there are some complete examples for basic java games
here is one I found using google:
Java Game Source Code
here is one I found using google:
Java Game Source Code
thanks you coz ur reply...
that tutorial i already read before... but it too hard to understand...
can i have another tutorial which similar with this??
thank you very much
#8
Re: Need help in my final project - java 2d game
Posted 28 July 2009 - 06:50 AM
Lesson learned here is bobjob used this site:
www.google.com
So getting your entire project done isnt going to be easy as ctrl+C, ctrl+V. If java confuses you there are hundreds of very simple tutorials both on this site and the aforementioned. As you get confused we will help you with each part, but no one is going to bend over backwards to find you all of your work.
www.google.com
So getting your entire project done isnt going to be easy as ctrl+C, ctrl+V. If java confuses you there are hundreds of very simple tutorials both on this site and the aforementioned. As you get confused we will help you with each part, but no one is going to bend over backwards to find you all of your work.
#9
Re: Need help in my final project - java 2d game
Posted 28 July 2009 - 09:40 PM
OK here is mine full coding...
i got few question need to ask...
1st question: why my mouse cursor didnt change to the image?
2nd question: why i cant play the sound? the program was run but without the sound...
3nd question: how to i delete the picture in check_hit ? using dispose() will remove whole frame... i just need to delete the current picture which hit by player...
Thank you very much
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import javax.sound.sampled.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class Level3 extends Frame implements MouseMotionListener, MouseListener
{
Image Background;
Image User;
Image Police;
int posX=0;
int posY=0;
public BufferedImage buffer;
Cursor c;
public Level3 ()
{
Image cursorImage = Toolkit.getDefaultToolkit().getImage("number1.gif");
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point( 0, 0), "" );
setCursor( blankCursor );
c = new Cursor (Cursor.CROSSHAIR_CURSOR);
this.setCursor (c);
int WIDTH=500;
int HEIGHT=600;
setTitle("Thief");
setSize(WIDTH, HEIGHT);
buffer = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
setVisible(true);
loadImage();
addMouseListener( this );
game();
}
public void game()
{
while(true)
{
updateWorld();
paintWorld();
repaint();
try{
Thread.sleep(1000);
} catch (InterruptedException e) {}
}
}
public BufferedImage loadImage()
{
Background=loadImage("city.jpg");
Police = loadImage("icon-police.gif");
User = loadImage("number1.png");
return null;
}
private Image loadImage(String fileName)
{
return new ImageIcon(fileName).getImage();
}
public void paintWorld()
{
Graphics g=buffer.getGraphics();
g.fillRect(0,0,getWidth(),getHeight());
drawImage(g,Background,0,0,null);
drawImage(g,Police,posX, posY,null);
}
public void paint(Graphics g) //function which paint the image
{
g.drawImage(buffer,0,0,this);
}
public void drawImage(Graphics g, Image image, int x, int y, String caption)
{
g.drawImage(image, x,y,null);
}
public void updateWorld()
{
posX=(int)(Math.random()*450);
posY=(int)(Math.random()*500);
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void playSound()
{
try{
File tadaSound = new File(System.getenv("windir") + "/" + "gun_fire.wav");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new FileInputStream(tadaSound));
AudioFormat audioFormat = audioInputStream.getFormat();
DataLine.Info dataLineInfo = new DataLine.Info(Clip.class, audioFormat);
Clip clip = (Clip) AudioSystem.getLine(dataLineInfo);
clip.open(audioInputStream);
clip.start();
} catch(Exception e)
{}
}
public void mouseClicked(MouseEvent e)
{
int ex = e.getX();
int ey = e.getY();
playSound();
if(check_hit(ex, ey))
{
dispose();
}
}
public boolean check_hit(int manus_x, int manus_y)
{
double diffX = manus_x - posX;
double diffY = manus_y - posY;
double distance = Math.sqrt ((diffX*diffX) + (diffY*diffY));
if(distance<80)
{
return true;
}
else return false;
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseDragged(MouseEvent e)
{
}
public void mouseMoved(MouseEvent e)
{
}
}
i got few question need to ask...
1st question: why my mouse cursor didnt change to the image?
2nd question: why i cant play the sound? the program was run but without the sound...
3nd question: how to i delete the picture in check_hit ? using dispose() will remove whole frame... i just need to delete the current picture which hit by player...
Thank you very much
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote








|