0% found this document useful (0 votes)
31 views23 pages

Tic Tac Toe

Tic toc toe

Uploaded by

royaljaanu6
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)
31 views23 pages

Tic Tac Toe

Tic toc toe

Uploaded by

royaljaanu6
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/ 23

SCHOOL OF ENGINEERING AND TECHNOLOGY

A Project Report
On

Space invader game”


Submitted in partial fulfillment of the requirements for the award of degree in

BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE

SUBMITTED BY-
K.Sindhu

23BBTCS105

GUIDED BY-
Prof. K.PRABHAKAR
Assistant Professor,

Dept. of IT,

SoET, CMRU, Bangalore.

Department of Computer Science and Engineering


Off Hennur - Bagalur Main Road,

Near Kempegowda International Airport, Chagalahatti,

Bangalore, Karnataka-562149
2024-2025
SCHOOL OF ENGINEERING AND TECHNOLOGY
Chagalahatti, Bengaluru, Karnataka-562149

Department of Computer Science and Engineering

CERTIFICATE

This is to certify that the Project entitled “Space invader game using C language” has been
successfully carried out by K.Sindhu (23BBTCS105) in partial fulfillment of the requirement
for the award of the degree Bachelor of Technology in Computer Science Engineering of
CMR University, Bengaluru during the academic year 2024-2025.The project report has
been approved as it satisfies the academic requirements in respect of project work
prescribed for the said degree.

Signature of the Guide Signature of HOD

____________ ___________

Prof. K.PRABHAKAR Dr.RUBINI.P

Assistant Professor Head of the Department

Dept. of IT Dept. of CSE

SoET, CMRU, Bangalore. SoET, CMRU, Bangalore.


ACKNOWLEDGEMENT

The satisfaction that accompanies the successful completion of this project would be
incomplete without the mention of the people who made it possible, without whose constant
guidance and encouragement would have made efforts go in vain.

I would like to express my thanks to Dr. Rubini.P, Professor and Head, Department of
Computer Science and Engineering, School of Engineering and Technology, CMR University,
Bangalore, for his encouragement that motivated me for the successful completion of Project
work.

I express my thanks to my Internal Project Guide Prof. K.Prabhakar Assistant Professor,


Department of Information Technology and Engineering, School of Engineering and
Technology, CMR University for her constant support.

i
DECLARATION

K.Sindhu (23BBTCS105) student of 3rd semester B.Tech, Computer Science and


Engineering, School of Engineering and Technology, Bangalore, hereby declare that the
project work entitled “Space invader game using C language” has been carried out by me
under the guidance of Prof. K.Prabhakar, Assistant Professor, Department of Information
Technology and Engineering, School of Engineering and Technology. This report is submitted
in partial fulfillment of the requirement for award of Bachelor of Technology in Computer
Science and Engineering, by CMR University, Bangalore during the academic year 2024-2025.
The project report has been approved as it satisfies the academic requirements in respect of
project work prescribed for the said degree.

Place: Bangalore

Date: 13-11-2024

ii
ABSTRACT
The Space Invader game, when implemented in the C programming language, serves as a
fundamental example of how to create an interactive, arcade-style game using basic
programming concepts. In this game, the player controls a spaceship that moves horizontally
at the bottom of the screen and shoots projectiles to destroy waves of alien invaders descending
from the top. The game is structured around a continuous loop where the alien invaders move
in patterns, and the player must react quickly to shoot them before they reach the bottom. Core
components of the C implementation include handling real-time user input, updating the
display with ASCII-based graphics, and managing game states such as score tracking and
player lives. The spaceship's movement is controlled by user input (typically using arrow keys
or other keyboard keys), while missiles are fired in response to a shooting command. Collision
detection plays a key role, determining when a missile hits an alien or when an alien reaches
the player's spaceship, causing game-over conditions. The use of functions like `printf()` and
`system("cls")` for screen updates, combined with logic for detecting collisions and
maintaining game flow, enables a simple yet engaging gameplay experience. The program is
an excellent exercise in learning how to implement basic game mechanics, such as movement,
firing, and enemy behavior, and offers a solid foundation for more advanced game development
projects. The Space Invader game in C demonstrates how efficient code can deliver an
interactive, dynamic gaming experience with minimal graphical resources, making it a useful
learning tool for budding programmers.
INDEX

SERIAL.NO TOPICS PAGE.NO


ACKNOWLEDGEMENT i
DECLARATION ii
ABSTRACT iii
1. INTRODUCTION
2. SOFTWARE REQUIREMENTS
3. METHODOLOGY
4. PROGRAM CODE
5. OUTPUT
6. CONCLUSION
7. REFERENCE
OBJECTIVE OVERVIEW
The objective of implementing the Space Invader game using the C programming language is to
develop a functional, interactive arcade-style game that demonstrates key programming concepts
such as game loops, user input handling, graphics manipulation, and collision detection. The
primary goal of the game is for the player to control a spaceship at the bottom of the screen and
shoot down waves of descending alien invaders before they reach the player's position. To
achieve this, the game must handle multiple core tasks: continuously updating the screen to
reflect movement of the spaceship, aliens, and missiles; processing real-time keyboard input for
spaceship movement and firing; detecting collisions between missiles and aliens or between
aliens and the spaceship; and managing game states, such as tracking the player's score,
remaining lives, and the number of aliens left. Additionally, the game must allow for the aliens
to move in a predefined pattern, with each level increasing in difficulty as the player progresses.
Through the implementation of these features, the game provides a hands-on opportunity to
apply fundamental C programming skills, while also giving insight into the design and
mechanics of a basic video game. Ultimately, the Space Invader game serves as both an
educational exercise and an example of how to create simple but engaging interactive
experiences using C.
SPACE INVADER GAME

1.INTRODUCTION

The "Space Invaders" game is one of the most iconic arcade games developed by Tomohiro
Nishikado in 1978. The objective of the game is to control a spaceship that can move
horizontally and shoot upwards to destroy waves of alien invaders that are descending toward the
player's ship. The player must avoid enemy fire while attempting to destroy all enemies on the
screen.

Basic Structure of the Game

In this implementation of Space Invaders in C, we'll break down the game into several
components:

1. Player Ship:

- The player controls a spaceship at the bottom of the screen that can move left or right and
shoot projectiles upwards.

2. Aliens (Invaders):

- A grid of alien invaders at the top of the screen moves horizontally across the screen. Once
they reach the edge of the screen, they move downwards and change direction.

3. Projectiles:

- Both the player's spaceship and the aliens can shoot projectiles. The player's projectiles go
upwards, and the alien projectiles move downwards. The player must avoid these projectiles.

4. Collisions:

- When a player's projectile hits an alien, the alien is destroyed, and the score increases.
Similarly, if an alien's projectile hits the player's spaceship, the player loses a life or the game
ends.
SPACE INVADER GAME

5. Game Over & Scoring:

- The game continues until all aliens are destroyed or the player loses all lives. The score is
calculated based on how many aliens are destroyed.

Implementation Overview

The game will utilize the following features of the C language:

- Graphics and Display: While C does not have built-in graphics, we can use text-based graphics
for a simple version of the game (using libraries like `ncurses` on Unix-like systems or `conio.h`
on Windows).

- Game Loop: The game will run in a continuous loop where the player can move the spaceship,
shoot, and interact with the invaders in real-time.

- Collision Detection: We'll implement basic collision detection between projectiles and
invaders, as well as the player’s ship and enemy projectiles.

- Input Handling: The player will use keyboard input to move the ship and fire projectiles.

Key Functions Explained

1. initializeGame(): Initializes the player’s ship position, alien positions, and game state (such as
score and lives).

2. drawScreen(): Clears the screen and redraws the player, aliens, and projectiles on the terminal.

3. movePlayer(): Takes input from the player (using `getch()` or similar methods) to move the
ship left or right.
SPACE INVADER GAME

4. shootProjectile(): Detects when the player presses the fire button and creates a new projectile
at the player’s ship position.

5. updateProjectiles(): Updates the positions of the projectiles and checks if they hit any enemies
or go off-screen.

6. checkCollisions(): Detects collisions between projectiles and aliens or between alien


projectiles and the player's ship.

7. checkGameOver(): Checks if the game is over based on whether all aliens are defeated or if
the player has lost all their lives.
SPACE INVADER GAME

2.SOFTWARE REQUIREMENTS

Basic Software Requirements

1. C Compiler:

- To compile and run the C code, you'll need a C compiler. Here are some commonly used
compilers:

- GCC (GNU Compiler Collection): Available on Linux, macOS, and Windows (via MinGW
or Cygwin).

- Clang: A compiler available for macOS, Linux, and Windows.

- MinGW (Minimalist GNU for Windows): A GCC-based compiler for Windows.

- Microsoft Visual Studio (MSVC): A compiler and IDE for Windows.

- Installation:

- On Windows, you can use MinGW or MSVC. MinGW can be installed via the [MinGW-
w64] website or by using package managers like Chocolatey.

- On Linux, GCC is typically pre-installed or can be installed via the package manager (e.g.,
`sudo apt install gcc` for Ubuntu).

- On macOS, Clang is available by default, or you can install GCC via Homebrew.

2. IDE or Text Editor:

- While you can write C code using any text editor, using an Integrated Development
Environment (IDE) can make development easier. Common IDEs for C programming include:

- Code::Blocks: A free, open-source C/C++ IDE that includes a built-in compiler (works
across Windows, Linux, and macOS).

- Dev C++: Another free IDE for Windows with a built-in compiler.

- Visual Studio: A powerful IDE for Windows that supports C/C++ development.
SPACE INVADER GAME

- Eclipse with CDT (C Development Tools): A cross-platform IDE that supports C/C++
development.

- Vim/Emacs: If you prefer a text editor with more control and customizability.

3. Graphics Library (Optional):

- If you want to add graphical features like images, colors, and animations to your Space
Invaders game, you might want to use a graphics library. However, for a simple text-based
implementation, no graphics library is necessary.

- Some common graphics libraries for C include:

- ncurses: A library for text-based user interfaces, useful for handling keyboard input and
screen updates in a terminal.

- SDL (Simple DirectMedia Layer): A library for handling graphics, events, and audio. It is
more suitable for graphical games and provides functions for rendering 2D images, handling
events, and more.

- OpenGL: A powerful graphics library primarily used for 3D rendering, but it can be used for
2D games as well.

- Allegro: A cross-platform library for game development that supports 2D graphics, sound,
input, and more.

-Installation (for SDL as an example):

- Linux: `sudo apt-get install libsdl2-dev`

- macOS: Install via Homebrew: `brew install sdl2`

- Windows: Download and install the development libraries from the SDL website, and set up
the development environment in your IDE (e.g., Visual Studio).

4. Terminal/Command Prompt (for text-based game):


SPACE INVADER GAME

- If you're making a text-based game (without graphics), you'll need access to a terminal
(Linux/macOS) or a command prompt (Windows). Most of the IDEs and text editors above
come with integrated terminal windows.

Optional Software (For Advanced Features)

1. Sound Libraries:

If you wish to add sound effects and music to your game, you can use libraries such as:

- SDL_mixer: An extension of SDL for handling audio (supports formats like MP3, WAV,
etc.).

- OpenAL: A cross-platform audio library for games and other 3D applications.

- FMOD: A comprehensive sound library for adding audio effects.

2. Version Control System:

- Git: A version control system is useful if you're working on the game over time or
collaborating with others. Git can help you track changes to your code, revert to previous
versions, and collaborate on projects.

- GitHub or GitLab: Platforms for hosting your code and collaborating with other developers.
You can easily integrate your project with a repository to keep track of changes and share your
game.
SPACE INVADER GAME

3.METHODOLOGY

1. Define Game Requirements

Before diving into coding, it's crucial to understand the basic mechanics and features of the game.
In Space Invaders, the main elements include:

- A player-controlled spaceship at the bottom of the screen.

- Waves of alien invaders at the top of the screen.

- Projectiles fired by the player and aliens.

- Collision detection between projectiles and aliens.

- Scoring and game-over conditions.

2. Design the Game Structure

Before coding, break down the game into manageable components:

- Game loop: This will repeatedly check user input, update the game state, and render the screen.

- Player: A structure to hold player properties (position, lives, score).

- Aliens: A structure to represent the alien invaders (positions, states).

- Projectiles: A structure to handle the player's bullets and alien bullets.

- Collision detection: A function to check if a projectile hits an alien or the player.

- Game state: Track whether the game is ongoing, paused, or over.


SPACE INVADER GAME

3. Game Flow and Logic

The game operates in a main loop that repeatedly:

- Takes input from the user.

- Updates the positions of player and alien, checks for collisions.

- Draws the game state to the screen.

- Checks for game-over conditions.

4.Coding key components

Initialize the Game

- Set up the player’s initial position, lives, and score.

- Initialize the alien grid at the top of the screen.

- Set up an array or list to hold active projectiles.

5. Rendering the Game (Drawing the Screen)

For a text-based game, draw the game state using `printf` or similar functions. For graphical games,
use libraries like SDL or ncurses.
SPACE INVADER GAME

6. Game Over and Restart Mechanism

After the player loses all lives or defeats all the aliens, show a game-over screen and provide an
option to restart.

4. PROGRAM OF SPACE INVEDER GAME

#include <stdio.h>

#include <stdlib.h>

#include <conio.h> // For _kbhit() and _getch()

#include <windows.h> // For Sleep()

#define SCREEN_WIDTH 50

#define SCREEN_HEIGHT 20

#define ALIEN_ROWS 3

#define ALIEN_COLS 5

#define MAX_PROJECTILES 5
SPACE INVADER GAME

// Structures for Player, Alien, and Projectile

typedef struct {

int x, y; // Position of the player

int lives;

int score;

} Player;

typedef struct {

int x, y; // Position of the alien

int alive; // Whether the alien is alive or not

} Alien;

typedef struct {

int x, y; // Position of the projectile

int active; // 1 if active, 0 if inactive

} Projectile;

// Global variables
SPACE INVADER GAME

Player player;

Alien aliens[ALIEN_ROWS][ALIEN_COLS];

Projectile projectiles[MAX_PROJECTILES];

int alienDirection = 1; // 1: move right, -1: move left

// Function prototypes

void initializeGame();

void drawScreen();

void processInput();

void moveAliens();

void moveProjectiles();

void checkCollisions();

void fireProjectile();

void updateGame();

int isGameOver();

void displayGameOver();

// Main function

int main() {
SPACE INVADER GAME

initializeGame();

while (!isGameOver()) {

drawScreen();

processInput();

moveAliens();

moveProjectiles();

checkCollisions();

updateGame();

Sleep(100); // Delay to control game speed

displayGameOver();

return 0;

// Initialize the game state

void initializeGame() {

player.x = SCREEN_WIDTH / 2;
SPACE INVADER GAME

player.y = SCREEN_HEIGHT - 2;

player.lives = 3;

player.score = 0;

// Initialize aliens

for (int i = 0; i < ALIEN_ROWS; i++) {

for (int j = 0; j < ALIEN_COLS; j++) {

aliens[i][

5.Output

--------------------------------------------------

| A A A A A | A A A A A | A A A A A|

--------------------------------------------------

| |

| |

| |

| |

| |

| P |
SPACE INVADER GAME

--------------------------------------------------

Score: 0 Lives: 3

--------------------------------------------------

--------------------------------------------------

| |

| |

| GAME OVER |

| Your Score: 20 |

| |

| |

--------------------------------------------------
SPACE INVADER GAME

6. CONCLUSION

The Space Invaders game implemented in C provides a simple yet engaging example of how to
develop an interactive, text-based game using fundamental programming concepts. By utilizing
basic structures, loops, conditionals, and handling user input, this project offers valuable insight
into core game development principles.This Space Invaders game in C is a great project for
learning the fundamentals of game development, especially in terms of handling user input,
game state management, and collision detection. Although the game is simple and text-based, it
serves as a solid foundation for more advanced games, and the skills gained from developing this
game can be applied to other game development projects, both in C and other programming
languages. The game demonstrates how a well-designed structure can lead to a functional and
enjoyable game, even within the limitations of a console environment.

19
20
SPACE INVADER GAME

7. REFERENCE

1.Geeks for geeks


2.Open-source Repositories
3.www.wikipedia.com

21
20

You might also like