GPWiki.org
GPWiki.org
It is currently Fri May 24, 2013 11:41 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Twin Stick Shooter?
PostPosted: Fri Jan 06, 2012 9:10 pm 
Super-dooper pooper scooper
User avatar

Joined: Tue Oct 11, 2011 8:08 pm
Posts: 170
A couple projects ahead of what I'm currently doing right now, I think I'm going to try to make a twin stick shooter in XNA. I.E. you walk with WASD, and shoot with the mouse. And then I realized I don't know how to direct a sprite to the cursor location... Anyway:

1. How do you rotate a sprite to point to the cursor? I don't know much trigonometry, so keep it sorta simple please. :)

2. Basic lighting effects with XNA? A good 2d tutorial link would be great, and google is turning up nothing. I haven't read much about this.

3. Do you have any suggestions about this tutorial's game state handling?

------------
Also: Graphics Styles: I've pretty much decided about I what my first large/commercial project to be. I was thinking about the graphics styles and I'd like everyone's opinion.

1. Isometric/2.5d: I have next to no idea how to implement this, but it could end up with very pretty results.

2. 2D-top down; non-tile based: Is this even feasible for say, walking around a large city? Making a map editor for this would be hell... Opinions?

3. 2D-top down; tile-based: This seems like the easiest and most feasible option, but can it look good? :O
Most of the tile-based games I've seen looked like crap, especially the sci-fi ones (which I'm trying to make).


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Fri Jan 06, 2012 9:33 pm 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
Quote:
1. How do you rotate a sprite to point to the cursor? I don't know much trigonometry, so keep it sorta simple please.


It'l require some trig to actually do it(easy to find on the net), but the basic logic goes something like this:

1) Get XY of Mouse Cursor
2) Get XY of Sprite
3) Get current angle of sprite
4) Calculate "Vector" between the cursor and sprite's XY (this is where the trig happens)
5) Figure out the difference between the angle your sprite is facing and the vector to the cursor
6) Figure out which direction to turn (i.e. which angle is smaller? Do i turn left 20 degrees or do i turn Right 340 degrees? left of course)
7) Turn sprite

I have an AI routine in my project that performs this kindof tracking. If you're interested, I can pull it out. Or if you'd prefer to figure it out first, thats cool too.

Quote:
2. Basic lighting effects with XNA? A good 2d tutorial link would be great, and google is turning up nothing. I haven't read much about this.


Theres an absolutely SICK lighting 'tutorial' on YouTube but it's anything but basic. You can simulate shadows by drawing the sprite again, offset a bit, black and somewhat transparent.

As for GameState handling, i feel bad but i didnt actually read through that article hehe. I'm experimenting with gamestates at the moment as well. It's amazingly helpfull to be enlightened to the concept of GameStates. What I'd suggest is a case switch statement in your "Update" or "Draw" routines, and they have seperate instructions they carry out based on which gamestate your in. like, case: "MainMenu"... *insert main menu logic here*.. case: "MainGameLoop" *insert main game loop logic here* ETC.

Quote:
1. Isometric/2.5d: I have next to no idea how to implement this, but it could end up with very pretty results.


Isometric is just top town 2d with sprite directions (Ne/SW/etc) and some very clever Layer Depth coding. Im not actually sure how its done, never looked into it. But I think the challenge is in working out the layer depths, which change dynamically.

Quote:
2. 2D-top down; non-tile based: Is this even feasible for say, walking around a large city? Making a map editor for this would be hell... Opinions?


Perfectly feasable. Map editor wouldn't be hell. Before much longer, I'l be writing one for my game. Because everything is viewed in terms of X,Y co-ords, you can generate a MASSIVE map with an actual map file that is incredibly small.

Quote:
3. 2D-top down; tile-based: This seems like the easiest and most feasible option, but can it look good?
Most of the tile-based games I've seen looked like crap, especially the sci-fi ones (which I'm trying to make).


Is your game turn based or real time? If it's turn based, tile-based mapping would be easy. You'd need a multidimensioned array to store which objects/chars are on which tiles. Or more than one array. Well programmatically theres many ways to do it, doesnt matter. If it's real time, tile-based could be very tricky.

Anyways, Hope this helps!

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Fri Jan 06, 2012 10:13 pm 
Super-dooper pooper scooper
User avatar

Joined: Tue Oct 11, 2011 8:08 pm
Posts: 170
Jimbo wrote:
...
Quote:
2. 2D-top down; non-tile based: Is this even feasible for say, walking around a large city? Making a map editor for this would be hell... Opinions?


Perfectly feasable. Map editor wouldn't be hell. Before much longer, I'l be writing one for my game. Because everything is viewed in terms of X,Y co-ords, you can generate a MASSIVE map with an actual map file that is incredibly small.

Quote:
3. 2D-top down; tile-based: This seems like the easiest and most feasible option, but can it look good?
Most of the tile-based games I've seen looked like crap, especially the sci-fi ones (which I'm trying to make).


Is your game turn based or real time? If it's turn based, tile-based mapping would be easy. You'd need a multidimensioned array to store which objects/chars are on which tiles. Or more than one array. Well programmatically theres many ways to do it, doesnt matter. If it's real time, tile-based could be very tricky.

Anyways, Hope this helps!


Its going to be a real-time, sci-fi, action-y shmup thing. :rock I have a few more ideas, but I'm not sure about them yet.
So how do you handle collision detection with option 2? Do you mean, instead of placing tiles, you place different sized objects into a empty map, and then the game handles each object? I don't see how that would make smaller map files.

Quote:
1) Get XY of Mouse Cursor
2) Get XY of Sprite
3) Get current angle of sprite
4) Calculate "Vector" between the cursor and sprite's XY (this is where the trig happens)
5) Figure out the difference between the angle your sprite is facing and the vector to the cursor
6) Figure out which direction to turn (i.e. which angle is smaller? Do i turn left 20 degrees or do i turn Right 340 degrees? left of course)
7) Turn sprite
I have an AI routine in my project that performs this kindof tracking. If you're interested, I can pull it out. Or if you'd prefer to figure it out first, thats cool too.


Could I see the part about vector calculations? ;)
Everything else seems pretty simple.


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Fri Jan 06, 2012 10:28 pm 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
Quote:
Its going to be a real-time, sci-fi, action-y shmup thing. I have a few more ideas, but I'm not sure about them yet.
So how do you handle collision detection with option 2? Do you mean, instead of placing tiles, you place different sized objects into a empty map, and then the game handles each object? I don't see how that would make smaller map files.


Yep. If it's tile based, youl have to have some kindof value in your map file for EACH TILE... regardless of how full (or empty it is)... if it's non tile based, all you need to do is have a list of XY coords of the stuff that DOES exist. To put it another way: a 1000 x 1000 tile map with say, 500 objects in it. Your map file would need info for EACH TILE.. (what kindof tile is it, what is on that tile, etc..) thats at least 1,000,500 peices of info.

Now. If it's NON tile based, all you need is 500 peices of info - where the objects are. Much smaller map file.

As for collision detection, there's some tutorials online but basically theres 2 types (Well, 3 i suppose. We'l ignore 'Circular' for now). There's "Rectangular".. which is very fast and efficient, but depending on your sprite artwork, can be somewhat innacurate. Alternatively, there's "Per-Pixel" AKA "Pixel-Perfect" collision detection.. which as the name implies, literally compares pixels to determine collision. While this is 100% accurate, it's fairly CPU heavy. If you've got a ton of sprites all performing pixel perfect collision tests... that can slow things down. If you do want to go pixel perfect, the trick is to perform Rectangular Collision first, on everything.. and ONLY when a rectangular collision happens do you go further and initiate the pixel-perfect test.

Quote:
Could I see the part about vector calculations?


Goes a little something like this:

Code:
public int FindAngle(Vector2 Vec1, Vector2 Vec2)
        {

            float Angle = 0;
            float sngXComp;
            float sngYComp;

            sngXComp = Vec2.X - Vec1.X;
            sngYComp = Vec1.Y - Vec2.Y;

            if (sngYComp > 0)
                Angle = (float)(Math.Atan(sngXComp / sngYComp));

            if (sngYComp < 0)
                Angle = (float)(Math.Atan(sngXComp / sngYComp) + Math.PI);

            if (Angle < 0)
            {
                Angle = RadToDeg(Angle);
                Angle = 360 - Math.Abs(Angle);
                Angle = DegToRad(Angle);
            }


            Angle = RadToDeg(Angle);
            return (int)(Angle);
        }


Don't worry about the RadToDeg thing near the end. That just converts from Radians to Degrees. I do it cuz i dont perosnally like seeing radians. All the calculations happen in radians, but i always like to output the result in terms of degrees. Just a personal preference.

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Fri Jan 06, 2012 10:44 pm 
Super-dooper pooper scooper
User avatar

Joined: Tue Oct 11, 2011 8:08 pm
Posts: 170
Very much appreciated, and whenever you get your map editor working, could I have a screenshot for an example? 8)


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Fri Jan 06, 2012 11:41 pm 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
lol we'l see. I've got a few back-end optomizations to take care of before i go making a map editor. But once i've got one up and running, il post some screenies for sure.

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Tue Jan 10, 2012 7:05 pm 
Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1553
Location: burrowed
Jimbo wrote:
Yep. If it's tile based, youl have to have some kindof value in your map file for EACH TILE... regardless of how full (or empty it is)... if it's non tile based, all you need to do is have a list of XY coords of the stuff that DOES exist. To put it another way: a 1000 x 1000 tile map with say, 500 objects in it. Your map file would need info for EACH TILE.. (what kindof tile is it, what is on that tile, etc..) thats at least 1,000,500 peices of info.


This is not quite true. You can simply disregard saving info on empty tiles since they're.. well .. empty. :P
When loading a map and a tile is empty.. well. guess what happens ;)

It simply depends on your saving routine.

Lexusjjss wrote:
Most of the tile-based games I've seen looked like crap, especially the sci-fi ones (which I'm trying to make).


How well your game looks depends entirely on the artist and not entirely on the rendering method. Tiles are just a method to easily place pixel art repetitively throughout the map to simplify work and to not have to hand draw every single one of them.
If you want to see some good tilemaps look at some of the more popular snes games. Seiken Densetsu 3 probably being the most impressive one regarding tilemaps, but there are many other great titles. It is an interesting and fun technology that is easy to handle for collision and pathfinding aswell as map design.

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Tue Jan 10, 2012 7:54 pm 
Super-dooper pooper scooper
User avatar

Joined: Tue Oct 11, 2011 8:08 pm
Posts: 170
(googles Seiken Densetsu 3) :thumbs

Also, how hard would it be to implement a random city system with tile-based graphics?
I.E. You have building templates and the computer creates a city based on slight variations of the templates, and random positioning. (hope I'm making sense) Would it be harder to do with tile graphics or object graphics?


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Tue Jan 10, 2012 9:32 pm 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
Quote:
This is not quite true. You can simply disregard saving info on empty tiles since they're.. well .. empty.
When loading a map and a tile is empty.. well. guess what happens


A few problems with that:

a) The tile may not have any mobs/objects on it, but what kindof terrain is it? Grass? Cobblestone? Any other special properties of this otherwise empty tile? That kindof info needs to be saved somewhere.

b) When your draw routine(or any other routine that looks through your tiles) looks at a tile that wasnt instantiated, you'l get null reference errors.

IMO, in a tile based system, 'disregarding' empty tiles is dangerous programming. Every tile in the playable area of your map grid needs to be programmatically mentioned somewhere in your code.

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Tue Jan 10, 2012 10:24 pm 
Super-dooper pooper scooper
User avatar

Joined: Tue Oct 11, 2011 8:08 pm
Posts: 170
Well, I'm not worried about map size massively, since I'm going to use something I call a Point of Interest system :yeah . You can only freely visit cities, or places where something will happen. (I.E. Fallout 1) If you try to visit a empty location, 99% of the time, there won't be anything there. And the only sprawling maps will be the ones involved with the main game story.


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Tue Jan 10, 2012 11:28 pm 
Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1553
Location: burrowed
Jimbo wrote:
a) The tile may not have any mobs/objects on it, but what kindof terrain is it? Grass? Cobblestone? Any other special properties of this otherwise empty tile? That kindof info needs to be saved somewhere.

b) When your draw routine(or any other routine that looks through your tiles) looks at a tile that wasnt instantiated, you'l get null reference errors.


you can easily define a default tile for empty/undefined in your code. It is not dangerous, it wont be null, because upon loading it gets assigned the default, which can easily be a translucent tile so you only see background images or whatever. It really depends on the project and how you implement it.

But in the end i mostly prefer untiled maps. Although i'm no pixel guy either ;p

_________________
Long pork is people!

wzl's burrow


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Wed Jan 11, 2012 1:17 am 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
Quote:
it wont be null, because upon loading it gets assigned the default


That's what I meant by 'programmatically mentioning' each tile ;) And unless the entire map is hardcoded into the game, all that info has to sit in a map file.

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
 Post subject: Re: Twin Stick Shooter?
PostPosted: Wed Jan 11, 2012 4:14 am 
Source Code Swashbuckler
User avatar

Joined: Wed Nov 09, 2011 3:58 am
Posts: 199
Location: Brazil
It would not be redundant choose this:
- Write in the map file that the tile is a pointer to a default condition which, by the way, will allocate memory for the tile anyway
than choose this:
- Write in the map file the tile, even if it has nothing, it would be something like "(0, 0)", that will allocate memory for a new tile anyway.

...?

Just my opinion, I think it is best to write the blank tile.

_________________
"Life finds a way." - Ian Malcolm
My WebBlog: PixelDeveloper
English is not my native language, so excuse me for any writing mistakes.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group