-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple Pokemon Gen 1 game wrapper
- Loading branch information
Showing
8 changed files
with
128 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# | ||
# License: See LICENSE.md file | ||
# GitHub: https://github.com/Baekalfen/PyBoy | ||
# | ||
from libc.stdint cimport uint8_t | ||
from pyboy.plugins.base_plugin cimport PyBoyGameWrapper | ||
cimport cython | ||
|
||
cdef class GameWrapperPokemonGen1(PyBoyGameWrapper): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# | ||
# License: See LICENSE.md file | ||
# GitHub: https://github.com/Baekalfen/PyBoy | ||
# | ||
__pdoc__ = { | ||
"GameWrapperPokemonGen1.cartridge_title": False, | ||
"GameWrapperPokemonGen1.post_tick": False, | ||
} | ||
|
||
import logging | ||
|
||
from pyboy.utils import WindowEvent | ||
|
||
from .base_plugin import PyBoyGameWrapper | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
try: | ||
from cython import compiled | ||
cythonmode = compiled | ||
except ImportError: | ||
cythonmode = False | ||
|
||
|
||
class GameWrapperPokemonGen1(PyBoyGameWrapper): | ||
""" | ||
This class wraps Pokemon Red/Blue, and provides basic access for AIs. | ||
If you call `print` on an instance of this object, it will show an overview of everything this object provides. | ||
""" | ||
cartridge_title = None | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.shape = (20, 18) | ||
super().__init__(*args, game_area_section=(0, 0) + self.shape, game_area_wrap_around=True, **kwargs) | ||
|
||
def enabled(self): | ||
return self.pyboy_argv.get("game_wrapper") and ((self.pyboy.cartridge_title() == "POKEMON RED") or | ||
(self.pyboy.cartridge_title() == "POKEMON BLUE")) | ||
|
||
def post_tick(self): | ||
self._tile_cache_invalid = True | ||
self._sprite_cache_invalid = True | ||
|
||
scanline_parameters = self.pyboy.botsupport_manager().screen().tilemap_position_list() | ||
WX = scanline_parameters[0][2] | ||
WY = scanline_parameters[0][3] | ||
self.use_background(WY != 0) | ||
|
||
def __repr__(self): | ||
adjust = 4 | ||
# yapf: disable | ||
return ( | ||
f"Pokemon Gen 1:\n" + | ||
"Sprites on screen:\n" + | ||
"\n".join([str(s) for s in self._sprites_on_screen()]) + | ||
"\n" + | ||
"Tiles on screen:\n" + | ||
" "*5 + "".join([f"{i: <4}" for i in range(10)]) + "\n" + | ||
"_"*(adjust*20+4) + | ||
"\n" + | ||
"\n".join( | ||
[ | ||
f"{i: <3}| " + "".join([str(tile).ljust(adjust) for tile in line]) | ||
for i, line in enumerate(self.game_area()) | ||
] | ||
) | ||
) | ||
# yapf: enable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters