I threw it on the GROUND!

Missed the post last night, I mostly worked on the throwing function and had a meeting with Jerry about my Programming1 assignment. I didn’t get very much done between the meeting and having to go home for the evening for a birthday. I got the throwing functionality working at least.

Today we have been working in the Game room all day, i’ve been adding doors all day, at first i made every door it’s own type of object and even had the collision working when bolt said to make the doors it’s own class and so i had to redo them all. Anyways, This week’s artifact post: Throwing.

This week’s artifact is the throwing system. It lets the player throw whatever item they have in their hand in a line in front of them and having it land on the floor once it hits a wall of a guard.

The way it’s built is that it all starts in the player’s update function where it checks for input, in this case the right mouse button. First it sets a “target” for the item which is a vector of the angle between the player and the mouse. Then it uses a virtual void in the Weapon class for throwing the weapon (more on this later.) The player has an integer for keeping track of what weapon is currently equipped which is set to 0 for the standard garrote,  the player also have a Weapon object attached for access to its functions, this is set to a nullpointer here just in case. It is then set to a new Garrote which is anther class inheriting the Weapon class. Please note the list of GameObjects in the constructor; this was cause of most of my issues. And lastly the weapon is attached to the player(This is so that guards will be able to use the same system for weapons later.)

Image

The following picture is the throw function of the Gun class for this example, the other weapons’ (with the exception of the base weapon, the garrote) functions for this looks the same but of course replacing gun with whatever other weapon is relevant. The first thing is that it creates a new instance of the Item class which unlike the Weapon class inherits from the GameObject class, this is to be able to draw the item easier. The Boolean in the constructor is to indicate that the item is thrown rather than dropped and the vector is the direction of the flying item. The drop function also looks the same except for not setting the item to be flying and the direction to 0.

Image

Next I will explain the picking up function, It begins in the same update functionality of the player with checking if the player is currently able to pick up an item (I.E not hiding) and then weather the item in question is within the reach of the player and of course intractable. If so it resumes into the interact function further down in the Player class.

Image

In the interact function the object’s type is checked (the type is a Enum set when an object is created) and different action can be taken depending on the type of the item. This part of the code shows what is done if the item type is Gun. First of all it makes sure the item isn’t removed from play (our current patchwork solution to removing items) then it sets the current weapon to a nullpointer just to make sure.

The current weapon is then set to a new Gun class, the class’ attached object is set to the player and the current weapon is set to two which is the corresponding number to the gun weapon, Pretty much the same as when throwing a weapon but the other way around. The weapon on the ground is set to be removed and no longer intractable or drawn out.

Image

I was having a lot of issues with this mostly because the item picked up was taking the wrong object list which lead to items only being useable the first time after loading the game. With this however the player is able to throw their weapon and pick it up again. The system have three main bugs right now, first of all the weapon does not retain its charges when and picked up and second the items will still kill guards if they walk over them laying on the ground, and finally the items are drawn after the player. These are, while important did not qualify for being fixed before the beta turn in.

Now I must return to those troubling doors.

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

1 Response to I threw it on the GROUND!

  1. valyyri says:

    Hi there!

    Now this is what I would call a detailed blog post. Personally I prefer to try and write so anyone can understand instead of going full code-speak, but since the blog’s target is mostly other programmers I guess I can’t nag about that, hehe. Anyhow, as I said I find this to be very detailed. You explain fully what you do and what that will accomplish, so there’s no confusion in the reading whatsoever. I like that you post a lot of the code so it’s easy to see what you’ve done (as sometimes it’s hard to explain in words), but Marcus recently sent out an email telling us to post less screenshots of code and more pictures of what you made happen with the code, so I guess that’s something you can keep in mind for future posts! 🙂

    It would’ve been interesting if you went over how you fixed the bugs you mention at the end as well, but since you didn’t have time to fix them yet it’s obviously understandable that there’s nothing about it there. Maybe for a future post.

    Anyway, good luck with the doors and the weapon bugs! I hope I get a chance to play it at release since the beta presentation looked rather good (shame about the garotte/strangling not working properly). It gave off a Hotline Miami sci-fi feel which sounds pretty awesome.

    /Joakim M

Leave a comment