Card Movement: 1 Step Forward and 2 Steps Back

Well the good news is amazing, my initial dive into coding in Unity has proven fruitful! I have been able to click a card on my screen and drag it anywhere around the gameboard! To add to that functionality I was able to make the card remain in its new location when it was dropped, which was a lot simpler than I thought it would originally be.

This simple movement of the cards is handled in Unity by two built in functions in a C# script:

OnMouseDrag () and OnMouseUpAsButton()

These two functions sense when the mouse has been clicked down on the card and when the card has been released respectively. Focusing on OnMouseDrag, I run two lines of code to make sure that the card object stays with the mouse so long as the player keeps the mouse pressed while dragging it across the screen. The first line is used to grab the coordinates of the mouse as a reference, and the second line takes the mouse coordinates and changes the cards coordinates to match the cards every single frame. These two lines are shown below:


Vector 3 WhereIsMouse = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, distanceFromCamera);

Vector3 objectPosition = Camera.main.ScreenToWorldPoint(WhereIsMouse);


The coordinate values in unity are handled on a 3D plane, with x, y, and z axes. The unity system handles these coordinates using the Vector3 data type, which holds each of these axes as a value in a 3 element list, (x, y, z). By using two of these Vector3 objects I am able to both track where the mouse is in comparison to the camera, and change the coordinates of the object being dragged.

This is my one step forward, and as I promised in the title, I have had some problems that have set me back.


As long as something works, something else has to break. I was ecstatic when I was able to get the card movement to work, so with adrenaline coursing through my veins, I set off to achieve bigger and better things. I Thought “The card moves, now its time to make it snap to a location on the board!” This went well at first, as I was able to use another built in function in unity to detect the collision of a card above a board location (there will be more on that function in my next post). However, when I attempted to make this code work for all 9 board locations, instead of just one, I ran into a multitude of complications.

Everything from the dragging suddenly not working, to the cards in my game bugging out and flying off into space began to happen to my program. Most of these issues I couldn’t explain or even reproduce for others to help me with. So here I am, staring at a bunch of broken code with one thought in mind, “I have to restart”. I have taken this initial dive, and learned a lot in the process. Now its time to put that knowledge to the test, go a little behind schedule, and reproduce a better set of scripts that better suit my needs. Next goal on my list, get all five cards to snap to different locations on the board without my code breaking!


Next time I will be exploring more in depth what I mean by cards “snapping” to the board, as well as showing snippets of my code to explain where I went wrong in my previous iteration. Until next time.

 

Forward Progression: Hurdles and Achievements.

So for starters, I have made some amazing progress since I have opened Unity and began to work in its environment, all of which will be elaborated on in due time. For this post I will be focusing on what I have achieved thus far: objects creation in the unity environment.

final-board

My Game board with 5 card objects placed on it.

The picture above, shows the fruit of my labor this past week. I have succeeded in the creation of two major components of my game: 5 card objects that will be moved around the board, and the game board that they will be moving around on.

At the moment the cards are just static objects with no scripts attached to them. For each of these objects I created a 3D cube and attached an image to it**. In order to complete this process one must import an image into their unity project, and change it to a sprite. Once this new sprite has been created, it can be attached to any object in the scene by simply dragging the sprite and dropping it on the object.

I had an issue with this process originally, as I was confused on how images were attached to Unity objects. So when the interface was not allowing me to drop my .png or .jpeg image on my card object, I became frustrated. A couple hours later, after scouring the internet for answers and nearly giving up to look for another solution all together, I finally found the problem, each image that is imported into the Unity environment defaults to be a texture. Textures cannot be attached to Unity objects in the manner that I was attempting. That is where I learned how to change the image to a sprite. Since changing this one setting, everything has been golden on this front, and all of my base objects are in place.

So what I’ve learned about creating objects in unity with images is that:

  • Create a 3D object
  • Upload an image into the project directory
  • In the unity interface, change the Texture type of the image from “Texture” to “Sprite (2D and UI)”
  • In the unity interface, click and drag the image onto the desired object (either in the Scene window, or the Hierarchy window)
    • Alternatively, each object has a section in their respective inspector windows that is called the Sprite Renderer. In this section of the inpsector window, you can drag the image over the text box named Sprite to get the same result as the previous method.
  • Congratulations, you have created an object with a picture.

In short, this has been a train wreck of a time that has resulted in a lot of fruitful knowledge of the Unity environment.


In my next post I will be exploring my initial dive into the Unity Coding Environment, and what I have achieved on that front. Until next time.


**As a disclaimer, the images that I am currently using are from the original Triple Triad game that is copyrighted by Squaresoft (Square Enix), and will only be used for testing purposes. In the future I will be using custom made images.  

Well, this is Awkward: Past Mistakes and Plans to Move Forward

It is with a heavy heart that I admit to a recent fault of mine. As of today it has been 22 days since my last post on this blog. For a project that requires constant documentation, this is really, really, bad. Many aspects of my personal and academic life have been getting in the way, and to be completely honest, I had completely forgotten to write any posts during this time. That is in the past! I have now set up reminders, on everything that I can to make sure that I write posts regarding the material that I work on! With no more excuses on missing blog posts, I will be planning on sending in at least 2 posts per week that will keep up with the topic that I am working on for that week.


Now that I’ve gotten that off my chest, its time to get right back into business! I have recently created a rough design document that serves as an overview of the project. Inside of this document I explain my purpose of choosing this project, what I expect to learn from it, a rough schedule of how I will be working on the project for the remainder of the semester, and the plans I have for the data models I will be following during the implementation! The best part of this document, however, is that it was completely coded in LaTeX. LaTeX has given me the creative freedom that Microsoft Word just couldn’t give me. I am able to tell the paper to do exactly what I want it to do, format it any way I like, and create these documents all for the low price of FREE. LaTeX aside, my design document is linked below for those who would like to take a look at it. This document is very rough, and shall be expanded on continually in the future. You can read my design document here, and if you have any feedback please let me know!

 

Digging Deeper: The Data Behind the Scene

TL;DR = Thinking on a much simpler level, I have decided to make use of lists to store my data rather than going over the top with databases, matrices, and dictionaries.


Over the past week I have been creating presentations that have been given to a small group of my peers in order to receive feedback on my Triple Triad project. The comments from the presentations, as well as other conversations with peers and professors alike, have opened my mind to a new way that I could approach creating my project. In other words, I have been overthinking how I would implement the program with the use of the Unity system, and I have decided to take a step back to focus on simplicity rather than complexity.

This affects my project in many ways. First, focusing on a simpler approach allows me to implement my game board using a 9 element list rather than using a 3 element list, where each element of that list is a 3 element list ( a list of lists or a 3×3 matrix). Using the 9 element list allows for a speed boost in search time when trying to keep track of what cards are on the game board as I will only have to search through 9 elements at most. Applying more layers, such as a list of lists, adds more time to the search since it has to go through multiple layers to get to the data that I need. However, even though speeding up the program is nice, the best part about having the simpler approach is that it allows for a simpler implementation of the game. Since there are distinct boundaries on my small 9 slot game board, I do not need to fear hard coding the transitions and comparisons since the game is so small. If the game were much larger, with more possibilities, then hard coding would eventually get out of hand and many algorithms would need to be put in place to handle the sheer amount of possibilities.

Second, the card objects themselves can have their values stored in lists to be applied later. In this case I will be using a 6 element list that will hold the following values for each card: Card Name, North Value, South Value, East Value, West Value, and Ownership Value. The card name will be a string variable that will be used as an identifier when moving the card object around the game screen (from the hand to the board). Each of the Cardinal Values will be integers between 1 and 9, and will denote that cards power in that cardinal direction. The ownership variable will be a string that will denote which player is currently in ownership of the card (ex. the string “player 1” will mean that player 1 owns the card, while “player 2” means player 2 owns the card).

This is only the start of a much more overarching data model. This surprises me to no end that I can theoretically complete this project using such simple data structures and hard coding most of the relationships. At this point, I have to say that I am ecstatic to begin work on this project… after a lot more planning!

The Reaping: Choosing my Favorite Project

In my  previous post I outlined three projects that I could possibly complete for my Senior Project this semester. Of those three projects, I have now honed in on the one I feel the most attached to: the Triple Triad remake.

Before I move further with the implementation of the program, I will be exploring the topic further and expanding on my previous post.

As a reminder, I will be using the Unity Game Creation Engine to create this project, as it gives me the full freedom of creating my own assets from scratch, and the writing of my own code to support the project.

To make this project much more manageable, I am going to split it into three main phases, or milestones: Object and UI Creation, Coding Gameplay, and AI creation/ Final Debugging. These three steps do not need to be completed in any specific order, but each of them is required for a complete working game that can mimic its predecessor.

Object and UI Creation

The first part of this project will revolve around me creating all the assets that I will need for the program. This step includes the creation of the game board, the playable card objects, and the user interface (UI).

When making the game board I will be expecting to make use of a matrix to keep track of each of the playable locations in the game. In this case I will be using a 3 by 3 matrix that will contain the XYZ coordinate values of an object that will reside within each element of the matrix. These objects will be used to track the availability of that specific location, and will also compare the values of the card taking residence in that space (if any) to the other cards cardinally surrounding it.

The playable card objects will be created to be held in a hand of five cards by the player, and will be visible to the player at all times during the game. What makes these objects special is that they will have 4 cardinal values (1 for each direction) that will define their “power” in that specific direction. When a player plays a card that has more power than an opposing card in any direction, then those opposing cards will fall into the current players control.

Finally the user interface of the program will have a few elements to it, but I would like to keep it as minimal as possible due to the nature of the project. This part of the creation process includes the addition of counters that will keep track of how many cards each player owns on the game board, a cursor to allow the player characters to select which card to play and where to play it, and an opening menu so the player can choose whether they would like to play against an AI opponent or a friend.

The amount of time that I estimate this section of the project taking is a total of 3-4 weeks.

Coding Gameplay

In this section of the project I will be hammering out exactly what players can do during their turn, what happens when they play cards on their turn, and will keep track of which cards belong to which player on the game board.

The player turn consists of two separate actions. First the player must choose a card from their hand, and second the player will place that card on one of the nine possible spots on the game board. Once the player has completed these two actions, their turn will immediately end, and the same process will be mirrored for the second player. When both players have completed their respective turns, a round will have passed and the turn order resets to the first player.

When a card is played from a players hand onto the game board, a series of comparison functions will be activated to see if the player wins any cards. These comparison functions are simply comparing each of the possible cards opposing cardinal values, and if the card currently being played has a higher value than any of the opposing values they will win those cards.

Once during each players turn, a function will access the current state of card ownership on the game board. In other words, the function will analyze how many cards each player owns and send that data to the UI to be displayed to the player(s).

I expect this section of the project to take some time, and I am uncertain how long it will exactly take. Just to give it a number, I can estimate this section to take anywhere from 5-6 weeks.

AI Creation / Final Debugging

This is the portion of the project that will be the most difficult for me to complete. I have no prior knowledge in creating AI for gaming programs such as this. However, after doing some research into two similar projects, I am sure that creating a complex AI for the player to play against will be possible.

The first of these two projects is from GitHub user Mnylen who based his Triple Triad recreation project on the negamax algorithm. I have never encountered this algorithm before so I decided to look it up on StackOverflow. If I implemented this algorithm I would be using a tree data structure in order to explore all possible moves on the game board given the cards in the AI’s hand. After exploring all possible moves, the AI will determine the “best” move and execute it. I do see one problem with this though, if the AI will always make the best move, then can the player ever win? If I were to base my program on the negamax algorithm I will have to create exceptions to the base algorithm in order to give the player a chance at winning.

The second project I found is from Visadb’s GitHub repository in which he created a bot to play triple triad for the player that would never lose, given that the chance to win was inherently possible. What I like about the algorithm that Visadb uses, is that he created it to be used only in this special circumstance of playing triple triad. It helps boost my confidence in the fact that if I needed to I could create my own algorithm to suit my programs needs. I don’t want to make the game impossible for the player to win, but rather give them a chance to outwit a very crafty AI system.

In addition to coding an AI for my game, I will also be using the remainder of the approximately 6-7 weeks left in my project to complete any final debugging and add any special flare that I would like to the program before calling it “finished”.

Final Thoughts

The more time I put into planning this project, the more I find possibly hang ups and roadblocks. To be completely honest, I am unsure as to how the AI system is going to work for me, if it will work at all. However, if half of a week of research can ease my thoughts on most of this process, then I am sure that as soon as I hit that roadblock I will find a way through it. I cannot wait to get started coding, the more I think about it the more excited I get.

Sources

https://github.com/mnylen/triple-triad

http://stackoverflow.com/questions/14787857/how-to-use-negamax-algorithm

https://github.com/visadb/ff8_tthelper

Cards, Classic Games, and Databases: Ideas for my Senior Project

The final year of my time at Berea College has begun, and with it has come many new hurdles to get over. The one staring me down at the moment is my Senior Projects class, which is as straightforward as the title suggests. Simply I will be creating something, whether it be digital or physical, that reflects on both my interests and the material I have learned up to this point.

At this moment I have three major ideas for this project and I will be exploring each of them in semi-depth in this post. Thanks for reading, and sorry for the length.


 

PROJECT IDEA 1: TRIPLE TRIAD REMAKE

hqdefault

The first of these three projects comes from one of my  favorite games from my childhood, Final Fantasy 8.

Project Summary

Triple Triad is a mini game from Final Fantasy 8. Played on a 3×3 grid, each playable card has 4 cardinal values. The goal: beat the opponent’s numbers to own the most cards.

Tools

In this project I plan to use the Unity game creation engine to create a similar game to Triple Triad. Unity gives me the freedom to create the game entirely from scratch and code all of the possible rule sets in Unity’s environment. All coding for this project can be completed in C# or javascript.

Project Timeline

The timeline that I have for this project will be as follows:

  1. Creating the assets/objects that will be needed to play the game – 1 Week
  2. Milestone 1: Have documentation for the rest of project underway, and have most if not all assets/objects needed for the testing of the project in place.
  3. Attach values to the card objects to make them unique, and start working on the user interface – 2 Week(s)
  4. Milestone 2: At this point I would like a working user interface that has 10 cards displayed as either player 1, or player 2’s hand, and be able to move them from each players hand to the game board.
  5. Adding in simple gameplay elements and refine them – 3 Weeks
  6. Add in local multiplayer and make the game completely playable for both players. Allow for bug fixing before moving forward – 2 Weeks
  7. Milestone 3: Have the game working on the simplest form by week 8 at the latest.
  8. Once the game is working in the simplest form, I would like to start work on and AI for the player to play against. – 3 to 4 weeks (depending on complexity of AI)
  9. Milestone 4: Have the game with working AI allowing for the player to play against, and have the game almost bug free at this point, taking all free time up to this point to fix bugs in the programming.
  10. For the rest of the project I plan on working to expand the rule sets, add in more cards, allow for each player to chose a set of 5 cards for their hands. This will be the final stage of the project and will stretch through the rest of the semester. – Approx. 2-3 weeks.
  11. Milestone 5: Final product review and final updates to the system will be put in place before turning it in for the semester.
  12. Total: 14 Weeks

The Appeal to Me

The original mini game this project is based off of has significant sentimental value to me, and I found it extremely enjoyable to play. I would even go as far to not play the actual game when booting up the system, and would spend hours on Triple Triad. I would like to take all of the knowledge I have gained by playing the game over the years and put it to good use to create the game from scratch.

What I plan to learn

With a project as simple as this on the surface, it would be easy to say that nothing could be learned from the project. However, what I plan to spend a lot of time on is creating a AI for the player to play against when there is no one else to work with. I do not know anything about artificial intelligence, and thus I expect it to be a large roadblock in this project. Without the AI, the game fails to achieve the same appeal as the original as you will always have to have a friend to play the game.


 

PROJECT IDEA 2: REMAKING CLASSIC ARCADE GAMES

pong   snake

Project Summary

This project focuses on recreating classic games, such as breakout, pong, and snake. Then putting them all in one game file to choose which one to play.

Tools

This project will utilize the unity game creation engine to recreate some classic arcade games that each have their own complexities.

Project Timeline

The timeline that I have for this project will be as follows:

  1. Milestone 1: Create Pong and debug it – 4 weeks
  2. Milestone 2: Create Snake and debug it –  4 Weeks
  3. Milestone 3: Create Breakout and debug it – 4 Weeks
  4. Milestone 4: Create the interface and menu to hold all three games together – 2 weeks
  5. Milestone 5: Final debugging – 1 week
  6. Total: 15 Weeks

The Appeal to Me

My dream is to use my coding experience to become a game developer in the near future, so having somewhere to start is great for this dream. Recreating these simple old games and putting them into their own mini arcade boosts my resume in the game development field.

What I plan to learn

I have yet to understand what it means to create a game from scratch, so starting with the basics will simply give me the experience of understanding the game creation process first hand.


 

PROJECT IDEA 3: POKEMON TRADING CARD COLLECTION DATABASE AND DECK BUILDER

tcg_product_gallery_169_en

The last of these three projects has come out of a more recent hobby of mine, the Pokémon Trading Card Game.

Project Summary

This database will track all cards that a player owns and allow them to filter the cards to find the ones they need. It will also function as a deck creator with a statistic generator.

Tools

For this project, I will be using PHPmyAdmin, MySQL, HTML, and CSS to create a local database on my machine. PHPmyAdmin and MySQL will be used to primarily create the database, and PHP code will be used along with HTML and CSS to create a user interface that interacts with the database and allows the user to view the data in a cleaner format.

Project Timeline

The timeline that I have for this project will be as follows:

  1. Create the documentation explaining just how the project will progress, as well as creating an ER diagram. – 2 weeks
  2. Milestone 1:  Have all preliminary creation documents in place and be prepared to start creating the database itself in PHPmyAdmin.
  3. Create the Back end, with all necessary tables, and create relationships between the tables. – 2 weeks
  4. Milestone 2: Have the back end completed.
  5. Refer back to what needs to be created on the front end as the initial design document shows. Start to create the pages noted. – 4 weeks
  6. Milestone 3: Have a few of the pages on the front end working with the relational database in the background to pull data to tables.
  7. Finish the Front-end pages, and work on the mathematics needed to grab the statistics from the tables for the deck creator part of the project. – 4 Weeks
  8. Milestone 4: Double check that the mathematics work correctly, and have the front end mostly finished.
  9. Add in any special flare using CSS, and any other properties that were not thought of yet, or were unable to be added until this point due to problems within the project. -2 Weeks
  10. Milestone 5: Final Debugging to make sure the CSS works with the existing code without breaking the current functionality.
  11. Total: 14 Weeks

The Appeal to Me

I have spent a lot of time searching my ever growing collection of Pokémon cards, and I have constantly imagined a system that would allow me to locate a card quickly instead of hunting it down every time that I want to build a deck with it. This system will not only allow me to have that luxury but I could also share it with other players in the area to share the love.

What I plan to learn

I worked on a project similar to this one in the past, however I did not get the full experience of working on both the front end and the back end. My partners focused on the back end while I was focusing on the front end. By doing this similar project I expect to learn about every step that goes into creating a database project, rather than just part of it.


 

Project Ironcircle Demo

As I mentioned in my previous post, I will be uploading the demo of Project Ironcircle so you all can see what I have worked on in the past.

I would like to give some awesome credit the KhasArcthunder and his Sapphire Action System IV, that I make use of in this demo, as well as a few of his maps. I do not plan on making money off of this game as it is a personal project just to learn the RPG Maker VX Ace system. If you would like to see more of Khas Archthunder’s work then follow his blog. I also want to give thanks to Galv, and Yanfly for their amazing scripts!

About my demo, it is a bit crazy at times, and the dialogue is to DIE for, no really its pretty bad. But I feel that the combined work of the above-mentioned people and some small story elements from me have made this small demo both playable and enjoyable. However, I still do not understand how to make AI better, so I apologize in advance for that. You’ll understand what I mean when you load up the game.

Download the demo from my google drive here – Click to Download.

I would love some criticism, so if you would like please leave me a comment! Thanks and enjoy the demo!