0% found this document useful (0 votes)
48 views59 pages

GD Lab Record

The document outlines the Game Development Laboratory course at Karpaga Vinayaga College of Engineering and Technology, detailing various experiments related to game development using Unity and Unreal Engine. It includes procedures for installation, character design, sprite creation, and implementing character movement mechanics. The document serves as a practical record for students participating in the course, highlighting essential skills in game development.

Uploaded by

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

GD Lab Record

The document outlines the Game Development Laboratory course at Karpaga Vinayaga College of Engineering and Technology, detailing various experiments related to game development using Unity and Unreal Engine. It includes procedures for installation, character design, sprite creation, and implementing character movement mechanics. The document serves as a practical record for students participating in the course, highlighting essential skills in game development.

Uploaded by

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

KARPAGA VINAYAGA

COLLEGE OF ENGINEERING AND TECHNOLOGY


Chinna Kolambakkam, Madhurantakam Tk, 603308

DEPARTMENT OF
ARTIFICIAL INTELLIGENCE AND DATA SCIENCE

CCS347
GAME DEVELOPMENT LABORATORY

NAME

REGISTER NO :

BRANCH

SEM/YEAR
KARPAGA VINAYAGA
COLLEGE ENGINEERING & TECHNOLOGY
Chinnakolambakkam, Madurantakam Tk, 603308

Name ………………………………………………………………………………………………………………………………………………….

Year……………………….. Semester ……………… Branch ………………………………………………………………………………

University Registration No: …………………………………………………………………………………………………………………

Certified that this is a bonafide record of work done by the above student in the ………………………………
………………………………………………………………………………… Laboratory during the year ………………………………

Signature of Staff In-Charge Signature of Head of the Department

Submitted for the University Practical Examination held on …………………………………………………………….

Signature of Internal Examiner Signature of External Examiner


INDEX

S.NO DATE EXPERIMENT TITLE PAGE. MARKS SIGN.

NO

1. INSTALLATION OF A GAME ENGINES 1-7


UNITY AND UNREAL ENGINE.
FAMILIARIZATION OF THE GUI IN
UNITY. CONCEPTUALIZE THE THEME
FOR A 2D GAME.

2.(a) CHARACTER DESIGN 8-9

2.(b) CHARACTER SPRITES 10 - 14

2.(c) CHARACTER MOVEMENT 15 - 24

2.(d) CHARACTER CONTROL 25 - 31

3. LEVEL DESIGN: DESIGN OF THE 32 - 39


WORLD IN THE FORM OF TILES
ALONG WITH INTERACTIVE AND
COLLECTIBLE OBJECTS

4. DESIGN OF INTERACTION BETWEEN 40 - 41


THE PLAYER AND THE WORLD

5. DEVELOPING A 2D INTERACTIVE 42 - 44
GAME USING PYGAME

6. DEVELOPING A PUZZLE GAME USING 45 - 47


PYGAME

7. DESIGN OF MENUS AND USER 48 - 50


INTERACTION IN MOBILE PLATFORMS

8. DEVELOPING A 3D GAME USING 51 - 53


UNREAL

9. DEVELOPING A MULTIPLAYER GAME 54 - 56


USING UNITY
Ex. No : 1 Installation of a Game Engines Unity and Unreal Engine.
Date: Familiarization of the GUI in Unity.
Conceptualize the theme for a 2D game.

Aim :
To install the game engines, Unity and Unreal Engine. Also to familiarize the GUI in Unity
and Conceptualize the theme for a 2D game.

1. Installation of Unity
Procedure:
Step 1: Download Unity Hub website (https://unity.com/) or (www.unityhub.com)
• Unity Hub is a management tool that allows you to install and manage different versions of
Unity, as well as access tutorials, projects, and assets.
• Go to the Unity website and download Unity Hub from the "Downloads" page.

Step 2: Install Unity Hub


• Open Unity Hub after installation.
• Go to the "Installs" tab.
• Click on the "Add" button to add a new Unity version.
• Select the version of Unity you want to install from the list of available versions.
• Click "Next" and follow the prompts to complete the installation process.

1
Step 3: Create or Sign in to Unity ID:
• If you haven't already, create a Unity ID by clicking on "Sign in" or "Create one" in the Unity
Hub.
• A Unity ID is required to download and activate Unity licenses.

Step 4: Activate Unity License (Optional):


• Unity offers both free and paid licenses. Depending on your needs, you may choose the
appropriate license.

2
Step 5 Start Using Unity:
• Once Unity is installed and activated, you can start using it to create games and other
interactive experiences.

Step 6. Explore Resources and Documentation:


• Unity offers a wealth of resources, tutorials, and documentation to help you get started
with game development.
• You can access tutorials and resources directly from Unity Hub or from the Unity website.

3
2. Installation of Unreal Engine
Procedure:
Step 1 : Install Unreal Engine
1. Access the website at https://www.unrealengine.com.
2. Register and download the Epic Games Launcher.
3. Install and start the launcher.
4. Click the Unreal Engine tab on the left-hand side.
5. Click on the Library tab that appears at the top of the screen.
6. Click the + button next to ENGINE VERSIONS to add a version of Unreal Engine to the
launcher. You can use the newest version available.
7. Click the Install button. The launcher will start downloading the files needed for installation
and may take a long time to complete.
8. Click the Launch button to start an already installed version. It is possible to have multiple
versions of Unreal Engine installed on the same machine – you simply set one of them as the
current version. The Launch button at the top right of the launcher will start the current
version.

Step 2: Creating new projects and using templates:


`After starting up Unreal Engine Editor, the Unreal Project Browser will appear. The
Recent Projects box on the top left is used to open existing projects and the other boxes on the left
are categories of templates used to create a new project. The following screenshot shows the
templates of the Games category.

4
Select the Third Person template, choose a location folder, and fill in the Name field for the
project. Select the Project Defaults mentioned in the previous list and then click the
Create button. After the project loads, the Unreal Engine Level Editor will be displayed, as shown
in the following screenshot:

Step 3: The Unreal Engine Level Editor


These are the key panels of the Level Editor:
1. Toolbar
2. Viewport
3. Content Browser
4. Outliner
5. Details.
Step 4: Blueprints Visual Scripting
The Toolbar Panel

The Toolbar panel is located at the top of the Blueprint Class Editor and contains some essential
buttons for editing Blueprints:

The buttons are described as follows:


The Components panel
The Components panel shows all the Components that are part of the current Blueprint.

3. Familiarization of Unity GUI


Procedure:
Step 1: Scene View:
• The Scene View is where you design and build your game world.
Step 2: Toolbar:
• The Toolbar provides quick access to common actions and tools.
Step 3: Unity Editor Layout

5
Step 4: Navigation and Manipulation

Step 5: Asset Management

Step 6: Scripting and Components

6
4. Conceptualize the Theme for a 2D Game

Procedure:
Step 1: Define the Theme and Story

Step 2. Theme: This 2D game combines the charm of a whimsical bakery with the underwater
world.

Step 3: Story (Optional): You are a friendly seahorse who has opened a unique bakery on the
ocean floor.

Step 4: Gameplay:
• Players collect ingredients by completing mini-games or tasks.

Step 5 : Art Style

Step 6 : Target Audience


• This game is perfect for casual gamers and families who enjoy relaxing and creative
experiences.
Step 7. Create Art Style and Assets
Step 8. Iterate and Refine

Result:
Thus the installation of a game engine, Unity, Unreal Engine, familiarization of the GUI was
verified and installed successfully.
7
Ex. No : 2 a) Character Design
Date:

Aim:
To conceptualize and finalize a character design for a game.

Algorithm:

Step : 1 Brainstorm character concepts considering the game's theme, setting, and requirements.
Step : 2 Sketch multiple rough designs exploring different characteristics and visual styles.
Step : 3 Select one concept and refine it based on feedback and artistic vision.
Create detailed artwork for the finalized character design, including front, side, and back views.
Programs for game character design: 3D modeling
• Autodesk Maya.
• 3DS Max.
• Zbrush.
• Blender.
• Makehuman.
• Unity.
• GameMaker Studio.
• Unreal Engine

Autodesk Maya:
• Developed for interactive 3D rendering in video games, animated features, television,
and movies, Maya has been used in multiple successful projects, from Game of Thrones
and Spider-Man to Halo and numerous Pixar movies.
Zbrush:
• One of the great alternatives to Autodesk software, it is also widely used for
modeling, texturing, and painting high-resolution 3D video game character models
Blender:
• Just like the previous tools, this software is used for modeling, designing, and
animating 3D characters.
Makehuman:
• Just like Blender, MakeHuman is an open source 3D graphics tool that can help you
create realistic human beings.
Unity:
• Unity is a game design engine that you can access for free. It presents different ways
to customize game character design and settings, building from predefined elements.
GameMaker Studio:
• GameMaker Studio is a game development tool with its own programming system.
Unreal Engine:
• Finally, let’s talk about Unreal Engine. This is a development engine that, for its next
version, will present a fully customizable character creator.

8
Output:

Result:
Thus the character design using blender verified and executed successfully.

9
Ex. No : 2 b) Character Sprites
Date:

Aim:
To create sprite animations for the designed character.
Algorithm:
Step 1: Break down the finalized character design into individual sprite frames for various
actions (e.g., walking, jumping, attacking).
Step 2: Use graphics software to create sprite sheets, ensuring consistency and clarity in sprite
design.
Step 3: Animate the sprite frames to create smooth transitions between different actions.
Create Character Sprites:
Step 1 – Create a new project in Scratch. To get started, create a new project in Scratch. ...
Step 1: Go to MIT Scratch.

Step 2: Click on Create.

Step 3: Choose a Backdrop.


How to use a backdrop in Scratch?
To use a backdrop in Scratch, you must follow the following steps:
• Step 1: Open Scratch and click on the “Choose a Backdrop” option which is in blue color in
the shape of a circle available at the extreme bottom left corner of the Scratch user interface.
• Step 2: Once you click on the blue button, the following options will appear on the screen.
You can choose, paint, surprise, and upload a backdrop using these options.

10
• Step 3: To choose a particular backdrop, click on the first option that says, “Choose a
Backdrop”.

• Step 4: To paint a backdrop, click on the second option that says, “Paint”.
• Step 5: To upload a particular backdrop, click on the last option that says, “Upload
Backdrop”.

How to edit the backdrop in Scratch?


To edit a backdrop in Scratch, the user must follow the following steps:
• Step 1: Click on the “Costumes” option available in the navigation bar at the top of the
screen.
• Step 2: Once the user clicks on the “Costume” option, the following screen will appear.

• Step 3: Click on the “Backdrops” box available at the extreme right of the screen under the
Stage.

11
• Step 4: Now the user can easily edit the backdrop using the available tools present on the
left side of the editing screen.
Step 4: Choose a Sprite.

Step 5: Write the script for the project.

Step 6 : Run.
Step 7 : Conclusion.

Step 2 – Select the “Paint” option to create a sprite. ...

12
Step 3 – Draw a sprite using the brush and shapes tools. ...
1. Select the tool and the fill color
2. Click on the canvas and drag your mouse to draw.
3. Create an outline of the sprite .

Step 4 – Fill in the sprite colors using the fill tool. ...
1. Click on the fill tool
2. Select the fill color
3. Click on the object to fill in.

Step 5 – Export the sprite.


1. Right-click on the sprite in the sprite menu
2. Click export.

13
If we want to save it as a .png file. Click on “Convert to Bitmap” then export.

OUTPUT:

Result:
Thus the Character sprites using blender verified and executed successfully.

14
Ex. No: 2 c) Character Movement
Date:

Aim:
To implement basic movement mechanics for the character.
Algorithm:
Step1: To implement basic movement mechanics for the character.
Step2: Implement logic to handle player input (e.g., arrow keys for movement).
Step3: Update the character's position based on input, considering collision detection with
obstacles.
Step4: Apply gravity or other physics principles to simulate realistic movement.
Creating Character Mavement:
• Inside your PlayerCharacter_AB Animation Blueprint, navigate to the Anim Graph.

• The AnimGraph is used to evaluate a final pose for the skeletal mesh.
• Right-click on the AnimGraph and from the Actions drop down menu, search for and select
Add New State Machine.

• Rename your State Machine node to Locomotion, then double-click the node to open its
graph. Drag off from the Entry pin, and from the Actions drop down menu, select Add State.

15
• Name the new state Movement, then double-click to open the Movement State Node.
Navigate to the Asset browser, and search for Locomotion_BS, then click and drag it into
the graph.

• From the My Blueprint tab, click and drag your Speed float variable into the Blend Space's
Speed vertical axis.

• Navigate back to the My Blueprint tab, then click and drag your Direction float
variable into the Blend Space's Direction horizontal axis.

16
• Connect the Animation Pose output pin to the Animation Pose Result pin of the Output
Animation Pose node.

• Compile and Save.

• Navigate back to the Locomotion state machine, then click and drag the Movement state
node to create a new Animation state named Crouch Movement.

• Double click the Transition rule node to open its Anim Graph.

17
• From the My Blueprint Tab, navigate to the variables category and drag your Is Crouched
boolean onto the Can Enter Transition input pin from the Result node.

• From the My Blueprint Tab, navigate to the variables category and drag
your Speed and Direction float variables into their respective pins on
the LocomotionCrouch_BS, then connect your LocomotionCrouch_BS Animation Pose
into your Output Animation Pose Result pin

• Compile and Save your Animation Blueprint.

18
• Navigate back to the Locomotion AnimGraph then click and drag off
the CrouchMovement Animation state and connect it to the Movement Animation
State.

• Double click the Transition rule node to open it's Anim Graph.

• From the My Blueprints tab, click and drag the Is Crouched boolean variable onto the
Anim Graph, select Get Is Crouched, then drag off from its output pin and in the drop down
actions menu search for and select NOT Boolean.

• Next, connect the NOT Boolean's return pin to the Can Enter Transition input pin.

• Compile and Save.

19
• Navigate back to the Anim Graph, then click and drag off from the Movement Animation
state and select Add State.

• Rename this Animation State to Jump, then double-click to open its animation graph.
Navigate to the Asset Browser and search for Jump_From_Jog, then drag it into the graph.

• Finish your Jump Animation State by connecting your Play Jump_From_Jog Animation
Pose to your Output Animation Pose Result pin.

• Navigate back to the Locomotion Anim Graph, then double-click the Movement to Jump
Transition rule node to open its Anim Graph.

20
• Inside the Transition Rule Anim Graph, navigate to the My Blueprints tab, and drag your
Is Jumping Boolean variable onto the Result node's Can Enter Transition input pin.

• Navigate back to the Locomotion Anim Graph, then click and drag off the Jump anim node
and create a transition to the Movement Anim Graph node.

• Double-click the Jump to Movement Transition rule node to open it's Anim Graph.

• From the My Blueprints tab, click and drag the Is Crouched, and Is Jumping Boolean
variable onto the Anim Graph, then drag off each of their output pins and from the drop
down actions menu search for and select NOT Boolean.

21
• Drag off the NOT Boolean output pin and search for and select for the AND Boolean.

• Connect both the Is Crouched, and Is Jumping NOT Boolean node output pins into the
AND Boolean node's input pins, then connect the AND boolean's output pin into the
Result node's Can Enter Transition Input pin.

• Navigate back to the Locomotion Anim Graph, then click and drag off the Crouch node
and create a transition to the Jump node.

• Inside the CrouchMovement to Jump transition rule Anim Graph, navigate to the My
Blueprint tab, then click and drag your Is Jumping bool variable onto the Result node's
Can Enter Transition input pin.

22
• Navigate back to the Locomotion Anim Graph, then drag off from the Jump
node to create a transition to the CrouchMovement node.

• Double-click the Jump to Crouch Movement Transition rule node to open it's Anim
Graph.
• From the My Blueprints tab, click and drag the Is Crouched and Is Jumping Boolean
variables onto the Anim Graph.

• Your completed Locomotion AnimGraph will resemble the image below.

23
• Navigate to the AnimGraph and connect the Locomotion Pose Output pin into
the Output Pose Result pin.

• Compile and Save.

OUTPUT:

Result:
Thus the character movement using blender verified and executed successfully.
24
Ex. No : 2 d) Character Control
Date:

Aim:
To design and implement controls for the player to interact with the character.
Algorithm:
Step 1: Map player inputs (e.g., keyboard keys, controller buttons) to character actions (e.g.,
moving, jumping, attacking).
Step 2: Provide options for customizing controls to accommodate player preferences.
Step 3: Implement special abilities or skills for the character, along with corresponding control
schemes.
1. Concepting. 5. UV unwrapping.
2. Blocking. 6. Baking.
3. Sculpting. 7. Texturing.
4. Retopology. 8. Rigging & Skinning.
Using Blueprint to Control the Character:
STEP 1:

1. In the Content Browser expand the Sources panel and create a folder called Movies. Then,
right-click on the new folder and select Show in Explorer.
In Explorer.

2. Drag the Sample Video (or your supported video) into the Content>Movies folder of your
project on your computer.
3. Inside your project, create a Media Player and associated Media Texture asset
called MediaPlayer and MediaPlayer_Video respectively.

25
4. Create a File Media Source asset called Video and inside it, point the File Path to the
video added in Step 2.

5. Open your Media Player asset and disable the Play on Open option.

6. In the Place Actors panel under Shapes, drag a Plane into the level and resize as desired
(Place Actors can be found under the Window tab if it's not already enabled).

26
7. Drag the MediaPlayer_Video texture onto the Plane, then in the Details panefor the Plane,
add a Media Sound Component set to use your Media Player asset.

Blueprint Setup:
Next, we want to set up our initial Blueprint, so later we can add functions to it.
1. From the Main Toolbar, click the Blueprints button then select Open Level Blueprint.

2. In the Level Blueprint, create a variable called MediaPlayer (of the Media Player Object
Reference type) and set it to point to your MediaPlayer asset.
3. Hold Ctrl and drag the MediaPlayer variable into the graph and use Open
Source and Event Begin Play to open your Video File Media Source asset.

27
Play/Pause – Up:
Add an Up keyboard event connected to a Flip Flop and off your Media Player variable,
use Play and Pause as shown below.

When the Player presses the Up arrow keyboard key, the Media Source will start playing while
pressing a second time will pause the video.
1. Add Left and Right keyboard events, then off your Media Player variable use Set Rate
with the left key at -2 and the right key at 2.

2. This will enable the Player to press the left arrow keyboard key to set the Play Rate of the
video to -2 (playing the video in reverse at double speed as a value of 1.0 is normal forward
playback).
3. You could add additional Blueprint logic to determine the number of times the Player presses
the rewind or fast-forward keys and increase or decrease the Play Rate from 2x to 4x or 6x
speeds or higher.

28
Keep in mind there is a distinction between Thinned and Unthinned rates. Thinned means that
some frames will be skipped at this rate, while Unthinned means that all frames will be decoded at
this rate.
Close/Resume – Down:
1. Add a Down keyboard event connected to a Flip Flop, then off a Media Player reference,
use the Get Time function call.

2. Right-click on the Return Value of the Get Time node and promote it to a variable
called Stop Time, then connect all nodes to a Close function call as shown.
This will close the Media Player when pressing the down arrow keyboard key, but store the
current time in which the Media Player was stopped.

3. Off the B pin of the Flip Flop use the Open Source node and set the Media Source to
your Video Media Source.
4. Drag off the Media Player reference and use the Assign On Media Opened Event
Dispatcher and connect as shown.

29
5. Off your Media Player reference, call the Seek function followed by the Play function.
6. Create a Stop Time variable and connect it to the Time pin on the Seek node. Then
connect the Seek and Play nodes to the OnMediaOpened event as shown.

7. Close the Level Blueprint and click the Play button from the Main Toolbar to play in the
Editor.
OUTPUT:

30
Result:
Thus the character control using unreal engine in blender verified and executed
successfully.
31
Ex. No : 3 Level Design: Design of the world in the form of tiles along
Date: with interactive and collectible objects

Aim:
To Level design of the world in the form of tiles along with interactive and collectible objects.
Algorithm:
Step 1: Create a New Project
Step 2: Understand the Unreal Engine Interface.
Step 3: Modify and Add Assets
Step 4: Blueprint Visual Scripting
Step 5: Level Design.
Step 6: Test and Iterate.
Step 7: Package and Share.
The Viewport panel

• The Viewport panel shows the visual representation of a Blueprint and its Components.
The Viewport panel has controls similar to the Level Editor, which you can use to
manipulate the location, rotation, and scale of the Components.

32
You can move around the Event Graph by right-clicking and dragging it to see the other Events.
STEP 1: Adding Components to a Blueprint
• Now, let's create our first Blueprint. It will be a very simple Blueprint that will only
contain Components. For now, we will not use Events or Actions:
• Double-click this Blueprint to open the Blueprint Editor.

• On the Details panel, there is a property named Static Mesh, which has a drop-down input.
Click on the dropdown and select the Static Mesh property named SM_Chair. This Static
Mesh is part of the starter content. The following screenshot shows the selected SM_Chair:

33
STEP 2: Create a New Level
1. Inside the Unreal Editor, click the File Menu option then select New Level... .

This will open the New Level dialog window:

2. Click the Empty Level to select it. Finished Step

• Placing Actors in the Level In the Place Actors panel on the left, click
the Geometry category and select the Box .

• Left-click and drag the Box into the Level Viewport .

34
• When you release the Left Mouse Button , the Box is added to the level.

• In the Details panel (lower-right window of the editor), with the Box still selected,
set Location and Rotation all to 0 .
• Set the Scale to 4 x 4 x 0.1 .

• We will use this as the floor on which the player can walk around.
• In the Place Actors panel select the Lights tab, then drag-and-drop a Directional
Light into the level on top of the floor.

35
• On the Translation Tool , click and drag the Z-Axis (blue) on the gizmo up, away from the
surface of the floor.

• If the Directional Light becomes unselected, you can re-select it by Left-clicking on it in


the Level Viewport .
• In the Place Actors panel, select the Visual Effects tab and drag-and-drop an Atmospheric
Fog into the level.

• The Atmospheric Fog Actor will add a basic sky to the level and the level will become
illuminated instead of dark.

• In the Place Actors panel, select the Volumes tab and drag-and-drop a Lightmass
Importance Volume into the level.

36
• Inside the Level Viewport , press R to switch to the Scale Tool .
• Click and drag the white box in the center of the Scale Tool so that the Lightmass
Importance Volume encapsulates the floor.

• Inside the Content Browser under Content > StarterContent > Props , drag-and-drop
the SM_TableRound into the level.

• Try to place the table in the center of the floor using the Move Tool (press W if it is not
selected).
• Also under Content > StarterContent > Props , drag-and-drop the SM_Chair into the level.

37
• With the SM_Chair selected inside the Level Viewport , press E to access the Rotation
Tool .

• Left-click and drag the blue axis arc (the gizmo will update to show degrees) and rotate
the chair to face the table.

• Using the placement methods above, create a small scene by adding more Actors from
the Modes Panel and Content Browser .

• Try adding some lights, props, walls and a roof (found under
the Content > StarterContent > Architecture folder

38
STEP 3: Test and iteration:

Result:
Thus the Level design of the world in the form of tiles along with interactive and collectible
objects using unreal engine is verified and executed successfully.

39
Ex. No : 4 Design of interaction between the player and the world
Date:

Aim:
To design of interaction between the player and the world.
Algorithm:
1. Initialize the Game Environment
2. Create the Player
3. Define the World
4. Handle User Input
5. Update Player Position
6. Detect Collisions
7. Update Game State
8. Render the Scene
9. Repeat
10. End the Game Loop
Program:
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((800, 600))
clock = pygame.time.Clock()
player_x, player_y = 400, 300
player_speed = 5
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[K_LEFT]:
player_x -= player_speed
if keys[K_RIGHT]:
player_x += player_speed
if keys[K_UP]:
player_y -= player_speed
40
if keys[K_DOWN]:
player_y += player_speed
player_x = max(0, min(player_x, 800))
player_y = max(0, min(player_y, 600))
screen.fill((0, 0, 0))
pygame.draw.circle(screen, (255, 255, 255), (player_x, player_y), 20)
pygame.display.flip()
clock.tick(60)
pygame.quit()
Output:

Result:
Thus the design of interaction between the player and the world, optionally using the
physics engine is written verified and executed successfully.
41
Ex. No : 5 Developing a 2D Interactive Game using Pygame
Date:

Aim:
To develop a 2D Interactive Game using Pygame.
Algorithm:
1. Initialize Pygame
2. Set Up the Screen
3. Load Assets
4. Define Game Objects
5. Handle User Input
6. Update Game State
7. Render Graphics
8. Repeat
9. Handle Game Over Conditions
10. Display Game Over Screen
11. Clean Up
Program:
import pygame
import random
pygame.init()
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Simple Game")
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
player_width = 50
player_height = 50
player_x = WIDTH // 2 - player_width // 2
player_y = HEIGHT - player_height - 20
player_speed = 5
obstacle_width = 50
obstacle_height = 50
obstacle_speed = 3
obstacles = []
clock = pygame.time.Clock()
42
spawn_obstacle_event = pygame.USEREVENT + 1
pygame.time.set_timer(spawn_obstacle_event, 1500)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == spawn_obstacle_event:
obstacle_x = random.randint(0, WIDTH - obstacle_width)
obstacle_y = -obstacle_height
obstacles.append(pygame.Rect(obstacle_x, obstacle_y, obstacle_width,
obstacle_height))
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player_x > 0:
player_x -= player_speed
if keys[pygame.K_RIGHT] and player_x < WIDTH - player_width:
player_x += player_speed
for obstacle in obstacles:
obstacle.y += obstacle_speed
if obstacle.y > HEIGHT:
obstacles.remove(obstacle)
player_rect = pygame.Rect(player_x, player_y, player_width, player_height)
for obstacle in obstacles:
if player_rect.colliderect(obstacle):
running = False
screen.fill(WHITE)
pygame.draw.rect(screen, BLACK, player_rect)
for obstacle in obstacles:
pygame.draw.rect(screen, BLACK, obstacle)
pygame.display.flip()
clock.tick(60)
pygame.quit()

43
Output:

Result:
Thus the development of 2D interactive using pygame is written verified and executed
successfully.

44
Ex.No: 6 Developing a Puzzle game using Pygame
Date:

Aim:
To develop a Puzzle game using pygame.
Algorithm:
1. Initialize Pygame
2. Set Up the Screen
3. Load Assets.
4. Split Image into Tiles.
5. Shuffle Tiles.
6. Draw the Puzzle
7. Handle User Input.
8. Move Tiles.
9. Check for Win Condition
10. Display Win Screen
11. Repeat
12. Clean Up
Program:
import pygame
import random
pygame.init()
WIDTH, HEIGHT = 480, 480
TILE_SIZE = 120
ROWS, COLS = 4, 4
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Sliding Puzzle")
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
image = pygame.image.load("puzzle_image.jpg")
image = pygame.transform.scale(image, (WIDTH, HEIGHT))
tiles = []
for y in range(ROWS):
for x in range(COLS):
rect = pygame.Rect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE)
tile = image.subsurface(rect)
45
tiles.append(tile)
shuffled_tiles = tiles[:]
random.shuffle(shuffled_tiles)
def draw_tiles():
for i, tile in enumerate(shuffled_tiles):
x = (i % COLS) * TILE_SIZE
y = (i // ROWS) * TILE_SIZE
screen.blit(tile, (x, y))
running = True
while running:
screen.fill(WHITE)
draw_tiles()
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
mouse_x, mouse_y = pygame.mouse.get_pos()
clicked_tile = (mouse_x // TILE_SIZE) + (mouse_y // TILE_SIZE) *
COLS
blank_tile = shuffled_tiles.index(None)
if clicked_tile - 1 == blank_tile or clicked_tile + 1 == blank_tile or
clicked_tile - COLS == blank_tile or clicked_tile + COLS == blank_tile:
shuffled_tiles[clicked_tile], shuffled_tiles[blank_tile] =
shuffled_tiles[blank_tile], shuffled_tiles[clicked_tile]
pygame.quit()

46
Output:

Result:
Thus the development of a puzzle game using pygame is written , verified and executed
successfully.

47
Ex. No : 7 Design of menus and user interaction in mobile platforms
Date:

Aim:
To Design of menus and user interaction in mobile platforms and user interaction in mobile
game development
Algorithm:
Step 1: Introduction to common components like buttons, sliders, discussing functions for user
interaction.
Step 2: Teaching wireframe/prototype creation, vital for iterating and refining UI designs.
Step 3: Provide game dev environment (e.g., Unity) guiding scene creation and linkage for menus.
Step 4: Introduce scripting concepts, offer code snippets for common interactions (e.g., button
clicks, transitions).
Step 5: Encourage testing on mobile devices, gathering feedback for iterative improvements.
Program:
using UnityEngine;
using UnityEngine.UI;
public class MenuController : MonoBehaviour
{
public GameObject mainMenuPanel;
public GameObject optionsMenuPanel;

void Start()
{
// Show the main menu panel and hide other panels
ShowMainMenu();
}

public void ShowMainMenu()


{
mainMenuPanel.SetActive(true);
optionsMenuPanel.SetActive(false);
}

48
public void ShowOptionsMenu()
{
mainMenuPanel.SetActive(false);
optionsMenuPanel.SetActive(true);
}

public void StartGame()


{
// Add code to start the game
Debug.Log("Starting the game...");
// For simplicity, let's load a new scene for the game
// Replace "GameScene" with the name of your game scene
UnityEngine.SceneManagement.SceneManager.LoadScene("GameScene");
}

public void QuitGame()


{
// Add code to quit the game
Debug.Log("Quitting the game...");
Application.Quit();
}
}

Output:

49
Result:
Thus design of menus and user interaction in mobile platforms verified and executed
successfully.

50
Ex. No : 8 Developing a 3D Game using Unreal
Date:

Aim:
To develop a 3D multiplayer game using Unreal Engine, focusing on implementing basic
player movement.
Algorithm:
Step 1: Understand the basics of Unreal Engine and its capabilities for developing 3D games.
Step 2: Launch Unreal Engine and create a new project.
Step 3: Design a simple 3D environment using Unreal Engine's built-in tools or assets from the
marketplace.
Step 4: Import or create a 3D character model to serve as the player character.
Step 5: Write code to handle character movement using Unreal Engine's built-in character
movement component such as walking, running, jumping, and crouching.
Step 6: Test the game to ensure character movement behaves as expected.
Program:
Header file (.h)
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"
UCLASS()
class YOURPROJECT_API AMyCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Constructor
AMyCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input

51
virtual void SetupPlayerInputComponent(class UInputComponent*
PlayerInputComponent) override;

// Function for moving the character forward/backward


void MoveForward(float Value);

// Function for moving the character right/left


void MoveRight(float Value);
private:
// Speed for character movement
UPROPERTY(EditAnywhere)
float MoveSpeed = 500.f;
};
Source file (.cpp)
// Source file (.cpp)
#include "MyCharacter.h"
// Sets default values
AMyCharacter::AMyCharacter()
{ // Set this character to call Tick() every frame
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent*
PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// Bind movement functions to input axes
PlayerInputComponent->BindAxis("MoveForward", this,
&AMyCharacter::MoveForward);

52
PlayerInputComponent->BindAxis("MoveRight", this,
&AMyCharacter::MoveRight);
}
// Function for moving the character right/left
void AMyCharacter::MoveRight(float Value)
{
// Move the character right based on input value
AddMovementInput(GetActorRightVector(), Value * MoveSpeed * GetWorld()-
>GetDeltaSeconds());
}
Output:

Result:
Thus the Developing a 3D Game using Unreal is , verified and executed successfully.

53
Ex. No : 9 Developing a Multiplayer game using unity
Date:

Aim:
To develop a real-time multiplayer game in Unity using the NetCode for GameObjects
framework, aiming to synchronize player data, optimize network serialization, and test
multiplayer functionality across multiple clients.
Algorithm:
Step 1: Understand Unity's NetCode for GameObjects framework for real-time multiplayer games
and recognize the importance of synchronized player data and efficient network transmission.
Step 2: Launch Unity, create a new project, and install required packages: NetCode for GameObjects,
Multiplayer Samples Utility, and Parallel Sync Helper via the Package Manager.
Step 3: Create a new GameObject named 'Network Manager', add the NetworkManager component
to it, and grasp the NetworkManager's role in managing connections.
Step 4: Design a player GameObject with PlayerController script and Rigidbody component, add
NetworkObject component to make it networked, and assign the player prefab to NetworkManager
for automatic spawning.
Step 5: Explore two methods for syncing player data: use Unity's ClientNetworkTransform for basic
synchronization.
Step 6: Test multiplayer functionality across multiple clients by starting a host server and
connecting as clients to observe synchronized player data.
Program:
Sample code for PlayerController script
using UnityEngine;
public class PlayerController : MonoBehaviour
{
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
// Add player movement controls here
}
}
54
Sample code for PlayerNetwork script
using MLAPI;
using MLAPI.NetworkVariable;
using UnityEngine;

public class PlayerNetwork : NetworkBehaviour


{
public NetworkVariable<Vector3> position = new
NetworkVariable<Vector3>(new NetworkVariableSettings{WritePermission =
NetworkVariablePermission.Everyone});
public NetworkVariable<Quaternion> rotation = new
NetworkVariable<Quaternion>(new NetworkVariableSettings{WritePermission =
NetworkVariablePermission.Everyone});

void FixedUpdate()
{
if (IsLocalPlayer)
{ // Update position and rotation variables based on local player input
position.Value = transform.position;
rotation.Value = transform.rotation;
}
}
}

55
Output:

Result:
Thus the Developing a Multiplayer game using unity is verified and executed successfully.

56

You might also like