Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
GAME PROGRAMMING
Name : Shaikh Mohd Kaunain
STD : TYCS
Roll No: 49
INDEX
SR DATE TITLE SIGN
NO.
1 26/06/24 Learn Basic Game Designing Techniques with
Pygame.
a) Create Window/Display
b) Circle
c) Rectangle
d) Square
e) Triangle
f) Change the Name of the title
2 03/07/24 Setup DirectX 11 , Window Framework and Initialize
Direct3D Device
3 06/07/24 Make a Snake game in pygame
4
Create a Terrain and add the following object.
a) Mountain
b) snow
c) Green Land
d) Boat
e) Sand
5 22/08/2024 Create a snow fall in unity
6 Coin animation
7 12/09/2024 Create camera shake effect in unity
8 19/09/2024 Create infinite background scrolling
9 19/09/2024 Gun Shooting
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
PRACTICAL NO 1
Aim : Learn Basic Game Design Techniques with pygame.
a. Create Window / Display
b. Circle
c. Rectangle
d. Square
A Create Window / Display
Step1: Install pygame
Open command prompt ◻ pip install pygame
CODE:
import pygame, sys
from [Link] import *
[Link]()
WINDOW_WIDTH = 600
WINDOW_HEIGHT = 500
WINDOW = [Link].set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
OUTPUT:
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Procedure:
B. CODE FOR CIRCLE :
import pygame, sys
from [Link] import *
[Link]()
WINDOW_WIDTH = 600
WINDOW_HEIGHT = 500
WINDOW = [Link].set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
[Link](WINDOW,(0,255,0),(300,100),70)
[Link]()
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
OUTPUT:
Procedure:
C. CODE FOR RECTANGLE
import pygame, sys
from [Link] import *
[Link]()
WINDOW_WIDTH = 600
WINDOW_HEIGHT = 500
WINDOW = [Link].set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
[Link](WINDOW,(255,0,0),(160,180,280,180))
[Link]()
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
OUTPUT:
Procedure:
D. CODE FOR SQUARE
import pygame, sys
from [Link] import *
[Link]()
WINDOW_WIDTH = 600
WINDOW_HEIGHT = 500
WINDOW = [Link].set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
[Link](WINDOW,(255,255,255),(150,150,250,250))
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
[Link]()
OUTPUT :
Procedure:
E. Code for Triangle
Syntax: [Link]()
CODE:
import pygame, sys
from [Link] import *
[Link]()
WINDOW_WIDTH = 600
WINDOW_HEIGHT = 500
WINDOW = [Link].set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
[Link](WINDOW,(255,0,255),[[400,400],[350,300],[300,400]])
[Link]()
OUTPUT:
Procedure:
F. Change the name of the Title
Syntax:
[Link].set_caption()
CODE:
import pygame, sys
from [Link] import *
[Link]()
WINDOW_WIDTH = 600
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
WINDOW_HEIGHT = 500
WINDOW = [Link].set_mode((WINDOW_WIDTH,WINDOW_HEIGHT))
[Link].set_caption('shape of the Triangle') [Link](WINDOW,(255,255,0),[[400,400],
[350,300],[300,400]])
[Link]()
OUTPUT:
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
PRACTICAL NO 2
STEP 1 :
· Open Visual Studio 2019
· Click on Create a new project
STEP 2 :
· Select Window Forms App (.NET Framework)
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
STEP 3 :
· Right click on Project Name
· click on Add
· click on Reference..
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Now Select Open Folders which contains .dll files
· [Link]
· [Link].Direct3D
· [Link].Direct3DX
Open All three folders and select .dll files
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
STEP 4 :
· Right click on Properties
· Click on open
· Click on Build
· Platform target à x86
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
STEP 5 :
· make Any CPU to x86 on Top menu
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
STEP 6 :
· Select file → Events (thunder sign) → Appearance à Pain à name_of_paint
#PROGRAM :
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link].Direct3D;
namespace MyFirstPract {
public partial class Form1 : Form
{ [Link]
device; public Form1() {
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
InitializeComponent();
InitDevice();
public void InitDevice() {
PresentParameters pp = new PresentParameters();
[Link] = true;
[Link] = [Link];
device = new Device(0, [Link], this, [Link],
pp);
private void Render()
{ [Link]([Link], [Link], 0, 1);
[Link]();
private void form1_paint(object sender, PaintEventArgs e) {
Render();
}
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
FINAL OUTPUT :
OUTPUT with (.NET Framework 4) :
OUTPUT with (.NET framework 3.5) :
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
PRACTICAL NO. 3
AIM : Make a Snake game in pygame.
STEP 1:
import pygame
import time
import random
snakeSpeed = 25
#window Size
window_x=720
window_y=480
#Defining colors
black= [Link](0,0,0)
white=
[Link](255,255,255) red=
[Link](255,0,0) green=
[Link](0,255,0) blue=
[Link](0,0,255)
OUTPUT :
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
STEP 2 :
#Initialization
[Link]()
[Link].set_caption("Snake Game")
game_window = [Link].set_mode((window_x , window_y))
#FPS
fps = [Link]()
OUTPUT :
STEP 3:
#snake Position
snakePosition = [100,50]
#Snake body
snakeBody = [[100,50],[90,50],[80,50],[70,50]]
#Fruit position
fruitPosition = [[Link](1,(window_x//10))*10,[Link](1,(window_y//10))*10]
fruitSpawn = True
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
#snake Direction
direction = 'RIGHT'
changeTo = direction
STEP 4 :
#initial Score
score = 0
def show_score(choice , color , font,size):
score_font = [Link](font,size)
score_surface = score_font.render('Score :- '+str(score),True,color)
score_rect = score_surface.get_rect()
game_window.blit(score_surface , score_rect)
STEP 5 :
#game Over Function
def game_over():
my_font = [Link]('times new roman',60)
game_over_surface = my_font.render('Your Score is :- '+str(score),True,red)
game_over_rect = game_over_surface.get_rect()
game_over_rect.midtop = (window_x/2 , window_y/4)
game_window.blit(game_over_surface , game_over_rect)
[Link]()
[Link](2)
[Link]()
quit()
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
OUTPUT :
STEP 6 :
#Main function
while True :
for event in [Link]():
if [Link] == [Link]:
if [Link] == pygame.K_UP:
changeTo = 'UP'
if [Link] == pygame.K_DOWN:
changeTo = 'DOWN'
if [Link] == pygame.K_LEFT:
changeTo = 'LEFT'
if [Link] == pygame.K_RIGHT:
changeTo = 'RIGHT'
#if Two Keys pressed simultenously then
if changeTo == 'UP' and direction !='DOWN':
direction = 'UP'
if changeTo == 'DOWN' and direction !='UP':
direction = 'DOWN'
if changeTo == 'LEFT' and direction !='RIGHT':
direction = 'LEFT'
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
if changeTo == 'RIGHT' and direction !='LEFT':
direction = 'RIGHT'
#moving the Snake
if direction == 'UP':
snakePosition[1] -= 10
if direction =='DOWN':
snakePosition[1] +=10
if direction == 'LEFT':
snakePosition[0] -= 10
if direction =='RIGHT':
snakePosition[0] +=10
STEP 7 :
#moving the Snake
if direction == 'UP':
snakePosition[1] -= 10
if direction =='DOWN':
snakePosition[1] +=10
if direction == 'LEFT':
snakePosition[0] -= 10
if direction =='RIGHT':
snakePosition[0] +=10
#snake body growing mechanism
# if fruits and snakes colide then increase the score
[Link](0, list(snakePosition))
if snakePosition[0] == fruitPosition[0] and snakePosition[1]== fruitPosition[1]:
score += 10
fruitSpawn = False
else:
[Link]()
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
STEP 8 :
if not fruitSpawn:
fruitPosition= [[Link](1,(window_x//10))*10,
[Link](1,(window_y//10))*10]
fruitSpawn = True
game_window.fill(black)
for pos in snakeBody:
[Link](game_window, green ,[Link](pos[0],pos[1],10,10))
STEP 9 :
[Link](game_window , white , [Link](fruitPosition[0],fruitPosition[1],10,10))
#Game over condition
if snakePosition[0] < 0 or snakePosition[0] > window_x-10:
game_over()
if snakePosition[1] < 0 or snakePosition[1] > window_y-10:
game_over()
#Touching the snake body
for block in snakeBody[1:]:
if snakePosition[0] == block[0] and snakePosition[1] == block[1]:
game_over()
STEP 10 :
show_score(1,white,'times new roman',20)
[Link]()
[Link](snakeSpeed)
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
OUTPUT :
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
PRACTICAL NO : 04
Aim : Create a Terrain and add the following components :
a) Mountain
b) Snow
c) Green Land
d) sand
e) Boat
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
PRACTICAL NO : 05
Aim : Create a snow fall in unity
Step 2 : Go to inspector → set shape → BOX (any shapes)
Step 3 : Go to Shape → scale to x= 15, y=20, z=20
Step 4 : Go to inspector → start speed = 0 ( It will move snow in the direction of box )
Step 5 : Set the velocity over lifetime
z == -5 : Practical will move down as they seem to be falling
Step 6 : Set the emission → rate over lifetime = 100 ( To get more snow particles )
Step 7: Set → start size → Random Between Two Constants
set value from 1 to 2
Step 8 : Snow particle will have parallel axis to the fall
Set velocity over life time → set y = -1 , z = -2
Step 9 : Set size over lifetime ( As will go down they will fade away )
Step 10 : To five more natural effect add noise
Go to noise → strength = 0.2
OUTPUT :
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Practical No. : 6
Aim : Coin Animation
Download on coin image from Google
1. Import this image in the unity
2. Click on Assestcoin-inspector--change the following properties
3. Texture type: sprite 2d and UI
4. Sprite Mode: Multiple
5. Click on Sprite Editor: Slice---Apply
6. Close it then Drag and Drop it on the screen
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Practical No. 07
Aim : Create camera shake effect in unity
#Program :
using UnityEngine;
using [Link];
public class CameraShake : MonoBehaviour
{
// Transform of the camera to shake. Grab the gameObject's transform
//if null
public Transform camTransform;
// How long the object should shake for
public float shakeDuration = 0f;
// Amplitude of the shake. A larger value shakes the camera harder
public float shakeAmount = 0.7f;
public float decreaseFactor = 1.0f;
Vector3 originalPos;
void Awake()
{
if (camTransform == null)
{
camTransform = GetComponent(typeof(Transform)) as Transform;
}
}
void OnEnable()
{
originalPos = [Link];
}
void Update()
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
{
if (shakeDuration > 0)
{
[Link] = originalPos + [Link] * shakeAmount;
shakeDuration -= [Link] * decreaseFactor;
}
else
{
shakeDuration = 0f;
[Link] = originalPos;
}
}
}
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Practical No. 08
Aim : Create infinite background scrolling
Program :
using [Link];
using
[Link];
using UnityEngine;
public class InfiniteScrolling :
MonoBehaviour { public float
speed;
[SerializeField]
private
Renderer bg;
// Update is called once per
frame void Update () {
[Link] += new Vector2(speed *
[Link], 0);
}
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Output :
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Practical No 9 :
Aim : Gun Shooting
#Program :
[ [Link] ]
using [Link];
using
[Link];
using UnityEngine;
public class Gun :
MonoBehaviour { public
Transform
bulletSpawnPoint; public
GameObject bulletPrefab;
public float bulletSpeed =
10;
// Update is called once per
frame void Update () {
if ([Link]([Link])) {
var bullet = Instantiate(bulletPrefab, [Link],
[Link]); [Link]<Rigidbody>().velocity =
[Link] * bulletSpeed;
}}}
[ [Link] ]
using [Link];
using
[Link];
using UnityEngine;
public class Bullet :
MonoBehaviour { public
float life = 3;
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
void Awake() {
Destroy(gameObject,
life); }
void OnCollisionEnter(Collision
collision)
{ Destroy([Link]);
Name : Shaikh Mohd Kaunain Roll no : 49 Game Programming 2024-2025
Destroy(gameObject);
}}
OUTPUT :