-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheaster_egg.py
142 lines (108 loc) · 4.14 KB
/
easter_egg.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
# -*- coding: utf8 -*-
import tkinter as tk
import time
import random
import re
import atexit
import subprocess
startMessage = True
shipX = 240
shipY = 200
rivalBeam = []
rivalBeamCount = 0
beamSpeed = 400
gameOver = 0
def shutdown(event):
quit()
def autoShutdown():
quit()
def spacePressed(event):
global startMessage
if startMessage == True:
startMessage = False
gameTitle.destroy()
promptStart.destroy()
gameCanvas.create_rectangle(shipX, shipY, shipX + 20, shipY + 20, fill='red', tag='ship')
howToPlay = tk.Label(gameCanvas, text='矢印キーで左右へ', bg='black', fg='red', font=('', 13, 'bold', 'roman', 'normal', 'normal'))
howToPlay.pack(anchor=tk.NW, expand=1)
root.after(beamSpeed, moveThings)
beamSound()
changeBeamSpeed()
def leftPressed(event):
global shipX
if startMessage == False:
if shipX >= 20:
shipX -= 20
gameCanvas.delete('ship')
gameCanvas.create_rectangle(shipX, shipY, shipX + 20, shipY + 20, fill='red', tag='ship')
def rightPressed(event):
global shipX
if startMessage == False:
if shipX <= 460:
shipX += 20
gameCanvas.delete('ship')
gameCanvas.create_rectangle(shipX, shipY, shipX + 20, shipY + 20, fill='red', tag='ship')
def moveThings():
global rivalBeam
global rivalBeamCount
rivalBeamLen = int(len(rivalBeam) / 3)
corsor = 0
for num in range(rivalBeamLen):
IDPrace = corsor
XPrace = corsor + 1
YPrace = corsor + 2
corsor += 3
rivalBeamID = rivalBeam[IDPrace]
rivalBeamX = rivalBeam[XPrace]
rivalBeamY = rivalBeam[YPrace]
gameCanvas.delete(rivalBeamID)
gameCanvas.create_line(int(rivalBeamX), int(rivalBeamY) + 20, int(rivalBeamX), int(rivalBeamY) + 40, fill='yellow', tag=rivalBeamID)
rivalBeam[YPrace] = str(int(rivalBeamY) + 20)
if int(rivalBeam[YPrace]) <= 200 and int(rivalBeam[YPrace]) >= 180 and int(rivalBeam[XPrace]) >= shipX and int(rivalBeam[XPrace]) <= shipX + 20:
global gameOver
gameOver += 1
gameOver = tk.Label(gameCanvas, text='Game Over', bg='black', fg='red', font=('', 30, 'bold', 'roman', 'normal', 'normal'))
gameOver.pack(side=tk.TOP, expand=0, fill=tk.BOTH)
beamSound('/home/pi/ORIZIN_Agent/sounds/soundEffects/wav/bomb1.wav')
root.after(3000, autoShutdown)
if int(rivalBeam[YPrace]) <= 0:
rivalBeam.pop(0)
rivalBeam.pop(1)
rivalBeam.pop(2)
X = random.randrange(0, 500, 20)
gameCanvas.create_line(X, 0, X, 20, fill='yellow', tag='rivalBeam' + str(rivalBeamCount))
rivalBeam.append('rivalBeam' + str(rivalBeamCount))
rivalBeam.append(str(X))
rivalBeam.append('0')
rivalBeamCount += 1
root.after(beamSpeed, moveThings)
def playSound(soundFile):
command = 'aplay ' + soundFile
global soundPlayer
soundPlayer = subprocess.Popen(command.split())
def beamSound(soundFile='/home/pi/ORIZIN_Agent/sounds/soundEffects/wav/laser1.wav'):
command = 'aplay ' + soundFile
subprocess.Popen(command.split())
root.after(1000, beamSound)
def stopSound():
soundPlayer.terminate()
def changeBeamSpeed():
global beamSpeed
beamSpeed -= 2
root.after(300, changeBeamSpeed)
atexit.register(stopSound)
root = tk.Tk()
root.title('ORIZIN Easter Egg')
root.geometry("500x300")
root.bind('<Control-q>', shutdown)
root.bind('<Left>', leftPressed)
root.bind('<Right>', rightPressed)
root.bind('<space>', spacePressed)
playSound('/home/pi/ORIZIN_Agent/sounds/musics/wav/natsuhasummer.wav')
gameCanvas = tk.Canvas(root, bg='black')
gameCanvas.pack(anchor=tk.NW, expand=1, fill=tk.BOTH)
gameTitle = tk.Label(gameCanvas, text='Space Battleship Game', bg='black', fg='red', font=('', 30, 'bold', 'roman', 'normal', 'normal'))
gameTitle.pack(expand=0, fill=tk.BOTH)
promptStart = tk.Label(gameCanvas, text='スペースキーを押してスタート', bg='black', fg='red', font=('', 15, 'bold', 'roman', 'normal', 'normal'))
promptStart.pack(anchor=tk.NW, expand=1, fill=tk.BOTH)
root.mainloop()