Pong in C++ – Setting up the Level

Every developer should develop a Pong game, so here is my attempt to make it. I’ve decided to do it using Unreal Engine 4. There is already an excellent tutorial made by Alex Young on how to make Pong in UE4. He does it in Blueprint. I will try to do it in C++.

Project Initialization

I’m creating a new blank project in UE4. I also use git for source control and Bitbucket for the remote repository. I’m creating the UE4 project directory named Pong, inside another Pong directory. By this way, I can add other files such as Readme or temporary images in the parent directory. The Git repository is initialized in this parent directory.

Setting up Level

I’m creating a new empty level and save it inside a Maps folder, naming it “1P” for One Player. In the Project Settings, I’m setting this map as the default one for now:ProjectSettings

I’m creating 2 folders: Materials and Textures. In Textures, I’m importing my Pong.png image:
Pong

Then I’m creating a new material named M_reference which will act as a reference to create my meshes. In the Material editor, I’m holding the “T” key and left-click to create a Texture Sample node.

I’m plugging this node to “Emissive Color“, setting the “Shading Model” to “Unlit“. I’m creating a BoundingBoxBased_0-1_UVW node:

BoundingBoxBased_0-1_UVW

Then I am adding a Component Mask to get only 2 dimensions and a CustomRotator with a rotation angle of 270 degree which is a 0.75 value:

 

 

M_reference

In the Level, I am adding a BSP Box, resizing it to the size of my texture (1290×900), but I’m inversing X and Y, because of the camera view. I’m pasting my material to the top face of the cube. With a top view I can see this:BSP_TopView

Making the Ball

To make the ball, I’m adding another BSP box in the level and I am re-sizing it to 100 x 100 x 100. This is a good size to have physics on it. Then I’m scaling the reference box, so that the ball in the reference is the same size than my ball. The value for the scale is 3.75 in all directions.

Selecting the ball brush, I’m creating a Static Mesh:

BallStaticMesh

I’m  naming it “SM_Ball” and I am placing it in a new “Meshes” folder.

Creating the Paddle

For the Paddle, I’m also creating a BSP Box, resizing it to 350 x 100 x 100 and creating a static mesh named SM_Paddle. I need to set collision for this paddle. To do so, I’m opening the mesh and in the collision menu, I’m selecting “Add Box Simplified Collision“.

Collision

Creating the Boundaries

For the boundaries, I need one new box. Its size is 150 x 5100 x 10. I’m making it a static mesh named SM_Boundary.

Creating the Score

For the score, I am creating a “Text Render“, and placing it on the “0”. I am rotating it with 180 x 90 x 0.  I am setting the text as “0”, the Horizontal Alignment as “Center“, the Vertical Alignment as “Text Center” and the World Size as 820.

TextRender

Then I am duplicating it, by dragging it while holding Alt, and I am placing the new one on the other “0”. I am renaming them “P1_Score_Text and “P2_Score_Text”

Material for the Meshes

I am creating a new material named “M_unlitWhite“. In the material, I am holding the “1” key and Left clicking to get a Constant. I am setting the value to “1” and plugging it to “Emissive Color“.  I am setting the “Shadding Model” to “Unlit“.

M_unlitWhite

For each mesh, I am using this material.

Next Step

That is just the beginning. Next we will setup the camera and move the paddle.

About

Gamer

Tagged with:

Leave a Reply