A fun and interactive browser-based game where you control a bat to swat mosquitoes! Test your reflexes and aim as you hunt down buzzing mosquitoes with realistic movement patterns.
- Interactive Controls: Move your bat with mouse movement and click to swat mosquitoes
- Realistic Physics: Mosquitoes move with random trajectories and vibration effects
- Score System: Track your mosquito-swatting prowess with a live score counter
- Visual Feedback: Dead mosquitoes fall down with red highlight effects
- Pause/Resume: Take breaks with the pause functionality
- Responsive Canvas: Game adapts to different screen sizes
- Modern web browser (Chrome, Firefox, Safari, Edge)
- Local web server (optional but recommended for image loading)
- Clone the repository:
git clone https://github.com/yourusername/mosquito-swatter-game.git
cd mosquito-swatter-game
- Add game assets:
Create an
images
folder and add:
bat.png
- The bat sprite imagemosqito.png
- The mosquito sprite image
- Run the game:
- Open
index.html
in your web browser, or - Use a local server:
# Using Python 3
python -m http.server 8000
# Using Node.js (if you have http-server installed)
npx http-server
mosquito-swatter-game/
├── index.html # Main HTML file
├── style.css # Game styling
├── script.js # Game logic and mechanics
├── images/
│ ├── bat.png # Bat sprite (you need to add this)
│ └── mosqito.png # Mosquito sprite (you need to add this)
└── README.md # This file
- Move the Bat: Move your mouse around the screen to control the bat's position
- Swat Mosquitoes: Click on mosquitoes to swat them with your bat
- Score Points: Each successful swat increases your score
- Pause/Resume: Use the pause button to take breaks during gameplay
- Watch the Action: Dead mosquitoes will fall down and disappear from the screen
- Canvas Rendering: Uses HTML5 Canvas for smooth 2D graphics
- Collision Detection: Rectangle-based collision system between bat and mosquitoes
- Animation Loop: 60 FPS animation using
requestAnimationFrame
- Random Movement: Mosquitoes move with random velocities and vibration patterns
- Object-Oriented Design: Mosquitoes and bat are represented as objects with properties
- Event Handling: Mouse events for movement and clicking
- State Management: Game pause/resume functionality with animation control
randomPoints()
- Generates initial mosquito positionsupdatePoints()
- Updates mosquito positions and handles physicscollision()
- Detects collisions between bat and mosquitoesanimate()
- Main game loop for rendering and updates
// In script.js, modify these values:
const numPoints = 20; // Number of mosquitoes (increase for harder gameplay)
mosqito.dx = randomInt(-2, 2); // Mosquito speed (increase range for faster mosquitoes)
// Modify canvas dimensions in script.js:
canvas.width = window.innerWidth;
canvas.height = window.innerHeight * 3 / 4;
Customize the game appearance by modifying style.css
:
- Change border colors and styles
- Adjust game container layout
- Modify button styling
- Ensure image files are properly loaded before starting the game
- Some browsers may require a local server to load images due to CORS restrictions
- Game performance may vary based on the number of mosquitoes spawned
- ✅ Chrome 60+
- ✅ Firefox 55+
- ✅ Safari 11+
- ✅ Edge 16+
- ✅ Mobile browsers (with touch support)
- Add sound effects for swatting and background music
- Implement different mosquito types with varying behaviors
- Add power-ups and special abilities
- Create levels with increasing difficulty
- Add high score persistence using localStorage
- Implement touch controls for mobile devices
- Add particle effects for mosquito swats
- Create different bat types with unique abilities
- Add timer-based challenges
- Implement multiplayer functionality
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Control | Action |
---|---|
Mouse Move | Move bat position |
Mouse Click | Swat mosquitoes |
Pause Button | Pause/Resume game |
- +1 point per mosquito swatted
- Score displayed in real-time at the top-left corner
- No penalties for missed swats
To run the game properly, you'll need these image files in the images/
directory:
- bat.png: Bat sprite (recommended size: 100x140 pixels)
- mosqito.png: Mosquito sprite (recommended size: 40x40 pixels)
Note: You can create your own sprites or find free game assets online.
Images not loading?
- Make sure image files exist in the
images/
folder - Check file names match exactly (
mosqito.png
, notmosquito.png
) - Try running on a local server instead of opening the HTML file directly
Game not responsive?
- Check browser console for JavaScript errors
- Ensure all files are in the correct directory structure
- Try refreshing the page
Made with ❤️ for game development enthusiasts
Have fun swatting those mosquitoes! 🦟