Tuesday, May 10, 2011

Vectors, Velocities, and movement patterns: How to drive a guy nuts.

This *should* be a quick update since I want to get to bed here pretty soon.  Like, four minutes ago!  Just great!
Not that I have experience with this, but I'd imagine it's the same feeling.
What have I done in the game today? SOMETHING TANGIBLE!
(this good news people!)
What exactly have I done?  I've just implemented a few enemy movement differences that help enemies move smoother/smarter.  The basics of what I did was smoothly adding velocity to enemies instead of adjusting their position by physically altering their X-and-Y positions every step of the game (which also made for pretty bad collision checking problems, too)
Movement, everybody, movement.
How I did this was pretty simple but I doubt I can explain it much outside of the context of XNA, so if you don't know programming... well I can try, anyway.

Basically I used these thingys called "Vector2" 's in XNA which correspond to having an X and a Y value, as well as a length or magnitude or what will you (I hate to admit it, but yes, I do use math.  Only a little bit, though, it's okay)  This magnitude extends to an X and Y length.  At each step in the program the sprite/image/object is moved X units by Y units in the game space by the length of my velocities X and Y.  If you think back to trig... (oh no!) you can recall that having an X length and a Y length connected means, you can get a third length, called the hypotenuse that with the other two lengths forms a triangle.  I basically fudged my way along to make sure I can alter this length or magnitude which is the number of steps X and Y my objects can move in a step.


That probably didn't make sense, but I tried.  It was simple stuff regardless, just a bit time consuming.
I figured it's about time I drew something that WASN'T terrible violent...
The second step that I was working on up until I started writing this was adding a method for enemies to have a stored list of targets that they can move to and cycle too.  Again this stuff isn't too terribly difficult, I just have a new object that stores a list of positions in 2D space, along with a certain time allotted for each position (after the time has run out, then the enemy moves to the next location in the list and so on and so forth.  It's very primitive but I hope it will work for the purposes of the game.  I'm still working on the system, mainly how to create lists of points that we can use and re-use (and name) to give the game some elements of strategy to it, and not just random-falling-gunplay.

Stand back: THIS IS SCIENCE
So yeah, there's a quick update of the game.  I didn't get as much done today as I wanted too, but what can I say, I had school and today was absolutely beautiful outside.

Well, minus the humidity.  Something I've learned isn't so amazing about the midwest is humidity.  Give me dry weather any day, man.  Humidity just makes me sweat profusely.

So, uh, yeah that's it.  Thanks for stopping by!

OH YEAH.  My best friend from home, Terrence, finally got a phone so we can talk again.
Happyface!
So keep on the lookout for a join Kevin-Terrence blog, we are talking about doing one.  Not like this, just joint artwork, solo work (he is a much better artist than me, for one thing he's actually an artist!)
It would also include us just talking about things (Games, music, art, girls, things that concern guys, haha) and possibly stuff like short stories or philosophical writings.  When me and T get together, you never know what's gonna happen!

Anyway, G'night interwebs.

- Kev
Don't you just hate it when that happens?

Sunday, May 8, 2011

Invisible Progress, everybody!

Invisible progress you say?

Why, yes! I do say so!  How so? More image manipulation! Muwahahaha!
Not THAT kind of image manipulation...
I had big plans for today... Finishing my paper, getting my reading done, going to bed early and programming! And lo and behold, I've achieved all! ...except for getting to be early.
Drat.
Well I got my reading done, drafted out the paper and did some programming, but made no visible progress with the game.  Instead I fiddled around with image-linking.  What is image-linking you ask?

Excellent question.  I have no idea if this is a valid concept or just something that I've come up with out of necessity.  Either way, I hope image-linking has more applications that to just my current game!  What image-linking is, in the context of my programming, is connecting two separate images (and separate game objects, say a player and an enemy) together so that they move with the same velocity, and no matter when one image is changed or modified the same effect is applied to the second image.
What? (All rights reserved on this idea, btw)
What that means is I needed a method for images to move together, get offset together, rotate together and scale together.  How does one go about doing this?

Well I delved back into my SpriteObject class (which is a FRIGGIN MONSTER DUDE) which is the basis of all my drawn images in the game.  Each sprite object has a list ready to hold other sprite objects, this is the linked-list.  When I want, I can link two sprites together and then they are added to each others linked list.  This means I can add a whole Lotta sprites onto each other if I really want to (don't get me started on this, I don't even know what would happen... oh gosh)

But having sprites (or images, If I forgot to mention this I apologize: 2D images in games are known as "sprites") know about other sprites they have been linked too is not enough.  In each function I've created that modifies a sprite (every function that moves, displaces, rotates or scales an image) the function checks the list of linked sprites, and if another sprite is in the list it applies a similar change to that linked sprite.  The key here is each image uses the same functions, and if they both know of each other in their own, private lists then the functions would call it self infinite times, since each image would check it's own list to see if it was linked, and then make a change to the other image, which would check it's own list... and etc.)

The solution here is pretty simple, just include a replica function of each image-modifying function, give it another name (i.e. SetVelocity() becomes SetVelocityUnlinked()) that doesn't check the linked-list which prevents a programing-freezing infinite recursion loop.
TOO MANY STRANGE CONCEPTS!!
So that wasn't so hard, what took up most of my night tonight was just working with finding "equations" to adjust the offset.

...the offset?  Yes, the offset.  See, when I link images they don't have the same center.  For instance, say I have a little bug that lands on my player.  The bug's center is not equal to the player's center, so when I go to rotate the player... the player image rotates around the center, but if I just rotated the bug around IT'S center then they would both rotate independently and it wouldn't look like the bug was stuck on the player, it would just look stupid.  Or perhaps like they are both breakdancing independently.  Depends on how you look at it.

So first I needed to find the distance (think x and y, distance formula from HS, remember?  the square-root of blah-blah-blah? yeah, it comes in handy! imagine that) and translate the x and y co-ordinates (or the center) of that bug in relevance to the player.  So when I rotate the player, I needed a way to move the center of the bug as if the bug was stuck to the player.  And if I was to scale the bug and the player, I need to also scale the distance between the two to keep the distance between the two consistent.  If I didn't the player and the bug would both get smaller around their own centers, instead of both around the player's center.

I won't bore you with the particulars (Particularly because I'm not even entirely sure how I did it myself...) but that's what I've been working on!

Congrats, you've sat through another lengthy jargon-filled update!

Kudos to you, my friend!

Enjoy your reward!  I know, I know, it's not much.  But I'm effectively broke, so, yeah.
Good... morning!?!

Well, yeah I guess,
Good morning Internet!
I'm going to bed, busy/long day tomorrow.

-Kev

Saturday, May 7, 2011

Mid-day update!

*LONG POST WARNING*
When I update this sucker mid-day it means two things:
a) I got stuff done
b) I'm putting off other stuff for the sake of writing this thing!
Funny thing is, I'm putting off writing a paper, by writing a blog.
David and I actually got a lot done this morning, both in terms of theory and practice.  Maybe not a whole lot in practice, but definitely a lot in theory.

In practice we got an new gameplay mechanism implemented with a new image (ooh, right? one new image!) and we saved ourselves oodles of processing power by "recycling" our bullets and our explosion effects which keeps new memory from constantly being allocated and saves us processing power on calls to the Garbage Collector.  Huzzah!  The game gets more-and-more mobile friendly!

Rock out with your... wait...
So even though none of you really want to hear how we did it, I'm going to tell you anyways.  Fundamentally the process is very simple and I'm not sure why we didn't think of it before, but for our bullet and explosion managers we simply set up two lists: A list of "live" bullets and explosions, and a list of "dead" bullets and explosions.  Those objects in the "live" lists are drawn, updated, and check for collisions within their respective managers (which, for whoever might be a coder among you, is it's own singular object) and those in the "dead" list are not, but instead are kept on standby.  When a new bullet or explosion is created the managers first check to see if there are any objects (bullets or explosions) in the standby list.  If there are, then the managers simply re-set the values of the standby bullet/explosion to act as if the object is "new" and re-position it.  If there aren't any in the dead-list, however, then a new object is created and added to the "live" list.

Whenever a "live" bullet/explosion reaches the end of it's lifetime (if it has reached the end of it's animation, or if it is out of the bounds of the game screen) instead of being destroyed by an apparently processor-heavy Garbage Collector call (which would free up some memory) the object is simply handed over to the "dead" list to await its recycling.
Alternatively: TA-DAAAA
Using the Garbage Collection method we would theoretically have more memory to work with when, say, there are no bullets on the screen as opposed to when the bullets are flying all over the place.  But forcing the Garbage Collector to work does kill one's processor, as we've figured out, and under the current scheme we have a grand total of only 15 bullets and 7 explosions (the max figure for both) in memory.  The entire game could just simply re-use the 15 bullets and 7 explosions.  Those are pretty low numbers if I do say so myself, and I can live with having 15 bullets in memory if it means I don't have to destroy and/or allocate any more memory during the course of the game!

You all still with me, or have I lost you?

Still here? Good.
So that was half of the programming aspect.  The other one I won't bother you with the details since it was much more application-based and there's less "theory" to discuss.
It essentially was just being able to slam enemies against the wall in order to kill them.
Enthralling! 
Click for the full screen to see what visual studio looks like? Like, if you want, I mean.  No pressure.
Yeah, it's kinda cool.  Yes, it's a main-ish feature of the game.


But wait, there's more! That's right, NOT DONE!
My Blog is like a picture book, you don't have to read, just look at the pretty pictures and feign comprehension.
 The theory aspect of what David and I discussed at length was almost as good if not better than what we physically achieved.  We discussed scoring options, enemy behavior, level design (Which personally I didn't think would factor much into a game of this type but I was oh so wrong) and implementation of a few key aspects of the game that I will probably try and get working on tonight, if I can get my paper and math done.
(I really, really have to stop putting my paper off)
And my attention span!
 I won't bore you with the details, though! (Or alternatively, I WON'T GIVE YOU OUR SECRETS!)
Besides, I have to go to judo now and get my butt kicked.  And afterwards... lunch!  I'm so hungry!
But know that this game is moving forward.  I will not be stopped by a petty college education! (Joking... joking, don't blow a gasket)

Without further ado, I bid thee fare-well world-wide-web
-Kev
P.S. MORE DOODLES
If your sensing a common trend...

Famous Last... Words?

Friday, May 6, 2011

Doodle-palooza

So I found one of my old notebooks and got a ton of new (old, really old) doodles!

Indeed

So today not much happened, in terms of homework or games.  I just had work, came back and actually cleaned a little bit.  I was supposed to get my laundry done, but... well that didn't happen.  I was accosted by friends before I got the chance to do my laundry.  Oh well!  It's a fun evening.
Never look a gift horse in the mouth.. unless it's from your ex-wife
So I worked today, and actually got some "spring cleaning" done.  Tomorrow morning I'm meeting up with David at 8 to work on the game until 12, then Judo, then the homework I was supposed to get done tonight.  Ah, well.
Since when do Ninja's carry guns?
I can't really say that there's anything else to update the game with right now unfortunately.  I'll include a game screenshot tomorrow, hopefully it will look differently than the previous screenshots and can show some semblance of progress.

Until then...
Apparently not...

- Kev

Thursday, May 5, 2011

Meh.

And he won't tell me what happens then, either. This guy is a JERK
I'd be lying if I said that today was a bad day, but it ended on a melancholy note.  I spend the day disregarding homework and hanging out with my friends.  Tomorrow is morning school, then work, then probably a DeFRAG (DePaul's gaming student body) event that I should go to since I want to be on the board.  Who knows if I'll have time for game work tomorrow.  The good news is I "kinda-sorta" fixed the problems I was having in my last blog installment (see below) so perhaps at work tomorrow (I'm allowed to do this, don't freak) if it's not too busy I can get some more game work done.  We shall see.
Winner, Winner, Chicken Dinner
As for the melancholy note... well it doesn't really matter what that was all about anyway.  I'm pretty sure it all could have just been in my head anyway.  Whatever, I just need to focus on school and the game, and hopefully do well with one or the other (preferably both...)
Preliminarily it looks like my class grades are going well.  I've managed to ace every midterm so far (now if only grades translated into actual intelligence and mental dexterity, I'd be in good shape)
This is the face of a (blob?) who doesn't say please.  What would his mother say?
So, game update basically is: It's in the works, hopefully David and I can meet up this weekend and get a rolling start on it.  Once I get this next mechanic down (halfway done) it's just adding content like enemy types, gun types, artwork, sound, "AI" and general game stuff. There's still some glitches with teh images I want to work out, but all in due time.

Yeah that's pretty much all I got for tonight, just tired I guess.

Lacking in enthusiasm,

-Kev
asdf

Wednesday, May 4, 2011

Code Monkey

Yeah that about sums it up, haha.
Only I'm not too fond of fritos, mountain dew or... tab?  I have been eating a lot of whole almonds, lately, though.  They are good (and hopefully good for me, hey man I'm tryin' here) but they do tend to get stuck in my teeth frequently.  But other than all that, you get the gist.

So, today was not so great for coding.  I fiddled around with stuff, but it didn't go so well... I'll have to re-examine my approaches tomorrow.
And what I doodle.
Essentially I just want my guy and the "enemy" when they run into each other to become connected and move with one another.  It sounds pretty simple, but when you have multiple influences on the velocities of both the enemy, and the player... well then you have yourself in one fine-and-dandy situation.

It really SHOULD BE simple, and I miiiight have just come up with a solution, but I don't know.  Basically I need to be able to essentially combine two images and make them behave as one big image, which I set my program up to do... just not two completely different objects.  I could fiddle around in my base SpriteObject class to see if I can essentially try and marry the velocities/positions of the sprites together, that might (*MIGHT*) solve my problem, but again, that still quite the doozy to program.  And all I want is for the enemies to be able to "latch on" to the player...

Ugh.
Welcome to the wonderful conundrums of Gameplay programming!  Well I'm really frustrated at this point, I FINALLY decided to tackle something that should have been insignificant and easy and I tried to just muddle my way through it.

Children, always, always, always...
I SAID ALWAYS
...think through what you have do code, BEFORE YOU START.  I've just gone and made a colossal mess of my code yet again that I'll have to wade through tomorrow... if I have any time tomorrow.  And Friday is practically booked... man.

This sucks.


It's too late and I'm too frustrated for anything really witty, so here are some more doodles and I'm signing off.

- Kev

#1 Dad
Batarang Prototype #1: "Too Sharp"


Monday, May 2, 2011

Dry Spell!

Spoiler: The blob dies
Sorry about the Dry spell in postings, Mr. Interwebz, but I've been pretty busy with midterms and the like.  As is, I still have a math midterm tomorrow which I have yet to fully study for, and potentailly a reading quiz.  Yikes!
Famous Last Words "Yikes!"
So, what's new on the game?  Unfortunately since my last major breakthrough, nothing is new.  I've been studying and trying to write a paper all weekend.  I'm not happy about that, but David and I have outlined at least a plan for the coming week of work (which hopefully we can get to) which involves re-working the Garbage Collection system (Turns out, calling the Garbage Collector wastes a lot of processing power...) which I'll explain in a bit, and then FINALLY I get to just work on art/gameplay programming which as fun as it sounds can actually be kind of tedious only because I know what I want it to do I just wish it would do it already.

To be fair, not all gameplay programming is tedious, I actually enjoy the most of it but like writing a book, starting a piece of art or an animation the hardest part is always getting started.  Once I get the momentum up, this puppy will (hopefully) start flying.  I'm praying that the motivation comes soon!
There's a difference between Coercion and Motivation, please keep that in mind
 So anyway, the Garbage Collection system that I had begged and pleaded with David to work on.. it sucks up processing power, esp. on mobile devices like we are aiming for.  Solution?  Instead of destroying bullets, when a bullet is "spent" and has achieved it's purpose put the bullet in a "dead" list of bullets that aren't displayed or updated, and then when a new bullet has to be fired, if their are members in the "dead" list they are re-activated and recycled, preventing us from creating any more memory that is necessary.  FRICKIN SWEET YO.  I should have probably thought of that earlier, but oh well, I can't expect myself to be a genius.  Or even competent.

As my C++ teacher said today in class "If you understand this, that's great you are more intelligent than me.  But, I'm more intelligent than you."  So I guess I can chalk this up to be a learning experience?
Learning Experience: Don't piss off the man with Shrink-o-vision
So, hopefully  by tomorrow I'll be done with midterms, and have some time to devote to Gameplay programming!  ...hopefully.  That, and I have to write a friggin' paper.  Why must school get in the way so much? It's terribly inconvenient!

Of course, I'm the one who just went to the southside to bake cookies with my InterVarsity group... haha.  Sue me, but at least I'm trying to live life.  I'm doing so-so on that aspect so far, some things I still need to get on.. but that's outside the scope of this blog.
Boom, programming reference.
Live long and prosper internet denziens,
-Kev