-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
542 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
name: "Don't Collide!" | ||
identifier: "dont-collide-starter" | ||
type: "python" | ||
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" |
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
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() |
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
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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() |
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
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" |
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
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.
11 changes: 11 additions & 0 deletions
11
en/code/dont_collide_dodge_asteroids_example/project_config.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NAME: "Don't Collide: Dodge Asteroids" | ||
IDENTIFIER: "dodge-asteroids-example" | ||
COMPONENTS: | ||
- name: "main" | ||
extension: "py" | ||
location: "main.py" | ||
index: 0 | ||
default: true | ||
IMAGES: | ||
- "moon.png" | ||
- "rocket.png" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.