├── requirements.txt ├── .gitignore ├── rock.png ├── missile.png ├── tank_red.png ├── tank_green.png ├── Pygame Workshop Draft.pdf ├── README.md ├── LICENSE └── main.py /requirements.txt: -------------------------------------------------------------------------------- 1 | pygame 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | __pycache__ 3 | venv 4 | .idea/ -------------------------------------------------------------------------------- /rock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-KJSCE/Shots_Fired/HEAD/rock.png -------------------------------------------------------------------------------- /missile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-KJSCE/Shots_Fired/HEAD/missile.png -------------------------------------------------------------------------------- /tank_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-KJSCE/Shots_Fired/HEAD/tank_red.png -------------------------------------------------------------------------------- /tank_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-KJSCE/Shots_Fired/HEAD/tank_green.png -------------------------------------------------------------------------------- /Pygame Workshop Draft.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CSI-KJSCE/Shots_Fired/HEAD/Pygame Workshop Draft.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Shots Fired 2 | This repo contains the complete source code for Game Development using Pygame Workshop 2019. 3 |
4 | Reference Draft for the workshop can be found [here](https://github.com/CSI-KJSCE/Shots_Fired/blob/master/Pygame%20Workshop%20Draft.pdf) 5 | 6 | To run it, 7 | ``` 8 | git clone https://github.com/CSI-KJSCE/Shots_Fired.git 9 | cd Shots_Fired 10 | pip install -r requirements.txt 11 | python main.py 12 | ``` 13 | 14 | ------------------------------------------ 15 |
16 | Made with :heart: by CSI KJSCE 17 |
18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 CSI-KJSCE 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import pygame as py 2 | import sys, random, math 3 | 4 | screen = py.display.set_mode((800,800)) 5 | py.init() 6 | tank_image1 = py.image.load('tank_green.png') 7 | tank_image2 = py.image.load('tank_red.png') 8 | obstacle_image = py.image.load('rock.png') 9 | bullet_image = py.image.load('missile.png') 10 | 11 | tank_dimensions = tank_image1.get_size() 12 | obstacle_dimensions = obstacle_image.get_size() 13 | bullet_dimensions = bullet_image.get_size() 14 | 15 | game_clock = py.time.Clock() 16 | 17 | tank_rect = tank_image1.get_rect() 18 | color = (0,0,0) 19 | 20 | Tank = { 21 | 'tank1' : { 22 | 'image' : tank_image1, 23 | 'new_image' : tank_image1, 24 | 'rect' : tank_image1.get_rect().copy(), 25 | 'center' : (25,25), 26 | 'angle' : 0, 27 | 'bullet' : { 28 | 'image' : bullet_image, 29 | 'rect' : bullet_image.get_rect() 30 | } 31 | }, 32 | 33 | 'tank2' : { 34 | 'image' : tank_image2, 35 | 'new_image' : tank_image2, 36 | 'rect' : tank_image2.get_rect().copy(), 37 | 'center' : (750,750), 38 | 'angle' : 0, 39 | 'bullet' : { 40 | 'image' : bullet_image, 41 | 'rect' : bullet_image.get_rect() 42 | } 43 | } 44 | } 45 | 46 | Tank['tank1']['rect'].center = (25,25) 47 | Tank['tank2']['rect'].center = (750,750) 48 | obstacles = [(random.randint(40,700),random.randint(40,700)) for i in range(30)] 49 | 50 | #checks if the point x,y lies in the circle (x-x1)^2 + (y-y1)^2 = r^2 51 | def collision(x,y,x1,y1,r,is_tank): 52 | if is_tank: 53 | r += tank_dimensions[0]/2 54 | term = (x-x1)**2 + (y-y1)**2 55 | return term <= r**2 56 | 57 | def obstacle_collision(x,y,is_tank): 58 | radius_obstacle = obstacle_dimensions[0]/2 59 | for i,j in obstacles: 60 | i,j = i+radius_obstacle, j+radius_obstacle 61 | if collision(x,y,i,j,radius_obstacle,is_tank): 62 | return True 63 | return False 64 | 65 | def draw(): 66 | screen.fill(color) 67 | draw_obstacles() 68 | screen.blit(Tank['tank1']['new_image'], Tank['tank1']['rect']) 69 | screen.blit(Tank['tank2']['new_image'], Tank['tank2']['rect']) 70 | py.display.update() 71 | 72 | def draw_obstacles(): 73 | for i,j in obstacles: 74 | screen.blit(obstacle_image, (i,j)) 75 | 76 | def rotate_tank(tank, clock): 77 | tank['angle'] = (tank['angle'] + clock) % 360 78 | tank['new_image'] = py.transform.rotate(tank['image'], tank['angle']) 79 | tank['rect'] = tank['new_image'].get_rect() 80 | tank['rect'].center = tank['center'] 81 | 82 | def translate(tank, direction): 83 | r = 2 84 | x,y = tank['center'] 85 | x += r*math.cos(math.radians(tank['angle']))*direction 86 | y -= r*math.sin(math.radians(tank['angle']))*direction 87 | boundary_condition = (0