https://github.com/wonder-tree/spaceshooter-posecamera
https://github.com/wonder-tree/spaceshooter-posecamera
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/wonder-tree/spaceshooter-posecamera
- Owner: Wonder-Tree
- License: apache-2.0
- Created: 2021-03-24T07:13:48.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-27T08:05:51.000Z (about 5 years ago)
- Last Synced: 2025-03-12T15:12:44.301Z (over 1 year ago)
- Language: Python
- Size: 3.97 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://www.codefactor.io/repository/github/wonder-tree/SpaceShooter-PoseCamera/overview/main)
## Space Shooter
Simple game in which you have to have to shoot meteoroids with you space craft and avoid meteoroids by moving left and right on your screen. Game uses our **PoseCamera** sdk to detect human body from webcam and controll space craft movement.
you can learn more about PoseCamera SDK on this link : https://github.com/Wonder-Tree/PoseCamera
### How to build
install requirements by running following command
```
pip install requirements.txt
```
and then start the game `python main.py`
### Science behind the game
The spaceship position is controlled by the following code in the game
```python
pose = self.camera.poses[0]
# Get left hip and right hip positon
r_hip = pose.keypoints[8]
l_hip = pose.keypoints[11]
# and find center
center = (
(l_hip[0] + r_hip[0]) // 2,
(l_hip[1] + r_hip[1]) // 2
)
# Set position
self.player.rect.x = center[0]
```
The following lines of code is used to spawn the bullets
```python
# Bullet spawn gesture
# if right or left hand is above neck
neck = pose.keypoints[1]
# Get left and right wrist positions
r_wrist = pose.keypoints[4]
l_wrist = pose.keypoints[7]
if r_wrist[1] < neck[1] or l_wrist[1] < neck[1]:
self.shoot = True
else:
self.shoot = False
```

## How to play
Follow 3 easy steps to play the game
1. Stand in the front of your laptop/pc webcam at atleast 4 feet distance. Make sure your hips are visible on the camera.
2. Move your body left and right to move space craft, space craft is attached to your horizontal body movements
3. To start shooting pull your right hand up, space craft will start shooting.