-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame-hide-ship.html
149 lines (119 loc) · 4.32 KB
/
game-hide-ship.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html>
<head>
<title>My Game</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@600&display=swap" rel="stylesheet">
<link href="style.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="gamefuncs.js" type="text/javascript"></script>
<script src="skulpt/skulpt_mods.js" type="text/javascript"></script>
<script src="skulpt/skulpt_lib.js" type="text/javascript"></script>
</head>
<body>
<script src="skulpt/skulpt_init.js" type="text/javascript"></script>
<div id="errorMessage"></div>
<div id='canvas'></div>
<script>
var prog =
`start()
######################## DO NOT EDIT ABOVE THIS LINE ###################
######################## PYTHON CODE BELOW #############################
import random
# Hide ship game
# Hide your ship behind the bouncing platforms to get points.
# If an alien hits a platform, alien points go up.
# If an alien hits your ship, game over.
instructions = print_text('''HIDE SHIP GAME <br>WASD or arrows to move.<br>Hide your ship behind the bouncing platforms.
''', 20)
place_element(instructions, 900, 30)
#function definitions
def alien_victory():
clear()
print_heading('Direct hit! You lost', 48)
play_audio(explode)
def alien_bomb_platform():
global alien_score
alien_score += 1
update_text(a_score_text, 'Aliens: '+str(alien_score))
if alien_score > 50:
scoreboard()
def safe_haven_points():
play_audio(player_score_sound)
global player_score
player_score += 1
update_text(p_score_text, 'PLayer: '+str(player_score))
if player_score > 50:
scoreboard()
def scoreboard():
clear()
if player_score > 50:
print_heading("You win!", 80)
play_audio(win)
else:
print_heading('Aliens win', 80)
play_audio(lose)
# Create scene
background_color("black")
add_background('background.jpg')
bg_music = add_audio("background.mp3")
# Add sound effects
player_score_sound = add_sound_effect("player-haven-score.mp3")
win = add_sound_effect("win.mp3")
alien_haven_score = add_sound_effect("alien-haven-score.mp3")
lose = add_sound_effect("lose.mp3")
explode = add_sound_effect("player-explosion.mp3")
# Add and position player's ship with WASD control
player_ship = add_image('my_ship.png', 150)
place_element(player_ship, 1000, 280)
wasd_move(player_ship)
arrows_move(player_ship)
# Add safe haven platforms
p_1 = add_image("platform-1.png", 200)
place_element(p_1, 50, 400)
bounce(p_1, 40)
p_2 = add_image("platform-2.png", 200)
place_element(p_2, 250, 450)
bounce(p_2, 50)
p_3 = add_image("platform-3.png", 200)
place_element(p_3, 550, 400)
bounce(p_3, 60)
p_4 = add_image("platform-4.png", 200)
place_element(p_4, 800, 350)
bounce(p_4, 50)
# list of platforms
platforms = [p_1,p_2,p_3,p_4]
# Add and animate aliens
aliens = []
for i in range(0,20):
image = add_image('alien.png', 80)
aliens.append(image)
random_x = random.randint(50,1300)
place_element(image, random_x, -100)
animate_y(image, -100, 1200, "infinite", True, 100);
animate_x(image, random_x, 200, "infinite", True, 200);
pause_time(.5)
# If an alien hits your ship, you lose
# If an alien hits a platform, aliens get 1 point
for alien in aliens:
detect_collision(alien, player_ship, alien_victory)
for platform in platforms:
detect_collision(platform, alien, alien_bomb_platform)
# Initialize, print, and position scores
player_score = 0
alien_score = 0
p_score_text = print_text('PLayer: '+str(player_score), 18)
a_score_text = print_text('Aliens: '+str(alien_score), 18)
place_element(p_score_text, 20, 20)
place_element(a_score_text, 20, 60)
# When you hide behind a platform, you get points
for platform in platforms:
detect_collision(platform, player_ship, safe_haven_points)
################################ PYTHON CODE ABOVE #############################
################################ DO NOT EDIT BELOW THIS LINE #############################
`;
readyCompiler(prog);</script>
</body>
</html>