Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"lives" variable is unclear #2

Open
SauceChord opened this issue Oct 16, 2020 · 5 comments
Open

"lives" variable is unclear #2

SauceChord opened this issue Oct 16, 2020 · 5 comments

Comments

@SauceChord
Copy link

I had a hard time getting what "lives" was used for. Its sent to player as "bob" parameter

turtle.onkey((lambda:player.headright(missile,lives)), "d")
turtle.onkey((lambda:player.headleft(missile,lives)), "a")
turtle.onkey((lambda:player.headdown(missile,lives)),"s")
turtle.onkey((lambda:player.headup(missile,lives)),"w")
turtle.onkey((lambda:player.headright(missile,lives)),"D")
turtle.onkey((lambda:player.headleft(missile,lives)), "A")
turtle.onkey((lambda:player.headdown(missile,lives)),"S")
turtle.onkey((lambda:player.headup(missile,lives)),"W")
turtle.onkey((lambda:player.drink(info)),"space")
turtle.onkey((lambda:player.fireball(missile2,info,lives)),"z")
turtle.onkey((lambda:player.fireball(missile2,info,lives)),"Z")

def headright(self,proj,bob):

and then to missiles and fireball as "mom".

proj.fire(self,bob)

7-Dungeons-Deep/proj.py

Lines 38 to 44 in 58d9f26

def fire(self,log,mom):
if self.status == "ready":
self.goto(log.xcor(), log.ycor())
self.setheading(log.heading())
self.status = "firing"
if mom != 3:
winsound.PlaySound(".\\sound\\swing.wav", winsound.SND_ASYNC)

It seems to be set to "3" when the game is over and used for not playing sound effects

7-Dungeons-Deep/game.py

Lines 2006 to 2015 in 58d9f26

for crown in crowns:
if player.is_collision(crown):
#winsound.PlaySound(".\\sound\\victory.wav",0)
player.destroy()
crown.destroy()
crowns.remove(crown)
lives=3 # prevent annoying ending bug where you can hear attack button.
game.win()

I am working on a branch to clean up some code and I am not really sure what this variable is intended to do. I could remove it but it would be annoying if you had plans on doing something else with it.

Instead of calling it lives, bob and mom, perhaps a less confusing name would be "ignore_audio" or "game_over" and make it a boolean?

@SauceChord
Copy link
Author

Also instead of passing it around to functions consider having a game state instance that your objects reference.

@Ninedeadeyes
Copy link
Owner

Hi, I think its to deactivate 'action' once the game has ended or you'll able to keep pressing attack and the attack sound still appear whilst this will deactivate once attack once game ends.. Yeah will clean up some of the variable names, oh and thanks for modulating my enemy class.

@Ninedeadeyes
Copy link
Owner

Ninedeadeyes commented Oct 24, 2020

I think you can definite make louds of improvements on the code.. I'm more of a hobbyist coder than it actually having to do with my day to day job so not learnt any 'best practice' rather learnt by looking at random codes on the internet as well as figuring stuff by myself so apologies for any poor code practice..,

@SauceChord
Copy link
Author

All good, I believe we are all "learning" something new everyday :) I am new to github collaboration so I dont know if I am really doing things the right way. I just wanted to help improve the code, not to derate you.

@Ninedeadeyes
Copy link
Owner

I am humbled that anyone would want to look and improve my code, so don't worry about it, I always welcome constructive criticism :) , I have no idea what I am doing on github at all.., I know enough just to put some of my projects online so it might help other beginners. Once I find the time I will probably will go though my codes again and change the variables so they make a little more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants