Skip to content

Commit 52622a6

Browse files
authored
Merge pull request #61 from sanchit1804/main
Typing Speed Game
2 parents 0eb58d5 + 84cd633 commit 52622a6

13 files changed

Lines changed: 474 additions & 58 deletions

File tree

.github/workflows/update-index.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Update Game Index
2+
23
on:
34
push:
45
branches: [ main, master ]
@@ -8,28 +9,32 @@ on:
89
jobs:
910
update-index:
1011
runs-on: ubuntu-latest
12+
1113
steps:
12-
- uses: actions/checkout@v3
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
1316
with:
1417
token: ${{ secrets.GITHUB_TOKEN }}
15-
18+
fetch-depth: 0 # Important for pushing commits back
19+
1620
- name: Set up Python
1721
uses: actions/setup-python@v4
1822
with:
1923
python-version: '3.x'
20-
24+
2125
- name: Update INDEX.md
2226
run: |
2327
python update_index.py
24-
25-
- name: Commit changes
28+
29+
- name: Commit and push changes
2630
run: |
2731
git config --local user.email "[email protected]"
2832
git config --local user.name "GitHub Action"
2933
git add INDEX.md
34+
3035
if [[ -n "$(git status --porcelain INDEX.md)" ]]; then
3136
git commit -m "Auto-update INDEX.md with new games [skip ci]"
32-
git push
37+
git push origin HEAD:${GITHUB_REF#refs/heads/}
3338
else
3439
echo "No changes to INDEX.md"
3540
fi

INDEX.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
Welcome to Game_Scripts — an open-source collection of mini games!
44
This index automatically tracks all games across different programming languages.
5-
Last updated: Fri Oct 17 14:33:32 UTC 2025
65

7-
Tracked 26 games across 3 languages.
86

97
## 📚 Table of Contents
108
- [Java](#java-games)
@@ -16,6 +14,9 @@ Tracked 26 games across 3 languages.
1614
### 🎯 [BrickBreakingGame](./Java/BrickBreakingGame/)
1715
A fun game built with core programming concepts
1816

17+
### 🎯 [FlappyBird](./Java/FlappyBird/)
18+
FlappyBird Game
19+
1920
### 🎯 [Hangman](./Java/Hangman/)
2021
🎮 Hangman GUI Game
2122

@@ -58,7 +59,6 @@ A fun game built with core programming concepts
5859
A simple yet elegant web-based stopwatch application with start, stop, and reset functionality.
5960

6061
### 🎯 [Typing Speed Game](./Javascript/Typing Speed Game/)
61-
A fast-paced browser game built with HTML, CSS, and JavaScript. Words fall from the top of the screen — type them before they hit the bottom! Designed to improve typing speed, accuracy, and reflexes.
6262

6363
### 🎯 [Weather Site](./Javascript/Weather Site/)
6464
A fun game built with core programming concepts

Java/FlappyBird/App.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import javax.swing.*;
2+
3+
public class App {
4+
public static void main(String[] args) throws Exception {
5+
int boardWidth = 360;
6+
int boardHeight = 640;
7+
8+
JFrame frame = new JFrame("Flappy Bird");
9+
// frame.setVisible(true);
10+
frame.setSize(boardWidth, boardHeight);
11+
frame.setLocationRelativeTo(null);
12+
frame.setResizable(false);
13+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
14+
15+
FlappyBird flappyBird = new FlappyBird();
16+
frame.add(flappyBird);
17+
frame.pack();
18+
flappyBird.requestFocus();
19+
frame.setVisible(true);
20+
}
21+
}

Java/FlappyBird/FlappyBird.java

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
import java.awt.*;
2+
import java.awt.event.*;
3+
import java.util.ArrayList;
4+
import java.util.Random;
5+
import javax.swing.*;
6+
7+
public class FlappyBird extends JPanel implements ActionListener, KeyListener {
8+
int boardWidth = 360;
9+
int boardHeight = 640;
10+
11+
// images
12+
Image backgroundImg;
13+
Image birdImg;
14+
Image topPipeImg;
15+
Image bottomPipeImg;
16+
17+
// bird class
18+
int birdX = boardWidth / 8;
19+
int birdY = boardHeight / 2;
20+
int birdWidth = 34;
21+
int birdHeight = 24;
22+
23+
class Bird {
24+
int x = birdX;
25+
int y = birdY;
26+
int width = birdWidth;
27+
int height = birdHeight;
28+
Image img;
29+
30+
Bird(Image img) {
31+
this.img = img;
32+
}
33+
}
34+
35+
// pipe class
36+
int pipeX = boardWidth;
37+
int pipeY = 0;
38+
int pipeWidth = 64; // scaled by 1/6
39+
int pipeHeight = 512;
40+
41+
class Pipe {
42+
int x = pipeX;
43+
int y = pipeY;
44+
int width = pipeWidth;
45+
int height = pipeHeight;
46+
Image img;
47+
boolean passed = false;
48+
49+
Pipe(Image img) {
50+
this.img = img;
51+
}
52+
}
53+
54+
// game logic
55+
Bird bird;
56+
int velocityX = -4; // move pipes to the left speed (simulates bird moving right)
57+
int velocityY = 0; // move bird up/down speed.
58+
int gravity = 1;
59+
60+
ArrayList<Pipe> pipes;
61+
Random random = new Random();
62+
63+
Timer gameLoop;
64+
Timer placePipeTimer;
65+
boolean gameOver = false;
66+
double score = 0;
67+
68+
FlappyBird() {
69+
setPreferredSize(new Dimension(boardWidth, boardHeight));
70+
// setBackground(Color.blue);
71+
setFocusable(true);
72+
addKeyListener(this);
73+
74+
// load images
75+
backgroundImg = new ImageIcon(getClass().getResource("./flappybirdbg.png")).getImage();
76+
birdImg = new ImageIcon(getClass().getResource("./flappybird.png")).getImage();
77+
topPipeImg = new ImageIcon(getClass().getResource("./toppipe.png")).getImage();
78+
bottomPipeImg = new ImageIcon(getClass().getResource("./bottompipe.png")).getImage();
79+
80+
// bird
81+
bird = new Bird(birdImg);
82+
pipes = new ArrayList<Pipe>();
83+
84+
// place pipes timer
85+
placePipeTimer = new Timer(1500, new ActionListener() {
86+
@Override
87+
public void actionPerformed(ActionEvent e) {
88+
// Code to be executed
89+
placePipes();
90+
}
91+
});
92+
placePipeTimer.start();
93+
94+
// game timer
95+
gameLoop = new Timer(1000 / 60, this); // how long it takes to start timer, milliseconds gone between frames
96+
gameLoop.start();
97+
}
98+
99+
void placePipes() {
100+
// (0-1) * pipeHeight/2.
101+
// 0 -> -128 (pipeHeight/4)
102+
// 1 -> -128 - 256 (pipeHeight/4 - pipeHeight/2) = -3/4 pipeHeight
103+
int randomPipeY = (int) (pipeY - pipeHeight / 4 - Math.random() * (pipeHeight / 2));
104+
int openingSpace = boardHeight / 4;
105+
106+
Pipe topPipe = new Pipe(topPipeImg);
107+
topPipe.y = randomPipeY;
108+
pipes.add(topPipe);
109+
110+
Pipe bottomPipe = new Pipe(bottomPipeImg);
111+
bottomPipe.y = topPipe.y + pipeHeight + openingSpace;
112+
pipes.add(bottomPipe);
113+
}
114+
115+
public void paintComponent(Graphics g) {
116+
super.paintComponent(g);
117+
draw(g);
118+
}
119+
120+
public void draw(Graphics g) {
121+
// background
122+
g.drawImage(backgroundImg, 0, 0, this.boardWidth, this.boardHeight, null);
123+
124+
// bird
125+
g.drawImage(birdImg, bird.x, bird.y, bird.width, bird.height, null);
126+
127+
// pipes
128+
for (int i = 0; i < pipes.size(); i++) {
129+
Pipe pipe = pipes.get(i);
130+
g.drawImage(pipe.img, pipe.x, pipe.y, pipe.width, pipe.height, null);
131+
}
132+
133+
// score
134+
g.setColor(Color.white);
135+
136+
g.setFont(new Font("Arial", Font.PLAIN, 32));
137+
if (gameOver) {
138+
g.drawString("Game Over: " + String.valueOf((int) score), 10, 35);
139+
} else {
140+
g.drawString(String.valueOf((int) score), 10, 35);
141+
}
142+
143+
}
144+
145+
public void move() {
146+
// bird
147+
velocityY += gravity;
148+
bird.y += velocityY;
149+
bird.y = Math.max(bird.y, 0); // apply gravity to current bird.y, limit the bird.y to top of the canvas
150+
151+
// pipes
152+
for (int i = 0; i < pipes.size(); i++) {
153+
Pipe pipe = pipes.get(i);
154+
pipe.x += velocityX;
155+
156+
if (!pipe.passed && bird.x > pipe.x + pipe.width) {
157+
score += 0.5; // 0.5 because there are 2 pipes! so 0.5*2 = 1, 1 for each set of pipes
158+
pipe.passed = true;
159+
}
160+
161+
if (collision(bird, pipe)) {
162+
gameOver = true;
163+
}
164+
}
165+
166+
if (bird.y > boardHeight) {
167+
gameOver = true;
168+
}
169+
}
170+
171+
boolean collision(Bird a, Pipe b) {
172+
return a.x < b.x + b.width && // a's top left corner doesn't reach b's top right corner
173+
a.x + a.width > b.x && // a's top right corner passes b's top left corner
174+
a.y < b.y + b.height && // a's top left corner doesn't reach b's bottom left corner
175+
a.y + a.height > b.y; // a's bottom left corner passes b's top left corner
176+
}
177+
178+
@Override
179+
public void actionPerformed(ActionEvent e) { // called every x milliseconds by gameLoop timer
180+
move();
181+
repaint();
182+
if (gameOver) {
183+
placePipeTimer.stop();
184+
gameLoop.stop();
185+
}
186+
}
187+
188+
@Override
189+
public void keyPressed(KeyEvent e) {
190+
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
191+
// System.out.println("JUMP!");
192+
velocityY = -10;
193+
194+
if (gameOver) {
195+
// restart game by resetting conditions
196+
bird.y = birdY;
197+
velocityY = 0;
198+
pipes.clear();
199+
gameOver = false;
200+
score = 0;
201+
gameLoop.start();
202+
placePipeTimer.start();
203+
}
204+
}
205+
}
206+
207+
// not needed
208+
@Override
209+
public void keyTyped(KeyEvent e) {
210+
}
211+
212+
@Override
213+
public void keyReleased(KeyEvent e) {
214+
}
215+
}

Java/FlappyBird/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# FlappyBird
2+
FlappyBird Game

Java/FlappyBird/bottompipe.png

13.6 KB
Loading

Java/FlappyBird/flappybird.png

1.47 KB
Loading

Java/FlappyBird/flappybirdbg.png

61.4 KB
Loading

Java/FlappyBird/toppipe.png

13.5 KB
Loading
Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
# 🕹️ Typing Speed Game
1+
🕹️ Typing Speed Game
22

33
A fast-paced browser game built with HTML, CSS, and JavaScript. Words fall from the top of the screen — type them before they hit the bottom! Designed to improve typing speed, accuracy, and reflexes.
44

5-
---
5+
🚀 Features
66

7-
## 🚀 Features
7+
🎮 Welcome screen with instructions and Start button
88

9-
- 🎮 Welcome screen with instructions and Start button
10-
- ⌨️ Real-time typing input and word matching
11-
- 🧠 Score tracking and game-over detection
12-
- ⏸️ Pause and resume functionality
13-
- 🔄 Restart button to replay instantly
14-
- 🧱 Responsive layout for desktop and mobile
9+
⌨️ Real-time typing input and word matching
1510

16-
---
11+
🧠 Score tracking and game-over detection
1712

18-
## 📦 Tech Stack
13+
⏸️ Pause and resume functionality
1914

20-
- **HTML**: Structure and layout
21-
- **CSS**: Styling and responsive design
22-
- **JavaScript**: Game logic, animation, and input handling
15+
🔄 Restart button to replay instantly
2316

24-
---
17+
🧱 Responsive layout for desktop and mobile
2518

26-
## 📸 Gameplay Preview
19+
⚡ Difficulty Settings: Easy, Medium, Hard
2720

28-
> Words fall from the top. Type them quickly to score points.
29-
> If a word reaches the bottom, the game ends.
30-
> You can pause and restart anytime.
21+
Easy: slower words, +1 point per correct word
3122

32-
---
23+
Medium: medium speed, +2 points per correct word
3324

34-
## 🛠️ How to Run
25+
Hard: faster words, +3 points per correct word
3526

36-
1. Clone the repository:
37-
```bash
38-
git clone https://github.com/devmalik7/Game_Scripts.git
39-
cd Javascript
40-
cd "Typing Speed Game"
41-
```
42-
2. Run **index.md** in your browser.
27+
📦 Tech Stack
28+
29+
HTML: Structure and layout
30+
31+
CSS: Styling and responsive design
32+
33+
JavaScript: Game logic, animation, input handling, and difficulty levels
34+
35+
📸 Gameplay Preview
36+
37+
Words fall from the top. Type them quickly to score points.
38+
If a word reaches the bottom, the game ends.
39+
You can pause, restart, and select difficulty anytime.
40+
41+
Select a difficulty (Easy, Medium, Hard) and start typing!

0 commit comments

Comments
 (0)