From 2e7e13996f27c91bab09521ef6c1d4974e8fb745 Mon Sep 17 00:00:00 2001 From: Pat Wick Date: Wed, 6 Mar 2024 22:05:52 -0500 Subject: [PATCH] updated player to be able to shoot projectiles used some of the movement system "vector" idea for the movement system to drive how the projectile moves. Direction is based on the last direction the player moved. Eventually damage and speed will depend on the race and class, but for now, it moves! --- __pycache__/player.cpython-310.pyc | Bin 1202 -> 1737 bytes __pycache__/projectile.cpython-310.pyc | Bin 0 -> 1110 bytes angband.py | 3 +-- player.py | 18 +++++++++++++++++ projectile.py | 26 +++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 __pycache__/projectile.cpython-310.pyc create mode 100644 projectile.py diff --git a/__pycache__/player.cpython-310.pyc b/__pycache__/player.cpython-310.pyc index 53a088e2ff3f3431b3d7d08e838e036e633604e6..eb0538488bf4dae9d7ad148179e4c363c72cc07a 100644 GIT binary patch literal 1737 zcmZuxUuzpj5Z~SVE9vA0Cyi|yh@nup7NjPHQfLVYY3h~~#l$JWM_@VMZsfC0I(6?9 zRpRvIQ2NxDegXS2Uuj?aCB#_I!^c4+1c6M*_+?|X7hHtNud4JxsZSQg#3+@ z%gutxedxv4AOsOKBSRWdiaN{K(26XhTbVs{B8QSaB5dKjCc-&okt^H-5_%VKmV{Kd zA1IYiAIsT;z8sZcu=nDjgt57=@)MbqX(kigd$}=~+=pI#145FB3KB6vBTKNz7FOg4 z8}4x;Pq@N+O(I|Tq5)$=G(`)>rU>94+S=XE;+a&MKGE*js23DGzF`XDCJJ>;5*vn9 zLmh8_2)&3vRJ0}x+O}(3!(?dX^Kk9+u&RBM6Gt=$mioP-q6HrR zC|!&~1UncF!x8=uE!NTkBi?6Lty62^f={n<&!Lh^U$jq6MI9LaAcw+@UdXin_|YN% z`Oy#0bOW`gKkfbaOzi-6hO!~Mcn8feS2e)8I`RFJ=RNJ>iC^~BEwfN>LZXMP);~cv zEf8<%uCdHpV>#Vj_OP*J&j<=sH$bNR@%j}oOs&Nhp1*b+k3=T<+RbgS z7GHvBQv3qy(}1}~2g$BlHrd^J*FW>EB{{Epe2=8>l|DiU=_2PqrX8|?Qda>`5cE1> zA?q0g;UT-(mt_q=!H;I^&_dh5U@%pmVL+}yskj>F$LsS@X6xhkFj!1pz-$QAemB3h z4B~&c_rey|DW;Bd-Q;|jiwS_ob-?+rlQ>(hG?L>OUWZaDg>Y&oldoi^c0sRmx{cZw zC^{(c^|&N3F$ya=fNq`wpV)Nu`OFW3+h)BNdb(vEl8%X5;iIaXwFTLr@O@C9qd?%z ap-UH;dkqcz@9I$Q;cHzZ;sucWP4+KjLzrLy literal 1202 zcmZuwUvJYe5VsvCO}lIiG`1opp5P%8T7`H6gf_t#Xs8=(2vH$fS?sl0+oU)hrBn9A zKFIb6AIYzXhkXQifjjq)%7i1I@8Y|k?|x@z^Yaw~!&HB&&?V#t8neRzV;yFG2ZSV& zc1V{tC?#7&GU=QV>3n4kCixx--AnKxAvNbv>)T&*}=eAhne38p-6*D z0tmF>NY>!ek^GD_TkQ)_p&_cCs`UY!*kU+)E;#ACBki_j;H)DDF^dX4xi-poZL$|5p_73}qiwVO z4oX3e$VYbSobrMmQAs}&9a@dGnO-g&=~PL<580`kdT6bTt%9Ai!o8s2&CZ>%=3?bG zngh;`)m*@NR5%6Dyh0{8XjQE>#d$Nu*()p#GB`U!uMQ0Q+nXQ6>&+MYri|L#S6eUl z^&Av(NkL2;p6|S`8xI}c?P??^nqEvR2n1)`5zxiDd6^h>i4H&K-t-w05DwO}? zE~h6eBL3@M4}H9=$h{DzB1AWn z$3U1cfe@dLqt1Az9JeAJ#eJpqB4&rrNmo(aMu7*;2;^SlWk$C=0O1o(As^;D!IIsn jhmM)EuV&4br;$RtGlOGcZ6p0Bqr{#fc{x%Zly0!UE9n$r diff --git a/__pycache__/projectile.cpython-310.pyc b/__pycache__/projectile.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7db3417d0fcba48cad05812750d5137f63293c1e GIT binary patch literal 1110 zcmZXT&2H2%5XU`^vztw~rJ{v`khpLm95x`X2#`4RRw0$s3dstw+s!s#b+Rm7r6>9X zJVAThSIU*sz5*v^yle@@lE-6v@*mI7PO-i1Gi>wGO8?-D{iI2^IXHQby?Tm9F$F2h zU<|+xnc~X1V#@i>$6SeH7Pu>nVF9$_Fv@gHlWs%#wbV;=G#i6r_#up)wa{27q1-Dr zc2!UHaqKBi4RGu$AH}y?|D!3UIvA({pnCRxMLLgS$2iXF2h z90gA6l|_}*Ns+e$l^7C4*R4veRUleX>GZ_(P{Z`ecxaZ)5T#%5!by?ou$(9HS(rs< zNq#ElNj;Hqp>&wd<5%G`&-*+ z6BAQKo93cJRoV(aq0_J_`^+!-B~~{D1&?jDQ@+m*Xb%*}722~aC;U=0aP2hW2F$ZY z5EmkXYv|wLebOv&jtrpoicH|H0az47q4knV>a46U+M&@|@m0&{ROdAY4rp7P;;pw_ zeZ!6+xt_}nX^U@dwrnVUOaZ*I2>k^oAG( zVD@oXa(gDTi~il@gEEaSWIZ$a9`078x&w>-PUhQy|I!l}o1X51klCc`3=eSWZm!)) zl&e(Z14+}Q!iV+B7K{s418hVXU_Avc7OdPN_2On}Ed*Yk$1-Jw6kw{Leu_h|@^-RQ_zReO=% QoAtTg5}1mh4B37D8^I&$S^xk5 literal 0 HcmV?d00001 diff --git a/angband.py b/angband.py index 99ee75e..192588d 100644 --- a/angband.py +++ b/angband.py @@ -26,11 +26,10 @@ input("Press Enter to continue. Good luck!") board_size = (25,25) x,y = board_size + walls = [Wall(position) for position in board_edges(board_size)] level = [Wall(position) for position in level_one(board_size)] game = Game(walls + level, {}, board_size = board_size) game.add_agent(Player((x//2,y//2),race,class_)) - - game.play() \ No newline at end of file diff --git a/player.py b/player.py index 6d35182..d235d96 100644 --- a/player.py +++ b/player.py @@ -6,28 +6,37 @@ # generally be adapted for other player character uses. from retro.agent import ArrowKeyAgent +from retro.game import Game +from projectile import Projectile class Player: character = "O" name = "player" level = 1 + direction = (1,0) + class_ = "" def __init__(self, position, race, class_): self.position = position if class_.capitalize() == "Warrior": self.color = "red" + self.class_ == class_ elif class_.capitalize() == "Rogue": self.color = "green" + self.class_ == class_ else: self.color = "blue" + self.class_ == class_ def handle_keystroke(self, keystroke, game): x, y = self.position if keystroke.name in ("KEY_LEFT", "KEY_RIGHT"): if keystroke.name == "KEY_LEFT": new_position = (x - 1, y) + self.direction = (-1,0) else: new_position = (x + 1, y) + self.direction = (1,0) if game.on_board(new_position): if game.is_empty(new_position): self.position = new_position @@ -35,12 +44,21 @@ class Player: if keystroke.name in ("KEY_DOWN", "KEY_UP"): if keystroke.name == "KEY_DOWN": new_position = (x, y + 1) + self.direction = (0,1) else: new_position = (x, y - 1) + self.direction = (0,-1) if game.on_board(new_position): if game.is_empty(new_position): self.position = new_position + if self.class_ != "Warrior" and keystroke == " ": + projectile = Projectile((self.position[0] + self.direction[0],self.position[1] + self.direction[1]), self.direction, 1) + game.add_agent(projectile) + print("pew pew pew") + + + def get_agent_in_position(self, position, game): agents = game.get_agents_by_position()[position] diff --git a/projectile.py b/projectile.py new file mode 100644 index 0000000..7ed6f3c --- /dev/null +++ b/projectile.py @@ -0,0 +1,26 @@ +from retro.game import Game + +class Projectile: + character = "*" + + def __init__(self, position, direction, speed): + self.position = position + self.direction = direction + self.speed = speed + + def move(self, game): + dx, dy = self.direction + new_position = (self.position[0] + dx * self.speed, self.position[1] + dy * self.speed) + if game.is_empty(new_position): + self.position = new_position + else: + game.remove_agent(self) + + def play_turn(self,game): + self.move(game) + + + + def handle_collision(self, game): + # need to fix this at some point + pass \ No newline at end of file