Skip to content

Commit 0ce3c00

Browse files
committed
NaiveBandori and Perfect Agents
0 parents  commit 0ce3c00

File tree

100 files changed

+2035
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2035
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
__pycache__

Diff for: Background.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pygame
2+
3+
4+
class Background(pygame.sprite.Sprite):
5+
6+
def __init__(self, const):
7+
super(Background, self).__init__()
8+
# para copy
9+
self.screen_width = const.width
10+
self.screen_height = const.height
11+
self.lineOffset = const.lineOffset
12+
self.lane1ScaleWidth = const.lane1ScaleWidth
13+
# lane (rail)
14+
lane1 = pygame.image.load('res/bg_line_rhythm.png')
15+
self.__lane1ScaleHeight = const.lane1HeightDivWidth * self.lane1ScaleWidth
16+
self.__laneSurface = pygame.transform.smoothscale(lane1, (round(self.lane1ScaleWidth), round(self.__lane1ScaleHeight)))
17+
# line (judgement)
18+
line1 = pygame.image.load('res/game_play_line.png')
19+
self.line1HeightDivWidth = 38.0 / 1800.0
20+
self.__line1ScaleWidth = 1800 * const.laneWidth / 1080
21+
self.__line1ScaleHeight = self.__line1ScaleWidth * self.line1HeightDivWidth
22+
self.__lineSurface = pygame.transform.smoothscale(line1, (round(self.__line1ScaleWidth), round(self.__line1ScaleHeight)))
23+
24+
def draw_lane(self, screen):
25+
screen.blit(self.__laneSurface,
26+
(self.screen_width / 2 - self.lane1ScaleWidth / 2,
27+
self.screen_height / 2 + self.lineOffset - self.__lane1ScaleHeight))
28+
29+
def draw_line(self, screen):
30+
screen.blit(self.__lineSurface,
31+
(self.screen_width / 2 - self.__line1ScaleWidth / 2,
32+
self.screen_height / 2 + self.lineOffset - self.__line1ScaleHeight / 2))

Diff for: ChartParser.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import json
3+
4+
5+
class ChartParser:
6+
"""
7+
--json detail--
8+
Single: Tap
9+
SingleOff: weak note, Tap
10+
Skill: now same as Single
11+
long: long start / end
12+
bar: green belt
13+
Tick: green bar's link
14+
sim: line
15+
Flick: pink
16+
"""
17+
18+
def __init__(self, song_id, difficulty):
19+
chart_path = 'chart/'+str(song_id)+'.'+difficulty+'.json'
20+
if not os.path.exists(chart_path):
21+
raise IOError('Chart', song_id, 'Not Found.')
22+
else:
23+
with open(chart_path, 'r') as f:
24+
self.chart = json.load(f)
25+
f.close()
26+
27+
if False:
28+
cp = ChartParser(73, 'expert')
29+
print(cp.chart)
30+
x = 14
31+
print(type(cp.chart[x]['type']))
32+
print(type(cp.chart[x]['lane']))
33+
print(type(cp.chart[x]['time']))
34+
type_set = set()
35+
for e in cp.chart:
36+
if e['type'] not in type_set:
37+
type_set.add(e['type'])
38+
print(type_set)

Diff for: Constant.py

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import sys
2+
import json
3+
import os
4+
import pygame
5+
from enum import Enum
6+
7+
8+
class Difficulty(Enum):
9+
easy = 1
10+
normal = 2
11+
hard = 3
12+
expert = 4
13+
14+
15+
class NoteType(Enum):
16+
flick = 'flick'
17+
long = 'long'
18+
normal = 'normal'
19+
sim = 'simultaneous_line'
20+
slide = 'slide_among'
21+
22+
23+
class NoteInfo:
24+
25+
def __init__(self):
26+
self.notesPNG = pygame.image.load("res/note 0.png")
27+
with open('res/note 0.json', 'r') as f:
28+
self.ni = json.load(f)['frames']
29+
f.close()
30+
31+
def __call__(self, notetype, lane=None):
32+
# lane in chart: 1 ~ 7
33+
# lane in self.ni: 0 ~ 6
34+
# long means long_start / end
35+
if notetype not in ['flick', 'long', 'normal', 'simultaneous_line', 'slide_among']:
36+
print('Unsupported Note Type.', file=sys.stderr)
37+
sys.exit(-3)
38+
if notetype in ['flick', 'long', 'normal'] and \
39+
(type(lane) is not int or lane > 7 or lane < 1):
40+
print('Invalid Lane Number.', file=sys.stderr)
41+
sys.exit(-2)
42+
return \
43+
self.ni['note_'+notetype+'_'+str(lane-1)+'.png']['frame'] \
44+
if notetype in ['long', 'normal'] else \
45+
(self.ni['note_'+notetype+'_'+str(lane-1)+'.png']['frame'],
46+
self.ni['note_flick_top.png']['frame']) \
47+
if notetype is 'flick' else \
48+
self.ni['simultaneous_line.png']['frame'] \
49+
if notetype is 'simultaneous_line' else \
50+
self.ni['note_slide_among.png']['frame']
51+
52+
53+
class NoteIMG:
54+
55+
def __init__(self):
56+
# as pygame.image.load will close the file buffers automatically
57+
# use sprite png or save pic root?
58+
self.note_img = {
59+
'long': ['res/chop/' + 'long' + '_' + str(i) + '.png' for i in range(1, 8)],
60+
'slide_among': ['res/chop/' + 'slide_among' + '.png'],
61+
'flick': ['res/chop/' + 'flick' + '_' + str(i) + '.png' for i in range(1, 8)],
62+
'flick_top': ['res/chop/flick_top.png'],
63+
'normal': ['res/chop/' + 'normal' + '_' + str(i) + '.png' for i in range(1, 8)],
64+
'simultaneous_line': ['res/chop/' + 'simultaneous_line' + '.png']
65+
}
66+
67+
def get(self, noteType, lane):
68+
if noteType in [NoteType.long, NoteType.flick, NoteType.normal]:
69+
if not (1 <= lane <= 7):
70+
print('Invalid Lane Number.', file=sys.stderr)
71+
sys.exit(-2)
72+
elif noteType != NoteType.flick:
73+
return self.note_img[noteType.value][lane-1]
74+
else:
75+
return (self.note_img[noteType.value][lane-1], self.note_img['flick_top'][0])
76+
if noteType in [NoteType.sim, NoteType.slide]:
77+
return self.note_img[noteType.value][0]
78+
79+
# def __del__(self):
80+
# for v in self.note_img.values():
81+
# for f in v:
82+
# f.close()
83+
84+
85+
class ConstPara:
86+
87+
def __init__(self, height=720, noteSpeed=9.0):
88+
# screen
89+
# lane: 1160 * 610
90+
# line: 1800 * 38
91+
self.size = self.width, self.height = int(height*16/9), height
92+
self.laneWidth = 0.8 * self.width
93+
self.laneHeight = self.laneWidth / 2 / 0.875
94+
self.lineOffset = 1.225 * self.laneHeight * (0.5 - 0.225 / 1.225)
95+
# background para
96+
self.lane1HeightDivWidth = 610.0 / 1160.0
97+
self.lane1ScaleWidth = 1160 * self.laneWidth / 1080
98+
self.lane1ScaleHeight = self.lane1HeightDivWidth * self.lane1ScaleWidth
99+
# note
100+
self.noteSpeed = noteSpeed
101+
self.noteWidth = self.lane1ScaleWidth / 7
102+
self.noteScreenTime = 5.5 - (self.noteSpeed - 1) / 2.0
103+
104+
105+
class SongChart:
106+
107+
def __init__(self, songNo, difficulty=Difficulty.expert):
108+
# song & chart
109+
songNoStr = str(songNo) if songNo > 99 else '0' + str(songNo) if songNo > 9 else '00' + str(songNo)
110+
self.songPath = 'song/' + songNoStr + '.mp3'
111+
self.chartPath = "chart/" + Difficulty(difficulty).name + '/' + str(songNo) + '.' + Difficulty(difficulty).name + '.json'
112+
if not os.path.exists(self.songPath) or not os.path.exists(self.chartPath):
113+
print('Song', songNo, 'Not Found')
114+
sys.exit(-1)
115+
116+
117+
class Action(Enum):
118+
release = 0
119+
tap = 1
120+
flick = 2

0 commit comments

Comments
 (0)