I want to make a location game in real time

0 votes
I want to to make a real time game in android. I should get two person locations and show it map. I will have one target, users should fine target.I can get one location and show map but ı dont know to get two location and show location in map

 

asked Jun 9, 2015 in App42 Cloud API-BaaS by orhandepedibi (10 points)
edited Jun 9, 2015 by orhandepedibi

1 Answer

0 votes

Hi Orhan,

You can use Location Service to get location of players in android and can use Google Map to show them on Map. Here is a tutorial for Google Map Sample integration in Android.

You can use AppWarp API's to create real time multiplayer game.

Let me know if it helps.

Thanks

Vishnu Garg

 

answered Jun 10, 2015 by Vishnu Garg (674 points)
Thanks for answer,
I use Google Map V2. I can get users location and show the map but I can't get user location in real time. I try to use AppWarp for real time multiplayer game. I dont know to use Appwarp for location game .
As you are using location services, whenever player location is changed you can send location coordinate to other player in so that you will be able to show it on opponent's map.
I try to edit Fruity Monster Multiplayer game . I can make a room .Other user can join the room.I can show first user location but dont show the other user in the map. I should solve isMine functions. (I can update latitude and longitude in sendupdate Event )
public void addMorePlayer(boolean isMine, String userName){
        if(userMap.get(userName)!=null){// if already in room
            return;
        }
        Log.d("userNameGame", userName);
        char index =  userName.charAt(userName.length()-1);
       
        if(index=='1'){
            canavar="monster1";
        }else if(index=='2'){
            canavar="monster2";
        }else if(index=='3'){
            canavar="monster3";
        }else if(index=='4'){
            canavar="monster4";
        }
       
       
        User user = new User(point);
       
        userMap.put(userName, user);
        if(isMine){
           
             
        }
    }
Whenever you send location co-ordinate mapped with username  in a room you will receive it in onUpdatePeersReceived method, once you will receive location and username, you can show locate player on Google Map.
thanks a lot for your response,
I do not know exactly which method of use. The first time I do a multiplayer game. have to go through what functions. And I continue using locationchanged?I use this class,
String kullanici_adi;
    private LocationClient locationClient;
    private LocationRequest locationRequest;
    private GoogleMap googleMap;
    private static double latitude;
    private static double longitude;
    public Location mCurrentLocation;
    private double distance = -1;
    private double lastDistance = -1;
    final private double range = 9;
    public static int puanim=0;
    public Random rnd = new Random();
    public static double x;
    public static double y;
    private static LatLng markr;
    public static Location log=new Location("");
    private WarpClient theClient;
       
    private Random ramdom = new Random();

    private HashMap<String, User> userMap = new HashMap<String, User>();
       
    private String roomId = "";
   
    public static String canavar;
    public static LatLng point;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map);
        try{
            theClient = WarpClient.getInstance();
        }catch(Exception e){
            e.printStackTrace();
        }
        userMap.clear();
    //    ActionBar actionBar = getActionBar();
     //   actionBar.setDisplayHomeAsUpEnabled(true);
        locationClient = new LocationClient(this, this, this);
       
        locationRequest = LocationRequest.create()
                  .setInterval(5000)
                  .setFastestInterval(5000)
                  .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
       
        SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        googleMap = supportMapFragment.getMap();
        googleMap.setMyLocationEnabled(true);
       
        Intent intent = getIntent();
        roomId = intent.getStringExtra("roomId");
        init(roomId);
    }
    private void init(String roomId){
        if(theClient!=null){
            theClient.addRoomRequestListener(this);
            theClient.addNotificationListener(this);
            theClient.joinRoom(roomId);
        }
    }
    public void addMorePlayer(boolean isMine, String userName){
        if(userMap.get(userName)!=null){// if already in room
            return;
        }
        Log.d("userNameGame", userName);
        char index =  userName.charAt(userName.length()-1);
       
        if(index=='1'){
            canavar="monster1";
        }else if(index=='2'){
            canavar="monster2";
        }else if(index=='3'){
            canavar="monster3";
        }else if(index=='4'){
            canavar="monster4";
        }
       
       
        User user = new User(point);
       
        userMap.put(userName, user);
        if(isMine){
           
             
        }
    }
    @Override
    public void onLocationChanged(Location location) {
    latitude=location.getLatitude();
    longitude=location.getLongitude();
    sendUpdateEvent(latitude, longitude);
   
       
    }
   
    private void sendUpdateEvent(double x,double y){
        try{
            JSONObject object = new JSONObject();
            double gelenx=x;
            double geleny=y;
            object.put("gelenx", gelenx);
            object.put("geleny", geleny);
            theClient.sendChat(object.toString());
            updateMove(true,Utils.userName,gelenx , geleny);
        }catch(Exception e){
            Log.d("sendUpdateEvent", e.getMessage());
        }
    }
   
    public void updateMove(boolean isRemote, String userName, double xPer, double yPer){
        if(userMap.get(userName)!=null){
            if(isRemote){
                 x=xPer;
                 y=yPer;
            }
             googleMap.addMarker(new MarkerOptions()
                .position(new LatLng(x, y))
               );
            }
    }
   
    @Override
    public void onChatReceived(ChatEvent event) {
        String sender = event.getSender();
        if(sender.equals(Utils.userName)==false){// if not same user
            String message = event.getMessage();
            try{
                JSONObject object = new JSONObject(message);
                double xCord = Double.parseDouble(object.get("gelenx")+"");
                double yCord =  Double.parseDouble(object.get("gelenx")+"");
                updateMove(true, sender, xCord, yCord);
            }catch(Exception e){
                e.printStackTrace();
            }
        }
       
    }
   
   
   
   
    @Override
    public void onSubscribeRoomDone(RoomEvent event) {
        if(event.getResult()==WarpResponseResultCode.SUCCESS){
            theClient.getLiveRoomInfo(roomId);
        }else{
            Utils.showToastOnUIThread(this, "onSubscribeRoomDone: Failed "+event.getResult());
        }
    }
    public void sendUpdatePeers ( byte [] update )   
    {
       
       
    }
    public void onSendUpdateDone(byte result)  {
       
       
       
    }
   
   
   
    @Override
    public void onJoinRoomDone(RoomEvent event) {
        if(event.getResult()==WarpResponseResultCode.SUCCESS){
            theClient.subscribeRoom(roomId);
        }else{
            Utils.showToastOnUIThread(this, "onJoinRoomDone: Failed "+event.getResult());
        }
    }

   
    @Override
    public void onGetLiveRoomInfoDone(LiveRoomInfoEvent event) {
        if(event.getResult()==WarpResponseResultCode.SUCCESS){
            String[] joinedUser = event.getJoinedUsers();
            if(joinedUser!=null){
                for(int i=0;i<joinedUser.length;i++){
                    if(joinedUser[i].equals(Utils.userName)){
                        addMorePlayer(true, joinedUser[i]);
                    }else{
                        addMorePlayer(false, joinedUser[i]);
                    }
                }
            }
           
        }else{
            Utils.showToastOnUIThread(this, "onGetLiveRoomInfoDone: Failed "+event.getResult());
        }
       
    }
   


   

    @Override
    public void onConnectionFailed(ConnectionResult arg0) {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void onConnected(Bundle arg0) {
        locationClient.requestLocationUpdates(locationRequest, this);
         mCurrentLocation=locationClient.getLastLocation();
        LatLng point = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());

    }

    @Override
    public void onDisconnected() {
        // TODO Auto-generated method stub
       
    }
   
    @Override
    protected void onResume() {
        super.onResume();
        locationClient.connect();
    }

    @Override
    public void onPause() {
        super.onPause();
       
        if(locationClient.isConnected())
            locationClient.removeLocationUpdates(this);
       
        locationClient.disconnect();
}..
You are using right API, in sendChat you are sending player location and on ChatReceived you are getting the location of that player. After that you have to show the location on your Google map.
Can you please specify more about your requirements.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...