Wednesday, March 29, 2017

First game character created

Last weekend I created our first character to play in the game. This is the basic sombrero character that tries to get over the wall. I created it in Adobe Animate, alltough I have never used that programm it didn't take long to learn the basic features. Also it is easy to export it as a sprite sheet, which we will have to use to implement in the game.

First "Sombrero" character animated

First I thought about the design og the hat, because all the sombrero characters will wear a sombrero hat. I had already drawn a hat for the Logo I made so I used that one. You can see the Logo here, alltough I will probably update this Logo and make it better for when the final version of our game comes out.
Logo, probably not the final version

Now back to the process of the first character. I started to think simple and only have a hat with feet. Also to learn the programm better. I came up with this:
First animated character

After that I started drawing some sketches at home. I started by looking at the "zombie" characters from the "Plants vs Zombies" game. I switched his head back, changed his mouth, added some big eyebrows (with a nice little animation) and made his clothes a little more "Mexican style". You can see the comparison below. I should probably make his head a little bigger.
Basic "Sombrero" character
"Plants vs Zombies" character





















As you can see this was quite a process and the next character will be a "Sombrero" on a donkey, in the game he will cost more recources than the basic version, but have more speed.

Saturday, March 25, 2017

JUnit | Adding JUnit Library to IntelliJ IDE

IntelliJ is shipped with JUnit versions but they are not added to your project by default. You have to add JUnit libraries to your project manually. I'll show you how to do it the easy way.
  1. Place the cursor at the end of the class name.
  2. The cursor should be exactly at the end of the class name
  3. Press Alt + Enter
  4. Alt-Enter pressed
  5. Click create test and choose the latest JUnit version. If JUnit is not in the module, press Fix
  6. Fix button shown up
  7. Use the JUnit library that comes with IntelliJ and check all the methods you want to test
  8. choose IntelliJ's JUnit distribution
    check the boxes and press ok!
  9. Go to project structure and set the scope to compile
Remark: It's conventional to have the same test class name as the class tested with the suffix 'test'.

Thursday, March 23, 2017

Off-Topic | Ubuntu | No wifi connection after standby modus

If you're using Ubuntu on Lenovo ThinkPad T430 series, you might have the same problem as me: No internet connection after you've woken up your laptop from standby modus.

I haven't found any better solution yet but this will solve your problem: go to terminal and run this code sudo service network-manager restart please write comments if you have more automated solution for me.

Wednesday, March 22, 2017

Java | The power of Anonymous Class

Overloading a method in an Anonymous class

Client Class
Client Controller JavaFX
As you can see on the pictures above, display method is defined and called in the client class. If we want that any process from the display method to be done in a different class, we can use an anonymous class. The idea is simple. you create an instance of a class that immediately invoked itself and overload all the methods which are defined and called in that class to be done in the target class.

Sunday, March 12, 2017

JavaFx | Basic Knowledge

The Stage

In JavaFX the The user interface is the 'Stage'. Like in a theater, the stage is where all the events will be presented to the audiences or the users.
To create a JavaFX application on IntelliJ, you simply have to create a new JavaFX class.
Creating JavaFX application
After you created the JavaFX application, you can see, there is a start method to be implemented. For now the curtains of the stage is still closed. You can open the curtains by adding primaryStage.show(); to the start method.
adding show method to open the stage
If you now run the application, you'll see an empty 'stage'. The stage is there, now it is up to you to perform a show

The Scene

Now that you have a stage, you might want to perform a show. To do that, you'll need a scene. In a scene, there are some props or in Java terms, 'nodes'. A node can be a button, text field or just a label. To create a good scene you might want all these nodes to be organized nicely. Some nodes that build one feature, should also be placed side by side so the user will know intuitively what these nodes are about. Nodes is organized in a class called Parent. In Web term, it is similar to div tags. You can organize the nodes vertically using VBox Parent or horizontally using HBox Parent.

Layouts

BorderPane
BorderPane is a layout with five areas: Top, left, center, right and bottom.
GridPane
As the name said, GridPane works with grid system.
use indexes to organize the nodes
use hgap and vgap to control the space between grid
when there is not enough space, the nodes will shrink to fit the window

Java Client Server | Simple Socket Programming

To make an application that can communicate with other applications like chat-app or multiplayer games, we need a server that serve data between clients. A Client send data to the server and the server send it to another client. Server and client send data to each other via sockets.
How to create a Server
  • Create a class with a main method
  • Create an instance of ServerSocket. You need to pass any port number as a parameter ServerSocket ss = new ServerSocket(9999);
  • In order to accept an incoming client connection, we have to call the ServerSocket.accept() method. As soon as connection request is made from client, this method will return a socket that created specifically for this client.
  • To send and receive data from client, you can use OutputStreamWriter and BufferedReader
  • The Server
How to create a Client
  • Create a class with a main method
  • Create an instance of Socket class and pass the port number and the private ip address of your server as parameter.  You can use localhost instead of ip for local testing. Socket s = new Socket(ip, port);
  • To send and receive data from client, you can use OutputStreamWriter and BufferedReader
  • The Client
How it works
Run the server. once the accept() method is called, the server will wait for a client to connect. When you run the client, a connection request is made and ServerSocket will then create a socket that is connected to the client's socket until Socket.close() method is called. To make a simple chat application, put a Writer and a Reader in a while loop and use a Scanner to take user input.

Saturday, March 11, 2017

Java | Try with resources statement

Since Java 1.7 you can declare all resources that can be closed. e.g BufferedReader right after the try statement. With this feature, all resources will be closed and errors will be caught automatically. Before Java 1.7 you'll have to close all resources manually. like this:
managing resources before java 1.7
Since Java 1.7 this is simplified to this:
managing resources after java 1.7

Git | Github | Summary

Quick setup

  • Install git, sudo apt-get install git
  • Create Github account
  • In terminal, generate SSH key cd ~/.ssh && ssh-keygen leave passphrase empty, just press enter until the key is created
  • While still in ssh directory, cat id_rsa.pub and copy the entire key
  • Go to your Github setting, SSH and add SSH. paste the key in the key field. Give it a proper name and save
  • Go back to terminal, setup username and email on git git config --global user.name "john" and git config --global user.email "john.doe@gmail.com" Remember the username and email address muss be the same as the ones used for Github account
  • Go back to Github, create a new repository.
  • Now go to the folder of your application. cd /path/of/your/application and run these command
  • git init
  • git add -A
  • git commit -m "any message e.g. 'my first commit'"
  • Add your ssh URL or copy paste from your Github repository page git remote add origin ssh://login@IP/path/to/repository
  • git push -u origin master

Thursday, March 9, 2017

Java | UDP Socket Programming

There are two types of Internet Protocols that maintain a network conversation between applications. TCP (Transmission Control Protocol) and UDP (User Datagram Protocol.

In UDP we don't have a continuous connection. Each time a data exchange is done, the relationship is done. Therefore, every package should know where they are going. You must mention IP address and Port number in every package