Fight Game with Python [Pygame]

Fight Game with Python [Pygame]

The Final Countdown

The Final Countdown is a video game I'm coding with Python. I should say that it's been almost two years since I don't touch or interact with Python code. My interest in this project started when I was interviewed for a big company; they said I would do the technical discussion with an OOP language. I said okay, I have only been coding with JavaScript for the last two years. It would be easier for me to interview in that language. They said okay, I've seen you used Python before. We're going to interview in that language, I said. Challenge accepted.

I had only two days to practice Python, the position was for a junior mobile developer, so it shouldn't be tough. Still, it's been a while since I didn't use it, so I thought I better start with the basics, "if statements," I looked for algorithms problems and started doing some basic exercises; I remember that week I had a lot of work to do, I was stressed, I remember my realistic objective was to make at least fifty exercises in these two days, at least level 5, at the end of the first day I've only done ten exercises. I said, okay, I need to do 35 for tomorrow. At the end of that day, I reached just twenty activities. I was, though, cause I didn't have time to do anything. To do that was an achievement. It's hard to think at 11 pm when you woke up at 6 am and worked all day. So I made my way to bed and fell asleep. I had the interview at 9 am.

I woke up, had coffee, organized my stuff, and prepared for the interview!

First question: What's a class?

Second question: What's an object?

Third question: What's inheritance?

Fourth question: How would you define polymorphism?

Then, what's the best practice to do this... tell me the definition of that... why is this concept useful?

I asked the interviewer, will I have to code anything? He said no, just a few questions. I'm not the best at theoretical questions, and I haven't studied this anywhere, but I said okay, and started to reply as I thought the answers were; this took me by surprise. I thought I would have only to code.

I failed the Inheritance question, a concept I've used before many times, but I didn't know it was called polymorphism. I have no idea, I said.

I could reply to most of the questions, but I would have prepared myself better knowing it was an interview like this; I think it's essential to understand theoric concepts since the questions were basic or it wasn't high-level. I managed to reply decently.

So after more than a week, I still have no reply, but these two days, I've had to code algorithms to remember Python; I felt so entertained, distracted, and relaxed that I felt like I was enjoying coding again; it's even three years since I'm doing web development with javascript, react, node, angular, express, I liked this, though I feel at this point I'm doing every day the same, not even mention that Python is very entertained to write. I wanted to do more.

I like Python; what can I do?

When coding projects to find a job, I did more than 50 projects, most of which were applications or websites, but I remember I once coded a football game with javascript. This was an excellent idea because there was no football game with javascript, at least not the way I wanted; in that project, I touched on every concept I've been studying; it was the best project I've done because I put in practice all the things I've been reading and learning.

I should do the same here. I'll make a game with PythonPython, which will help me remember the syntax and concepts of the language, and this is how the project started.

I wanted something like space invaders. So I started the project in that way direction.

I understood that the library pygame was the best for this kind of project. So I entered the website and started to check out how to start. I wanted the most simple thing. I have first done a square and made it move. in an 800x600 screen. It first looked like this:

4.png

5.png

What is used in this project?

  • Class

  • Functions

  • Something else

  • Arrays

  • Objects

  • if statements

  • for Loops

  • While Loops

  • array properties

  • remove element

  • time management

  • style_Images

  • pygame library

I didn't use many libraries for this; as I said, my objective with this project was to understand Python better; IPython had an excellent time coding this. This is what the game looks like now.

2.png

I made the main menu; when the game is executed, you can see two buttons; you start the game and have to select your warrior; once you choose your warrior, you can start fighting.

1.png

It's a straightforward game, you move with the arrows, and with the space bar, you can shoot or hit your opponent. Each time the health bar of a warrior gets to zero, the player standing gets a point; if you reach 5 points, you win. This is the first version of the game. I want to do more, improve it, and add more features and objectives. I hope I find time to do it in the future.

I think it's understood that to learn a language, you have to write in that language and do a project, I enjoy coding this kind of thing, but I've also experienced coding algorithms, coding websites, and programs.

The repository link on GitHub