1️⃣

4.1 - Imports, Images, and Constants

4.1 Imports, Images, and Constants

We’ve learned how to use the pygame library to create a simple application. We’ve also learned how to let this application be interactive for the user. In this chapter, we’ll be using object-oriented programming to code a tank game.
Before you begin, you’ll want to import the following modules. You’ll also need to download the required images and define the necessary constants.
import pygame from pygame.locals import ( K_w, K_s, K_a, K_d, KEYDOWN, KEYUP, QUIT, RESIZABLE, MOUSEBUTTONDOWN, ) import time import math import random BULLET_IMG_PATH = "./bullet.png" TARGET_IMG_PATH = "./target.png" TANK_IMG_PATH = "./completetank.png" BLACK = (255, 255, 255) DIRTBROWN = (168, 95, 0) SANDBROWN = (237, 201, 175) TANKSPEED = [2, 2] # speed x and speed y BULLETSPEED = [8, 8]
 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.