Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3

Author Topic: im trying to do a 2D space game...  (Read 4740 times)

xaritscin

  • Bay Watcher
    • View Profile
im trying to do a 2D space game...
« on: December 26, 2015, 08:36:51 pm »

so after spending a good chunk of christmas playing SPAZ and looking for good 2D space games to play i finally decided to put whatever few skills i have in programming in order to make a game of my own...

turns out, Java has completelly wrecked me in terms of any way to make the thing work. the only stuff i have been able to compile is just a screen with a sprite in the middle. not even looking to my old projects in computer graphics helped me (an amateur clone of space invaders that uses the mouse instead of keyboard to operate) has helped me to organize what i want to do.

the lack of good tutorial material has made it worse, with only a few pages repeating the same over and over with clones of games that dont really fit what i want to do.

so i picked Unity. and have found a good script for spaceship controls. but still, it seems there's so few material avaliable for study related to the main concepts i need.

im not asking for help in the project, but if any of you know of guides, books or pieces of code that i could chew in order to get a better hand on this, i would appreciate it.

for now the first prototype is just a handmade rocket sprite with WASD controls(W and S for foward/backwards, AD for lateral rotation) but i think i may need to change the script later. controls get a little bit annoying sometimes.

for those wondering about the project as a whole well the main features of the game were based around certain titles that have been discussed in the forums:

-top down view

-2D vector graphics instead of pixel art a la Galaxial (in development, no release yet) or Reassembly

-WASD controls for propulsion, mouse for rotation and clicking for interaction (think like SPAZ) maybe some other controls like spacebar for braking and some kind of turret enumeration for player control (swapping turret controls with number keys for example).

-procedural star systems (assets made by hand, but each system should have its own randomized configuration the milestone here is at least to have a single working solar system)

-basic geometric hull editor which allows to create ships and other structures using simple shapes.

-basic internal workings editor which allows the player to make the internals of the hull the general idea of the editor is to make the hull first with geometrical objects then carve the insides for different internal layouts, instead of having pieces designed to work as solid modules the player could just mark a piece of the hull for certain functions and construct the room around it. internal machinery like thrusters, reactors and turrets would then be pasted on the designated room by the player and maybe with the option for external mounts or other external expansions (solar sails, comunications, etcetera).

those are the main concepts i want to achieve for the firsts prototypes and proofs of concept. in the case i could finish those parts at least at a barely working stage then i should look at stuff like:

-NPCs
-player and NPC factions
-resource gathering
-tech trees
-economics
-player characters (the player should be able to explore the internals of its own ship, stations, and planets)
-NPC crew and agents (hirable people that would help the player with the larger craft. maybe son "FUN" related incidents when in combat or during deep space exploration)

so that's it, i'll try to update the thread with whatever images i can get of the prototypes. thankyou for any constructive criticism you can give about the project. it looks heavy but the idea is to go shooting each feature one by one.



Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #1 on: December 26, 2015, 11:45:54 pm »

continuing with the WASD movement thing. i have been theorying about how could i improve on the script i found. right now the movement is done like this:

W moves the sprite forward

S  moves the sprite backwards

D rotates the sprite clockwise

A rotates the sprite counterclockwise

while this works fine and the ship seems to follow the directions im giving, it feels a little bit off. so the idea is to add changes to how the thrusters work(heck i dont even have thrusters in the sprite anyways).

the change is the following:

instead of making A y D to rotate the ship, they should be pushing the ship on that direction. like if the rocket had side thrusters, this means i should be able to push the sprite "left" or "right" without having to turn on that direction. (yeah i know there's no set directions in space but its for clarity).

so what happens with the rotation part?, well. if the side thrusters are capable of moving the body in a lineal movement when both are activated. then having only one working would move only a side of the ship. so yeah, activating only one side thruster in that direction would provoke a torque. so the idea is to use the Alt key (or another key that would be more fitting) to activate rotation.

TL:DR

A y D moves the ship to the left or right sprite wise

Alt+A and Alt+D activate counter and clockwise rotation for the ship






Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #2 on: December 27, 2015, 12:31:40 pm »

the spaceship controls change was easier than i expected. after analizing and finding how to assign specifics keys to the input. i was able to modify the code given to do the following:

A y D move the ship laterally

Q y E rotate the ship counter and clockwise respectivelly

i had to scrap the idea of using alt because it seems i cant assign two different outcomes from a single key. so instead i used two keys closer to the WASD to make the function.

now, this works with a normal complete sprite. i dont know how im gonna explain the complex shapes to the system. but for now this system should suffice.

next in on the list should be to put more sprites on the scene like asteroids. so i can test weapons (maybe turret gameplay)
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #3 on: December 27, 2015, 03:00:36 pm »

just found that Unity has an script for camera follow. added it and put a background to the camera. also, made the sprite of an asteroid and made its rotation complete from scratch. the code is used to simulate random rotation so each asteroid should have a diferent movement i guess. have to add more of them to the scene.

the think is taking shape slowly, here, have a short video:

https://igcdn-videos-b-8-a.akamaihd.net/hphotos-ak-xat1/t50.2886-16/12445530_1007249962675068_1383546336_n.mp4

next thing to shoot would be combat controls. the conceptualization that i got yesterday could be resumed in 3 parts:

1. if the weapon is fixed, then it should shoot in whatever position is pointing (side cannons, fron cannons, bla bla bla)

2. if the weapon is mounted on a turret, then it should be able to be aimed with the mouse help, and it should have extensions for manual aiming and automatic locking of targets. target aiming would be mostly related to guided missiles but there should be the tactical option of allowing the player to set its turrets to focus in a single target. turret management is something im looking forward actually. both in manual and tactical modes.

i have already made a sprite of a turret, i'll see if i can do tests with it for both systems. but missiles, mines, bombs and drones are still out of the field for now. have to figure out that.

oh and have to think about a nice background for the screen, playing in a black screen feels a little off. may i can do a background in Inkscape. i dunno.
« Last Edit: December 27, 2015, 03:51:02 pm by xaritscin »
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #4 on: December 27, 2015, 10:19:48 pm »

got against several obstacles regarding the system i wante to make:

1. i need to find a way to attach the turret to the ship. in more general terms, i need a fixed position script to have it facing only in the direction i give to her on the escene. so it basically becomes a fixed mount. however, i dont see much guides about parenting and that sort of stuff.

2. there has to be also an script for mobile turrets so i have to find how to attach it and allow it to aim with the mouse.

3. i was planning to add brakes to the ship, but the current script for navigation became problematic when trying to add a simple solution to it (brakes were planned to just set the thrusting speed and rotation to cero so the ship, the problem is that it keeps it that way and the controls dont really activate the movement again).

4. i dont have a bullet system yet, the sprite is avaliable and had already made it a prefab but it doesnt have the script for it. need to get over the rest of the issues first

5. nor the ship nor the asteroid have hitpoints, this has been fixed though. made a health script which allows me to give a maximum health and current health to whatever object i want. it also takes in account methods to modify health so i can use them in damage calculations.

6. things were going better in the collision department. may try to see if i can make a collision damage script so when the ship collides with the asteroid it gets destroyed or something. they interact in insteresting ways already.


so yeah, plenty of stuff to take out in order to advance.
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #5 on: December 28, 2015, 10:26:40 am »

woke up early with a concept floating:

as of now, the spaceship controls are based around adding forces to the ship's movement. lateral and frontal/backwards force use a multiplier of the velocity of the spaceship in its respective componente along with thrust speed and the input.

rotation is done using a torque that uses the lateral component of the velocity and multiplies it with the turnspeed.

both turnspeed and thrust are set parameters and that's why i couldnt find how to add brakes to the ship. the ship moves with the same speed no matter what i do to stop it. so i may have to add acceleration and deceleration controls.

but this opens another hole in the plan, the prototype as it is uses a single sprite. whereas the long term idea is to have an editor which means i have to figure out how to put separated objects and then fuse them in Unity. for now i only know that i can take a piece, give it properties and then convert it into a prefab. but how to attach them and convert them in a single entity is out of my grasp.

for now im taking inspiration from this thread  http://www.bay12forums.com/smf/index.php?topic=135838.0 which at its basics cover what i wanted to do regarding the editor. i mean:

-make an editor with a set of pieces
-fuse them in the game
-fuse all the collision meshes to make a single one
-generate a mesh from the collision one so i can use it for the interior editor

as for the turret issue. i found a code to make the thing rotate with the mouse. however, the sprite rotates around its hypotethical center of mass, maybe once i find how to add it to the mesh i will be able to change the pivot to the base of the turret or something. however this is only for a free moving turret. fixed mounts are still being thinked of.
« Last Edit: December 28, 2015, 10:28:47 am by xaritscin »
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #6 on: December 28, 2015, 01:59:09 pm »

i'll scrap the spaceship movement for the time being. the acceleration/deceleration controls worked but it didnt stop the ship from keeping the momentum it had.

it seems more of an issue of choosing between realism and gameplay comfort. the controls are technically enough as it is, just that theres no drag to make the ship loose its movement after a time. maybe i'll have to scrap the part of keeping it realist and just add a littbe bit of inertia to soft the controls.

as for the mesh stuff. havent found anything related to it. the only thing i found that could help me with building editors is a tutorial for making a base-building game which im analyzing. you can find the first part here:

https://www.youtube.com/watch?v=_lQw3YA7Jok (my youtube settings must show it in low quality but you can change it)

the tutorial has given me some interest into looking at the worldgen as a whole. so im gonna stay out of the spaceship gameplay and look at what something more important to the project that is related to how im supposed to generate a galaxy or at least a small cluster of stars so the player can navigate between them.

the first pass im doing is to make a small scene with a star and some planets with scripts for orbits.

next should be to figure a code to generate a fixed number of planets at random positions on the map. maybe the worldgen script of the other tutorial should prove usefull for this.



Logged

HavingPhun

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #7 on: December 28, 2015, 03:46:03 pm »

Though I can't be much help as I don't get on the forums very much anymore I would like to offer some of my thoughts, I have only skimmed your posts so forgive me if I missed something.

First, projects like this are great, I didn't really understand C++ until I finally took up a project and created a procedural world generator this spring. That said, always try to start small on these projects and work from goal to goal. Before my world generator I had countless projects that failed because I had hugely ambitious plans for a game and did not pace myself in creating it, expecting all of the features to be done in an instant.

Last thing, you mentioned generating a small galaxy with planets orbiting stars and such. I haven't yet worked on any generation code for that, but, I did play around with planetary orbits. As you might know, most planetary orbits are not perfect circles, but ellipses. They have a value called eccentricity. Eccentricity can be valued from 0 to 1. An eccentricity of 0 would mean the orbit is a perfect circle. However, as an orbit's eccentricty moves closer to 1, the orbit becomes more elliptical. What this amounts to is that an orbit has a lowest point, it's aphelion, and a highest point, it's perihelion.

That said, the math involved in simulating elliptical orbits confused the hell out of me, and I found simulating circular orbits much more easy to do. It all probably just boils down to what you mentioned earlier, whether you care more about realism or if circular orbits are fine. If you are interesting in elliptical orbits, I would take a look at "Kepler's Laws of Planetary Motion". Circular orbits are fairly simple, you simply have a circle with the radius of the planet's orbit, and an angle which is the planets angle in it's orbit. You increment the angle at each timestep and calculate x and y like so:

x = OrbitRadius * cosine(OrbitAngle);
y = OrbitRadius * sine(OrbitAngle);

Let me know if you would like more explanation and please someone point it out if I am wrong somewhere.
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #8 on: December 28, 2015, 05:24:16 pm »

yeah i know its a fairly large project, that's why im starting with small easy to understand prototypes. some of them based on scripts i found avaliable on the internet.

yeah i was actually trying to adapt a code i found in a wiki, but it was in javascript. maybe i should have just pasted it in Js script but i dont really know at this point if it would interfere with the rest of the code which is being written in C#;

it wouldnt matter probably since orbits shouldnt really have an effect in gameplay. its just to add dinamism to the world map.

the galaxy map is more of a far vision. for now the main concerns of the project is to:

1. get a working navigation system
2. get a working solar system
3. get working ship editor
4. get working interior editor
5. get working combat

im trying to get all the documentation i can in the subject to make my own approaches but it has been quite hard.

i didnt really wanted to go on realism, but i felt the controls i saw in other games were a bit unforgiving sometimes. its not like the game would have photorealistic models or something.

so i guess putting simple circular orbits would do fine. same for the controls, if i cant put a real brake system them i'll just put some drag to it and see what happens.

im gonna test those equations to see what happens.



Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #9 on: December 28, 2015, 06:18:17 pm »

orbits and movement issues aside. i think i have figured out how im gonna do the star map for this game. althought it would be a bit unorthodox.

according to the guides found on procedurals they usually use noise or sometimes take a particle generator that produces the points that would later serve to generate the star systems later. however, im not a master in computer graphics, my knowledge of procedural generation is barely existant and i only know the fundamentals, i have never actually done a system that can get close to what these people can do.


but my  current analysis on tutorials goes around a tilegrid generator for a local map. so i could expand on the fundamentals of this system to generate a 2D coordinates map of a galactic cluster. certain key elements like the central blackhole could just be placed in the coordinates i want. but the rest of the star systems could be placed around random positions in the tilemap. as long as they dont collide in the same positions of course.

its more  or less similar to doing a watered down version of DF or Rimworld world generators. but it would be a massive jump into advancement for the game. the only thing i have to make sure is that stars can be linked by some sort of scene loader. but that cant be difficult, i guess.

the grid system could help me too to organize the solar system, structure system and spaceship editor if i get lucky with this. but i fear the gamecould end a little bit boxy in that department. i would have to see how much it affects this graphics wise.

« Last Edit: December 28, 2015, 06:21:53 pm by xaritscin »
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #10 on: December 29, 2015, 08:23:30 pm »

waiting for the rest of the base building tutorials to come. learned how to add a primitive UI for creation/destruction of tiles along with wall placing. it needs optimizations however.

as for the project itself. im currently working on the script for the Galaxy Generator. as i said, it would be very simple and may not be realistic for that matter but it should do the following:

1. define a set number of stars (including black holes)
2. define a set size in the X and Y coordinates
3. each segment of the grid is defined as a Sector
4. each Sector should receive a random amount of astral bodies from the general pool avaliable.
5. define Wormholes as connections between sectors (it should be a class of object different to stargates for now)
6. add a number of wormholes consistent with the amount of adjacent sectors for each sector (so sectors in a corner have only 3 wormholes, bla bla bla).

for now the idea is that the galactic grid only defines object placements. there's no limitation in navigation yet. but the system should itself show how to do it. the idea is that the player traverses the galaxy using either 3 methods, stargates for interestellar travel, wormholes for inter-sector travel and jumpdrives for direct teleportation galaxy wide (albeit with fuel limitations i think).

each star, planet, moon, or other spatial landmark should load as its own grid scenario. i would like to make everything free roam but its out of my capacities with all the zooming and scale i would have to put.

EDIT:

this is going to get a litle bit inception like. i would have to create a sector tile, then a startile, then an orbital tile, and guess then i would get to local ship space which would be bound to a fixed distance i guess.
« Last Edit: December 29, 2015, 09:00:59 pm by xaritscin »
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #11 on: December 29, 2015, 11:53:07 pm »

decided to do some changes to the movement script for the spaceship, adding drag to the system is present and it gives some help to the movement. but the controls are still too clunky, changing the speed values of the ship doesnt help it either.

maybe i'll have to scrap these controls and use another script i found in a tutorial.

the turret code worked though, the visual issues were changed just changing the pivot point of the sprite and parenting the model to the player's spaceship so, free moving turret (no shooting yet).

i'll change those controls tomorrow to see what happens, meanwhile i'll keep thinking in the galaxy code. the classes are set but i still have some doubts about the grid generation workings that i have to clear out. mostly the issues related to invoking the sprites. have two examples for now, but they should serve me well. i dunno.
« Last Edit: December 29, 2015, 11:55:05 pm by xaritscin »
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #12 on: December 30, 2015, 12:55:44 pm »

tested the other script for movement, and turns out it doesnt works with physics, it actually glitches during collision. the script used transformations and quaternions to move the spaceship so it didnt give any feel of drift or movement during the test.

i aint using that. so i decided to check how could i improve the 2d physics i used for movement. a few searches in google drove me to find a way to fix the rotation issue, which was mostly due to a lack of limitants to the angular velocity. a simple addition to the conditional gave what i needed.

as for the rest of the issues, adding drag to the normal state of the ship in a small amount helped to give that feel of drifting while not stopping the ship instantly. the change in speed is still grazy in terms of rotation but it can be fixed now that i know that i can limit the rotation speed.

and then i discovered how to implement brakes. so yeah. the ship is capable of stopping, i may tweak the numbers a little in the future, because even with a drag of 1 the ship keeps certain motion. but its still enough for a fast stop.

nothing on galaxy generation yet. will take a rest and retake it later today.

EDIT:

made some bugfixing to the movement script. turns out there was a moment when the drag was being kept even after releasing the brake button. it has been fixed, it also helped me optimize the drag and angular drag functions.

the movement script should actually serve for a thruster component actually. rather than a single ship. but until i get how to make a ship out of prefabs i can only use it on this small rocket.

the idea is that the script would be added to a thruster prefab that respondes differently depending on the type of thruster and its properties. for example, one thruster would have faster rotation buy may have a low speed. another thruster may achieve top speeds faster but it would probably be hard to turn with it.

in the end the maximum limitation of this is due to physics, or at least related to the lack of strafing maneuvers. the system only applies forces to the ship in order to move it, for example, moving forward pushes the ship in that direction, lateral movement is done also in a linear pattern while rotation is done with torques which of course take into account the ship's center of mass.

now, this happens into a single entity. i would have to test how it works in a composed entity where they could be multiple thrusters and their locations.

i may have to test that soon.
« Last Edit: December 30, 2015, 01:55:09 pm by xaritscin »
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #13 on: December 30, 2015, 03:51:45 pm »

started analyzing ways to make player movement more fluid and ended making a toggeable system. by pressing left ctrl the player can toggle between mouse based navigation and key based navigation. the system should prove usefull in different situations for example, when the player needs to use the turrets for common stuff like mining asteroids it would just need to press ctrl and then it would be able to aim the mining laser with the mouse while staying in place using WASD controls.

this doesnt seem much but its an incredible evolution from the initial code i had which was really clunky and restraining.

so yeah. i think this should be the last part to have in the movement script for now.

in fact, i have just started to look for guides into how to make a custom editor, need to test those movement scripts with something more complex than a simple rocket ship.
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: im trying to do a 2D space game...
« Reply #14 on: December 31, 2015, 10:03:11 am »

spent a good part of yesterday trying to find some kind of introduction into how to make an in-game editor. but it seems there's no material regarding that avaliable.

so, i'll have to figure it myself. gonna toy with the code i have to see how i can make a drag and drop script, and then look at an script for object generation. then it should be a way to create a script that analyzes the object's geometry in order to find attachable nodes or something. i dont know.

but it should be similar to what is done in Reassembly. each ship component has a set of small nodes which define how do you attach tem in order to make the ship. i should start with cubes first since they are easier to accomodate. but then i should also check about rotation scripts. copying from the movement script should be the way to go on that.

strange, it seems easier than it looked on paper. i have almost all the fundamentals present with the other prototypes. except for one thing, saving methods, i dont know a damn about saving objects to a file.
Logged
Pages: [1] 2 3