Generic game programming / C# thread

Anything else
User avatar
Korban3
Posts: 4146
Joined: Tue May 31, 2011 9:14 pm
Location: 42nd St E, Hell

Re: Generic game programming / C# thread

Post by Korban3 » Wed Sep 21, 2011 6:18 pm

Cool beans education stuff. I'm pretty self taught, but I have a basic game design course that I do and I get help from the instructor.
Actually, C++ doesn't draw at all on it's own. It can print to the console, but that's really it. You need to use OpenGL, or another graphics library for drawing. I'm using the graphics library of SFML for my sprites. I'm just packaging my position and other variable updates with the drawing functions because they both happen right at the end of my main loop, and they happen in a consistent sequence. It's mostly possible because SFML greatly simplifies drawing sprites. WindowName.Draw(DrawableThing) is all it is.
The data for positions and things are kept in a Sprite class who's texture is defined at the start of the program by a Texture class. It's a little odd to work with at times, but I'm getting used to it.
I'm actually getting close to finishing all the basic procedures for drawing and moving many instances. I took a page out of your book and inverted my characters array so that it starts at the top, and works down to the 0 position. I don't know how well that'll work once I start dynamically allocating memory to the array, but for a preset max number of instances, it's great. If I have to invert it again later on, it's only a few lines I have to edit, so it's not a really big deal.
I have a player who can be moved left and right, and he flips on the X Axis to face the direction he's moving. Characters have SpeedPulse() function that this character is using for the Space key as a jump, but I don't have collisions yet, so there isn't gravity either. So he just flies up.
After this update and drawing portion is done, the next big steps are collisions, player controls and world navigation, and then some basic AI. I'm sure little things will pop up often that will be important too, but those are the big ones. I just have to make sure that I remember to make a mirror of the character system for the items too since those two instances have separate classes :P
And yeah, we produce lots of walls of text.

Code: Select all

<o>  <3  Code

User avatar
Korban3
Posts: 4146
Joined: Tue May 31, 2011 9:14 pm
Location: 42nd St E, Hell

Re: Generic game programming / C# thread

Post by Korban3 » Thu Sep 22, 2011 4:42 pm

Hmm, those are interesting. I didn't know there was a vector I could use. I may use those if normal arrays become inconvenient, but I just got my drawing and updating code completely functioning during my game course today. At first, the 3 test sprites would flash over and over because it drew the screen every time a single sprite was rendered, then I got the flashing to a much smaller amount by clearing the screen before I started drawing and updating and then displaying after that. I now have no flashing at all because the game does all the updating, drawing and such, THEN it clears, then it displays so there are no gaps in any instance's display. Also, any character can be defined as a human controlled being via it's constructor and will be controlled properly. It's only the main character for now that is, but it works for the others.
I've also been using this array to add gravity to the other two characters. There's an ugly bug that causes them to fly downwards like there's no tomorrow, but that's because I haven't added a speed cap yet.
The controls were originally very buggy. Because the keys are checked every time a human controlled instance is updated, they would make him move sporadically, and would rarely trigger friction when released so I used a set of bool values that keep track of what was pressed and released. That left motions smooth, clean display, and basic motion physics all at a level I was happy with. My next step is going to be some basic collisions which I will create manually. This collision will then be recreated by writing a system that tracks a set of vertical and horizontal lines. I'll be using the basic "If left border is inside the right border move right etc etc etc" method since my characters and items are all rectangles and my world collisions will be rectangles. Haven't thought about how I want to do slanted or round collisions yet, and I doubt i will do those for this project. I just want to be able to jump around. I also need ground collisions minimum to get my friction set up entirely.
Now that that wild tangent is kind of over, thanks for telling me about the vectors. I'll have to learn about them later so I can use them. They sound really useful. For now, I will work with max caps on the character and item arrays and add dynamic memory later.

User avatar
Korban3
Posts: 4146
Joined: Tue May 31, 2011 9:14 pm
Location: 42nd St E, Hell

Re: Generic game programming / C# thread

Post by Korban3 » Fri Sep 23, 2011 12:19 pm

Skomakar'n wrote: Slopes can actually be made fairly easily with no advanced trigonometry. I'm not sure of the exact English name of the formula that I am thinking of, but directly translated from the Swedish name, it would be something like 'the formula of the straight angle', which you can use to easily calculate the vertical position at a certain point of a slope that has a straight angle; to get more varying terrain, you could just create several slope blocks with different angles, and mix and match those to create something quite organic looking.

A slope with a 45° angle, tilted upwards, could be defined as a line using the points A(0,64) -> B(64,0), relative to the actual position of the block. To get the vertical position of, say, the 32nd pixel horizontally, which would of course also be 32, since the angle is 45° and reaches from 0 to 64 vertically, the expression (A.y / B.x) would first tell you how much the vertical value changes for each pixel that it increases horizontally, which would be 1, and by multiplying this value with your desired horizontal location, (32 * 1), you'll get the correct answer. Just make sure that you always define your points from bottom to top, left to right, and you should have no problems.
Just don't forget it!
That's very useful as well. I may use slopes, I dunno. I'll make verticals and horizontals first, get those working and then do slopes if I still feel like it. I may just save slopes for my next project. Thanks for the help. Always appreciated.

User avatar
Endoperez
Posts: 5668
Joined: Sun Jan 11, 2009 7:41 am
Location: cold and dark and lovely Finland

Re: Generic game programming / C# thread

Post by Endoperez » Sat Sep 24, 2011 1:10 pm

Oh my god.

You know when you've been coding too much when you automatically press F5 when you finish writing. Lol. Protip - on browsers it's "update page", not "compile and debug". :D


My team's adventure game is nearing it's completion. Two of the three puzzles work. The third is missing graphical assets, so it might not be ready on Monday any way, so I'm not stressing over it that much. Besides, with the functionality already in place, I can do a quick sorta-kinda-working version of it really fast.

Today, I've been doing the easy part, adding existing functionality into all kinds of places and making the game seem a lot more polished. However, I've actually mostly been doing hacks instead of proper bugfixing or coding. For example, items that are activated stop being activated if you activate a different item. Not good. So I stop the player from activating anything else instead until the item has handled whatever it's going to handle. Player can no longer move before he's finished the previous movement, or cancel item activation by clicking a new target, or the ground.

Another example: I made a "fade in from black" effect that appears when screens are changed. Actually, it's a single black particle of insane proportions spawned when the scene changes. Because, you know, particles fade towards transparency as they age...

I've learned many things during this project.
1) I can code a lot better than I thought.
2) I'm still not THAT good at coding, though.
3) I'm not very interested in coding, either... Give me a small, separate subsystem and I can do an okay job with it. Give me a huge project, and I lose track of what I was meant to do, how I can achieve it, and the quality of my code drops quite fast. I might look into shader programming if they teach it at this school, because they're relatively small and quite independent from each other.

User avatar
Korban3
Posts: 4146
Joined: Tue May 31, 2011 9:14 pm
Location: 42nd St E, Hell

Re: Generic game programming / C# thread

Post by Korban3 » Sat Sep 24, 2011 11:42 pm

Endoperez wrote:So I stop the player from activating anything else instead until the item has handled whatever it's going to handle. Player can no longer move before he's finished the previous movement, or cancel item activation by clicking a new target, or the ground.
It may be that I just started playing Runescape again for nostalgia's sake again, but this reminds me of how that game works with interaction. The game seems to run a cycle in large-timed steps where it computes what should be done. These steps are much larger than those of drawing or movement updates, but it uses this all over the place.
So my thinking is that it checks to see if the client is interacting with something this cycle the action is defined for later use. Because hese are updated on each of these action cycles, there is a delay between when you cancel/choose your action and when what it is actually done/begun. This is generally considered a negative thing in games since it reduces responsiveness, but it adds a predictable structure to a game where you click to move.

This leaves Runescape with two kinds of interactions, at its basest handling:
Committed interactions cannot be canceled, so they must be finished before you can do something else. Smelting bars, smithing them into items, casting a spell, swinging a sword. These are usually pretty short so that the player does not lose control for too long.
Uncommitted interactions are things like moving, attacking and resource collection to name a few. These can be 'canceled' or changed every interaction cycle and are generally longer in duration. Walking is a good example. You click to set walk target, and the character walks. This can go on for quite a while and when you click again, you are changing where the current action is wanting go (Or you're deleting the current action and creating a new one with the new position; both have same effect).

So, you gotta be careful what you leave cancelable and what you make a committed action. Even though this system runs in large cycles of time, it works pretty well for movement and resource collection, while it feels lacking for combat. I always say to myself, "I wish Runescape's combat was more active!" when I'm playing. Although, to its credit, it is more active and responsive than some other MMOs out there.

User avatar
Endoperez
Posts: 5668
Joined: Sun Jan 11, 2009 7:41 am
Location: cold and dark and lovely Finland

Re: Generic game programming / C# thread

Post by Endoperez » Mon Sep 26, 2011 1:12 pm

Yay, an adventure game is done! We presented it in the front of the glass, together with the 11 other groups/games! 8)
I didn't make any of the graphics in the image. This is from the near-final version, with 45 minutes less work than the one that was presented in front of the class.

Image

So yeah, that's that. It's a basic adventure game, more or less. It wasn't very difficult, code-wise, but then, I wasn't very good as a programmer! :lol: Getting it to work took lots of work, and some underhanded coding practices I'm not very proud of.


We made up new groups. For my next trick, I'll give you a turn-based combat system! ON.... 10.10. ?!??!! :? Okay, this is a crazy school. This time, I won't be the coder!

User avatar
Aaron
Posts: 595
Joined: Tue Feb 16, 2010 12:13 pm
Location: About 2 hours away from Anton
Contact:

Re: Generic game programming / C# thread

Post by Aaron » Mon Sep 26, 2011 1:54 pm

Endoperez wrote:Yay, an adventure game is done!
Any chance of you uploading it? I did a similar thing last year, making a game in a short time for a competition, and I would love to see someone else's work :)

User avatar
Endoperez
Posts: 5668
Joined: Sun Jan 11, 2009 7:41 am
Location: cold and dark and lovely Finland

Re: Generic game programming / C# thread

Post by Endoperez » Mon Sep 26, 2011 2:03 pm

Samusaaron3 wrote:
Endoperez wrote:Yay, an adventure game is done!
Any chance of you uploading it? I did a similar thing last year, making a game in a short time for a competition, and I would love to see someone else's work :)
I'm not sure. If it is, I assume it will be up in the school's site. However, I'm doubtful, because 1) it's way too big (90 MBs, somehow...) 2) it's very short (you can play it in 1 minute if you don't read all the texts...) and 3) it was made in two weeks, and it shows. It's decent, but not that good.

User avatar
Korban3
Posts: 4146
Joined: Tue May 31, 2011 9:14 pm
Location: 42nd St E, Hell

Re: Generic game programming / C# thread

Post by Korban3 » Mon Sep 26, 2011 5:03 pm

The images didn't appear in my browser, but it's cool that you got it done. 1 minute games FTW, although I'd like mine to be at least slightly marketable once I finish it. 10 cents, only 10 cents a copy! :lol: Shows how high I'm setting my standards here.

EDIT: Yay! The images are showing up now. Looks cool. Have fun with the next one.

User avatar
Korban3
Posts: 4146
Joined: Tue May 31, 2011 9:14 pm
Location: 42nd St E, Hell

Re: Generic game programming / C# thread

Post by Korban3 » Tue Sep 27, 2011 6:08 pm

Ok, I started collisions up today. WHAT A HEADACHE! So freakin' difficult to get it to do what I want! I'm going to be grinding through this for a few days I think. After that I can start getting levels put together I think. That's going to be cool, but the code for my collision boxes needs a ton of work right now.

User avatar
Korban3
Posts: 4146
Joined: Tue May 31, 2011 9:14 pm
Location: 42nd St E, Hell

Re: Generic game programming / C# thread

Post by Korban3 » Mon Oct 03, 2011 4:45 pm

Scrapped the buggy collision system I had and am starting over with a better idea of what I want. Hopefully goes smoother this time.

User avatar
blood-shard
Posts: 499
Joined: Mon Oct 20, 2008 5:31 pm
Location: in a house in a heartbeat 28 miles away 28 days later

Re: Generic game programming / C# thread

Post by blood-shard » Tue Nov 01, 2011 4:39 pm

Yay I'm so happy someone made this thread :D

Now perhaps I can get some help with getting started in C# so I can eventually move on to XNA.

I have mild programming experience from C/C++.
And I find that C# Is definitely much easier. Atm I'm working on a turn based RPG CONSOLE application game. Ya ya, pick on me because I'm not awesome like you guys, harh harh :P .

I'm trying to figure out how to make a system that sort of resembles the random outcome of rolling a dice. But It's pretty difficult, and I would be really happy is someone could come with a basic concept for me to examine.

I tried looking around on google, but some of them were simply too advanced for me to comprehend yet.

User avatar
blood-shard
Posts: 499
Joined: Mon Oct 20, 2008 5:31 pm
Location: in a house in a heartbeat 28 miles away 28 days later

Re: Generic game programming / C# thread

Post by blood-shard » Tue Nov 01, 2011 8:00 pm

Well I didn't convey what it is I wanted with the proper use of words I guess.
It's because I'm afraid that if I say exactly what it is I want to do, I'll spoil the learning experience by being told exactly what to do heh.

It's hard to explain what I want exactly. Because what I had in mind was sort of like what you experience when you play a board game. You roll a dice, and out comes a random number of course. That number is supposedly gonna affect how well you do.

So what I want is to know, a practical way of generating a number, which I can then use as an output for example... (I don't know if this is exactly how it works, But) the increment of a set damage.

Is it possible to do this in a simple way. Or is there a better way to go about it?

User avatar
Korban3
Posts: 4146
Joined: Tue May 31, 2011 9:14 pm
Location: 42nd St E, Hell

Re: Generic game programming / C# thread

Post by Korban3 » Wed Nov 02, 2011 1:03 am

Hmm. A purely random number huh? I know that some languages have functionality for this. I'm not sure about C#, but std namespace in C++ has a random number thing I think> I haven't played with that yet though. Maybe David on the IRC could help you with probability.

Oh, and yeah. I got collisions working within a week and have gotten a climbing system put in. Now I'm cleaning my code up before implementing a more usable animation system and then integrating items.

User avatar
blood-shard
Posts: 499
Joined: Mon Oct 20, 2008 5:31 pm
Location: in a house in a heartbeat 28 miles away 28 days later

Re: Generic game programming / C# thread

Post by blood-shard » Wed Nov 02, 2011 8:10 am

Nice to hear about your progress :D

Please get back to us as soon as possible, on how that's gonna turn out :)

Post Reply