Results 1 to 3 of 3

Thread: [help] mau membuat karakter yang berbeda

  1. #1
    vicqyyy is offline Anggota BabaFlash
    Join Date
    Jun 2012
    Posts
    4

    Default [help] mau membuat karakter yang berbeda

    selamat malam kakak-kakak senior . saya yang masih newbie ini. mau mencoba game online multiplayer dari buku yang ane baca judulnya " jago bikin game online ". ane mau bikin modifikasi game asteroid duel.

    ane coba utak atik codingnya tapi ada kegagalan yang ane dapatkan...

    ane mau bikin karakter tiap pemain itu berbeda yakni dalam hal ini yaitu asteroidnya.

    karena game online jadi ada client side sama server side...

    client side mengunakan action script 3 dan server side mengunakan bhs program C#

    ini kode Server sidenya mengunakan C#.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;
    using PlayerIO.GameLibrary;
    using System.Drawing;
    
    using System.Timers;
    
    namespace MyGame
    {
        public class Player : BasePlayer
        {
            public string Name;
            public int posX;
            public int posY;
            public int rotation;
            public int hit;
        }
    
        [RoomType("asteroidduel")]
        public class GameCode : Game<Player>
        {
            private Player[] playerArr;
    
            public override void GameStarted()
            {
                Console.WriteLine("Game is started: " + RoomId);
    
                playerArr = new Player[5];
            }
    
            public override void GameClosed()
            {
                Console.WriteLine("Game closed: " + RoomId);
            }
    
            public override void UserJoined(Player player)
            {
                Console.WriteLine("UserJoined: " + player.ConnectUserId);
    
                JoinGame(player);
                Broadcast("ChatJoin", player.ConnectUserId);
            }
    
            public override void UserLeft(Player player)
            {
                Broadcast("ChatLeft", player.ConnectUserId);
    
                for (int i = 0; i < playerArr.Length; i++)
                {
                    if (playerArr[i] != null)
                    {
                        if (playerArr[i].ConnectUserId == player.ConnectUserId)
                        {
                            playerArr[i] = null;
                            break;
                        }
                    }
                }
    
                Broadcast("left", player.ConnectUserId);
            }
    
            public override void GotMessage(Player player, Message message)
            {
                for (int i = 0; i < playerArr.Length; i++)
                {
                    if (playerArr[i] != null)
                    {
                        if (playerArr[i].ConnectUserId == player.ConnectUserId)
                        {
                            player = playerArr[i];
                        }
                    }
                }
    
                Console.WriteLine("GotMessage: " + message.Type);
    
                switch (message.Type)
                {
                    case "Chat":
                        {
                            String messageText = message.GetString(0);
                            Broadcast("Chat", player.ConnectUserId, messageText);
                            break;
                        }
                    case "RotateLeft":
                        {
                            player.rotation -= 5;
                            if (player.rotation <= 0) player.rotation = 360;
                            Broadcast("UpdateRocket", player.ConnectUserId, player.posX, player.posY, player.rotation);
                            break;
                        }
                    case "MoveUp":
                        {
                            player.posY += (int)(Math.Sin((player.rotation - 90) * (Math.PI / 180)) * 10);
                            player.posX += (int)(Math.Cos((player.rotation - 90) * (Math.PI / 180)) * 10);
                            if (player.posX < 32 || player.posX > 365 || player.posY < 42 || player.posY > 290)
                            {
                                player.posY -= (int)(Math.Sin((player.rotation - 90) * (Math.PI / 180)) * 10);
                                player.posX -= (int)(Math.Cos((player.rotation - 90) * (Math.PI / 180)) * 10);
                            }
                            else
                            {
                                Broadcast("UpdateRocket", player.ConnectUserId, player.posX, player.posY, player.rotation);
                            }
                            break;
                        }
                    case "RotateRight":
                        {
                            player.rotation += 5;
                            if (player.rotation >= 360) player.rotation = 0;
                            Broadcast("UpdateRocket", player.ConnectUserId, player.posX, player.posY, player.rotation);
                            break;
                        }
                    case "MoveDown":
                        {
                            player.posY -= (int)(Math.Sin((player.rotation - 90) * (Math.PI / 180)) * 10);
                            player.posX -= (int)(Math.Cos((player.rotation - 90) * (Math.PI / 180)) * 10);
                            if (player.posX < 32 || player.posX > 365 || player.posY < 42 || player.posY > 290)
                            {
                                player.posY += (int)(Math.Sin((player.rotation - 90) * (Math.PI / 180)) * 10);
                                player.posX += (int)(Math.Cos((player.rotation - 90) * (Math.PI / 180)) * 10);
                            }
                            else
                            {
                                Broadcast("UpdateRocket", player.ConnectUserId, player.posX, player.posY, player.rotation);
                            }
                            break;
                        }
                    case "Shoot":
                        {
                            Broadcast("Shoot", player.ConnectUserId);
                            break;
                        }
                    case "HitRocket":
                        {
                            Console.WriteLine("HitRocket: " + player.ConnectUserId);
                            player.hit++;
                            Broadcast("HitRocket", message.GetString(0), message.GetInt(1));
    
                            if (player.hit >= 5)
                            {
                                EndGame();
                            }
                            break;
                        }
                }
            }
    
            private void EndGame()
            {
                String result = "";
    
                for (int i = 0; i < playerArr.Length; i++)
                {
                    if (playerArr[i] != null)
                    {
                        for (int j = i; j < playerArr.Length; j++)
                        {
                            if (playerArr[j] != null)
                            {
                                if (playerArr[j].hit < playerArr[i].hit)
                                {
                                    Player tempPlayer = playerArr[i];
                                    playerArr[i] = playerArr[j];
                                    playerArr[j] = tempPlayer;
                                }
                            }
                        }
                    }
                }
    
                for (int i = 0; i < playerArr.Length; i++)
                {
                    if (playerArr[i] != null)
                    {
                        result += (i + 1) + ". " + playerArr[i].ConnectUserId + ", " + playerArr[i].hit + "x hit\n";
                    }
                }
    
                Console.WriteLine("EndGame: " + result);
                Broadcast("EndGame", result);
            }
    
            private void JoinGame(Player user)
            {
    
                Random rand = new Random();
                int posX = rand.Next(350) + 30;
                int posY = rand.Next(250) + 40;
    
                user.posX = posX;
                user.posY = posY;
                user.rotation = 0;
                user.hit = 0;
    
                
                    for (int i = 0; i < playerArr.Length; i++)
                    {
                        if (playerArr[i] == null)
                        {
                            playerArr.SetValue(user, i);
                            Console.WriteLine("user " + user.Id);
                            Broadcast("join", user.ConnectUserId, posX, posY);
                            break;
                        }
    
    
    
                    
    
                }
    
    
                for (int i = 0; i < playerArr.Length; i++)
                {
                    if (playerArr[i] != null && playerArr[i] != user)
                    {
                        Console.WriteLine("user " + user.Id);
                         Broadcast("addRocket", playerArr[i].ConnectUserId,  playerArr[i].posX, playerArr[i].posY, playerArr[i].rotation);
                        break;
                    }
                }
            }
        }
    }
    ini screenshotnya




    yang ane tanyakan di dalam server side ini bagaimana supaya karakternya bisa berbeda . pada tampilan screenshot diatas. pemain 1 dan pemain 2 tetap sama karakternya. sedangkan di pemain kedua berbeda.. padahal dalam 1 permainan


    mohon bantuannya para kakak-kakak master semua. ane masih newbie....

  2. #2
    vicqyyy is offline Anggota BabaFlash
    Join Date
    Jun 2012
    Posts
    4

    Default

    uppppp... mohon bantuannya kakak-kakak senior semua....

  3. #3
    Ricko88's Avatar
    Ricko88 is offline Pahlawan BabaFlash
    Join Date
    Jun 2011
    Location
    Padang Kota Tercinta
    Posts
    320

Similar Threads

  1. Puluhan angka yang berbeda
    By papercut in forum ActionScript
    Replies: 2
    Last Post: 11-24-2011, 12:22 PM
  2. soal kuis yang berbeda
    By rere in forum ActionScript
    Replies: 10
    Last Post: 04-02-2011, 11:30 AM
  3. function di file swf yang berbeda
    By papercut in forum ActionScript 1.0/2.0
    Replies: 4
    Last Post: 07-02-2010, 10:29 PM
  4. buat ngdrag layer yang berbeda..?
    By babaforum in forum Feed Milis BabaFlash
    Replies: 0
    Last Post: 06-03-2010, 09:11 PM
  5. Re: buat ngdrag layer yang berbeda..?
    By babaforum in forum Feed Milis BabaFlash
    Replies: 0
    Last Post: 05-29-2010, 02:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •