GamesStatusCodes, Status 6, STATUS_NETWORK_ERROR_OPERATION_FAILED - java

Hello guys,
I have been trying to implement google play services with LibGDX and am trying to create a Quickgame() where everyone is auto matched. However, on the public void onRoomCreated(int arg0, Room arg1) method, the when i print out the status code, it keeps giving me 6.
I have tried several solutions but to no avail
Relinking the game and ensuring the SHA1 code is correct. (Sign in works correctly)
Checking my phones network status, it is connected to the internet.
Does anyone perhaps have a solution? Thank you!
public class GSGameHelper extends GameHelper implements RoomUpdateListener, RealTimeMessageReceivedListener,RoomStatusUpdateListener {
final static String TAG = "ButtonClicker2000";
static final int RC_SELECT_PLAYERS = 10000;
static final int RC_WAITING_ROOM = 10002;
private Activity activity;
private String mRoomID;
private MacroHardv2 game;
public GSGameHelper(Activity activity, int clientsToUse) {
super(activity, clientsToUse);
this.activity = activity;
// TODO Auto-generated constructor stub
}
public void quickGame(){
Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0);
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.setAutoMatchCriteria(am);
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);
// prevent screen from sleeping during handshake
//getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
public void initMatch(){
Intent intent = Games.RealTimeMultiplayer.getSelectOpponentsIntent(getApiClient(), 1, 1);
this.activity.startActivityForResult(intent, RC_SELECT_PLAYERS);
}
private RoomConfig.Builder makeBasicRoomConfigBuilder() {
return RoomConfig.builder((RoomUpdateListener) this)
.setMessageReceivedListener((RealTimeMessageReceivedListener) this)
.setRoomStatusUpdateListener((RoomStatusUpdateListener) this);
}
public void onActivityResult(int request,int response, Intent data){
if (request == GSGameHelper.RC_WAITING_ROOM){
if (response == Activity.RESULT_CANCELED || response == GamesActivityResultCodes.RESULT_LEFT_ROOM ){
Games.RealTimeMultiplayer.leave(getApiClient(), this, mRoomID);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
BaseGameUtils.showAlert(activity, "Partida abandonada");
}else{
BaseGameUtils.showAlert(activity, "Comenzando partida");
this.game.multiplayerGameReady();
}
}
else if (request == GSGameHelper.RC_SELECT_PLAYERS){
if (response != Activity.RESULT_OK) {
// user canceled
return;
}
// get the invitee list
Bundle extras = data.getExtras();
final ArrayList<String> invitees =
data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
// get auto-match criteria
Bundle autoMatchCriteria = null;
int minAutoMatchPlayers =
data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
int maxAutoMatchPlayers =
data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
Gdx.app.log("J", "Jmin" + minAutoMatchPlayers + " Jmax:" + maxAutoMatchPlayers);
for (String invitee : invitees){
Gdx.app.log("L" , invitee);
}
if (minAutoMatchPlayers > 0) {
autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
minAutoMatchPlayers, maxAutoMatchPlayers, 0);
} else {
autoMatchCriteria = null;
}
// create the room and specify a variant if appropriate
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.addPlayersToInvite(invitees);
if (autoMatchCriteria != null) {
roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
}
RoomConfig roomConfig = roomConfigBuilder.build();
Games.RealTimeMultiplayer.create(getApiClient(), roomConfig);
// prevent screen from sleeping during handshake
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}else{
super.onActivityResult(request, response, data);
}
}
#Override
public void onJoinedRoom(int arg0, Room arg1) {
if (arg0 != GamesStatusCodes.STATUS_OK) {
Gdx.app.log("R", "Joined FAILED");
}else{
Gdx.app.log("R", "Joined Room");
}
}
#Override
public void onLeftRoom(int arg0, String arg1) {
BaseGameUtils.makeSimpleDialog(activity, "Abandonado partida");
Gdx.app.log("LEAVE", "Me fui de la Room");
}
#Override
public void onRoomConnected(int arg0, Room arg1) {
// TODO Auto-generated method stub
}
public void setGame(MacroHardv2 game){
this.game = game;
}
#Override
public void onRoomCreated(int arg0, Room arg1) {
if (arg0 != GamesStatusCodes.STATUS_OK) {
//BaseGameUtils.showAlert(activity, "Room creation error");
BaseGameUtils.makeSimpleDialog(activity, "Error al crear la partida", "Room creation error " + arg0).show();
Gdx.app.log("R", "Room Created FAILED");
}else{
Gdx.app.log("R", "Room Created");
mRoomID = arg1.getRoomId();
Intent i = Games.RealTimeMultiplayer.getWaitingRoomIntent(getApiClient(), arg1, 2);
this.activity.startActivityForResult(i, RC_WAITING_ROOM);
}
}
public void sendPos(float x,float y){
try{
byte[] mensaje;
mensaje = ByteBuffer.allocate(8).putFloat(x).putFloat(y).array();
Games.RealTimeMultiplayer.sendUnreliableMessageToOthers(getApiClient(), mensaje, mRoomID);
}catch(Exception e){
}
}
#Override
public void onRealTimeMessageReceived(RealTimeMessage rtm) {
float x, y;
byte[] b = rtm.getMessageData();
ByteBuffer bf = ByteBuffer.wrap(b);
x = bf.getFloat();
y = bf.getFloat();
game.updateGameWorld(x,y);
}
#Override
public void onConnectedToRoom(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onDisconnectedFromRoom(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onP2PConnected(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onP2PDisconnected(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPeerDeclined(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerInvitedToRoom(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerJoined(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeerLeft(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeersConnected(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onPeersDisconnected(Room arg0, List<String> arg1) {
// TODO Auto-generated method stub
}
#Override
public void onRoomAutoMatching(Room arg0) {
// TODO Auto-generated method stub
}
#Override
public void onRoomConnecting(Room arg0) {
// TODO Auto-generated method stub
}
}

Based on this documentation, you need to check if multiplayer support is enabled for your client ID. You need to enable real-time multiplayer support in the Developer Console. Check this link on how to enable multiplayer support.
This SO ticket might also help.

Related

Google BillingClient v3 to v4/v5 - Issues with orders?

I foolishly thought simply changing my build.gradle file to use
implementation 'com.android.billingclient:billing:5.0.0'
instead of
implementation 'com.android.billingclient:billing:3.0.0'
Would solve all issues, and even though the project compiles, I can't be sure it works correctly.
my IAPServices.java is;
public class IAPServices {
public IabHelper mHelper;
public IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener;
public OnPurchaseRemoveAd mOnPurchaseRemoveAd;
Activity context;
public IAPServices(Activity context)
{
this.context = context;
}
public void loadAppPurchase() {
String base64EncodedPublicKey = AppicationContants.GooglePlayAppId;
// compute your public key and store it in base64EncodedPublicKey
mHelper = new IabHelper(context, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
#Override
public void onIabSetupFinished(
com.zeapps.util.IabResult result) {
// TODO Auto-generated method stub
if (!result.isSuccess()) {
Log.d("Purchase", "In-app Billing setup failed: " + result);
} else {
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
#Override
public void onQueryInventoryFinished(IabResult result,
com.zeapps.util.Inventory inventory) {
// TODO Auto-generated method stub
if (result.isFailure()) {
// handle error
// showToast("Fail Purchase");
return;
} else {
// showToast("Success Purchase");
Purchase removeadvertsPurchase = inventory
.getPurchase(AppicationContants.REMOVE_ADVERTS_ID);
AppicationContants.RemoveAdvertisements = (removeadvertsPurchase != null);
}
}
};
mHelper.queryInventoryAsync(mGotInventoryListener);
}
}
});
mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
#Override
public void onIabPurchaseFinished(IabResult result,
Purchase purchase) {
// TODO Auto-generated method stub
if (result.isFailure()) {
} else if (result.isSuccess()) {
String sku = purchase.getSku();
if (sku.equals(AppicationContants.REMOVE_ADVERTS_ID)) {
RaiseOnPurchaseRemoveAd();
AppicationContants.RemoveAdvertisements = true;
}
}
}
};
}
public void showInAppPurchase(String id) {
if (mHelper != null)
mHelper.flagEndAsync();
mHelper.launchPurchaseFlow(context, id, AppicationContants.IAP_REQUEST,
mPurchaseFinishedListener, "");
}
private void RaiseOnPurchaseRemoveAd() {
if (mOnPurchaseRemoveAd != null) {
mOnPurchaseRemoveAd.onEvent();
}
}
public interface OnPurchaseRemoveAd {
public void onEvent();
}
}
But I see so many 'cancelled' orders that have not even been purchased, so cannot help but think it is not correct, although no errors are showing.
Is the billing upgrade a bit more than just upgrading the gradle file??

subscribeOn has no effect when creating new Observables [duplicate]

I am using rxjava in eclipse. I cretaed the below posted example.
the issue is,, when i run the code, I receive only
onSubscribe: 0
and I dont receive any output from onNext.
please let me know why I do not receive any output from onNext, and how to fix it
code:
public static void main(String[] args) {
Observable<String> stringObservable = Observable.just("Hello from just Operator1");
stringObservable
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io())
.subscribe(new Observer<Object>() {
#Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("onComplete: OK");
}
#Override
public void onError(Throwable arg0) {
// TODO Auto-generated method stub
}
#Override
public void onNext(Object arg0) {
// TODO Auto-generated method stub
System.out.println("onNext: " + (String) arg0);
}
#Override
public void onSubscribe(Disposable arg0) {
// TODO Auto-generated method stub
System.out.println("onSubscribe: " + arg0);
}
});
}

Handling OnPause and OnResume inside fragments android

I am trying to communicate with USB using InputOutput stream, I use constructor and make the communication part in a common class and I do use it inside a fragment, if i use it inside an activity it works properly if i use inside a fragment, the application hangs to overcome the problem i terminated the connection while OnPause but while resume connection not retains only on fragment same logic works on activity, I use some animations inside like Video is that be a reason?
#SuppressLint("ValidFragment")
public class Run_Screen extends Fragment implements OnClickListener {
Usb_Communciation usbCom;
RelativeLayout R_RelativeLayout, Run_Screen_Layout, Screen_Lock_Layout;
static SharedPreferences sharedpreferences;
Animation wipe;
static int machine;
MyLog myLog = new MyLog();
View root = null;
static Activity thisActivity = null;
#Override
public void onAttach(Activity activity) {
act = activity;
super.onAttach(activity);
thisActivity = Run_Screen.this.getActivity();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (Vars.Screen_Size == 400) {
root = inflater.inflate(R.layout.run_screen_400, container, false);
} else if (Vars.Screen_Size == 600) {
root = inflater.inflate(R.layout.run_screen_600, container, false);
} else if (Vars.Screen_Size == 800) {
root = inflater.inflate(R.layout.run_screen_800, container, false);
} else {
root = inflater.inflate(R.layout.run_screen, container, false);
}
sharedpreferences = this.getActivity().getSharedPreferences(Vars.MyPre, Context.MODE_PRIVATE);
GlobalClass.Current_Screen = "Run_Screen";
cmg = new Comment_Generate(act);
R_Wiper = (ImageButton) root.findViewById(R.id.R_Wiper);
wipe = AnimationUtils.loadAnimation(act, R.anim.wipe);
wipe.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
Wiper_anim.setVisibility(View.INVISIBLE);
R_Wiper.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
Wiper_anim.setVisibility(View.VISIBLE);
}
});
R_Pause_Play.setOnClickListener(this);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public void onStart() {
super.onStart();
}
#Override
public void onResume() {
super.onResume();
usbCom = new Usb_Communciation(Run_Screen.this.getActivity(), getActivity().getIntent());
}
#Override
public void onPause() {
super.onPause();
Usb_Communciation.AppDisconnect(Run_Screen.this.getActivity());
}
public void CheckFunc(){
if(Vars.ChangeMAchine==1){
R_Progress.setVisibility(View.VISIBLE);
R_Separator.setVisibility(View.VISIBLE);
R_Run.setVisibility(View.INVISIBLE);
R_Pause.setVisibility(View.VISIBLE);
R_Stop.setVisibility(View.VISIBLE);
R_Pause_Play.setVisibility(View.INVISIBLE);
}
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.R_Pause_Play:
DisableAll();
Reset_Machine_State(-2);
Vars.ChangeMAchine=1;
CheckFunc();
R_Progress.setVisibility(View.VISIBLE);
Send_Comment(Vars.C_Start_Machine, 0, 0);
myLog.Cmd("Write", Vars.C_Start_Machine, "0", "0",
"Start The Machine");
break;
}
}
private void Send_Comment(String Comment_No, int Address, int Data) {
Sending_Comment = cmg.Generate_Comment_for(Comment_No, Address, Data);
usbCom.Send_message(Sending_Comment);
}
public void SetUserLevelControls() {
Vars.CurrentUserLevel = sharedpreferences.getInt(Vars.UserLevel, 5);
if (Permission.Launcher_Operator_Screen_Defect_Height <= Vars.CurrentUserLevel) {
Screen_Lock_Layout.setVisibility(View.GONE);
} else {
Screen_Lock_Layout.setVisibility(View.VISIBLE);
}
if (Permission.Launcher_Operator_Screen_General <= Vars.CurrentUserLevel) {
R_Run.setOnClickListener(this);
R_Pause.setOnClickListener(this);
R_Stop.setOnClickListener(this);
R_Pause_Play.setOnClickListener(this);
Run_Lock.setVisibility(View.GONE);
} else {
R_Run.setOnClickListener(null);
R_Pause.setOnClickListener(null);
R_Stop.setOnClickListener(null);
R_Pause_Play.setOnClickListener(null);
Run_Lock.setVisibility(View.VISIBLE);
}
}
}
constructor class
public Usb_Communciation(Context mContext, Intent intent) {
try {
PackageManager manager = mContext.getPackageManager();
PackageInfo info = manager.getPackageInfo(mContext.getPackageName(), 0);
Log.d(TAG, "Info:" + info.packageName + "\n" + info.versionCode + "\n" + info.versionName);
} catch (PackageManager.NameNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
accessoryManager = new USBAccessoryManager(handler, USBAccessoryWhat);
accessoryManager.enable(mContext, intent);
}
AppDisconnect
public static void AppDisconnect(Context context) {
switch(firmwareProtocol) {
case 2:
byte[] commandPacket = new byte[2];
commandPacket[0] = (byte) APP_DISCONNECT;
commandPacket[1] = 0;
accessoryManager.write(commandPacket);
break;
}
try {
while(accessoryManager.isClosed() == false) {
Thread.sleep(2000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
accessoryManager.disable(context);
disconnectAccessory();
}

WebSocket Connection for xmpp

I am trying to establish a websocket connection with port:5280,but unable to connect(server is not listening).
public static WebSocketClient cc;
public static void main(String[] args) throws URISyntaxException
{
cc=new WebSocketClient(new URI("ws://localhost:5280"))
{
#Override
public void onOpen(ServerHandshake arg0)
{
// TODO Auto-generated method stub
System.out.println("onOpen" +arg0);
}
#Override
public void onMessage(String arg0)
{
// TODO Auto-generated method stub
System.out.println("onMessage");
}
#Override
public void onError(Exception arg0)
{
// TODO Auto-generated method stub
System.out.println("onError");
}
#Override
public void onClose(int arg0, String arg1, boolean arg2)
{
// TODO Auto-generated method stub
System.out.println("onClose");
}
};
cc.connect();
Above one is working with new URI("ws://localhost:8887/8080/5120") but having some problem with port no-5280.
Give me any Fix??

Slick2d State Transition Error

I followed a tutorial to make my first slick2d game, unfortunately a problem appears when transition from the play ground state to the menu state.
I tried many things but I didn't recognize the problem
this is the main class (GAME)
package javagame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame {
public static final String gamename = "Ham Blaster";
public static final int menu = 0;
public static final int play = 1;
public Game(String gamename)
{
super(gamename);
this.addState(new Menu(menu));
this.addState(new Play(menu));
this.addState(new Play(play));
this.addState(new Menu(play));
}
public void initsStatesList(GameContainer gc) throws SlickException
{
this.getState(menu).init(gc, this);
this.getState(play).init(gc, this);
this.enterState(menu);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
AppGameContainer appgc;
try {
appgc = new AppGameContainer(new Game(gamename));
appgc.setDisplayMode(640,360,false);
appgc.start();
}
catch(SlickException e)
{
e.printStackTrace();
}
}
public void initStatesList(GameContainer arg0) throws SlickException {
// TODO Auto-generated method stub
}
}
The Menu Class
package javagame;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.*;
public class Menu extends BasicGameState implements GameState {
private int state;
Image playNow;
Image exitGame;
public Menu(int menu) {
// TODO Auto-generated constructor stub
}
public void init(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
}
public void render(GameContainer arg0, StateBasedGame arg1, Graphics g)
throws SlickException {
// TODO Auto-generated method stub
playNow = new Image("res/playNow.png");
exitGame=new Image("res/exitGame.png");
g.drawString("Welcome to BuckyLand", 100, 50);
g.drawImage(playNow, 100, 100);
g.drawImage(exitGame, 100, 200);
}
public void update(GameContainer gc, StateBasedGame sbg, int arg2)
throws SlickException {
int posX = Mouse.getX();
int posY = Mouse.getY();
if (posX > 100 && posX < 100+playNow.getWidth() && posY > 209 &&posY<260)
{
if (Mouse.isButtonDown(0)) {
sbg.enterState(1);
}
}
if (posX > 100 && posX < 100+playNow.getWidth() && posY > 109 &&posY<160)
{
if (Mouse.isButtonDown(0)) {
System.exit(0);
}
}
}
public void mouseClicked(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mouseDragged(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mouseMoved(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mousePressed(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void mouseReleased(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void mouseWheelMoved(int arg0) {
// TODO Auto-generated method stub
}
public void inputEnded() {
// TODO Auto-generated method stub
}
public void inputStarted() {
// TODO Auto-generated method stub
}
public boolean isAcceptingInput() {
// TODO Auto-generated method stub
return false;
}
public void setInput(Input arg0) {
// TODO Auto-generated method stub
}
public void keyPressed(int arg0, char arg1) {
// TODO Auto-generated method stub
}
public void keyReleased(int arg0, char arg1) {
// TODO Auto-generated method stub
}
public void controllerButtonPressed(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void controllerButtonReleased(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void controllerDownPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerDownReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerLeftPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerLeftReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerRightPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerRightReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerUpPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerUpReleased(int arg0) {
// TODO Auto-generated method stub
}
public void enter(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
public int getID() {
// TODO Auto-generated method stub
return 0;
}
public void leave(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
}
The Play Class
package javagame;
import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.*;
public class Play extends BasicGameState {
Animation bucky,movingUp,movingDown,movingLeft,movingRight;
Image worldMap;
boolean quit = false;
int[] duration={200,200};
float buckyPosX = 0;
float buckyPosY = 0;
float shiftX = buckyPosX + 320;
float shiftY = buckyPosY + 160;
public Play(int play) {
// TODO Auto-generated constructor stub
}
public void mouseClicked(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mouseDragged(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mouseMoved(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void mousePressed(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void mouseReleased(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
public void mouseWheelMoved(int arg0) {
// TODO Auto-generated method stub
}
public void inputEnded() {
// TODO Auto-generated method stub
}
public void inputStarted() {
// TODO Auto-generated method stub
}
public boolean isAcceptingInput() {
// TODO Auto-generated method stub
return false;
}
public void setInput(Input arg0) {
// TODO Auto-generated method stub
}
public void keyPressed(int arg0, char arg1) {
// TODO Auto-generated method stub
}
public void keyReleased(int arg0, char arg1) {
// TODO Auto-generated method stub
}
public void controllerButtonPressed(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void controllerButtonReleased(int arg0, int arg1) {
// TODO Auto-generated method stub
}
public void controllerDownPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerDownReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerLeftPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerLeftReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerRightPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerRightReleased(int arg0) {
// TODO Auto-generated method stub
}
public void controllerUpPressed(int arg0) {
// TODO Auto-generated method stub
}
public void controllerUpReleased(int arg0) {
// TODO Auto-generated method stub
}
public void enter(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
public int getID() {
// TODO Auto-generated method stub
return 1;
}
public void init(GameContainer arg0, StateBasedGame sbg)
throws SlickException {
// TODO Auto-generated method stub
worldMap = new Image("res/world.png");
Image[] walkUp = {new Image("/res/buckysBack.png"),new
Image("res/buckysBack.png")};
Image[] walkDown = {new Image("/res/buckysFront.png"),new
Image("res/buckysFront.png")};
Image[] walkLeft = {new Image("/res/buckysLeft.png"),new
Image("res/buckysLeft.png")};
Image[] walkRight = {new Image("/res/buckysRight.png"),new
Image("res/buckysRight.png")};
movingUp = new Animation(walkUp,duration,false);
movingDown = new Animation(walkDown,duration,false);
movingLeft = new Animation(walkLeft,duration,false);
movingRight = new Animation(walkRight,duration,false);
bucky = movingDown;
}
public void leave(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
public void render(GameContainer arg0, StateBasedGame arg1, Graphics g)
throws SlickException {
// TODO Auto-generated method stub
worldMap.draw(buckyPosX,buckyPosY);
bucky.draw(shiftX, shiftY);
g.drawString("Bucky Xpos = "+buckyPosX+"\nBucky YPos = "+buckyPosY,400,20);
if(quit)
{
g.drawString("Resume(R)\nMenu(M)\nExit(Q)", 150, 200);
if(!quit) g.clear();
}
}
public void update(GameContainer gc, StateBasedGame sbg, int delta)
throws SlickException {
// TODO Auto-generated method stub
Input input = gc.getInput();
if(!quit)
{
if(input.isKeyDown(Input.KEY_UP))
{ bucky = movingUp;
buckyPosY += delta * 0.1f;
if(buckyPosY > 162)
buckyPosY -= delta * 0.1f;
}
if(input.isKeyDown(Input.KEY_DOWN))
{ bucky = movingDown;
buckyPosY -= delta * 0.1f;
if(buckyPosY <- 600)
buckyPosY += delta * 0.1f;
}
if(input.isKeyDown(Input.KEY_LEFT))
{ bucky = movingLeft;
buckyPosX += delta * 0.1f;
if(buckyPosX > 324)
buckyPosX -= delta * 0.1f;
}
if(input.isKeyDown(Input.KEY_RIGHT))
{ bucky = movingRight;
buckyPosX -= delta * 0.1f;
if(buckyPosX < -840)
buckyPosX += delta * 0.1f;
}}
if(input.isKeyDown(Input.KEY_ESCAPE))
quit = true;
if(quit)
{
if(input.isKeyDown(Input.KEY_R))
quit = false;
if(input.isKeyDown(Input.KEY_M))
sbg.enterState(1);
if(input.isKeyDown(Input.KEY_M))
System.exit(0);
}
}
}
Thank You Very Much !!
You're switching to your play state in your play state. In the Play class, put, sbg.enterState(0) instead of sbg.enterState(1).

Categories