Author Topic: little xna c# pong game  (Read 11179 times)

0 Members and 1 Guest are viewing this topic.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
little xna c# pong game
« on: October 23, 2009 »
hey every one i thought i would make a little game to get my feet wet with coding again i made this little game in xna c# as i never got to much time to mess around with xna before so here goes.

could you guys test this for me as i have no idea if and how xna games run on pc's without the xna library being installed.

<edit ahh sorry guys if you wont to run this you will have to install the xna redis files from here first>
http://www.microsoft.com/downloads/details.aspx?familyid=15fb9169-4a25-4dca-bf40-9c497568f102&displaylang=en

now here is the game.
use f1 to toggle between full screen and windowed.
up and down arrows to move player bat.
esc to quit if in fullscreen mode or cross otherwise.

also not really having done very much in c# i was wondering if someone would be up for having a quick skim through my source and tell me if im doing roughly the right sort of things cheers.
« Last Edit: October 23, 2009 by ninogenio »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: little xna c# pong game
« Reply #1 on: October 24, 2009 »
Welldone Nino :)
The ball speed could do with being a touch faster, and player2 ( computer guy ) can move left and right.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: little xna c# pong game
« Reply #2 on: October 25, 2009 »
Crashed here (WinXP) - guess I need to install additional
libs to run it. The NET framework is installed btw.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline staticgerbil

  • Atari ST
  • ***
  • Posts: 113
  • Karma: 8
    • View Profile
Re: little xna c# pong game
« Reply #3 on: November 24, 2009 »
Hey Nino,

Nice job, works well for me.

The white lines on the black screen play tricks on my eyes :)

XNA is a pretty good setup isn't it.  I've just started playing with it myself.

Here's what I've been playing with...

http://users.on.net/~jkgale/

It was / is the start of some kind of multiplayer dungeon based action game.  I'm having second thoughts about doing it in XNA though, I have some friends who are interested in doing something similar in c++ for win / linux / mac.

A quick warning though, it installs itself and automatically downloads the appropriate framework so be prepared for that if you try it out.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: little xna c# pong game
« Reply #4 on: November 26, 2009 »
hey sg!!,

i really like xna. it isnt for everyone but certinly i think a great platform for full profing ideas. testing pixel/vertex shaders etc...

i am doing little experiments with shaders like applying filters on post screen renders. black and white art work stencils, gusian filter bloom glows and in xna its increadably simple.

i tryed your little game but it crashed stright out so when i ran it in the debugger i get device does not support non power of 2 textures, figures i guess as i have an ati chip  :(

any way nice to see you around mate  :cheers:
« Last Edit: November 26, 2009 by ninogenio »
Challenge Trophies Won:

Offline staticgerbil

  • Atari ST
  • ***
  • Posts: 113
  • Karma: 8
    • View Profile
Re: little xna c# pong game
« Reply #5 on: November 26, 2009 »
Yeah it's good to be back.

Hopefully I might actually hang around for a while this time :)

I've fixed up that texture for you.  I was kind of ignoring the error because it works on my desktop and laptop and I just couldn't have been bothered opening up my 3D software to fix it :)

Basically you can run around a grid based world, the other blue girl is (will be) your friend and the grey girl is the bad one.

Buttons 1-6 on the keypad cast abilities 1-6.  They each have a cast time and a cooldown.  The grey girl takes about 2 hits to kill and then randomly respawns.

I'm not real sure what I have planned for xna yet.  I'd like to do a 2d fighter (street fighter style) and maybe something along the lines of soldat.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: little xna c# pong game
« Reply #6 on: November 26, 2009 »
hey sg thats really neat mate, it looks like you have quite a bit of your engine sorted wich is the hard part, a 2d fighter would be good.

i personally am not sure what even if i want to do much in the way of full projects in xna its just a really easy way for me to experiment with diffrent things.
Challenge Trophies Won:

Offline staticgerbil

  • Atari ST
  • ***
  • Posts: 113
  • Karma: 8
    • View Profile
Re: little xna c# pong game
« Reply #7 on: November 27, 2009 »
I'm almost using XNA for the exact opposite reasons :)

Basically I much prefer to play games on a console and I feel like XNA is a great way for me to get some console work done. 

The tools are fantastic, free, legal and there is official support.

Another huge upside is that any of my friends with Xbox's will be able to play my game without having to mod anything.

The only real downside is that you can't get a game onto the community site without charging people for it :(
At the same time I totally understand their choice.  They are offering a great service to us bedroom coders the least we can do is make them a dollar or two for every download.

(Who would have thought I'd be giving Microsoft that kind of praise!)

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: little xna c# pong game
« Reply #8 on: November 27, 2009 »
 :) oh yeah i totally understand that mate,

i havent got a 360 so i simply use it for windows stuff and to be honest it seems just as capable as any other languge on the windows platform.

my problem more so than any thing else is that i havent got that much motivation or time right now so this just seems to be perfect for me i can simply bash stuff up in a quarter of the time.

that reminds me have you run into timer problems with xna yet? it took me a while to realise that microsoft sets the window to fixedtimesteps and screws up any timers you have if fixed time step is enabled you might as well increment a self timer by 16.7 every update. but handily for the xbox guys you can switch it off and let it run at full whack with proper timers but you must delta time all your variables.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: little xna c# pong game
« Reply #9 on: November 27, 2009 »
Quote
also not really having done very much in c# i was wondering if someone would be up for having a quick skim through my source and tell me if im doing roughly the right sort of things cheers
I'm really sorry, but I've only just got round to looking at the code.
It's OK, but it's not really using inheritance the way it's supposed to be used - all your classes seem to inherit off one another and the base class is the keyboard reading code.
That's not really how it's supposed to be used.
Having said that, it's really good that you have broken your code up into sane pieces.  Keyboard, bats, ai, collision.  That is great.
You're not really in need of most OO features in this program.
Right now you've used 'Composition' to join all those four bits into one super-class which can control everything.  This isn't great.  It would be better to have one controlling class, say GameControl.  It would create an instance of each of the sub-classes and marshall data between them - in the constructor create a keyboard reader, ai controller, scene drawer, then that top level class controls everything - e.g. read the keyboard, feed that into the movement routine.  Run the ai routine.  Feed that into the drawing routine.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: little xna c# pong game
« Reply #10 on: November 27, 2009 »
ahh thanks jim k+,

i can see what your saying, when i was coding this i could feel that i was doing it wrong it seemed to me that if it was a really large project it would get overly complicated. my mind still works far to c orientated for these new object languages  :).

i will try what you have said there jim and see what it looks like. cheers
Challenge Trophies Won:

Offline staticgerbil

  • Atari ST
  • ***
  • Posts: 113
  • Karma: 8
    • View Profile
Re: little xna c# pong game
« Reply #11 on: November 27, 2009 »
Have you been using properties?

I can't get used to them.  I like my good old Get / Set functions :)

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: little xna c# pong game
« Reply #12 on: November 27, 2009 »
ahh k+ sg,

thats a really cool feature i totally overlooked there is so much new stuff to play around with in c# but its all good fun.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: little xna c# pong game
« Reply #13 on: November 27, 2009 »
If you do re-jig it, one simple thing to try to see how OO should be helping might be to make it work with a choice of mouse or keyboard.
Make 2 classes that implement an IBatController interface which has a method called GetYMovement() which returns up or down.  Then you can create either one and plug it into the bat controller.
something like
Code: [Select]
public interface IBatController
{
int GetYMovement();
}
public class KeyController : IBatController
{
public int GetYMovement()
{
...keyboard code
}
}
public class MouseController : IBatController
{
public int GetYMovement()
{
...mouse code
}
}
Then, in your setup code:
Code: [Select]
public class GameControl
{
IBatController batController;
//doesn't have to be in the constructor, it could be in another init function somewhere
public GameControl(bool usemouse)
{
  if (usemouse)
     batController = new MouseController();
  else
    batController = new KeyController();
}
...
}
Then in your main code
Code: [Select]
int batYMovement = batController->GetYMovement();
The great thing about that is your main code couldn't give a rats whether you are using mouse or keyboard.  This is brilliant because you've simplified the game code so it has one thing less to care about. You've separated out the implementation of the controller from its interface so implementations of the controllers are totally opaque to the application, and you've encapsulated the actual controller code in one place.
Of course, you can do all this in C without OO, but C# is a really nice language for doing this kind of thing.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: little xna c# pong game
« Reply #14 on: November 27, 2009 »
ahh i see how doing this sort of thing is going to help it really is a great way of thinking.

i am in the process of rearranging the code but i will put your idea there to use too thanks jim!
Challenge Trophies Won: