質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.41%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

838閲覧

Git-HubでPyMario-masterという、スーパーマリオワールドの1面を模したゲームを見つけたので編集したいが、ステージの編集方法が分からない。

phpuser567

総合スコア12

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2023/03/05 06:36

タイトルの通り、
Git-HubでPyMario-masterという、スーパーマリオワールドの1面を模したゲームを見つけたので編集したいが、ステージの編集方法が分からない。
のです。
Mario_Bros.pyが実行ファイルで、これを実行するとプレイできます。

Mario_Bros.py

python

1from data import main 2from data import menu 3from data import config as c 4import pygame as pg 5import os 6import sys 7 8class App(): 9 def __init__(self): 10 self.menu = None 11 self.main = None 12 13 def run(self): 14 self.menu = menu.Menu() 15 self.menu.menu_loop() 16 if self.menu.quit_state == 'play': #Check whether to continue to game or quit app 17 self.main = main.Main() 18 self.main.main_loop() 19 if self.main.quit_state == 'menu': 20 #If you think this is a cheat 21 #to avoid destroying instances, 22 #you are right, I'm just too 23 #lazy to do that. 24 os.execl(sys.executable, sys.executable, *sys.argv) #Restart game 25 26if __name__ == '__main__': 27 pg.init() #Initialize pygame module 28 c.screen = pg.display.set_mode((c.SCREEN_SIZE.x, c.SCREEN_SIZE.y)) 29 pg.display.set_caption(c.CAPTION) 30 c.clock = pg.time.Clock() 31 32 app = App() 33 app.run() 34 35 pg.quit()

ここにステージ情報はなさそうです。data>components>tilesは、

tiles.py

1from .. import config as c 2from ..basetypes import Vector2, Game_Object, State_Machine, State, Entity, Rectangle 3from .. import sprites 4from .. import sounds 5from ..utils import accelerate 6from .. import level 7import pygame as pg 8 9 10class Collider_Rect(Game_Object): 11 """Class for static colliders""" 12 def __init__(self, rect): 13 super(Collider_Rect, self).__init__(rect) 14 15class Question(Game_Object): 16 """Question Block""" 17 def __init__(self, rect, contents): 18 super(Question, self).__init__(rect) 19 self.contents = contents 20 21 self.animation = self.Animation(self.pos.y) 22 self.state_machine = State_Machine(self.Closed_State(), self) 23 24 def update(self): 25 self.state_machine.update() 26 27 def draw(self, pos): 28 c.screen.blit(sprites.tile_set, (pos.x, pos.y), self.animation.current_sprite) 29 30 class Animation(): 31 """Contains specific animation variables and functions for this class""" 32 def __init__(self, start_height): 33 self.current_sprite = sprites.Q_BLOCK_CLOSED[0] 34 35 self.outer_timer = c.INITIAL_TIMER_VALUE 36 self.inner_timer = c.INITIAL_TIMER_VALUE 37 self.closed_frame = 0 38 self.closed_frames = [0, 1, 2, 1, 0] 39 40 self.start_height = start_height 41 self.bounce_iteration = 0 42 self.new_y = start_height 43 44 def closed_anim(self): 45 """Animation when not opened""" 46 self.current_sprite = sprites.Q_BLOCK_CLOSED[self.closed_frames[self.closed_frame]] 47 self.outer_timer += c.delta_time 48 if self.outer_timer > 20 * c.delta_time: 49 self.inner_timer += c.delta_time 50 if self.inner_timer > 6 * c.delta_time: 51 self.closed_frame += 1 52 self.inner_timer = 0 53 54 if self.closed_frame == 5: 55 self.outer_timer = 0 56 self.closed_frame = 0 57 58 def bounce_anim(self): 59 """Animation when bouncing""" 60 self.new_y = self.start_height - self.bounce_anim_function(self.bounce_iteration) 61 self.bounce_iteration += 4 62 63 def bounce_anim_function(self, bounce_iteration): 64 """Returns new y position based on mathematical function""" 65 return -abs(bounce_iteration - 24) + 24 66 67 class Closed_State(State): 68 """State when not opened yet""" 69 def on_event(self, event): 70 if event == 'bounce': 71 return Question.Bounce_State() 72 return self 73 74 def update(self, owner_object): 75 owner_object.animation.closed_anim() 76 77 class Bounce_State(State): 78 """State when opening""" 79 def on_event(self, event): 80 if event == 'open': 81 return Question.Open_State() 82 return self 83 84 def on_enter(self, owner_object): 85 owner_object.animation.current_sprite = sprites.Q_BLOCK_OPEN 86 if owner_object.contents.__class__.__name__ == 'Coin': 87 owner_object.contents.deployed = True 88 c.total_score += c.COIN_SCORE 89 c.collected_coins += 1 90 sounds.coin.play() 91 else: 92 sounds.powerup_appears.play() 93 94 def update(self, owner_object): 95 owner_object.animation.bounce_anim() 96 owner_object.pos.y = owner_object.animation.new_y 97 if owner_object.animation.bounce_iteration > 48: 98 owner_object.state_machine.on_event('open') 99 100 class Open_State(State): 101 """State when opened""" 102 def on_event(self, event): 103 return self 104 105 def on_enter(self, owner_object): 106 owner_object.contents.deployed = True 107 108class Brick(Game_Object): 109 """Brick class""" 110 def __init__(self, rect): 111 super(Brick, self).__init__(rect) 112 113 self.animation = self.Animation(self.pos.y) 114 self.state_machine = State_Machine(self.Idle_State(), self) 115 116 self.remove = False 117 118 def update(self): 119 self.state_machine.update() 120 121 def draw(self, pos): 122 c.screen.blit(sprites.tile_set, (pos.x, pos.y), sprites.BRICK) 123 124 def instantiate_fragments(self): 125 """Instantiate fragments when broken""" 126 level.brick_fragments.append(Brick_Fragment(Vector2(self.pos.x, self.pos.y), Vector2(-0.1, -0.5), Rectangle())) 127 level.brick_fragments.append(Brick_Fragment(Vector2(self.pos.x + 24, self.pos.y), Vector2(0.1, -0.5), Rectangle())) 128 level.brick_fragments.append(Brick_Fragment(Vector2(self.pos.x + 24, self.pos.y + 24), Vector2(0.1, -0.4), Rectangle())) 129 level.brick_fragments.append(Brick_Fragment(Vector2(self.pos.x, self.pos.y + 24), Vector2(-0.1, -0.4), Rectangle())) 130 131 class Animation(): 132 """Contains specific animation variables and functions for this class""" 133 def __init__(self, start_height): 134 135 self.bounce_iteration = 0 136 self.new_y = start_height 137 self.start_height = start_height 138 139 def bounce_anim(self): 140 self.new_y = self.start_height - self.bounce_anim_function(self.bounce_iteration) 141 self.bounce_iteration += 4 142 143 def bounce_anim_function(self, bounce_iteration): 144 return -abs(bounce_iteration - 24) + 24 145 146 class Idle_State(State): 147 """State when not interacting with anything""" 148 def on_event(self, event): 149 if event == 'bounce': 150 return Brick.Bounce_State() 151 elif event == 'break': 152 return Brick.Break_State() 153 return self 154 155 class Bounce_State(State): 156 """State when small mario hits brick from under""" 157 def on_event(self, event): 158 if event == 'idle': 159 return Brick.Idle_State() 160 return self 161 162 def update(self, owner_object): 163 owner_object.animation.bounce_anim() 164 owner_object.pos.y = owner_object.animation.new_y 165 if owner_object.animation.bounce_iteration > 48: 166 owner_object.animation.bounce_iteration = 0 167 owner_object.state_machine.on_event('idle') 168 169 class Break_State(State): 170 """State when big mario hits brick from under""" 171 def __init__(self): 172 self.wait_for_frame = 0 173 174 def on_enter(self, owner_object): 175 owner_object.instantiate_fragments() 176 sounds.brick_smash.play() 177 178 def update(self, owner_object): 179 if self.wait_for_frame > 0: 180 level.dynamic_colliders.remove(owner_object) 181 self.wait_for_frame += 1 182 183class Brick_Fragment(Entity): 184 """Handles individual brick fragments and their animations""" 185 def __init__(self, pos, vel, rect): 186 super(Brick_Fragment, self).__init__(vel, rect) 187 self.rect.pos = pos 188 self.animation = self.Animation() 189 190 def update(self): 191 accelerate(self, 0, c.GRAVITY) 192 self.pos += self.vel * c.delta_time 193 self.animation.anim() 194 self.check_for_destroy() 195 196 def check_for_destroy(self): 197 """Checks if instance can be destroyed""" 198 if self.pos.y > c.SCREEN_SIZE.y: 199 level.brick_fragments.remove(self) 200 201 def draw(self): 202 view_pos = c.camera.to_view_space(self.pos) 203 c.screen.blit(sprites.tile_set, (view_pos.x, view_pos.y), self.animation.current_sprite) 204 205 class Animation(): 206 """Contains specific animation variables and functions for this class""" 207 def __init__(self): 208 self.current_sprite = None 209 self.anim_frame = 0 210 self.anim_timer = c.INITIAL_TIMER_VALUE 211 212 def anim(self): 213 self.current_sprite = sprites.BRICK_FRAGMENT[self.anim_frame % 2] 214 self.anim_timer += c.delta_time 215 if self.anim_timer > 8 * c.delta_time: 216 self.anim_frame += 1 217 self.anim_timer = 0 218 219class Flagpole(Game_Object): 220 """Handles flagpole at the end of level and triggers win events""" 221 def __init__(self, rect, flag_pos): 222 super(Flagpole, self).__init__(rect) 223 self.flag_pos = flag_pos 224 225 def update(self): 226 if self.rect.check_collisions([c.mario]) is not None: 227 c.mario.mario_states.on_event('win') 228 229 if c.mario.current_mario_state == 'Win_State': 230 if not self.flag_pos.y >= self.pos.y + self.rect.h - 60: 231 self.flag_pos.y += 4 232 233 def draw_flag(self): 234 view_pos = c.camera.to_view_space(self.flag_pos) 235 c.screen.blit(sprites.tile_set, (view_pos.x, view_pos.y), sprites.FLAG)

こんな感で、tileというからステージ情報なのかなと思いましたが、自分の考えている行列形式のステージ構成になっておらず、数値ばかりでよく分かりません・・・。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tmp

2023/03/05 07:14

キャラがそのままでな気がするので、日本では問題があるかもしれませんよ。 map.pngがステージデータで、グラフィックエディタで編集できると思います。 1ピクセル毎の色でなんのブロックが決まってます。色についてはlevel.pyを読んでみましょう tileは、よくあるのはチップデータでよくみかけます。 あなたの言うステージはlevelが結構みかけますよ
guest

回答1

0

自己解決

ご回答ありがとうございました。

投稿2023/06/30 13:46

phpuser567

総合スコア12

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.41%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問