Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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]
1  Game Development / Newbie & Debugging Questions / Re: Multiple keys pressed at once! on: 2004-11-17 23:16:00
Quote
whenever a key is pressed, trigger the switch of a boolean.  Don't actually act on it until you run all of the logic of your game.



You mean like have it switch threads at such a fast rate that the human eye cannot notice that it is switching between the threads.  I understand what that does but not reall sure how to accomplish that.   No one that we seem to know, knows how to Multithread.  through our reacsurch online we kinda figured out that we mostlikly need to use the try command and sleep command.  Is this true?

thanks for your help
(Smeghead)
2  Game Development / Newbie & Debugging Questions / Re: Multiple keys pressed at once! on: 2004-11-16 03:13:13
Sorry this code sample is for one tank.  if you want our code for both tanks just ask and i'll post it here.
3  Game Development / Newbie & Debugging Questions / Multiple keys pressed at once! on: 2004-11-16 03:11:45
Yes hi

I am currently taking a AP programming class and my group of friends and i are trying to make a Tank wars game.  We are having a problem with making it so two players can move thier tank at the same time.   Here is our code so you can see what we have.

/*
     Trivial applet that displays a string
*/

import java.awt.*;
import java.applet.Applet;
import javax.swing.*;
import java.awt.event.*;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TrivialApplet extends Applet
{
     Image image;
     Image image2;
     Image image3;
     Image image4;
     Image image5;
     Image display;
     int x_pos = 10;                  
     int y_pos = 10;            
     private Image dbImage;
     private Graphics dbg;
     
    public void init()
    {
         image = getImage(getDocumentBase(), "Tank1.2LEFT.GIF");
         image2 = getImage(getDocumentBase(), "Tank1.2UP.GIF");
         image3 = getImage(getDocumentBase(), "Tank1.2DOWN.GIF");
         image4 = getImage(getDocumentBase(), "Tank1.2RIGHT.GIF");
         image5 = getImage(getDocumentBase(), "MAP-1 copy.jpg");
    }

     public void update (Graphics g)  
     {      
           if (dbImage == null)
           {
                 dbImage = createImage (this.getSize().width, this.getSize().height);
                 dbg = dbImage.getGraphics();            
           }

           dbg.setColor (getBackground());      
           dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);

           dbg.setColor (getForeground());
           paint (dbg);

           g.drawImage (dbImage, 0, 0, this);
     }

      public boolean keyDown(Event e, int key) {
     
         if (key == Event.LEFT){
                 x_pos = x_pos -3;
                 display = image;
           }
           else if (key == Event.RIGHT){
                 x_pos = x_pos +3;
                 display = image4;
           }
           else if (key == Event.UP){
                 y_pos = y_pos -3;
                 display = image2;
           }
           else if (key == Event.DOWN){
                 y_pos = y_pos +3;
                 display = image3;
           }
           repaint();
           return true;
     
      }
     
       public void paint(Graphics g)
    {
         g.drawImage(image5, 0, 0, this);
         repaint();
         return true;
         g.drawImage(display, x_pos, y_pos, this);
    }

}

Now what we want to acomplish is to make it so player one with the keys Up, down, left, and right can be pushing thier keys at the same time as player two who has the keys w, s, a, and d  without overiding the other players commands.   We have an idea that we are going to have to multi thread but don't know how to.

Also we want to have music playing in the background and sounds can you tell us how to do those as well.  

on another note we are working on making it so the tanks can fire but when the tanks fires a "Bullet" it will just pass over the other tank.  how do we make it reconize that it touched the other "Tank".

If you could help us that would be very helpfull.

Please send your hints or answers to smeeging@hotmail.com as well as post them.

again this would be very helpfull.

Smeghead out!  
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (31 views)
2014-04-15 18:08:23

BurntPizza (28 views)
2014-04-15 03:46:01

UprightPath (43 views)
2014-04-14 17:39:50

UprightPath (26 views)
2014-04-14 17:35:47

Porlus (43 views)
2014-04-14 15:48:38

tom_mai78101 (64 views)
2014-04-10 04:04:31

BurntPizza (124 views)
2014-04-08 23:06:04

tom_mai78101 (224 views)
2014-04-05 13:34:39

trollwarrior1 (190 views)
2014-04-04 12:06:45

CJLetsGame (198 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!