|
| 11 Oct 2013 08:17 AM |
Ok i am making my first simple java game everything goes right with my x and y but when i get to my collision check with the enemy and me for some reason it does not register the x and y correctly
PLEASE DO NOT STEAL MY CODE ALL CODE IS MADE BY ME AND ME ONLY!
package javaapplication1;
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;
import javax.swing.*;
/** * * @author jayden */ public class Chaser extends JFrame implements ActionListener{ /* * This is just making JButtons and JPanels ignore look to buttom */ public JButton up, down, left, right,exit; public JPanel playingField , grid3 = new JPanel(); public JPanel grid1 = new JPanel(), grid2 = new JPanel(); public double enemyX=400, enemyY=400, enemyXVel=0, enemyYVel=0, enemyR=10; public double myX=40, myY=40, myXVel=0, myYVel=0, myR=10; public Chaser(){ /* * Constructor */ super(); this.setSize(500,500); this.setExtendedState(MAXIMIZED_BOTH); this.setVisible(true); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLayout(new GridLayout(1,2)); grid1.setLayout(new GridLayout(3,1)); grid2.setLayout(new GridLayout(1,2)); grid3.setLayout(new GridLayout(1,2)); up = new JButton("UP"); up.addActionListener(this); up.setBackground(Color.yellow); grid1.add(up); grid1.add(grid2); down = new JButton("DOWN"); down.addActionListener(this); down.setBackground(Color.yellow); grid1.add(down); left = new JButton("LEFT"); left.addActionListener(this); left.setBackground(Color.yellow); grid2.add(left); right = new JButton("RIGHT"); right.addActionListener(this); right.setBackground(Color.yellow); grid2.add(right); playingField = new JPanel(); playingField.setBackground(Color.WHITE); grid3.setBackground(Color.WHITE); this.add(grid1); this.add(playingField); while(true){ this.collisionCheck(); this.updatePos(); } } //main function public static void main(String[] args) {new Chaser();} //action performed: computer goes here everytime a buton is pressed. @Override public void actionPerformed(ActionEvent ae) { if(ae.getSource().equals(up)){ myXVel -= .001; } if(ae.getSource().equals(left)){ myYVel -= .001; } if(ae.getSource().equals(right)){ myYVel += .001; } if(ae.getSource().equals(down)){ myXVel += .001; } } // This is where i have my x + y stuff private void updatePos() { myX += myXVel; myY += myYVel; Graphics g = playingField.getGraphics(); g.setColor(Color.blue); g.fillOval((int)myY ,(int) myX ,(int) myR ,(int) myR); this.repaint(); Graphics g2 = playingField.getGraphics(); g.setColor(Color.red); g.fillOval((int)enemyY ,(int) enemyX ,(int) enemyR ,(int) enemyR); this.repaint(); if(myX < enemyX) { enemyX -= .009; } else { enemyX += .009; } if(myY < enemyY) { enemyY -= .009; } else { enemyY += .009; } } private void collisionCheck() { // my wall bounce stuff if(myY > playingField.getHeight()){ myYVel = -myYVel; } if(myX > playingField.getWidth()){ myXVel = -myXVel; } if(myY < 0){ myYVel = -myYVel; } if(myX < 0){ myXVel = -myXVel; } // This is where i want the exit button to show up but it does not, it does not register the x and y it seems like if(myX == enemyX) { myX += myXVel; myY += myYVel; class exitApp implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } this.add(grid3); exit = new JButton("EXIT"); exit.addActionListener(new exitApp()); exit.setBackground(Color.yellow); playingField.add(grid3); playingField.add(exit); } if(myY == enemyY) { class exitApp implements ActionListener { public void actionPerformed(ActionEvent e) { System.exit(0); } } this.add(grid3); exit = new JButton("EXIT"); exit.addActionListener(new exitApp()); exit.setBackground(Color.yellow); playingField.add(grid3); playingField.add(exit); } } }
There
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 11 Oct 2013 08:34 AM |
| You make your own game? barely anyone knows how to script with codes like these. |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 08:38 AM |
| Um.. Yes it's java alot of guys no how to script javva... |
|
|
| Report Abuse |
|
|
kinkyoyo
|
  |
| Joined: 10 Jul 2010 |
| Total Posts: 1557 |
|
|
| 11 Oct 2013 09:04 AM |
i thought this is only for LUA.
ᕙ(●̮̃●)ᕗ Fite me irl |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:06 AM |
| Ok just.......................... ok.................. |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:10 AM |
1. this forum is for Lua only
2. I doubt you made this
my reasons are that you don't know the difference between scripting and coding You can't spell |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:10 AM |
public static double enemyX=400, enemyY=400, enemyXVel=0, enemyYVel=0, enemyR=10; public static double myX=40, myY=40, myXVel=0, myYVel=0, myR=10;
Maibi? |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:21 AM |
| 1 yes i did. 2 coding and scripting are the same thing(kinda). 3 I can spell. 4 I see JAVA post all the time. |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:21 AM |
| No static did not work it does not mess it up but also does not fix the problom |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:25 AM |
No they're not at all Scripting is using a small language to outgo specific tasks (e.g. JavaScript, flash actionscript) Coding is using a language that is made for a purpose, but not for specific tasks (e.g. C, C++, Java, Python) |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:29 AM |
| You do you just said it means the same thing(pretty much) at a smaller and bigger scale right? if not leave this forum because it's not for idoits |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Oct 2013 09:49 AM |
@jay the irony You don't know the difference between "no" and "know" Also They're really not saying what your saying is like saying the quadratic formula is the same as using functions. |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:52 AM |
using functions overall*
And now I know you didn't make this as you are simply too idiotic to do so |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 09:56 AM |
Um... like i said get out because will they dictionary Computers. to translate (a program) into language that can be communicated to the computer.
now scripting To tell the computer to do something, translate(a program) Into a visible idea. Communicate to the computer.
Hm.. sounds close to me. |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Oct 2013 10:02 AM |
definition of scripting
"A simple program in a utility language or an application's proprietary language."
"utility"
A utility language is a language designed to do a single thing much like a utility (i know it's supposed to be an but an utility sounds off)
while a tool language is a language designed for you to be able to build stuff with it much like a tool |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 10:02 AM |
also I've been here longer than you and you're obviously less educated about computers |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 10:05 AM |
| At a quick glance of your username, everything i now explained. |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 10:06 AM |
| "i can't come up with a rebuttal so ill respond with sayin his nam is stpd XD!!!!!!!!!!!!!!!!!!!!!!!!" -jay |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Oct 2013 10:23 AM |
Whenever trying to access a variable in non-static classes, try putting "this." in front of it. I'm not an expert at Java, but when I was making my own game, that resolved my variable errors.
This is my siggy when I'm at school c: |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2013 10:26 AM |
| No it did not work also there are no errors it says it's fine but when i run it it does not work |
|
|
| Report Abuse |
|
|