Skip to content

Saiprakashreddy9/Mosquito_Swatter_Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦇 Mosquito Swatter Game

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.

🎮 Game Features

  • 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

🚀 Getting Started

Prerequisites

  • Modern web browser (Chrome, Firefox, Safari, Edge)
  • Local web server (optional but recommended for image loading)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/mosquito-swatter-game.git
cd mosquito-swatter-game
  1. Add game assets: Create an images folder and add:
  • bat.png - The bat sprite image
  • mosqito.png - The mosquito sprite image
  1. 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

📁 Project Structure

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

🎯 How to Play

  1. Move the Bat: Move your mouse around the screen to control the bat's position
  2. Swat Mosquitoes: Click on mosquitoes to swat them with your bat
  3. Score Points: Each successful swat increases your score
  4. Pause/Resume: Use the pause button to take breaks during gameplay
  5. Watch the Action: Dead mosquitoes will fall down and disappear from the screen

🛠️ Technical Details

Game Mechanics

  • 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

Code Architecture

  • 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

Key Functions

  • randomPoints() - Generates initial mosquito positions
  • updatePoints() - Updates mosquito positions and handles physics
  • collision() - Detects collisions between bat and mosquitoes
  • animate() - Main game loop for rendering and updates

🎨 Customization

Adjust Game Difficulty

// 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)

Canvas Size

// Modify canvas dimensions in script.js:
canvas.width = window.innerWidth;
canvas.height = window.innerHeight * 3 / 4;

Styling

Customize the game appearance by modifying style.css:

  • Change border colors and styles
  • Adjust game container layout
  • Modify button styling

🐛 Known Issues

  • 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

🔧 Browser Compatibility

  • ✅ Chrome 60+
  • ✅ Firefox 55+
  • ✅ Safari 11+
  • ✅ Edge 16+
  • ✅ Mobile browsers (with touch support)

🚀 Future Enhancements

  • 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

🤝 Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🎮 Game Controls

Control Action
Mouse Move Move bat position
Mouse Click Swat mosquitoes
Pause Button Pause/Resume game

📊 Scoring System

  • +1 point per mosquito swatted
  • Score displayed in real-time at the top-left corner
  • No penalties for missed swats

🎨 Assets Required

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.

🐞 Troubleshooting

Images not loading?

  • Make sure image files exist in the images/ folder
  • Check file names match exactly (mosqito.png, not mosquito.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! 🦟

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published