Wednesday, April 27, 2011

Making Music

One of my favorite parts about developing video games is that I get to make art, music, and programming all by myself. I love all of those things, so video game is a perfect way to combine all of them.

But I've had some serious issues with making music lately.
The song I want to write is not the one that I end up making.

Summary of the last song I made:
Goal: 10+ minute ambient, electronic song. That can be looped and played as background music.
End Product: 6 minute progressive electronic song (good start) with a hardcore dubstep style drop at the end.

I mean, imo it sounds really good, its just not what im looking for.

I ,must be doing something wrong.

Thursday, April 21, 2011

Has anyone seen these errors before?

These errors keep popping up when ever I try to load images.

libpng warning: Incomplete compressed datastream in iCCP chunk
libpng warning: Profile size field missing from iCCP chunk

It looks like other people have had this error come up. But I cant find hardly anything relating to pygame or python.

Wednesday, April 20, 2011

Update on the Multiplayer game

Im going to try to post smaller posts more often instead of posting alot of content, really fast (and then getting burnt out, and not posting for a week or two) (which is what ive been doing, heh..)

Ive had alot of progress lately. The game no longer has (as bad of) lag issues.
This is because I am sending the objects velocity, instead of the position. It really helps a lot because instead of sending, for example, 200 object's positions, every frame (40 x a second). I only need to send the velocity of the object once, and the client will take care of the future physics updates. 

I also made it so that each client uses a delta time value in the physics updates. I get delta time by subtracting the previous frame's time from the current time. Something like:

Happens every frame:

import time # except this

previous_time = current_time # sets the previous time before we get the new current time
current_time = time.time() # get the current time
delta_time = current_time -= previous_time # get delta time


I then use the delta_time in calculating current position of objects.
This means that, even if one client has a wooden computer, from 1980, that requires a refueling of coal every 30 minutes. It will still have (in most cases) the same display as the kid down the street using his dads new super duper, high tech, state of the art, mega 2000X computer. 
The point is, no matter the frame rate, the computers will have the same basic visual output.

Monday, April 4, 2011

AHHHHHH ITS WORKING@#$%@#%$^@%^!@&*&^%$#

When I realized it was working, This is how i felt

What was it that makes me feel like a kid who just got blastoise?

Funny you should ask..

I've spent all day working on my game, and at this point I can start up the server on my PC, start a client on my PC, which connects to the server. I can then move my character around and get everything displayed to the client HUD. 


I can also start up a client on my Mac, which i then connect to my PC server,
And the best part is?
Both the PC and the MAC client each have their own character which they can move around, and each client can see the other client's characters moving around also!!!

Note: there may be a number of subliminal key things which i mentioned here, that you may have missed.
In the interest of getting the reader (you) to a point of more understanding and awe inspired gratefulness, I will list the things you may have missed, and what they mean.

1) The server is running on a PC, and I was able to connect with a Mac client.
    This is great because it means my multiplayer software is cross platform. And there will be no issues with running the game from, well, pc to mac, or mac to pc. (a big plus) (thanks for this goes to twisted)

2) Each client can see the other clients characters
    This took a lot lot lot of thinking on how to do. But it ended up working. Basically, the game state is sent to all of the clients, so they all see the same game. Sounds easy, but, well, whatever...

3) The Mac client connected after the PC client
    This took forever to figure out how to do. Because when a new client joins, there are already tons of objects on the screen which the new client has no clue about 
so when the server says: hey client! update these (insert potentially big number here) objects, move them to this position! The client says: uh, I have no clue what those are! I wasn't around when those were made!)

So I fixed this by having the server send out the entire game state when a new client connects (which I had to organize, and package into useful stuff, then unpack on the client side, and use the info to get up to the same level as the server). Again, it sounds like a matter of: Oh, just do this... But. theres a lot more to it than it sounds.

Wrap up

Yeah thats pretty much it, I guess ill note that at this point the code is 1000+ lines, which is already one seventh of the code in Color Tower Defense. And all it does is moves a character around. Wait, thats just the mentality that I was saying don't have. Cause as I mentioned, It does a lot more than just move characters around. But anyways. Without the Network code and multiplayer, this would have taken < 100 lines of code to do. Big difference.

The Future is in the FUTURE

some good news is that I have a knowledge of how to send info back and forth between the clients and server. So at this point I can focus on adding features, as in more gameplay stuff. My next goal is to make it so each character can shoot projectiles, and the other characters have to dodge them, while shooting back! It could actually be fun.

Stay tuned...

Sunday, April 3, 2011

How To Meet The Girl of Your Dreams


Twisted Tutorials and Helpful Stuff..

I've been trying to get a multiplayer game working for awhile now, and during that time i have searched far and wide to find some half decent tutorials and other helpful stuff. I have talked with a lot of different people in hopes of getting some good help, and, while I have not found anything I would call really, really helpful, I have stumbled upon a few sites that have pointed me in the right direction.

Pygame Twisted Tutorial
This guide does a great job of explaining how to use a MVC model to make games. Its really good and all, except on the part where it tries using twisted to make the game. In this aspect, its very close to garbage.
Regardless, this is the tutorial that i have been using mostly. I went through all of SJBrown's source code (the person who wrote the tutorial) desperately trying to make sense of what I was seeing. (Because he doesn't explain it very well in the tutorial) My goal was to look at his example until I knew how it worked well enough to implement it in my game. The source was nearly impossible to follow because he has the code split up into unorganized modules and other reasons (especially the parts where he is sending objects back and forth between the server and client, thats confusing). And it didn't help that he has a stupid map object that is integrated with the character's movement, or that his example game doesn't even work with multiple clients connected to the server (WHAT the HECK is that about? whats the point of using twisted if its only going to be a single player game?!?!?!) I ended up going through the source code line by line, copying it down using my own variables and values. 

Its been a long process but it has finally been working. There were alot of things i had to change 
(And i got mocked a few times on IRC because people would say stuff like: What? why do you need to know what that means? That code is terrible. If your doing it that way then your doing it wrong, do it this much more simple way... 
To which I would reply: Oh sorry, Im just trying to follow this tutorial and thats how he's doing it. I didn't write that code.)

if SJBrown ever reads this post:
Dont get me wrong, I'm thankful for what helpful info your tutorial has taught me. 


Game physics in a network game
I have not got to a point in development where i will need to use this. But it is very helpful. And well written. Not specific to twisted

Crazy Russian Twisted Example├╝hrung/#grobe-struktur-eines-einfachen-twistedprogramms
This is a helpful example, very well structured and easy to see whats going on
note: it may not be russian, thats just a guess. I used google.translate to read the intro.

General Networking Development
This is professionally written, and really helpful, I would recommend it to EVERYONE. Its not really talking about twisted though.

Twisted Actual Game Example
This is a real game that is in development, It is open source. I've looked through it for a little bit, but the networking code appears tightly integrated into the rest of the game. So at this point I have not taken the time to look through it and try to understand how it works. But I have talked with one owner of this game and he was a twisted pro, he knew what he was doing. 

This list Is the ones that are actually helpful. I've gone through a lot more tutorials than these. I have not really seen any ones that sort of "explain it all". But I have been able to figure out a lot using these. 

Update On My Game
At this point in my game, it is possible to connect multiple clients to the server. You can then control the character on the screen using the w,a,s,d keys. The next thing i'm working on is making it so multiple characters can be controlled by different people (so every person will have their own character, and each person playing can see everyone else's characters).

I also need to think of a name for the game.
At this point its project defender. But that was sort of because I couldn't think of anything better.

Have a nice day.

Saturday, April 2, 2011

Feeding the Blog

Sorry about the not posting in awhile...

Regional Science Fair
Lets just say the Regional science fair was, uh, fun?
yeah, it was fun. It was also a lot of other things.
I would call it surprising, unexpected, and tiring.

But, yeah I won 6 awards total.

§ BYU Central Utah Science and Engineering Fair computer science first place winner
§ 2nd place winner of the BYU CUSEF Symantec Software Scholarshop
§ Winner of the Stevens-Henager College 2011 $10,000 scholarship award
§ Winner of the BYU Dean’s Award
§ Winner of the Westminster College $4,000 scholarship award
§ Winner of the Intel Excellence in Computer Science Award

It was very fun, I got to go up on stage a bunch and do the whole bowing thing.
At one point, I was walking back to my seat (after receiving an award) and my name got called as I was about 5 feet away. So i gave my award to my dad and walked right back up. :)

My Next Game

I created a new google project page for my new multiplayer game
I also set up subversion control (super confusing!) so you can browse the source code. As I have said before, I'm using Twisted for the networking. At this point, I have a decent understanding of how to send info back and forth between the client and server, The issue i'm trying to overcome at this point is just creating pygame sprite objects and controlling them using player input. Its been very frustrating, but It may just end up working.