Click to See Complete Forum and Search --> : Arm Wrestling Game


aznkidlee
May 8th, 2004, 09:44 AM
For my final project I am going to make a arm wrestling game. I have a bunch of ideas and I need some suggestions on where to start and how to code.

Ideas
1. User will be taping a key and that will move the arm.
2. 2d or 3d graphics
3. Power bar that represents the strength of user.
4. Timebase

dlorde
May 9th, 2004, 04:53 PM
Could you explain a bit more about how it would work? I can't see how this could be made a computer game...

Feeling a bit dim today...

aznkidlee
May 9th, 2004, 08:43 PM
Basically there would be a some type of picture on the screen. When the game has started, an object will moved towards the side of the screen and the user will have to tap a key on the keyboard which will push the object back to other side.

Joe Nellis
May 9th, 2004, 09:58 PM
Sounds like it could pull dual purpose as a keyboard stress testing program. I would consider using a more dexteritous approach than just pounding one key repeatedly. I would have the user hit two keys alternating each one. You could then use the number of successful alternations as a base metric for POWER. Then to add offense and defense characteristics, you could say Offensive power is based on speed of keystrokes while defensive power is based on how rhythmic someone can make their keystrokes (steady time between keystrokes). The idea being that fingering keys repeatedly does take its toll on the human hand fairly quickly, so the idea of offense and defense can be translated to bursts of speed when the hand is capable, or to a slower rythmic when the hand is starting to cramp.

cjard
May 10th, 2004, 04:43 AM
daley thomson's decathlon on the Commodore 64! Knackered joysticks all round! :)

aznkidlee
May 10th, 2004, 10:24 PM
Does anybody want to help me with some coding? Right now I have a line and I want the bottom part to be stationay and the top part to move. I'm having trouble coding this and I kno I need a loop that will either redraw the line everytime or move the line everytime.

Joe Nellis
May 10th, 2004, 11:08 PM
Originally posted by cjard
daley thomson's decathlon on the Commodore 64! Knackered joysticks all round! :)
OMG! That game was ridiculous. Seeing how I had an Atari 2600 long before the C64, my joysticks were already knackered, rebuilt and reknackered.

Joe Nellis
May 10th, 2004, 11:39 PM
Originally posted by aznkidlee
Does anybody want to help me with some coding? Right now I have a line and I want the bottom part to be stationay and the top part to move. I'm having trouble coding this and I kno I need a loop that will either redraw the line everytime or move the line everytime.

You can override the paint(Graphic g) method of your frame or applet to accomplish the drawing part. No loop is necessary. You would addKeyListener(this) somewhere in the frame constructor and then handle modifying variables in the keyPressed() method (the key event handler). At the end of the keyPressed() method you call repaint().

The variable(s) you would modify in the keyPressed() method would relate to the needle gauge going left or right that the paint() method will use to actually draw the needle.

cjard
May 11th, 2004, 04:27 AM
Originally posted by Joe Nellis
OMG! That game was ridiculous. Seeing how I had an Atari 2600 long before the C64, my joysticks were already knackered, rebuilt and reknackered.

the only stick i never ever saw broken, where those red and black ones that you held in the palm of one hand.. it was shaped kinda like a backwards question mark, your left hand pressed fire, and the right hand used the stubby red stick on top..

maybe it was just cause they were no good for DTD.. whereas the quickshots with the suckers on the bottom were perfect waggle hammers...

remember Kickstart II ? not a joystick knackerer, but one of the best games on the 64.. ;)

cjard
May 11th, 2004, 04:30 AM
Originally posted by Joe Nellis

The variable(s) you would modify in the keyPressed() method would relate to the needle gauge going left or right that the paint() method will use to actually draw the needle.

to be honest, i'd use keyReleased, because look at the event path if i hold a key down:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

KeyPressed
<pause while windows waits for keyboard repeat>
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyPressed
KeyReleased

see that keypressed fires repeatedly if the key is held down, but key released only fires when the key is released?

i.e. the event queue is not:

KeyPressed
KeyReleased
KeyPressed
KeyReleased
KeyPressed
KeyReleased
KeyPressed
KeyReleased
KeyPressed
KeyReleased
KeyPressed
KeyReleased
KeyPressed
KeyReleased

so to avoid cheating by just holding the button, use keyreleased

aznkidlee
May 11th, 2004, 05:14 PM
I'm having trouble starting and this is what I have so far. Could some body help me?

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class testing2 extends Applet implements KeyListener
{
int x1, x2, y1, y2; // coordinates for line


public void init()
{

addKeyListener(this);
}

public void keyReleased(KeyEvent event)
{
int key=event.getKeyCode();

if (key == KeyEvent.VK_LEFT)
{

}

if (key == KeyEvent.VK_RIGHT)
{

}

repaint();

}

public void keyPressed(KeyEvent event) {}
public void keyTyped(KeyEvent event) {}

public void paint(Graphics g)
{
// simple text displayed on applet
g.setColor(Color.blue);
g.drawLine(x1, x2, y1, y2);

}

}

Joe Nellis
May 11th, 2004, 11:02 PM
A very good start. Do you know any simple trigonometry? A needle extends from a centerpoint to some endpoint along an arc. This ensures the needle is drawn at the same length.

You've decided to have member variables of your game class be X & Y coordinates relating directly to your drawline method. Try to be more object oriented though. What you really want is something that retains the "arm strength" status of each player. So, since in arm wrestling, if one player is winning the other is losing because their hands are locked in unison. This means you really only need to track one variable. You make a mental model that says if the armStrength variable is negative then the left player is winning, if its positive the right player is currently winning.

Drawline() takes xy coordinates. These should be computed on the fly in the paint method based on some function performed on the variable armStrength (computeNeedle() comes to mind as a good name for this). What that function is, is up to you. Because you are modeling the action of a needle, the needle line (RADIUS) is going to be the same, the first point (CENTERPOINT) is going to be the same always. draw a picture.

Here's a hint:
x = r * cos(Theta*m + c)
where r is radius, m is a multiplier constant, c is an angle offset constant, and Theta is an angle in degrees.

aznkidlee
May 12th, 2004, 06:41 AM
This is what I have so for and I'm having trouble with your suggestion.
Is computeNeedle() a java method? I tried searching for it and I didn't find much info on it.

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class testing2 extends Applet implements KeyListener
{
int x1=300, y1=150;
int x2=50, y2=150;

public void init()
{
// provide any initialisation necessary for your Applet
addKeyListener(this);
}

public void keyReleased(KeyEvent event)
{
int key=event.getKeyCode();

if (key == KeyEvent.VK_LEFT)
{
x1 -= 1;
x2 -= 1;
repaint();
}

if (key == KeyEvent.VK_RIGHT)
{
x1 +=1;
x2 +=1;
repaint();
}



}

public void keyPressed(KeyEvent event) {}
public void keyTyped(KeyEvent event) {}



public void start()
{
// provide any code requred to run each time
// web page is visited

}


public void paint(Graphics g)
{
// simple text displayed on applet
g.setColor(Color.blue);
g.drawLine(x1, x2, y1, y2);

}
}

mikeBarr81
May 12th, 2004, 07:09 AM
no, computeNeedle() is not a java method. Joe just suggested it as a good name for a method you could make yourself. You need to write the method and give it functionality yourself.

aznkidlee
May 18th, 2004, 08:41 PM
Right now I'm having trouble controlling the red line after I animated. Can anyone help me fix this problem?

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.applet.AudioClip;
public class testing2 extends Applet implements Runnable, KeyListener //KeyboardAnimationApplet2
{

/** BLUE
* x1=250, y1=200;
* x2=290, y2=195;
*/
int x1=250, y1=200; // coordinates for line for player
int x2=290, y2=195;

/** RED
* x1_2=210, y1_2=90;
* x2_2=200, y2_2=250;
*/
int x1_2=210, y1_2=90;
int x2_2=200, y2_2=240;

int frame;
int delay;
Thread animator;

AudioClip background;

/**
* This method is called by the thread that was created in
* the start method. It does the main animation.
*/
public void run ()
{
long tm = System.currentTimeMillis();
while (Thread.currentThread() == animator )
{
repaint();
try
{
tm += delay;
Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
}
catch (InterruptedException e)
{
break;
}
frame++;
}
}

/**
* Initialize the applet and compute the delay between frames.
*/
public void init ()
{
String str = getParameter("fps");
int fps = (str != null) ? Integer.parseInt(str) : 10;
delay = (fps > 0) ? (1000 / fps) : 100;
background = getAudioClip(getCodeBase(), "dj sammy feat. carisma - Sunlight (Exteded Mix).wav");
addKeyListener(this);
}

public void keyReleased(KeyEvent event)
{
int key=event.getKeyCode(); //Keyboard code for the pressed key.

if (key == KeyEvent.VK_LEFT)
{
y1 -= 1; //BLUE
y2 -= 1;
x1_2 -= 1; //RED
x2_2 -=1;
repaint();
}

if (key == KeyEvent.VK_RIGHT)
{
y1 +=1; //BLUE
y2 +=1;
x1_2 +=1; //RED
x2_2 +=1;
repaint();
}



}

public void keyPressed(KeyEvent event) {}
public void keyTyped(KeyEvent event) {}

/**
* This method is called when the applet becomes visible on
* the screen. Create a thread and start it.
*/
public void start()
{
animator = new Thread(this);
animator.start();
background.loop();
}

public void stop()
{
animator = null;
background.stop();

}

public void paint(Graphics g)
{
// simple text displayed on applet
g.setColor(Color.blue);
g.drawLine(x1, x2, y1, y2);
g.setColor(Color.red);
g.drawLine(x1_2, x2_2, y1_2, y2_2);
g.setColor(Color.green);
g.drawRect(170,160,10,10);
g.drawRect(238,225,10,10);

y1 -= 1; //BLUE
y2 -= 1;

}
}

cjard
May 19th, 2004, 10:24 AM
why is a separate thread needed?

xlurk
June 5th, 2004, 02:40 AM
Click on the applet after you start running it. Your arrow keypresses will be silently ignored if you don't.

look for a suitable focus method to correct this.