Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .devcontainer/Dockerfile

This file was deleted.

19 changes: 4 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@
{
"name": "Python 3",

// This is the default
// "image": "mcr.microsoft.com/devcontainers/universal:2",

// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
//"image": "mcr.microsoft.com/devcontainers/python:1-${templateOption:imageVariant}",
//"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm",

"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm",

"containerEnv": {
"VNC_RESOLUTION": "600x600x16",
"SDL_VIDEO_WINDOW_POS": "0,0", // GUI Windows all the way in the upper left.
"SDL_AUDIODRIVER": "dummy" // Disable audio
},

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/desktop-lite:1": {
"ghcr.io/devcontainers/features/desktop-lite:1.2.7": {
"password" : "code4life"
}
},



// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [6080, 5901],

Expand All @@ -48,8 +38,7 @@
"customizations": {
"codespaces": {
"openFiles": [
//"lessons/00_Turtles/01_Get_Started.ipynb"
"README.md"
"lessons/00_Getting_Started/README.md"
]
},
"vscode": {
Expand Down
Empty file added .devcontainer/package.json
Empty file.
Empty file added .devcontainer/vscode-setup.ts
Empty file.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ https://python-apprentice.jointheleague.org/) class, you are ready to continue
your Python journey by learning to program games.

To get started, either clone this repository to your local machine, or fork and
create a Codespace, then open the file [lessons/00_Getting_Started/README.md](lessons/00_Getting_Started/README.md).
create a Codespace, then open the file
[lessons/00_Getting_Started/README.md](lessons/00_Getting_Started/README.md).
This will give you an overview of the module and how to get started.

The easiest way to get started is, from the [Python-Games Github Repo](https://github.com/league-curriculum/Python-Games),
click on the green ![code](https://images.jointheleague.org/github/code_button_sm.png) button, then select the 'Codespaces' tab, then ![ccom](https://images.jointheleague.org/github/create_codespace_sm.png).
This will create a codespace for you to work in, which has a web based IDE and all the necessary tools to get started.
The easiest way to get started is, from the [Python-Games Github Repo](https://github.com/league-curriculum/Python-Games), click on the green
![code](https://images.jointheleague.org/github/code_button_sm.png) button, then
select the 'Codespaces' tab, then
![ccom](https://images.jointheleague.org/github/create_codespace_sm.png). This
will create a codespace for you to work in, which has a web based IDE and all
the necessary tools to get started.

It's easiest to read the lesson documentation on Github; just click on the link in the `Next Steps` section below, but you
will also see all of the documentation in your coding editor.
It's easiest to read the lesson documentation on Github; just click on the link
in the `Next Steps` section below, but you will also see all of the
documentation in your coding editor.


## Next Steps

Open the file [lessons/00_Getting_Started/README.md](lessons/00_Getting_Started/README.md) to begin the lessons.
Open the file
[lessons/00_Getting_Started/README.md](lessons/00_Getting_Started/README.md) to
begin the lessons.

-------------------

Development of The LEAGUE's curriculum is generously funded by the Itzkowitz Family Foundation.
106 changes: 0 additions & 106 deletions lessons/01_Motion_and_Physics/05_gravity_bounce.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Motion and Physics\n",
"\n",
"# Physics for Games\n",
"\n",
"Most of the games we will be writing have some physics, which is the motion of\n",
"objects in the game that should look realistic, like jumping or falling. Pygame\n",
Expand All @@ -20,7 +19,7 @@
"\n",
"## Assignment 1\n",
"\n",
"1. Open the program `01-move.py` \n",
"1. Open the program `01_move.py` \n",
"2. Run the program and see what it does. Use the arrow keys to move the square\n",
" around the screen.\n",
"3. Read the code and try to understand how it works.\n",
Expand Down Expand Up @@ -83,7 +82,7 @@
"\n",
"## Assignment 3\n",
"\n",
"The most common game mechanic with acelleration is jumping. Let's look at\n",
"The most common game mechanic with acceleration is jumping. Let's look at\n",
"what it takes to make a player jump.\n",
"\n",
"1. Open `04_gravity.py` \n",
Expand Down Expand Up @@ -112,9 +111,10 @@
"collision is to just not let the player move into the wall, but a more realistic\n",
"way is to bounce the player off the wall.\n",
"\n",
"Collisions with the edges of the screen are simple to detect: the player's position in x or y either\n",
"exceeds the screen size or goes below zero. Making the player bounce is also easy: just reverse the\n",
"velocity in the direction of the collision. \n",
"Collisions with the edges of the screen are simple to detect: the player's\n",
"position in x or y either exceeds the screen size or goes below zero. Making the\n",
"player bounce is also easy: just reverse the velocity in the direction of the\n",
"collision. \n",
"\n",
"```python\n",
"if player.x < 0 or player.x > screen_width:\n",
Expand All @@ -126,7 +126,7 @@
"\n",
"## Assignment 2\n",
"\n",
"1. Copy `05_gravity_bounce.py` into this directory.\n",
"1. Open and read through `05_gravity_bounce.py`.\n",
"2. Change the program so that the player doesn't always jump. Instead, the player\n",
" jumps only when the `space` key is pressed.\n",
"3. Change the program so that the player can jump to the left or right by pressing\n",
Expand All @@ -136,25 +136,31 @@
" less than 0.1, set it to zero. This will make the player slow down and stop.\n",
" If the Players velocity is zero, the player can jump again. The player\n",
" shoud bounce off the ground.\n",
"5. Change the program to account for elasticity. The ball should lose a bit of\n",
" energy each time it bounces. \n",
"\n",
"Hints: \n",
"\n",
"* Jumping up will involve setting the y velocity, and jumping left or right\n",
"will also involve setting the x velocity.\n",
"* Jumping up will involve setting the y velocity, and jumping left or right will\n",
" also involve setting the x velocity.\n",
"* You can implement drag either by subtracting off a little bit of the velocity,\n",
" but you will need to make sure the velocity doesn't go negative. Another way\n",
" to do this is to multiply the velocity by a number less than 1, like 0.99.\n",
" to do this is to multiply the velocity by a number less than 1, like 0.99.\n",
"* Elasticity works a lot like drag, except it only causes a reduction in\n",
" velocity when the ball bounces, not every time step. \n",
"\n",
"\n",
"## Next Steps\n",
"\n",
"First, check in your code! You should check in ( commit ) and push your code\n",
"regularly. \n",
"\n",
"Second, don't forget about the [Pygame Documentation](https://www.pygame.org/docs/index.html). Your programs will\n",
"get better the more you know about Pygame.\n",
"Second, don't forget about the \n",
"[Pygame Documentation](https://www.pygame.org/docs/index.html). \n",
"Your programs will get better the more you know about Pygame.\n",
"\n",
"Open [lessons/02_Classes_and_Objects/README.md](../02_Classes_and_Objects/README.md) to start the next lesson. "
"Open [lessons/02_Classes_and_Objects/README.md](../02_Classes_and_Objects/README.md) \n",
"to start the next lesson. "
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
import pygame


# Initialize Pygame
pygame.init()

Expand All @@ -16,9 +17,12 @@
SQUARE_SIZE = 50
SQUARE_COLOR = (0, 128, 255) # Red-Green-Blue color in the range 0-255
BACKGROUND_COLOR = (255, 255, 255) # White
SQUARE_SPEED = 5
SQUARE_SPEED = 300
FPS = 60

v = SQUARE_SPEED # Speed of the square in pixels per second
d_t = 1 / FPS # Time step for physics calculations

# Initialize the screen
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Move the Square")
Expand All @@ -29,14 +33,13 @@
# Main function
def main():
# Initial position of the square
square_x = SCREEN_WIDTH // 2 - SQUARE_SIZE // 2
square_y = SCREEN_HEIGHT // 2 - SQUARE_SIZE // 2
x = SCREEN_WIDTH // 2 - SQUARE_SIZE // 2
y = SCREEN_HEIGHT // 2 - SQUARE_SIZE // 2

running = True

while running:


# Event handling
for event in pygame.event.get():

Expand All @@ -48,27 +51,39 @@ def main():
# with a boolean value of whether they are pressed or not
keys = pygame.key.get_pressed()

# Calculate the change tin the position
d_x = 0
d_y = 0

# Move the square based on arrow keys
if keys[pygame.K_LEFT]:
square_x -= SQUARE_SPEED
d_x = -v * d_t

if keys[pygame.K_RIGHT]:
square_x += SQUARE_SPEED
d_x = v * d_t

if keys[pygame.K_UP]:
square_y -= SQUARE_SPEED
d_y = -v * d_t

if keys[pygame.K_DOWN]:
square_y += SQUARE_SPEED
d_y = v * d_t

# Update the position of the square
x = x + d_x
y = y + d_y


# Prevent the square from going off the screen
square_x = max(0, min(SCREEN_WIDTH - SQUARE_SIZE, square_x))
square_y = max(0, min(SCREEN_HEIGHT - SQUARE_SIZE, square_y))
x = max(0, min(SCREEN_WIDTH - SQUARE_SIZE, x))
y = max(0, min(SCREEN_HEIGHT - SQUARE_SIZE, y))

# This will clear the screen by filling it
# with the background color. If we didn't do this,
# the square would leave a trail behind it.
screen.fill(BACKGROUND_COLOR)

# Draw the square
pygame.draw.rect(screen, SQUARE_COLOR, (square_x, square_y, SQUARE_SIZE, SQUARE_SIZE))
pygame.draw.rect(screen, SQUARE_COLOR, (x, y, SQUARE_SIZE, SQUARE_SIZE))

# Update the display. Imagine that the screen is two different whiteboards. One
# whiteboard is currently visible to the player, and the other whiteboard is being
Expand Down
Loading