Created
March 21, 2022 21:50
-
-
Save novialriptide/4121c585984afc643b498f244ef58c8b to your computer and use it in GitHub Desktop.
thecoderschool example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Hi Nick, I added some comments and stuff while you were teaching. | |
Hope you have less stressful sessions than I did! | |
- Andrew | |
""" | |
import pygame | |
screen = pygame.display.set_mode((256, 224)) | |
moving_right = False | |
moving_left = False | |
moving_down = False | |
moving_up = False | |
pos = [0, 0] # player's position | |
speed = 0.25 # player's speed | |
""" | |
I had a really simple game idea for the two | |
students, it was where you would dodge | |
a bunch of pygame rectangles being spawned | |
and you have to dodge the rectangles being spawned. | |
There are a bunch of example code within pygame itself | |
https://github.com/pygame/pygame/tree/main/examples | |
If you need help with pygame, you can DM me through Discord, | |
novial#1450. Maybe I can ask some Rutgers advice as well. | |
NOTE: pygame's y value is weird. | |
It's the complete opposite, if you want | |
to go down, you got to increase the y value. | |
If you want to go up, you got to decrease the y value. | |
NOTE: pygame's x value is normal. | |
pygame.Rect() DOES NOT SUPPORT FLOAT/DOUBLES | |
""" | |
while True: | |
for i in pygame.event.get(): | |
if i.type == pygame.KEYDOWN: # IF ANY KEY IS PRESSED DOWN | |
if i.key == pygame.K_UP: # IF UP KEY IS PRESSED DOWN | |
moving_up = True | |
if i.key == pygame.K_DOWN: # IF DOWN KEY IS PRESSED DOWN | |
moving_down = True | |
if i.key == pygame.K_LEFT: # IF LEFT KEY IS PRESSED DOWN | |
moving_left = True | |
if i.key == pygame.K_RIGHT: # IF RIGHT KEY IS PRESSED DOWN | |
moving_right = True | |
if i.type == pygame.KEYUP: # IF ANY KEY IS PRESSED UP | |
if i.key == pygame.K_UP: # IF UP KEY IS PRESSED UP | |
moving_up = False | |
if i.key == pygame.K_DOWN: # IF DOWN KEY IS PRESSED UP | |
moving_down = False | |
if i.key == pygame.K_LEFT: # IF LEFT KEY IS PRESSED UP | |
moving_left = False | |
if i.key == pygame.K_RIGHT: # IF RIGHT KEY IS PRESSED UP | |
moving_right = False | |
if moving_left: | |
pos[0] -= speed | |
if moving_right: | |
pos[0] += speed | |
if moving_down: | |
pos[1] += speed | |
if moving_up: | |
pos[1] -= speed | |
screen.fill((0, 0, 0)) | |
pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(pos[0], pos[1], 25, 25)) | |
pygame.display.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks so much!! Appreciate all the comments too