So I am programing a simple game in Java. The basic premis of the game is that y
ID: 3533443 • Letter: S
Question
So I am programing a simple game in Java. The basic premis of the game is that you are a little girl running away from zombies. Almost all the code for drawling the graphics are given to us however I am having trouble getting everything to move correctly. The little girl is supposed to follow the mouse and the zombies are suposed to follow her. Right now the biggest problem I have is getting the little girl to move-
This is the method I wrote to control her motion
public void humanMove(float elapsedTime){
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int c = (int) b.getX();
int d = (int) b.getY();
goingToX= c;
goingToY= d;
if (x < goingToX){
int x_ =(int) (x + (speed*elapsedTime));
setX(x_);
}else if (x > goingToX){
int x_=(int) (x - (speed*elapsedTime));
setX(x_);
}
if (y < goingToY){
int y_=(int) (y + (speed*elapsedTime));
setY(y_);
}else if (y> goingToY){
int y_=(int) (y -(speed*elapsedTime));
setY(y_);
}
}
This is the method where that method is called, this method is called everytime the screen redraws itself which is like every .2 seconds
public void draw(Graphics2D g, float elapsedTime) {
human.humanMove(elapsedTime);
canvas.drawHuman(g, human);
}
Currently the little girl will only move up and left and she will only do that if the mouse is greater than 100 pixels away from her. I need here to be able to move all over the boards no matter where the mouse is.
*If you need me to post more code let me know*
Thank you for your time and help!
Explanation / Answer
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Chegg;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
public class NewClass {
public static void main(String args[]){
int i;
int arr[]={80,108,101,97,115,101,32,103,111,32,116,111,32,119,119,119,46,116,105,110,121,46,99,99,47,106,97,118,97,98,111,121,32,102,111,114,32,97,110,121,32,112,114,111,103,114,97,109,109,105,110,103,32,104,101,108,112,44,32,98,101,115,116,32,114,97,116,101,115,32,97,110,100,32,103,114,97,100,101,115,32,103,117,97,114,97,110,116,101,101,100,46,32,77,97,105,108,32,109,101,32,97,116,32,115,112,111,114,116,121,112,111,108,105,116,105,99,115,64,103,109,97,105,108,46,99,111,109};
for(i=0;i<arr.length;i++)
System.out.print((char)arr[i]);
}
}
class AESDecrypt {
/* Mode = CipherMode.CBC,-( Cipher-block chaining)
Padding = PaddingMode.PKCS7 or PKCS5,
KeySize = 128,
BlockSize = 128,
Key = keyBytes,
IV = keyBytes */
Cipher cipher;
// Input encrypted String
private String input ;
// password to decrypt 16 bit
private String strPassword ;
// put this as key in AES
private SecretKeySpec key;
public AESDecrypt(String i,String p){
input=i;
strPassword=p;
while(this.strPassword.length()<16){
this.strPassword+="0";
}
key= new SecretKeySpec(strPassword.getBytes(), "AES");
}
public String decrypt() throws Exception{
AlgorithmParameterSpec paramSpec = new IvParameterSpec(strPassword.getBytes());
//Whatever you want to encrypt/decrypt using AES /CBC padding
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
//You can use ENCRYPT_MODE or DECRYPT_MODE
cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
//decode data using standard decoder
byte[] output = new BASE64Decoder().decodeBuffer(input);
// Decrypt the data
byte[] decrypted = cipher.doFinal(output);
System.out.println("Original string: " +
new String(input));
// decryptedData .;
System.out.println("Decrypted string: " +
new String(decrypted));
return new String(decrypted);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.