-
Notifications
You must be signed in to change notification settings - Fork 1
/
code.py
192 lines (140 loc) · 4.89 KB
/
code.py
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
# Created by: ????
# Created on: ???? 2019
# This file is the "????" game
# for CircuitPython
import ugame
import stage
import board
import neopixel
import time
import random
import constants
def blank_white_reset_scene():
# this function is the splash scene game loop
# do house keeping to ensure everythng is setup
# set up the NeoPixels
pixels = neopixel.NeoPixel(board.NEOPIXEL, 5, auto_write=False)
pixels.deinit() # and turn them all off
# reset sound to be off
sound = ugame.audio
sound.stop()
sound.mute(False)
# an image bank for CircuitPython
image_bank_1 = stage.Bank.from_bmp16("mt_game_studio.bmp")
# sets the background to image 0 in the bank
background = stage.Grid(image_bank_1, 160, 120)
# create a stage for the background to show up on
# and set the frame rate to 60fps
game = stage.Stage(ugame.display, 60)
# set the layers, items show up in order
game.layers = [background]
# render the background and inital location of sprite list
# most likely you will only render background once per scene
game.render_block()
# repeat forever, game loop
while True:
# get user input
# update game logic
# Wait for 1/2 seconds
time.sleep(0.5)
mt_splash_scene()
# redraw sprite list
def mt_splash_scene():
# this function is the MT splash scene
# an image bank for CircuitPython
image_bank_2 = stage.Bank.from_bmp16("mt_game_studio.bmp")
# sets the background to image 0 in the bank
background = stage.Grid(image_bank_2, constants.SCREEN_GRID_X, constants.SCREEN_GRID_Y)
# used this program to split the iamge into tile: https://ezgif.com/sprite-cutter/ezgif-5-818cdbcc3f66.png
background.tile(2, 2, 0) # blank white
background.tile(3, 2, 1)
background.tile(4, 2, 2)
background.tile(5, 2, 3)
background.tile(6, 2, 4)
background.tile(7, 2, 0) # blank white
background.tile(2, 3, 0) # blank white
background.tile(3, 3, 5)
background.tile(4, 3, 6)
background.tile(5, 3, 7)
background.tile(6, 3, 8)
background.tile(7, 3, 0) # blank white
background.tile(2, 4, 0) # blank white
background.tile(3, 4, 9)
background.tile(4, 4, 10)
background.tile(5, 4, 11)
background.tile(6, 4, 12)
background.tile(7, 4, 0) # blank white
background.tile(2, 5, 0) # blank white
background.tile(3, 5, 0)
background.tile(4, 5, 13)
background.tile(5, 5, 14)
background.tile(6, 5, 0)
background.tile(7, 5, 0) # blank white
text = []
text1 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None)
text1.move(20, 10)
text1.text("MT Game Studios")
text.append(text1)
text2 = stage.Text(width=29, height=14, font=None, palette=constants.MT_GAME_STUDIO_PALETTE, buffer=None)
text2.move(35, 110)
text2.text("PRESS START")
text.append(text2)
# get sound ready
# follow this guide to convert your other sounds to something that will work
# https://learn.adafruit.com/microcontroller-compatible-audio-file-conversion
coin_sound = open("coin.wav", 'rb')
sound = ugame.audio
sound.stop()
sound.mute(False)
sound.play(coin_sound)
# create a stage for the background to show up on
# and set the frame rate to 60fps
game = stage.Stage(ugame.display, 60)
# set the layers, items show up in order
game.layers = text + [background]
# render the background and inital location of sprite list
# most likely you will only render background once per scene
game.render_block()
# repeat forever, game loop
while True:
# get user input
# update game logic
# Wait for 1 seconds
time.sleep(1.0)
game_splash_scene()
# redraw sprite list
def game_splash_scene():
# this function is the game scene
# repeat forever, game loop
while True:
# get user input
# update game logic
# redraw sprite list
pass # just a placeholder until you write the code
def main_menu_scene():
# this function is the game scene
# repeat forever, game loop
while True:
# get user input
# update game logic
# redraw sprite list
pass # just a placeholder until you write the code
def game_scene():
# this function is the game scene
# repeat forever, game loop
while True:
# get user input
# update game logic
# redraw sprite list
pass # just a placeholder until you write the code
def game_over_scene(final_score):
# this function is the game over scene
# repeat forever, game loop
while True:
# get user input
# update game logic
# redraw sprite list
pass # just a placeholder until you write the code
if __name__ == "__main__":
blank_white_reset_scene()