--- a/gaota.py +++ b/gaota.py @@ -1,4 +1,7 @@ import pyxel +# FredyGames port: the game was written for Pyxel 0.9 (2019). This version runs on Pyxel 2.x: the resource file +# is converted to .pyxres at build time (convert-pyxel-assets.py), tilemap calls use the 2.x API (tile units for +# pget/blt, pixels for bltm) and arrow keys / gamepad work besides H J K L Z. #from collections import namedtuple #Point = namedtuple("Point", ["x", "y"], "Tile_Point", ["x", "y"]) @@ -28,12 +31,36 @@ IMG_LADDER_LEFT = 4 IMG_LADDER_RIGHT = 5 +def key_left(): + return pyxel.btn(pyxel.KEY_H) or pyxel.btn(pyxel.KEY_LEFT) or pyxel.btn(pyxel.GAMEPAD1_BUTTON_DPAD_LEFT) + + +def key_right(): + return pyxel.btn(pyxel.KEY_L) or pyxel.btn(pyxel.KEY_RIGHT) or pyxel.btn(pyxel.GAMEPAD1_BUTTON_DPAD_RIGHT) + + +def key_up(): + return pyxel.btn(pyxel.KEY_K) or pyxel.btn(pyxel.KEY_UP) or pyxel.btn(pyxel.GAMEPAD1_BUTTON_DPAD_UP) + + +def key_down(): + return pyxel.btn(pyxel.KEY_J) or pyxel.btn(pyxel.KEY_DOWN) or pyxel.btn(pyxel.GAMEPAD1_BUTTON_DPAD_DOWN) + + +def key_spit(): + return pyxel.btn(pyxel.KEY_Z) or pyxel.btn(pyxel.KEY_SPACE) or pyxel.btn(pyxel.GAMEPAD1_BUTTON_A) + + +def key_reset(): + return pyxel.btnp(pyxel.KEY_R) or pyxel.btnp(pyxel.GAMEPAD1_BUTTON_START) + + # TODO:Classing, OVERALL!!!!!! class App: def __init__(self): # TODO:wanna gorgeous title! - pyxel.init(WINDOW_W, WINDOW_H, caption="gaota", fps=25) - pyxel.load('assets/gaota.pyxel') + pyxel.init(WINDOW_W, WINDOW_H, title="gaota", fps=25, quit_key=pyxel.KEY_NONE) + pyxel.load('assets/gaota.pyxres') self.title() self.deep_reset() self.reset() @@ -64,9 +91,7 @@ self.stage = 0 def update(self): - if pyxel.btnp(pyxel.KEY_Q): - pyxel.quit() - elif pyxel.btnp(pyxel.KEY_R): + if key_reset(): self.reset() self.deep_reset() @@ -102,7 +127,7 @@ self.spew_count += 1 # push h to move to left - elif pyxel.btn(pyxel.KEY_H) and self.x>0: + elif key_left() and self.x>0: self.move_x = -1 self.vector = 1 if ( @@ -119,7 +144,7 @@ self.move_x = 0 # push l to move to right - elif pyxel.btn(pyxel.KEY_L) and self.x<112: + elif key_right() and self.x<112: self.move_x = 1 self.vector = 0 if ( @@ -136,7 +161,7 @@ self.move_x = 0 # push k to move up - elif pyxel.btn(pyxel.KEY_K): + elif key_up(): self.move_y = 0 if ( self.target(self.tile_x+0, self.tile_y+1) in [ @@ -151,7 +176,7 @@ self.is_laddering = True # push j to move down - elif pyxel.btn(pyxel.KEY_J): + elif key_down(): self.move_y = 0 if ( self.target(self.tile_x+0, self.tile_y+2) in [ @@ -166,7 +191,7 @@ self.is_laddering = True # push z to spew a rock - elif pyxel.btn(pyxel.KEY_Z): + elif key_spit(): if self.is_rock_fall: pass elif self.rock_count == 0: @@ -208,11 +233,11 @@ i = self.rock_count j = 1 while i > 0: - #pyxel.tilemap(0).copy( + #pyxel.tilemap(0).blt( # j, # 16, # 7, 2, 0, 1, 1) - #pyxel.tilemap(0).copy( + #pyxel.tilemap(0).blt( # j, # 16, # 7, 2, 1, 1, 1) @@ -220,17 +245,19 @@ j * 8, 132, 0, - 2, 0, 1, 1) + 2 * 8, 0 * 8, 8, 8) pyxel.bltm( j * 8, 10, 0, - 2, 1, 1, 1) + 2 * 8, 1 * 8, 8, 8) j += 1 i -= 1 def target(self, x, y): - return pyxel.tilemap(0).get(x, y) + # 2.x tilemaps hold (column, row) of the 8x8 tile in the image; the stage code uses the 0.9 tile number. + tile_u, tile_v = pyxel.tilemap(0).pget(x, y) + return tile_v * 32 + tile_u def is_puttable(self): if self.vector == 0: @@ -267,7 +294,7 @@ # put static rock after landing. # TODO:i think i should not use tilemap().copy. # actually im using tilemap(7) to copy tile and that is not good, i think. - pyxel.tilemap(0).copy( + pyxel.tilemap(0).blt( self.rock_tile_x, self.rock_tile_y, 7, 0, 0, 2, 2) @@ -310,7 +337,7 @@ def delete_behind(self): # TODO: i think i should not use tilemap().copy. - pyxel.tilemap(0).copy( + pyxel.tilemap(0).blt( self.tile_x, self.tile_y, 1, 2, 0, 2, 2) @@ -340,10 +367,10 @@ x = 0 y = 0 tm = 0 - u = self.stage * 16 + u = self.stage * 16 * 8 v = 0 - w = 16 - h = 16 + w = 16 * 8 + h = 16 * 8 pyxel.bltm(x, y, tm, u, v, w, h) def title(self):