scieee AI-readable full text Open interactive document viewer

Multiplayer video game for public spaces

Rufo Tena, Víctor

Abstract

Raid and Go is a two dimensions (2D) raid-style turn-based online video game that aims to be locate to public spaces, such as parks or iconic city locations but it could be used in long-distance public transport as well. The work covers two large development blocks, one consisting on the creation of a system of multiplayer rooms where players can enter and leave whenever they want, and the other that represents the complete development process of a game. Academically, this document consists of the final degree project report of the Video game Design and Development bachelor´s degree at the Jaume I University.

Full text

Multiplayer video game for public spaces Víctor Rufo Tena Final Degree Project Bachelor’s Degree in Video Game Design and Development Universitat Jaume I July 18, 2023 Supervised by: José Vicente Martí Avilés Acknowledgments To start with, I would like to thank David and Andriu for their interest in this project and thank José Vicente for his guidance. I want to thank my parents for their constant support during these months as well. I also would like to thank Sergio Barrachina Mir and José Vte. Martí Avilés for their inspiring LaTeX template for writing the Final Degree Work report, which I have used as a starting point in writing this report. i Abstract Raid and Go is a two dimensions (2D) raid-style turn-based online video game that aims to be locate to public spaces, such as parks or iconic city locations but it could be used in long-distance public transport as well. The work covers two large development blocks, one consisting on the creation of a system of multiplayer rooms where players can enter and leave whenever they want, and the other that represents the complete development process of a game. Academically, this document consists of the final degree project report of the Video game Design and Development bachelor´s degree at the Jaume I University. iii Contents Contents v 1 Introduction 1 1.1 WorkMotivation................................ 2 1.2 Objectives.................................... 2 1.3 Environment and Initial State . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.4 Keywords .................................... 3 2 Planning and resources evaluation 5 2.1 Planning..................................... 5 2.2 ResourceEvaluation .............................. 8 3 System Analysis and Design 11 3.1 RequirementAnalysis ............................. 12 3.2 SystemDesign ................................. 22 3.3 SystemArchitecture .............................. 27 3.4 InterfaceDesign................................. 27 4 Work Development and Results 29 4.1 WorkDevelopment............................... 29 4.2 Results...................................... 37 5 Conclusions and Future Work 39 5.1 Conclusions................................... 39 5.2 Futurework................................... 39 5.3 Platforms and Market analysis . . . . . . . . . . . . . . . . . . . . . . . . 40 Bibliography 41 A Appendix 43 List of Figures 43 List of Tables 44 v vi Contents B Source code 45 Chapter 1 Introduction Contents 1.1 WorkMotivation.............................. 2 1.2 Objectives ................................. 2 1.3 Environment and Initial State . . . . . . . . . . . . . . . . . . . . . . 3 1.4 Keywords.................................. 3 When the job proposals were presented by the tutors, the truth is that I placed this one quite high, possibly because days before I caught a flight and the entertainment was playing with other passengers the typical competitive games present in these means of transport and it seemed interesting to me the idea of creating a different game away from them. [9] There are a lot of fans of RPG video games (Role Playing Games) where the player controls a character, or several, in an adventure of medium or long duration. In particular, what likes the most about these games is their fighting style, which almost always uses a turn-based and rarely finds itself with a multiplayer system. This is the reason why it was found interesting to make a turn-based game adapted to the multiplayer room system that the project requested. What attracts the most for lovers of these RPG games is the art of the game, that the character sprites need to be pleasant and differentiated, as well as that the functions that are added to the combat system have to be fun and comforting. Therefore, it has always been considered very important to dedicate a lot of time to it. 1 8 Planning and resources evaluation 2.2 Resource Evaluation Here, an analysis about the theorical amount of money and time that the project would cost is made. Due to the fact that both programming and artistic tasks have been worked on, the cost of one and the other will be calculated separately to later make an approximate sum. On the one hand, in this project the number of hours used in programming and designing was 135 hours. With this in mind, in Spain a junior programmer earns 8.39 euros per hour on average, so its final cost would be 1132,65 euros. [20] On the other hand referencing the art, 60 hours were worked on. About the costs, in Spain a settled 2D designer earns 14,79 euros per hour on average, so its final cost would be 887,4 euros. [19] Speaking of some expenses that are usually overlooked, such as the cost of the residence (without taking into account food costs or extra expenses) or the Internet connection. A studio apartment for rent in Castellón de la Plana (Spain) costs 450 euros per month on average, so in three months the figure would rise to 1350 euros. [17] For an acceptable speed Internet of fiber type, it costs about 50 euros per month in the main companies, so during this time 150 euros would go to have access. [23] In addition, the electricity consumption of an entire property is usually 30 euros per month, therefore in three months it would mean 90 euros that are added to the price. [25] With these quick calculations and ignoring the previous research work, focusing only on the more technical development of the project, the total cost of the work would be 3610,05 euros. Now, it is important to differentiate between hardware and software: •Hardware: Even if the used computer does not have the most actual components it is still pretty decent and has a price of about 700 euros, with a useful life of two to four years: – CPU: Intel Core i7-8550 – GPU: Nvidia GeForce MX150 – RAM: Intel 8GB •Software: – Unity(Free): It is a cross-platform game engine developed by Unity Technologies to create 2D and 3D games, even VR games. [27] – Photon Engine(Free Version): Allows projects to be online and can be easily related with Unity. [7] 2.2. Resource Evaluation 9 – Visual Studio(Free): It is an IDE developed by Microsoft that is compatible with almost every highly used programming language. It is really helpful in association with Unity because it shows directly errors and other features. [22] – Krita(Free): Digital drawing and illustration program that is perfect for creating 2D art and being able to export it in good quality. [26] – Overleaf(Free): This online LaTeX is the one that has been used to write this report. [16] – Google Tools(Free): Some tools offered by Google have been really useful for the development of the project, such as Docs for the formalization of the documentation and Drive for storing useful files. [13] – FakeYou(Free): This free program has been used to create some audio tracks that have been used in the work. [24] With all the costs already displayed, the total cost of the project can be calculated. Being the cost of residence and everything that involves it of 3610,05 euros, and the Hardware section of 700 euros, since in terms of Software programs with free functionalities have been used entirely, the development of this project costs 4310,05 euros. Chapter 3 System Analysis and Design Contents 3.1 RequirementAnalysis........................... 12 3.2 SystemDesign............................... 22 3.3 SystemArchitecture............................ 27 3.4 InterfaceDesign .............................. 27 This chapter presents the requirements analysis, design and architecture of the proposed work. It also shows the design of the GUI (see figure 3.1), known as the game user interface. The functionality of the project will be described, with all the possibilities that are offered to the user. To do this, in the different sections screenshots will be shown to help understanding and varied graphics of the possible actions of the player once inside the game will be presented. 11 12 System Analysis and Design Figure 3.1: Image that shows the Game User Interface 3.1 Requirement Analysis Having a job to do can also be seen as a problem to solve. The problem to solve here is the development of a video game, one with a free theme that could be used in public spaces and with a multiplayer system that allows the players to connect between them by rooms. Raid and Go is the particular solution. It proposes a game that is different from those located in current public spaces and that complies with a solid system of multiplayer rooms. As soon as the game is opened, a title screen (see figure 3.2) will be displayed, with a message inviting the player to click anywhere on the screen to access the game. Once clicked, the main menu will show up (see figure 3.3) where three options appear, the Play button and two galleries, one for the playable characters and another for the enemy monsters, called Bosses. Since the game is supported by a funny character design, the galleries are really useful in this video game style. 3.1. Requirement Analysis 13 Figure 3.2: The title screen Figure 3.3: The main menu screen In the first gallery called Gallery (see figure 3.4), the four playable monsters are shown so that when clicking on the one the player is interested in seeing, a description of it and a larger image will appear (see figure 3.5). It includes an exit button to return to the beginning of this section of the menu as well. 14 System Analysis and Design Figure 3.4: The playable monsters gallery screen Figure 3.5: The description screen 3.1. Requirement Analysis 15 If it is the first time accessing the Bosses gallery, they will appear with a dark art, this says that they have not been defeated yet (see figure 3.6). Once achieved this, the image will be replaced with a full color one that will be kept for future play sessions (see figure 3.7). Figure 3.6: First time accessing the bosses gallery Figure 3.7: Accessing the bosses gallery after defeating one of them 16 System Analysis and Design And finally the Play button where the player will access the screen to choose character and select whether he want, to enter a room created by another player or open a new one to play alone while waiting for help (see figure 3.8). Figure 3.8: Selection screen Once inside the game, the player will be able to choose the option to be performed from among three possible ones by clicking on them in his turn (see figure 3.1): •Attack: The player´s monster will attack the enemy with his current attack stat, lowering the opponent´s health. •Heal: The player´s monster will recover as much life as the value of its healing stat. •Boost: This will randomly raise a stat from the player´s monster, these can be: – Raise our attack: The damage that the player´s monster will deal to the enemy will be increased. – Lower the boss´s attack: The damage that the enemy will deal to the player´s monster will decrease. – Increase our healing value: The amount of health restored will increase for the rest of the match. Must be careful since the boss can also do all of this. The objective is clear, to make use of the previous actions to lower the boss´s life to zero while trying to keep the personal character alive. In case of being defeated, the raid will be terminated with a defeat message and a return to the title screen will happen to try again if the player wants to. The same will happen if winning but with a more lively message. 3.1. Requirement Analysis 17 It is appreciated to comment on how the game works in case of entering multiplayer as well (see figure 3.9), where two players will have to cooperate to defeat the boss. Figure 3.9: Ingame screen with two players A player must create a room first, if the join button is clicked and none exists, one room will be created where the player will be alone fighting while waiting (acts as the Create button). The boss to fight in that specific room may be different from other players, due to it chooses between the possible two randomly. By clicking on join, if there are several rooms, the system will match with one randomly, something that is better than simply showing the list of all the available ones, for system speed and for gameplay quality. Once player two accesses, player one (who created the room) could have decided to go alone, so the boss will already have a decrease on his stats or life, just like the partner player (see figure 3.10). 24 System Analysis and Design Figure 3.12: Class diagram 3.2. System Design 25 Figure 3.13: Activities diagram 26 System Analysis and Design Figure 3.14: Interaction diagram 3.3. System Architecture 27 3.3 System Architecture This section describes the minimum architecture a PC must have in order to be able to run the game. These data is taken from the Unity documentation. [28] Note that the project has been developed with Unity2D engine, specifically the 2021.3.15f1 (LTS) version. •Operating system: –Windows 7 SP1+ –macOS 10.12+ –Ubuntu 16.04+ •CPU: SSE2 instruction set support. •GPU: Graphics card with DX10(shader model 4.0) capabilities. •It is obligatory the use of a mouse or touch panel for playing. 3.4 Interface Design The GUI is really simple and referenced by the classic RPGs (see figure 3.15). Being the main objective to show the art that, as has been commented, must be pleasant for the player. This art not only includes the design of the characters, which is clearly the main one, also the bases where they stand, the status boxes located on their sides and the dialogue panel. The background must be simple so that everything is perfectly visible, being in classic RPG´s a completely matte background, which is the one chosen for the project. Continuing with the order mentioned at the beginning of the section, the art of the characters and the bases are completely inanimate, that is, they do not make any changes during the course of the game. On the other hand, the status boxes of each character show his name and his amount of life, which varies depending on whether he is attacked or healed. And the dialogue panel where the action buttons that the player can press on his turn are located and that also shows the course of the game at all times, for example the action taken by each monster. 28 System Analysis and Design Figure 3.15: Vision Raiders Entertainment RPG combat sample Chapter 4 Work Development and Results Contents 4.1 WorkDevelopment ............................ 29 4.2 Results ................................... 37 This chapter is an explanation of how the project has been developed since his start until the end of it. It also includes an assessment of the results and how some ideas were changed during this process. And how others can be treated for convenience in the future. 4.1 Work Development In this section it will be discussed what has been done and the decisions that have been taken. Much of the information for the realization of this project comes from articles and tutorials on YouTube [14] that will be cited as they arise. This includes the implementation of certain functionalities in Unity. Now proceed to comment the development of the project following a chronological order. When understanding the type of project that was proposed, all the thoughts were about trying to find a different game capable of be settled in public spaces. Being all the common ones Tetris [6] or Angry Birds [18], among others. It was at this point that it occurred to choose to develop a competitive player versus player card game. But the idea that the second player could join a game started where 29 30 Work Development and Results he trailed by an abysmal distance is not fun. So it was decided to discard the competitive idea for a cooperative one. The truth is that cooperative games have a bad point that is shared by the most important point of them, and this is that each player, wanting or not, depends on the other, so it was interesting the idea of making one that allowed a player to win without depending on anyone. This idea was mixed with one of the favorites video games players genre, RPGs, from which the combat style was taken. This is how the idea of Raid And Go would be born, a 2D raid-style turn-based game that drank from the great classic Pokémon games [10], due to its very nice looking appearance. Once discussed with the tutor and giving green light, the research work started, trying to get all the resources ready for when decided to enter into the project programming. From this research, it was extracted that making a functional multiplayer game is really complicated, and also, since it is something that is not learned on any subject, it was decided to leave it for the last. As a personal objection the development of a video game can not be started without its minimal art done, so it started with drawing the characters with their normal and combat stances, the HUD, the logo and the different buttons and texts, in that order. Immediately below are samples of all the art made. The character´s normal stances can be seen in figure 4.1, the HUD art in figure 4.2 and their combat stances in figure 4.3. 4.1. Work Development 31 Figure 4.1: Characters representation art Figure 4.2: HUD assets art 32 Work Development and Results Figure 4.3: Characters combat art When the minimal art was done was moment to open Unity and began to design a 2D video game with a turn-based system. With the intention to later link it with a multiplayer room system. The development of the turn-based game ended without any problem, taking as reference a simple tutorial [4]. First up was the placement of the HUD in Unity´s 2D project space. This includes the status boxes of the characters, with a text that is the name and a slider with the amount of life, the dialogue panel with the buttons and the art of the bases. And then the creation and staging of the player prefabs, with their own characteristics such as the life, base damage and current healing. With the scene built, it was time to develop the turn-based system, that means that the game changes between some states: start game (make appearance of the elements), player´s turn, enemy´s turn and end game. 4.1. Work Development 33 The next step was to make game state changes happen. Which was consistent with developing a basic turn-based game. At the start of the game it will ask if everything is in place, so it will go to the player´s turn state, once a button is touched, it will wait a few seconds and it will go to the enemy´s turn, which again, will wait for a few seconds and it will go back to the player´s turn, until one of the two has zero life, and then it will go to the end game state. The state change was done, so it was time to make the button press happen what was requested, lower health on attack button and restore on heal. And most importantly, that the dialogue panel will be updated with each action, friendly or enemy, changing its displayed text every time something happens. Or what is the same, change its content within each function in code. At this time the turn-based game was done, just needed to polish it while working on other parts of the project, and proceed with the multiplayer system. It was at this point when saw that aesthetically making the game for two players was the right option, the first thought was to make it for three or even four. But this is not a problem for future revisions, since it could perfectly be adapted for more, only that the perspective of the game should be changed so that the art would be seen correctly, neither very small or with rendering errors. Once reviewed the information that it was thought that will be useful for knowing how to make a multiplayer network, result of the research work, it was realized that practically none of it was worth, so looking for new one was necessary. One of the problems with creating a multiplayer game is that few people dare, again, because of how expensive and complicated it can be, so finding useful information is often impossible. The main problem encountered was that most of the options to create the multiplayer system for rooms were not free, with high monthly charges to keep servers active that could not afford. In addition, making the connection with Unity was very complex. Luckily a tutorial was found [12], one that would help to understand how to create a multiplayer system in Unity. In a free and apparently simpler way. This tutorial gave as a starting point the use of the Photon technologies for multiplayer, using its free features of having a server with the maximum capacity of 20 simultaneous people, so it is perfect for this type of project (see figure 4.4). The first and most important thing was to link this newly created server with the Unity´s project in question (the 2D turn-based game) in order to use the online features offered. 40 Conclusions and Future Work work well in demos I did not add them. Being a game dedicated to public spaces, it seemed a good idea to me that the appearance of a specific boss was related to the location, using the GPS position of the players, instead of being random as it is now. This will force players to move to other locations if they want to complete the trophy gallery and will improve the gameplay. This is a very interesting topic for which I would like to dedicate a section to it below. And finally, the extension that we would all do in our video games, expand the content, in my case, adding new playable characters, more bosses and making them be controlled when they were defeated. 5.3 Platforms and Market analysis Currently the game is focused on PC, again, because it is a project that has had to be developed under various parameters such as deadlines and presentations. The game as it is at this moment is perfect to be placed as entertainment on public transport, such as planes or trains. Because it is not very practical to take a laptop to a park to play, for example. So we could talk about its future becoming a mobile game, where we can transport our small collection of pocket monsters wherever we go and make use of them in raid battles in different real-world places. This change takes time, but it would not be hard because the game is based on clicking, which would be transformed into touch screen taps. Once on mobile devices, what would it face? Well, it is evident that its main competitor would be Pokemon Go [11], which has similar mechanics and charismatic characters of a lifetime. But this would not be a concern since there are already similar games on the market that have made their way and are profitable, such as Nexomon. [21] Bibliography [1] Ansimuz. Warped shooting fx. https://assetstore.unity.com/packages/2d/texturesmaterials/abstract/warped-shooting-fx-195246. Accessed: 2023-06-24. [2] Various Artists. Songs playlist. https://www.youtube.com/watch?v=hcWJ9453z4list = P LRkD5IV T T W uN −F MRBgmlql5LOyEe90 −xIindex = 5. Accessed : 2023 −06 −24. [3] AurynSky. Simple gems pack. https://assetstore.unity.com/packages/3d/props/simplegems-ultimate-animated-customizable-pack-73764. Accessed: 2023-06-24. [4] Brackeys. Turn-based game. https://www.youtube.com/watch?v=1pzohupP s.Accessed : 2023 −06 −24. [5] Wallpaper Cave. Wallpaper cave. https://wallpapercave.com/. Accessed: 2023-06-24. [6] The Tetris Company. Tetris. https://tetris.com/play-tetris. Accessed: 2023-06-24. [7] Photon Engine. Photon. https://www.photonengine.com/. Accessed: 2023-06-24. [8] Photon Engine. Photon manual. https://docapi.photonengine.com/en/pun/v2/classphoton11pun11photonnetwork.html. Accessed : 2023 −06 −24. [9] Germán Fabregat Llueca. Guía para la redacción de las memorias. http://mermaja.act.uji.es/itis/IS31/guia_memoria.pdf. Accessed: 2019-02-28. [10] Nintendo Game Freak. Pokémon. https://www.pokemon.com/es. Accessed: 2023-06-24. [11] Nintendo Game Freak. Pokémon go. https://pokemongolive.com/. Accessed: 2023-06- 24. [12] Aangmar Games. Room system for unity. https://www.youtube.com/watch?v=pQxscGB7S4c. Accessed: 2023-06-24. [13] Google. Google tools. https://www.google.es/. Accessed: 2023-06-24. [14] Google. Youtube. https://www.youtube.com/. Accessed: 2023-06-24. [15] Music Technology Group. Freesound. https://freesound.org/. Accessed: 2023-06-24. 41 42 Bibliography [16] John Hammersley and John Lees-Miller. Overleaf. https://www.overleaf.com/. Accessed: 2023-06-24. [17] idealista. Studio apartment price. https://www.idealista.com/alquileroficinas/castellon-de-la-plana-castello-de-la-plana/centro/zona-hospital-plaza-del-real/. Accessed: 2023-06-24. [18] Jaakko Iisalo. Angry birds. https://www.angrybirds.com/play/. Accessed: 2023-06-24. [19] Indeed. 2d designer salary. https://es.indeed.com/career/dise%C3%B1ador- gr%C3%A1fico/salaries. Accessed: 2023-06-24. [20] Indeed. Junior programmer salary. https://es.indeed.com/career/salaries/programador%20junior %20Salaries%7D%7D. Accessed: 2023-06-24. [21] Vewo Interactive. Nexomon. http://www.vewointeractive.com/. Accessed: 2023-06-24. [22] Microsoft. Visual studio. https://visualstudio.microsoft.com/es/. Accessed: 2023-06-24. [23] Rastreator. Fiber type internet price. https://www.rastreator.com/telefonia/tarifas/tarifasde-fibra-mas-baratas.aspx. Accessed: 2023-06-24. [24] Storyteller. Fake you. https://fakeyou.com/. Accessed: 2023-06-24. [25] tarifaluzahora. Electricity consumption price. https://tarifaluzhora.es/info/consumomensual-luz. Accessed: 2023-06-24. [26] Krita Team. Krita. https://krita.org/. Accessed: 2023-06-24. [27] Unity Technologies. Unity. https://unity.com/es. Accessed: 2023-06-24. [28] Unity Technologies. Unity manual. https://docs.unity3d.com/Manual/UnityManual.html. Accessed: 2023-06-24. A p p e n d i x A Appendix List of Figures 2.1 Tasks ........................................ 6 2.2 GanttChart .................................... 7 3.1 Image that shows the Game User Interface . . . . . . . . . . . . . . . . . . . 12 3.2 Thetitlescreen................................... 13 3.3 Themainmenuscreen............................... 13 3.4 The playable monsters gallery screen . . . . . . . . . . . . . . . . . . . . . . . 14 3.5 Thedescriptionscreen............................... 14 3.6 First time accessing the bosses gallery . . . . . . . . . . . . . . . . . . . . . . 15 3.7 Accessing the bosses gallery after defeating one of them . . . . . . . . . . . . 15 3.8 Selectionscreen................................... 16 3.9 Ingame screen with two players . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.10 Player two joins an already started game . . . . . . . . . . . . . . . . . . . . 18 3.11Caseofusediagram ................................ 23 3.12Classdiagram.................................... 24 3.13Activitiesdiagram ................................. 25 43 3.14Interactiondiagram ................................ 26 3.15 Vision Raiders Entertainment RPG combat sample . . . . . . . . . . . . . . 28 4.1 Characters representation art . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 4.2 HUDassetsart................................... 31 4.3 Characterscombatart............................... 32 4.4 Raid and Go´sPhotonprojectlink........................ 34 List of Tables 3.1 Functional requirement «CRED1. Enter the Main Menu» . . . . . . . . . . . 19 3.2 Functional requirement «CRED2. Enter the characters gallery» . . . . . . . . 19 3.3 Functional requirement «CRED3. Enter the bosses gallery» . . . . . . . . . . 19 3.4 Functional requirement «CRED4. Exit the galleries» . . . . . . . . . . . . . . 20 3.5 Functional requirement «CRED5. Enter the character and match selection screen» ....................................... 20 3.6 Functional requirement «CRED6. Enter the game» . . . . . . . . . . . . . . . 20 3.7 Functional requirement «CRED7. Attack the boss» . . . . . . . . . . . . . . 20 3.8 Functional requirement «CRED8. Heal your character» . . . . . . . . . . . . 20 3.9 Functional requirement «CRED9. Raise a stat of your character» . . . . . . . 21 3.10 Functional requirement «CRED10. Boss´sturn» ................ 21 3.11 Functional requirement «CRED11. Switching to a multiplayer match» . . . . 21 3.12 Functional requirement «CRED12. Share information with the new player» . 21 3.13 Functional requirement «CRED13. Take no action in combat» . . . . . . . . 22 3.14 Functional requirement «CRED14. Save the information for future play sessions» ........................................ 22 44 A p p e n d i x B Source code This appendix compiles the most relevant and the commented scripts throughout the entire document, more specifically in the development section. The project has about 17 scripts, so it is understandable that not all of them are included here. If you are interested in seeing all the code of the project, you can find the link to it in section 4.2 . 45 46 Source code Create Room Script 1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using Photon.Pun; 5using Photon.Realtime; 6 7public class Crear_Room : MonoBehaviourPunCallbacks 8{ 9public int numero; 10 11 12 // Start is called before the first frame update 13 void Start() 14 { 15 16 } 17 18 public void CrearRoom() 19 { 20 numero = Random.Range(1, 100); 21 22 Debug.Log("Se va a crear una nueva sala"); 23 24 PhotonNetwork.JoinOrCreateRoom("Sala no." + numero, new RoomOptions() { MaxPlayers = 2 }, 25 TypedLobby.Default); 26 27 Debug.Log("Se creo una nueva room" + numero); 28 29 PhotonNetwork.LoadLevel("Combate"); // 30 31 //PhotonNetwork.LoadLevel("Multijugador"); 32 } 33 34 public override void OnCreateRoomFailed(short returnCode, string message) 35 { 36 Debug.Log("No se pudo crear la sala, se vuelve a intentar"); 37 38 CrearRoom(); 39 } 40 } Source code 47 Join Room Script 1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using Photon.Pun; 5using Photon.Realtime; 6 7public class Unirse_Room : MonoBehaviourPunCallbacks 8{ 9public int numero; 10 11 12 // Start is called before the first frame update 13 void Start() 14 { 15 16 } 17 18 public void UnirseRoom() 19 { 20 PhotonNetwork.JoinRandomRoom(); 21 Debug.Log("Se unio a una room aleatoria"); 22 } 23 24 public override void OnJoinRandomFailed(short returnCode, string message) 25 { 26 Debug.Log("No se pudo unir a ninguna sala, se creara una nueva"); 27 CrearRoom2(); 28 } 29 30 public void CrearRoom2() 31 { 32 numero = Random.Range(1, 100); 33 34 Debug.Log("Se va a crear una nueva sala"); 35 36 PhotonNetwork.JoinOrCreateRoom("Sala no." + numero, new RoomOptions() { MaxPlayers = 2 }, 37 TypedLobby.Default); 38 39 Debug.Log("Se creo una nueva room" + numero); 40 41 PhotonNetwork.LoadLevel("Combate"); // 42 43 //PhotonNetwork.LoadLevel("Multijugador"); 44 } 45 46 public override void OnCreateRoomFailed(short returnCode, string message) 47 { 48 Debug.Log("No se pudo crear la sala, se vuelve a intentar"); 49 50 CrearRoom2(); 51 } 52 } 48 Source code Characters Unit Script 1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Unit : MonoBehaviour 6{ 7public string unitName; 8 9public int damage; 10 11 public int maxHP; 12 public int currentHP; 13 14 public int healing; 15 16 public bool TakeDamage(int dmg) 17 { 18 currentHP -= dmg; 19 20 if(currentHP <= 0) 21 { 22 return true; 23 } 24 25 else 26 { 27 return false; 28 } 29 } 30 31 public void Heal(int amount) 32 { 33 currentHP += amount; 34 if(currentHP > maxHP) currentHP = maxHP; 35 } 36 } Source code 49 On joined room Function 1public override void OnJoinedRoom() 2{ 3//if(battleCreated) return; 4 5jugadores = PhotonNetwork.PlayerList; 6 7jugador = jugadores.Length; 8 9Debug.Log("Se unio el jugador no." + jugador + "a la sala."); 10 11 PhotonNetwork.NickName = jugador.ToString(); 12 13 state = BattleState.START; 14 //string playerName = (jugadores.Length == 1 ? "Player" : "Player2"); 15 string playerName = "Player" + (PlayerPrefs.GetInt("monster") + 1).ToString(); 16 if (playerName == "Player1") playerName = "Player"; 17 18 string monsterName; 19 20 if(jugador == 1) 21 { 22 Hashtable hash = new Hashtable(); 23 int random = Random.Range(0,2); 24 hash.Add("monsterType", random); 25 PhotonNetwork.LocalPlayer.SetCustomProperties(hash); 26 PlayerPrefs.SetInt("monsterType", random); 27 monsterName = "Enemy" + (random + 1).ToString(); 28 if (monsterName == "Enemy1") monsterName = "Enemy"; 29 } 30 31 else 32 { 33 monsterName = "Enemy" + ((int)PhotonNetwork.PlayerListOthers[0] 34 .CustomProperties["monsterType"] + 1).ToString(); 35 if (monsterName == "Enemy1") monsterName = "Enemy"; 36 } 37 38 if(!battleCreated) StartCoroutine(SetupBattle(playerName, monsterName)); // 39 40 this.photonView.RPC("UpdateBossHPFromMaster", RpcTarget.MasterClient); 41 Debug.Log("Actualizando vida"); 42 43 /* 44 if(battleCreated) 45 { 46 this.photonView.RPC("SetBossHPAll", RpcTarget.All, enemyUnit.currentHP); 47 Debug.Log("Actualizando vida"); 48 } 49 */ 50 51 battleCreated = true;// 52 } 56 Source code 53 } 54 } 55 } Connect to Master Script 1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using Photon.Pun; 5using Photon.Realtime; 6 7public class ConectMaster : MonoBehaviourPunCallbacks 8{ 9// Start is called before the first frame update 10 void Start() 11 { 12 PhotonNetwork.GameVersion = "0.1"; 13 14 PhotonNetwork.ConnectUsingSettings(); 15 Debug.Log("Se va a conectar al servidor Maestro"); 16 } 17 18 public override void OnConnectedToMaster() 19 { 20 PhotonNetwork.AutomaticallySyncScene = true; 21 22 Debug.Log("Se ha conectado al servidor Maestro"); 23 } 24 25 public override void OnDisconnected(DisconnectCause cause) 26 { 27 Debug.Log("Problema al conectar al servidor"); 28 } 29 }