Skip to content

Commit

Permalink
Merge pull request #109 from raspberrypilearning/draft
Browse files Browse the repository at this point in the history
Draft
  • Loading branch information
MarcScott authored Nov 10, 2023
2 parents 25d2c0e + c0ae8f2 commit 3d8b2ab
Show file tree
Hide file tree
Showing 31 changed files with 560 additions and 0 deletions.
Binary file added en/code/dont-collide-starter/astronaut1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/astronaut2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/earth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/flowers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/iss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions en/code/dont-collide-starter/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/python3

from p5 import *
from random import randint, seed

# Include global variables here


def setup():
# Put code to run once here


def draw():
# Put code to run every frame here


# Keep this to run your code
run()
Binary file added en/code/dont-collide-starter/moon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/planet1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/planet2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions en/code/dont-collide-starter/project_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
NAME: "Don't Collide!"
IDENTIFIER: "dont-collide-starter"
COMPONENTS:
- name: "main"
extension: "py"
location: "main.py"
index: 0
default: true
IMAGES:
- "astronaut1.png"
- "astronaut2.png"
- "earth.png"
- "flowers.png"
- "iss.png"
- "moon.png"
- "planet1.png"
- "planet2.png"
- "rocket1.png"
- "rocket2.png"
- "shark.png"
- "tree.png"
- "treefeller.png"
- "turtle.png"
Binary file added en/code/dont-collide-starter/rocket1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/rocket2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/shark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/treefeller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added en/code/dont-collide-starter/turtle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 119 additions & 0 deletions en/code/dont_collide_avoid_germs_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/python3

from p5 import *
from random import randint, seed

level = 1
score = 0

def safe_player():
global player_y

# Face
fill(200, 134, 145)
ellipse(mouse_x, player_y, 60, 60)

# Eyes
fill(178, 200, 145)
ellipse(mouse_x - 10, player_y - 10, 20, 20)
ellipse(mouse_x + 10, player_y - 10, 20, 20)
fill(0)
ellipse(mouse_x - 10, player_y - 10, 10, 10)
ellipse(mouse_x + 10, player_y - 10, 10, 10)
fill(255)
ellipse(mouse_x - 12, player_y - 12, 5, 5)
ellipse(mouse_x + 12, player_y - 12, 5, 5)

# Mouth
fill(0)
ellipse(mouse_x, player_y + 10, 15, 10)
fill(200, 134, 145)
ellipse(mouse_x, player_y + 5, 10, 10)

def crashed_player():
global player_y

# Face
fill(178, 200, 145)
ellipse(mouse_x, player_y, 60, 60)

# Eyes
fill(149, 161, 195)
ellipse(mouse_x - 10, player_y - 10, 20, 20)
ellipse(mouse_x + 10, player_y - 10, 20, 20)
fill(0)
ellipse(mouse_x - 10, player_y - 10, 10, 10)
ellipse(mouse_x + 10, player_y - 10, 10, 10)
fill(255)
ellipse(mouse_x - 12, player_y - 12, 5, 5)
ellipse(mouse_x + 12, player_y - 12, 5, 5)

# Mouth
fill(0)
ellipse(mouse_x, player_y + 15, 15, 10)
fill(178, 200, 145)
ellipse(mouse_x, player_y + 20, 10, 10)

def draw_player():

global player_y, safe, score, level

player_y = int(height * 0.8)

collide = get(mouse_x, player_y).hex
collide2 = get(mouse_x, player_y + 30).hex
collide3 = get(mouse_x + 30, player_y).hex
collide4 = get(mouse_x, player_y - 30).hex

if mouse_x < width: # off the left of the screen
collide2 = safe.hex

if mouse_x > width: # off the right of the screen
collide3 = safe.hex

#print(collide, collide2, collide3, collide4)

if collide == safe.hex and collide2 == safe.hex and collide3 == safe.hex and collide4 == safe.hex:
safe_player()
score += level
else: # Collided
crashed_player()
level = 0

def draw_obstacles():
global level

seed(41143644)

if frame_count & height == height - 1 and level < 5:
level += 1
print('You reached level', level)

for i in range(9 + level):
ob_x = randint(0, width)
ob_y = randint(0, height) + frame_count
ob_y %= height
text('🦠', ob_x, ob_y)

def setup():
# Put code to run once here
size(400, 400) # width and height
no_stroke()
text_size(40)
text_align(CENTER, TOP)

def draw():
# Put code to run every frame here
global safe, score, level

safe = Color(149, 161, 195)

if level > 0:
background(safe)
fill(145, 134, 126)
text('Score: ' + str(score), width/2, 20)
draw_obstacles()
draw_player()

# Keep this to run your code
run()
8 changes: 8 additions & 0 deletions en/code/dont_collide_avoid_germs_example/project_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
NAME: "Don't Collide: Avoid the Germs"
IDENTIFIER: "avoid-germs-example"
COMPONENTS:
- name: "main"
extension: "py"
location: "main.py"
index: 0
default: true
Binary file added en/code/dont_collide_clean_car_example/car.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions en/code/dont_collide_clean_car_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/python3

# Import library code
from p5 import *
from random import randint, seed

level = 1
score = 0

# The draw_obstacle function goes here
def draw_obstacles():
global level

seed(123456789)

if frame_count % width == width - 1 and level < 10:
level += 1
print('You reached level', level)

for i in range(6 + level):
ob_x = randint(0, width) - (frame_count * level)
ob_y = randint(0, height)
ob_x %= width # wrap around
text('πŸ’©', ob_x, ob_y)

# The draw_player function goes here
def draw_player():
global score, level

player_x = int(width * 0.2)
player_y = mouse_y

collide = get(player_x + 50, player_y + 15).hex
collide2 = get(player_x + 50, player_y - 15).hex
collide3 = get(player_x, player_y + 15).hex
collide4 = get(player_x, player_y - 15).hex
collide5 = get(player_x - 50, player_y + 15).hex
collide6 = get(player_x - 50, player_y - 15).hex

if player_y > height - 18: # Off the bottom of the screen
collide = safe.hex
collide3 = safe.hex
collide5 = safe.hex

elif player_y < 18: # Off the top of the screen
collide2 = safe.hex
collide4 = safe.hex
collide6 = safe.hex

if collide == safe.hex and collide2 == safe.hex and collide3 == safe.hex and collide4 == safe.hex:
image(car, player_x, player_y, 100, 31)
score += level
else:
text('πŸ’₯', player_x, player_y)
level = 0


def setup():
# Setup your animation here
size(400, 400)
global car
car = load_image('car.png')
image_mode(CENTER)


def draw():
# Things to do in every frame
global score, safe, level
safe = Color(128)

if level > 0:
background(safe)
fill(255)
text_size(16)
text_align(RIGHT, TOP)
text('Score', width * 0.45, 10, width * 0.5, 20)
text(str(score), width * 0.45, 25, width * 0.5, 20)
text_size(20)
text_align(CENTER, TOP) # position around the centre, top
draw_obstacles()
draw_player()

run()
10 changes: 10 additions & 0 deletions en/code/dont_collide_clean_car_example/project_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
NAME: "Don't Collide: Clean Car"
IDENTIFIER: "clean-car-example"
COMPONENTS:
- name: "main"
extension: "py"
location: "main.py"
index: 0
default: true
IMAGES:
- "car.png"
127 changes: 127 additions & 0 deletions en/code/dont_collide_dodge_asteroids_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/python3

# Import library code
from p5 import *
from random import randint, seed

level = 1
score = 0
lives = 3
invun = 0

# The draw_obstacle function goes here
def draw_obstacles():
global level

seed(random_seed)

if frame_count % height == height - 1 and level < 8:
level += 1
print('You reached level', level)

for i in range(6 + level):
ob_x = randint(0, width)
ob_y = randint(0, height) + (frame_count * level)
ob_y %= height # wrap around
push_matrix()
translate(ob_x, ob_y)
rotate(degrees(randint(1, 359)+frame_count / 1000))
image(rock, 0, 0, randint(18,24), randint(18,24))
pop_matrix()


# The draw_player function goes here
def draw_player():
global score, level, lives, invun

player_y = int(height * 0.8)
player_x = mouse_x

collide = get(player_x, player_y).hex
collide2 = get(player_x - 18, player_y + 17).hex
collide3 = get(player_x + 18, player_y + 17).hex
collide4 = get(player_x, player_y + 25).hex

if player_x < width: # off the left of the screen
collide2 = safe.hex

if player_x > width: # off the right of the screen
collide3 = safe.hex

if (collide == safe.hex and collide2 == safe.hex and collide3 == safe.hex and collide4 == safe.hex) or invun > 0:
if lives == 0 and frame_count % 12 == 0:
tint(200, 0, 0)

image(rocket, player_x, player_y + 25, 64, 64)
score += level
invun -= 1
no_tint()

if invun > 0:
stroke(220)
fill(220, 220, 220, 60)
ellipse(player_x, player_y + 18, 47, 47)

elif lives > 1:
lives -= 1
invun = 50
tint(200, 0, 0)
image(rocket, player_x, player_y + 25, 64, 64)
no_tint()
score += level
else:
text('πŸ’₯', player_x + 10, player_y + 5)
level = 0


def display_score():
global level

fill(255)
text_size(16)
text_align(RIGHT, TOP)
text('Score', width * 0.45, 10, width * 0.5, 20)
text(str(score), width * 0.45, 25, width * 0.5, 20)

if score > 10000:
level = 0
print('πŸŽ‰πŸŽ‰ You win! πŸŽ‰πŸŽ‰')


def display_lives():
fill(255)
text_size(16)
text_align(LEFT, TOP)
text('Lives', width * 0.05, 10, 30, 20)

for i in range(lives):
image(rocket, width * 0.05 + i * 25, 40, 20, 20)


def setup():
# Setup your animation here
size(400, 400)
global rocket, rock, random_seed

text_size(40)
text_align(CENTER, TOP) # position around the centre, top

rocket = load_image('rocket.png')
rock = load_image('moon.png')
random_seed = randint(0, 1000000)

def draw():
# Things to do in every frame
global score, safe, level
safe = Color(0)

if level > 0:
background(safe)
fill(255)
image_mode(CENTER)
draw_obstacles()
draw_player()
display_score()
display_lives()

run()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3d8b2ab

Please sign in to comment.