0% found this document useful (0 votes)
153 views35 pages

GD Manual

The document details how to develop a puzzle game using Python and Pygame. It explains downloading Python and Pygame, setting up the environment, collecting requirements, and implementing representation, user interaction, move validation, and solution checking to create the puzzle game.

Uploaded by

S.Vigneshwaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views35 pages

GD Manual

The document details how to develop a puzzle game using Python and Pygame. It explains downloading Python and Pygame, setting up the environment, collecting requirements, and implementing representation, user interaction, move validation, and solution checking to create the puzzle game.

Uploaded by

S.Vigneshwaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

1.

INSTALLATION OF GAME ENGINE


Unity

Introduction

Unity is a cross-platform game engine for creating games in both 2D and 3D. Unity supports building
games for many platforms such as iOS, Android, Windows, PlayStation, Oculus Rift, and many [Link]
guide shows you how to install Unity Personal on Windows; however, installing Unity on macOS follows
a very similar procedure.

Installing Unity

1. Go to Unity’s Download Page and click “Download Installer for Windows”. A UnityDownloadAssistant-
[Link] file should be downloaded to your “Downloads” folder (where x.x is the current Unity version).

2. Open the downloaded installer. You will see a screen like this:

3. Accept the license and terms and click Next.

4. Select the components you would like to be installed with Unity and click “Next”. Note: If you ever
want to change the components, you can re-run the installer.
5. You can change where you want Unity installed, or leave the default option and click “Next”.

6. Depending on the components you selected, you may see additional prompts before installing. Follow
the prompts and click “Install”. Installing Unity may take some time. After the installation is finished,
Unity will be installed on your computer.

RESULT

Thus the Unity game Engine have been verified and executed successfully.
[Link] 2D INTERACTIVE USING PYGAME

ALGORITHM:

STEP:1 Install Python using ([Link])

STEP:2 Install Pygame Module using "pip install pygame"

STEP:3 Run a simple test script to confirm that Pygame is installed correctly.

STEP:4 After installation process , Start the game developing process.

STEP:5 Adding sound, Music & Physics.

STEP:6 After adding all the components then Executed Snake game.

SOURCE CODE:

import pygame

import time

import random

[Link]()

white = (255, 255, 255)

yellow = (255, 255, 102)

black = (0, 0, 0)

red = (213, 50, 80)

green = (0, 255, 0)

blue = (50, 153, 213)

dis_width = 600

dis_height = 400

dis = [Link].set_mode((dis_width, dis_height))

[Link].set_caption('Snake Game by Intellipaat')

clock = [Link]()

snake_block = 10

snake_speed = 15
font_style = [Link]("bahnschrift", 25)

score_font = [Link]("comicsansms", 35)

def Your_score(score):

value = score_font.render("Your Score: " + str(score), True, yellow)

[Link](value, [0, 0])

def our_snake(snake_block, snake_list):

for x in snake_list:

[Link](dis, black, [x[0], x[1], snake_block, snake_block])

def message(msg, color):

mesg = font_style.render(msg, True, color)

[Link](mesg, [dis_width / 6, dis_height / 3])

def gameLoop():

game_over = False

game_close = False

x1 = dis_width / 2

y1 = dis_height / 2

x1_change = 0

y1_change = 0

snake_List = []

Length_of_snake = 1

foodx = round([Link](0, dis_width - snake_block) / 10.0) * 10.0

foody = round([Link](0, dis_height - snake_block) / 10.0) * 10.0

while not game_over:

while game_close == True:

[Link](blue)

message("You Lost! Press C-Play Again or Q-Quit", red)

Your_score(Length_of_snake - 1)

[Link]()

for event in [Link]():


if [Link] == [Link]:

if [Link] == pygame.K_q:

game_over = True

game_close = False

if [Link] == pygame.K_c:

gameLoop()

for event in [Link]():

if [Link] == [Link]:

game_over = True

if [Link] == [Link]:

if [Link] == pygame.K_LEFT:

x1_change = -snake_block

y1_change = 0

elif [Link] == pygame.K_RIGHT:

x1_change = snake_block

y1_change = 0

elif [Link] == pygame.K_UP:

y1_change = -snake_block

x1_change = 0

elif [Link] == pygame.K_DOWN:

y1_change = snake_block

x1_change = 0

if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:

game_close = True

x1 += x1_change

y1 += y1_change

[Link](blue)

[Link](dis, green, [foodx, foody, snake_block, snake_block])

snake_Head = []
snake_Head.append(x1)

snake_Head.append(y1)

snake_List.append(snake_Head)

if len(snake_List) > Length_of_snake:

del snake_List[0]

for x in snake_List[:-1]:

if x == snake_Head:

game_close = True

our_snake(snake_block, snake_List)

Your_score(Length_of_snake - 1)

[Link]()

if x1 == foodx and y1 == foody:

foodx = round([Link](0, dis_width - snake_block) / 10.0) * 10.0

foody = round([Link](0, dis_height - snake_block) / 10.0) * 10.0

Length_of_snake += 1

[Link](snake_speed)

[Link]()

quit()

gameLoop()

OUTPUT:
RESULT:

Thus the python program to developing 2d snake game using Pygame module have been verified and
executed successfully.
[Link] PUZZLE GAME

ALGORITHM:

STEP1 : Start the program

STEP2 : Downloding python using [Link]

STEP3 : Setup Environment variables and installing pygame module using (pip install pygame)

STEP4 : After downloading module then collecting all the requirements.

STEP5 : Representation, initial state, user interaction, move validation, puzzle solvability, solution
checking and feedback.

STEP6 : Stop the program

SOURCE CODE:

import pygame
import random
import pyautogui
from [Link] import *

class Tiles:
# main method for initializing different variables
def __init__(self, screen, start_position_x,
start_position_y, num, mat_pos_x, mat_pos_y):
[Link] = (0, 255, 0)
[Link] = screen
self.start_pos_x = start_position_x
self.start_pos_y = start_position_y
[Link] = num
[Link] = tile_width
[Link] = tile_depth
[Link] = False
self.position_x = mat_pos_x
self.position_y = mat_pos_y
[Link] = False

# Draw tiles
def draw_tyle(self):
[Link]([Link], [Link], [Link](
self.start_pos_x, self.start_pos_y, [Link], [Link]))
numb = [Link](str([Link]), True, (125, 55, 100))
[Link](numb, (self.start_pos_x + 40, self.start_pos_y + 10))

# Mouse hover chnage the color of tiles


def mouse_hover(self, x_m_motion, y_m_motion):
if x_m_motion > self.start_pos_x and x_m_motion < self.start_pos_x
+ [Link] and y_m_motion > self.start_pos_y and y_m_motion <
self.start_pos_y + [Link]:
[Link] = (255, 255, 255)
else:
[Link] = (255, 165, 0)

# when mouse clicks check if a tile is selected or not


def mouse_click(self, x_m_click, y_m_click):
if x_m_click > self.start_pos_x and x_m_click < self.start_pos_x +
[Link] and y_m_click > self.start_pos_y and y_m_click <
self.start_pos_y + [Link]:
[Link] = True
else:
[Link] = False

# when mouse click released unselect the tile by setting False


def mouse_click_release(self, x_m_click_rel, y_m_click_rel):
if x_m_click_rel > 0 and y_m_click_rel > 0:
[Link] = False

# Move the tile(i.e hower)


def move_tyle(self, x_m_motion, y_m_motion):
self.start_pos_x = x_m_motion
self.start_pos_y = y_m_motion

# Create tiles w.r.t to no of tiles available

def create_tyles():
i = 1
while i <= tile_count:
r = [Link](1, tile_count)
if r not in tile_no:
tile_no.append(r)
i += 1
tile_no.append("")
k = 0
for i in range(0, rows):
for j in range(0, cols):
if (i == rows - 1) and (j == cols - 1):
pass
else:
t = Tiles(screen, tile_print_position[(
i, j)][0], tile_print_position[(i, j)][1],
tile_no[k], i, j)
[Link](t)
matrix[i][j] = tile_no[k]
k += 1
check_mobility()

# check if the tile can be places on the


# required position where the
# player is trying to move the tile

def check_mobility():
for i in range(tile_count):
tile = tiles[i]
row_index = tile.position_x
col_index = tile.position_y
adjacent_cells = []
adjacent_cells.append([row_index-1, col_index, False]) # up
adjacent_cells.append([row_index+1, col_index, False]) # down
adjacent_cells.append([row_index, col_index-1, False]) # right
adjacent_cells.append([row_index, col_index+1, False]) # left
for i in range(len(adjacent_cells)):
if (adjacent_cells[i][0] >= 0 and adjacent_cells[i][0] < rows)
and (adjacent_cells[i][1] >= 0 and adjacent_cells[i][1] < cols):
adjacent_cells[i][2] = True

for j in range(len(adjacent_cells)):
if adjacent_cells[j][2]:
adj_cell_row = adjacent_cells[j][0]
adj_cell_col = adjacent_cells[j][1]
for k in range(tile_count):
if adj_cell_row == tiles[k].position_x and adj_cell_col
== tiles[k].position_y:
adjacent_cells[j][2] = False

false_count = 0

for m in range(len(adjacent_cells)):
if adjacent_cells[m][2]:
[Link] = True
break
else:
false_count += 1

if false_count == 4:
[Link] = False

# if after iterating the matrix the


# string we get is 12345678_ then
# the player has won("Game Over")

def isGameOver():
global game_over, game_over_banner
allcelldata = ""
for i in range(rows):
for j in range(cols):
allcelldata = allcelldata + str(matrix[i][j])

if allcelldata == "12345678 ":


game_over = True
game_over_banner = "Game Over"

print("Game Over")

for i in range(tile_count):
tiles[i].movable = False
tiles[i].selected = False

# Window dimension
page_width, page_depth = [Link]()
page_width = int(page_width * .95)
page_depth = int(page_depth * .95)

# tile dimensions
tiles = []
tile_width = 200
tile_depth = 200

# no of rows & column i.e puzzle size


rows, cols = (3, 3)
tile_count = rows * cols - 1 # how many tiles should be created
matrix = [["" for i in range(cols)] for j in range(rows)]
tile_no = []
tile_print_position = {(0, 0): (100, 50),
(0, 1): (305, 50),
(0, 2): (510, 50),
(1, 0): (100, 255),
(1, 1): (305, 255),
(1, 2): (510, 255),
(2, 0): (100, 460),
(2, 1): (305, 460),
(2, 2): (510, 460)}

# initial values of variables


mouse_press = False
x_m_click, y_m_click = 0, 0
x_m_click_rel, y_m_click_rel = 0, 0
game_over = False
game_over_banner = ""

# initialize pygame and set the caption


[Link]()
game_over_font = [Link]('[Link]', 70)
move_count = 0
move_count_banner = "Moves : "
move_count_font = [Link]('[Link]', 40)
screen = [Link].set_mode((page_width, page_depth))
[Link].set_caption("Slide Game")
font = [Link]('[Link]', 200)

# creation of tiles in the puzzle


create_tyles()

running = True
while running:
[Link]((0, 0, 0)) # fill with black color
# start drawing the gui board of sliding puzzle
[Link](screen, (165, 42, 42), [Link](95, 45, 620, 620))
game_over_print = game_over_font.render(
game_over_banner, True, (255, 255, 0))

# blit() will take that rectangular Surface


# and put it on top of the screen.
[Link](game_over_print, (950, 100))

# render the move_count with the use of str


if move_count == 0:
move_count_render = move_count_font.render(
move_count_banner, True, (0, 255, 0))
else:
move_count_render = move_count_font.render(
move_count_banner + str(move_count), True, (0, 255, 0))
[Link](move_count_render, (1050, 200))

# Get events from the queue.


for event in [Link]():
# if its quite operation then exit the while loop
if [Link] == [Link]:
running = False
# if mouse click are detected then find (x,y)
# and then pass them to mouse_hover method
if [Link] == [Link]:
x_m_motion, y_m_motion = [Link].get_pos()
for i in range(tile_count):
tiles[i].mouse_hover(x_m_motion, y_m_motion)
# if the tile is selected & mouse is pressed
# then pass the coords to move_tyle method
for i in range(tile_count):
if tiles[i].selected and mouse_press:
tiles[i].move_tyle(x_m_motion, y_m_motion)
# Moving tile downwards
if [Link] == [Link]:
mouse_press = True
x_m_click, y_m_click = [Link].get_pos()
for i in range(tile_count):
tiles[i].mouse_click(x_m_click, y_m_click)
# Moving tile upwards
if [Link] == [Link]:
mouse_press = False
x_m_click_rel, y_m_click_rel = [Link].get_pos()
x_m_click, y_m_click = 0, 0
cell_found = False
for i in range(0, rows):
for j in range(0, cols):
tile_start_pos_x = tile_print_position[(i, j)][0]
tile_start_pos_y = tile_print_position[(i, j)][1]

if (x_m_click_rel > tile_start_pos_x and x_m_click_rel


< tile_start_pos_x + tile_width) and (y_m_click_rel > tile_start_pos_y and
y_m_click_rel < tile_start_pos_y + tile_depth):
if matrix[i][j] == "":
for k in range(tile_count):
if game_over == False:
if tiles[k].selected:

if tiles[k].movable:
cell_found = True
dummy =
matrix[tiles[k].position_x][tiles[k].position_y]
matrix[tiles[k].position_x]
[tiles[k].position_y] = matrix[i][j]
matrix[i][j] = dummy
tiles[k].position_x = i
tiles[k].position_y = j
tiles[k].start_pos_x =
tile_print_position[i, j)][0]tiles[k].start_pos_y = tile_print_position[(
i, j)][1]
move_count += 1
isGameOver()
check_mobility()

if cell_found == False:
for k in range(tile_count):
if tiles[k].selected:
mat_pos_x = tiles[k].position_x
mat_pos_y = tiles[k].position_y
tiles[k].start_pos_x = tile_print_position[(
mat_pos_x, mat_pos_y)][0]
tiles[k].start_pos_y = tile_print_position[(
mat_pos_x, mat_pos_y)][1]
break

for i in range(tile_count):
tiles[i].draw_tyle()
# allows only a portion of the screen to updated,
# instead of the entire area,
# If no argument is passed it
# updates the entire Surface area like pygame.
[Link]()
# Update the whole screen
[Link]()

Output
Result

Thus the python program to developing the puzzle game have been verified and executed successfully.
[Link] A MULTIPLAYER GAME USING UNITY

The Unity Game Engine


Today, I will teach you how to create a small multiplayer experience using one of the most powerful game
engines out there- the Unity game engine. It is a great engine for game making, as it comes with a slew of
premade tools that you can mix and match at you’re leisure to craft your game.

A newly integrated tool is the Unity Multiplayer Networking library or MLAPI. This tool allows you to create
remote procedure calls with annotations, and it also offers security that was lacking in Unity’s previous
networking library.

Let’s Get Started

 Download Unity from the official website, which can be found here: [Link]

 You’re going to create a new project and name it: “MyMLAPITest”. Make sure to select the
template of 3D.

 Next, you’re going to install the MLAPI library to the version corresponding to the version of Unity
you downloaded. To do this you can follow these instructions [Link]
[Link]/docs/migration/install. Now that we have MLAPI set up, our project is
ready to go.

Creating our Simple Multiplayer Experience


First, we need to create our network manager for the sample scene in which we will be building our game.
Right-click on the hierarchy tab and click on “Create Empty”. Like in the screenshot below:
Now, to this empty Gameobject, we will be adding a component to it. Click on the “Gameobject” we just
created.

Next, in the Inspector tab, click on “Add component” and then type “Network Manager”. Add that
component to the empty Gameobject.
Next, we need to select a transport for our networking. Click on the “UnetTransport” in the select a
transport part of the network manager. Note that you don’t need to know what transport is, just know that
it is part of what MLAPI uses for networking.

We are now ready to create the player prefab for when players connect to our server. If you don’t know
what a prefab is, it’s a collection of game objects and components that can be stored in a disk and reused in
scenes. It is an abstraction that allows us to manipulate complex composite game objects.

Let’s start creating a player prefab by creating a cube as is shown below. Right-click on the scene hierarchy
tab and then select “3D Object > Cube”.
Next, we are going to make the cube a network Gameobject by adding to it a component, as we did for the
network manager. The difference is this time we are going to add two components: one called
NetworkTransform and the other called NetworkObject.

Now, we are going to save our prefab as a file by dragging and dropping the PlayerPrefab Gameobject into
the tab below which shows us the project’s files.
Now, we add the prefab to the list of prefabs instantiated when a player joins a server. We do this by
clicking on the empty game object we created to have the network manager component. Then, on the
NetworkPrefabs part, we click on the “+” icon and drag the player prefab from the file system. Make sure to
click on the checkbox “Default Player Prefab”.

Next, we need to download the HelloWorldManager from:


[Link]
[Link]

Download it to the Assets folder inside our current project. Then, add this script as a component to the
NetworkManager.

We then add physics to our game. We do this by adding a rigid body to our player prefab. Click on the
prefab and then in the inspector tab, adding a component name “RigidBody”.
Here, we can make a point to add material to the PlayerPrefab cube. For more details, you can visit this
tutorial: [Link]
in-unity2/

Next, we add terrain upon which our players can fall into. Right-click on the Scene Hierarchy tab and click on
“3D Object > Terrain”.

Now, we move our terrain below the position where our players spawn. To do this, click on the terrain
object in the scene view and then look at the inspector and edit the values that appear on the transform
component to the following:” X:-500, Y:-10, Z:-500″.

Move the camera so that you can see the new players fall on the terrain. To do this, we again click on the
scene view, but this time we select the object named Main Camera and then move to the inspector and edit
the values that appear on the transform component to the following: “X:0, Y:–10, Z:-10”.
Testing the Game
Let’s compile our game and run it. To do this, go to “File > Build Settings > Player Settings” and in fullscreen
mode, select “Windowed” and put in the desired resolution.

Build the game by clicking on “File > Build Settings” and then on “build”. Select the folder where your game
will be saved and then open two instances of it.
Once the game is built, open two windows and test that every time a player connects, a new cube is created
and dropped. It should look something like this :
RESULT:

Thus the developing a Multiplayer game using unity have been verified and executed successfully.

[Link] A 3D GAME USING UNREAL

Moving the Player Forward

Navigate to the Blueprints folder and open BP_Player.

To move the player forward, you will add an offset to the player’s location each frame.

First, you need to create a variable to define the speed of the player’s forward movement. Create
a Float variable named ForwardSpeed and set its default value to 2000.
Next, make sure you are in the Event Graph and then locate the Event Tick node. Create the following
setup:

By multiplying ForwardSpeed with Delta Seconds, you get a frame rate independent result.
Note: If you aren’t familiar with frame rate independence, please read our Blueprints tutorial. We cover
it in the Frame Rate Independence section.

Next, you will use this result to move the player along a single axis.

Moving Along a Single Axis

To move the player, create an AddActorWorldOffset node. Set Sweep to true by left-
clicking its checkbox.
If you try to connect the Float result to the Delta Location input, Unreal will automatically convert it to
a Vector.

However, this will put the Float value into the X, Y and Z components of the Vector. For this game, the
forward movement should only be along the X-axis. Luckily, you can split a Vector into
three Float components.

Make sure the Delta Location pin of the AddActorWorldOffset node has no connections. Right-
click the Delta Location pin and select Split Struct Pin.
Finally, connect everything like so:

Let’s recap:

1. Every frame, the game will multiply ForwardSpeed and Delta Seconds to get a frame rate
independent result

2. The AddActorWorldOffset will use the result to move the player along the X-axis

3. Since Sweep is enabled, the player will stop moving forward if anything blocks it

Click Compile and then go back to the main editor. If you press Play, you will move through the tunnel.
Instead of placing tunnels manually, you can create a Blueprint that spawns tunnels automatically.

Creating the Tunnel Spawner

Go to the Content Browser and make sure you are in the Blueprints folder. Create a new Blueprint
Class with Actor as the parent class. Name it BP_TunnelSpawner and then open it.

Since the game will be spawning tunnels constantly, it’s a good idea to create a spawning function. Go
to the My Blueprint panel and create a new function named SpawnTunnel. The purpose of this function
will be to spawn a tunnel at a provided location.

To pass a location to the function, the function needs an input parameter. These will appear as input
pins when you call the function.

They will also appear as output pins on the Entry node of the function.
Let’s go ahead and create an input parameter. Make sure you are in the graph for
the SpawnTunnel function. Select the Entry node and then go to the Details panel. Click the + sign next
to the Inputs section.

Rename the input parameter to SpawnLocation and change its type to Vector.

To spawn a tunnel, add a Spawn Actor From Class node. Click the drop-down located to the right of
the Class pin and select BP_Tunnel.

To set the spawn location, right-click the Spawn Transform pin and select Split Struct Pin. Afterwards,
link the Spawn Actor From Class node to the Entry node like so:
Now, whenever you call the SpawnTunnel function, it will spawn an instance of BP_Tunnel at the
provided location.

Let’s test it out!

Testing the Tunnel Spawner

Switch to the Event Graph and locate the Event BeginPlay node. Add a SpawnTunnel node and connect
it to the Event BeginPlay node.

On the SpawnTunnel node, set Spawn Location to (2000, 0, 500).

Now, when the game starts, it will spawn a tunnel up and away from the player. Click Compile and then
go back to the main editor.

First, delete BP_Tunnel from the level. Do this by left-clicking on BP_Tunnel in the World Outliner.
Afterwards, press the Delete key to remove it from the level.
Next, go to the Content Browser. Left-click and drag BP_TunnelSpawner into the Viewport. This will add
an instance of it to the level.

If you press Play, the game will spawn a tunnel above and away from the player.

Restarting the Game

There are two things the game needs to do when restarting:

1. Reset the player. This includes removing the restart button from the screen.

2. Respawn the tunnels. This is so the player starts at the beginning of the tunnel.

Let’s start with resetting the player.

Resetting the Player

Open BP_Player and then create a new function called RestartGame. Create the following graph:

Summary:

1. Set Is Dead sets IsDead to false. This re-enables forward movement.

2. Remove From Parent removes RestartWidget from the screen

3. Set Input Mode Game Only re-enables game input so the player can move around

4. Set Show Mouse Cursor hides the mouse cursor

Next, let’s respawn the tunnels.

Respawning the Tunnels


Click Compile and then close BP_Player.

Open BP_TunnelSpawner and make sure you are in the SpawnInitialTunnels graph.

First, you need to remove the existing tunnels before you spawn new ones.

Add a Sequence node after the Entry node. Connect the Then 1 pin to the ForLoop node.

Note: The Sequence node executes its outputs in sequential order. It is a great way to organize your
graph vertically especially since node chains can get very long.

Next, create the following nodes:

This setup will get all the existing tunnels and remove them from the game.

Finally, connect the Then 0 pin of the Sequence node to the Get All Actors of Class node. This will make
sure the tunnels are removed before the spawning process.

Here is the final graph:


The last thing to do is handle the button click.

Handling Button Clicks

Click Compile and then close BP_TunnelSpawner.

Go to the Content Browser and navigate to the UI folder. Double-click on WBP_Restart to open it.

Select RestartButton and then go to the Details panel. Go to the Events section and click
the button next to OnClicked.

This will create a node called On Clicked (RestartButton). This node will execute when the player clicks
on RestartButton.

Recreate the following:


Summary:

1. Get Owning Player Pawn returns the Pawn that the player is currently controlling

2. Cast to BP_Player checks if the Pawn is of class BP_Player

3. If it is, it will call the RestartGame function. This function resets the player and hides the restart
button.

4. Get All Actors of Class and Get returns BP_TunnelSpawner and then calls SpawnInitialTunnels.
This function will remove existing tunnels and spawn new ones.

Note: You might be wondering why I used Get All Actors Of Class instead of using a reference
to BP_TunnelSpawner. The main reason is because BP_Tunnel doesn’t have a relationship
to WBP_Restart. For a simple game like this, it is easier to do the above method rather than figuring out
where to store a reference.

Click Compile and then close the Blueprint editor. Press Play to test out the restart button!
RESULT :

Thus the developing a 3D game using unreal have been verified and executed successfully.

You might also like