Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Skibum

Member Since 31 Oct 2001
Offline Last Active Apr 16 2012 07:52 PM

Topics I've Started

Ship Sinker - Working game; please review

06 March 2012 - 08:17 PM

Salutations and good evening.

I thought I'd post my first XNA game and see what the community thought. This is a C#, XNA 4.0 game I created over the last few weeks. The graphics are very simple and leave a lot to be desired but it's a working game.

I created it in C# using the XNA 4.0 studio and it should have all of the files to open it up in Visual Studio Express 2010. The game is a simple clone. Start a game, place your ships, take turns shooting until someone wins. Seemed easy enough weeks ago when I started it but now it's working well enough to see what others think while I'm wrapping up the code.

What I'm after are developers with a bit more experience that have a bit of time to check it out and provide some pointers as to how to make the code better though, of course, anyone can offer suggestions.

Subversion command to download : svn checkout http://ship-sinker.googlecode.com/svn/trunk/ ship-sinker-read-only

Main source file if you just want to look.

Thank you for your time!

-Skibum

Is Microsoft.DirectX.Direct3D.Sprite.Draw2D buggy?

15 July 2009 - 08:20 AM

I'm using C# in a windows app and DirectX 9 on a vista machine. What I'm trying to do is to rotate an image in place so I can avoid having to make a ton of images all facing different directions. The png file "Ship.png" is a simple image, a 32x32 ship facing straight up. I have an Init and a Render which I think is all that needs shown here for this example. In my class:
	private Texture t = null;
	Sprite s = null;
	float rotationAngle = 0;

public void Init(Device d)
{
	// Load the Texture into variable "t", seems to work fine
	// My transparent color is 0x00FF00FF shown by the last argument
	t = TextureLoader.FromFile(d, "Ship.png", 32, 32, 0, Usage.Dynamic,
		Format.Unknown, Pool.Default, Filter.None, Filter.None,
		Color.FromArgb(255, 0, 255, 0).ToArgb());
	// init the sprite with the device
	s = new Sprite(d);
}


This will display the ship at 0,0, unmoving, good
	Texture t = null;
	Sprite s = null;
	float rotationAngle = 0;
	Point position = new Point(0, 0);
	Point rotationCenter = new Point(0, 0);

public void Render(Device d)
{
	s.Begin(SpriteFlags.AlphaBlend);
	s.Draw2D(t, rotationCenter, rotationAngle, position, Color.White.ToArgb());
	s.End();
}


So from the above Render I change to the following and end up with a rotating ship revolving around the top left corner counter-clockwise in and out of my window.
	Texture t = null;
	Sprite s = null;
	float rotationAngle = 0;
	Point position = new Point(0,0);
	Point rotationCenter = new Point(0, 0);
public void Render(Device d)
{
	s.Begin(SpriteFlags.AlphaBlend);
	rotationAngle -= 0.05f;
	s.Draw2D(t, rotationCenter, rotationAngle, position, Color.White.ToArgb());
	s.End();
}


So I change the rotationCenter line and nothing else and I end up with a ship that is rotating on the top left point of my window in the center of the ship, just like what I want but not where, it's 3/4 off the screen because the ship center is my top left window pixel.
	Texture t = null;
	Sprite s = null;
	float rotationAngle = 0;
	Point position = new Point(0,0);
	Point rotationCenter = new Point(16, 16);
public void Render(Device d)
{
	s.Begin(SpriteFlags.AlphaBlend);
	rotationAngle -= 0.05f;
	s.Draw2D(t, rotationCenter, rotationAngle, position, Color.White.ToArgb());
	s.End();
}


So then I change the position to Point(16, 16) thinking it will move the ship and keep it rotating like it should. It moves the ship to 16,16 but it still rotates around the 0,0 of the window so it's on and off the screen. That seems so messed up. If, instead of my Draw2D function I use Draw instead like below then it will work like I want it to but I have next to no idea why this will work and not the Draw2D.
	s.Transform = Matrix.Transformation2D(new Vector2(0, 0), 0, new Vector2(1, 1),
		new Vector2(16, 16), rotationAngle, new Vector2(0, 0));
	s.Draw(t, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0),
		new Vector3(0, 0, 0), Color.White);


If I want to change the location of the image in my window then I would change the change below. I used (X-COORD, Y-COORD) to designate the locations in the source.
	s.Transform = Matrix.Transformation2D(new Vector2(0, 0), 0, new Vector2(1, 1),
		new Vector2(16, 16), rotationAngle, new Vector2(X-COORD, Y-COORD));
	s.Draw(t, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0),
		new Vector3(0, 0, 0), Color.White);


The Transform on the sprite does not seem to change the working of s.Draw2D(). It's almost like whatever I do the Sprite.Draw2D function ignores my rotationCenter and uses Point(0,0) instead. I'm at a loss to figure this out. I've tried many more iterations than show above and haven't come up with a conclusion as to how to fix it (obviously, or I wouldn't be posting). Edit - change a comment

Scripting confusion, how far and how?

27 May 2009 - 04:04 PM

Well I've done my own versions of blocks, a pac-man and asteroids. Next on my list is something that requires more of a game world and some extra added challenge. As I really enjoyed the game Dragon Warrior I was considering it as a project (2d top down scrolling rpg with random monster encounters). I'm trying to get a high level overview before I start into it. Considering the amount of content a game like this would have I decided a scripting engine would be much better than writing everything in code (that's why I'm here). What I'm curious about is how the script and game will interact and how much to script vs code. So for an example when I press the up arrow if there is a menu on screen the cursor should move up but if not then the character should attempt to move up, should this be handled in script or is it better to allow the code to do it? I'm going to guess that the maps should be scripted somehow as well though I'm not quite sure to go about it at this point. It should probably provide the terrain, NPC locations and so on right? Last thing I can think of at this point would be when you want to speak with an NPC, walk up to hit, hit enter (or whatever), how do you run the script for this particular NPC? I've been reading as much as I can find about Lua but I can't seem to find a small or sample game written with it (just examples like Warcraft... not so helpful at my level). I'm not tied to Lua or any particular script language though so any recommendations (free please!) would be considered. Any and all help is appreciated and if you happen to be able to recommend a good book on this subject that would be great as well. Thank you!

PARTNERS