As always, click here to download the desktop version if you want the full experience. My code can be found at my GitHub (star, fork, subscribe, whatever people call it these days)
If you couldn't tell, the main focus of this week was bullets. I coded in bullets to appear whenever the user clicks a mouse (with a little spread, to make weapons realistic). There were 3 main features bullets had to have: they had to move in a straight line, they had to deal damage to zombies, and they had to disappear when they collided with something. Surprisingly, programming this was a lot easier this week than last week was. This is mainly because I could apply all the basics that I learned last week programming zombies.
Applying Knowledge! Who knew learning comes in handy!?
Bullet Paths
So last week I talked about how I used vectors to make the zombies follow the player. Well, turns out that is the same method for making bullets move towards the cursor! Zombies had a position, and a destination to walk towards. I could use the same code, but replace the zombie's position with the bullet's position, and the destination with coordinates for where the mouse pressed!
The code to do this is flightPath = new Vector2().set(clickLocation).sub(startPosition).nor();
This makes the cursor vector and subtracts the start position (bullets stem from the player). the command nor() normalizes the vector, which means it sets its length to 1. This allows me to scale the speed of the bullet.
New Stuff!
Drawing Bullets
Drawing the bullets on the screen was mostly the same as drawing zombies, but slightly different. I needed to rotate the bullets in the direction they were being shot, or else it would look like a horizontal line moving on a diagonal. This presented one of the issues that became a recurring theme when working with external libraries like libGDX. I wanted a command that would do: draw(image, xCoordinate, yCoordinate, rotation). Instead, the only draw command in libGDX with rotation as a parameter is
draw(Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY).
Ew.
But I had to use it because that was all I've got to work with *sad face*
Hitboxes
Now, the next issue was hitboxes. I had used libGDX's circle class for zombie hitboxes, but that wouldn't work for bullets. Instead, I had to use libGDX's polygon class. That wasn't too bad. I just inputted coordinates for a rectangular polygon and applied the same rotation as I did to the bullet drawing. Collisions, however, were more annoying. You see, libGDX has an Intersector class that deals with polygon collisions. Hurray, I thought. It would take care of everything for me.
Well... nope. You see, I needed a collision for Polygon on Circle. The Intersector class had
test(Polygon, Polygon)
test(Circle, Circle)
test(Circle, Rectangle)
test(Circle, line)
test(Polygon, line)
...
LITERALLY EVERYTHING EXCEPT test(Polygon, Circle)!!!
So, I was forced to search the internet for a custom intersection function. I ended up writing a function that would test every line of my polygon against a circle for intersections. That was fun...
Next week on... Programming for Gamers...
So, next week, I plan on spicing the game up a bit. Now that I have a framework for shooting bullets, I plan on making a variety of guns that do different amounts of damage. If I have time, I also want to make different zombie types so there is variation in the enemies you fight. Finally, and this will probably be in a couple of weeks, but I want to make the game look better than just blue and green circles. I was lucky enough to have someone at computer club (shoutout to CS club, it is a lot of fun and you should join) make some pixel art for me, so hopefully I can add that to the game soon.
Well, that's all for this week folks. See ya later!
This is really cool! I love that you were able to embed a copy of your game into the blog site, it looks great! What is your final goal with this project/how far do you want to get?
ReplyDeleteThanks! I'm glad you like it. There is not a specific end goal for this project, as I want it to be as good as possible. At a minimum, I want to have multiple weapons, enemies, a money + ammo system, and graphics + particle effects to make it look good. I don't want to just abandon the game after the genius project is over. I hope to continue working on it for a while!
DeleteI'm excited to see what you do in the future. I think it's awesome watching you code this game because you demonstrate just how much of programming I do not understand. This is exciting because it shows how much there is to learn. And sidenote: It looks like computer club will have a new member next year. If you ever need someone to Beta test the game for you before your blog post, you can always let me mess around with it.
ReplyDeleteI would love beta testers! When I start making new weapons/enemies, I will need people to test to see I they are balanced. I can send you build files, but if you want to ever mess with the game yourself, you can download the code off GitHub and open it in Eclipse as a "Gradle Project." Then, run DesktopLauncher.java as a Java Application.
DeleteWow, this is so cool! I have very limited coding knowledge. I have tried making graphics before, though, and it's really difficult - I can imagine how much time it takes to actually make those elements interact. In the end, will you spend any extra time developing graphics, or are you mostly focused on gameplay?
ReplyDeleteI am hoping to spend the last two weeks of the project on adding graphics and effects to the game. I want to give players and zombies pixel art, as well as animate walking/shooting/dying. However, I am a terrible artist, so it's up in the air how well that will turn out...
DeleteWatching you slowly build your game is one of the coolest things ever. Are you thinking of making more complicated models for both player and zombie or are you just going to leave them as circles? While I understand that that would be pretty difficult, I'm sure that you could do it and that it would be worth it. It'd be twice as cool if you did some sort of collaboration with Matt Daly since he is doing pixel art. Maybe you could commission some art? Also, I think it'd be nice if you implemented some sort of score system. Your game has a very arcade feel to it and I can only see it as a game that would get progressively harder as you got more points. I'm...not quite sure how you'd program that but again, I believe in you.
ReplyDelete