# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### 2D All the way! / 2d s problem in 3d game

Message
Posted: 11th Oct 2011 10:17
heres the problems..

1] I need to restrict a mouse cursor to move within a center circle area of the screen but not beyond the boundary of the circle .(no need to draw the circle to screen)

2] I need to use the distance of the cursor from the center pixel as data , how could i do that ?

this is all for player controls in my space game , the distance between cursor and center pixel will determine a turn speed and the position of the cursor will determine the direction .

I could do it with a circular plain attached to the screen and do screen pick but i think there is a much better way with mathematics (which im terrible at)

thanks for any help.
Posted: 11th Oct 2011 13:56
First thing to do is work out the difference between the screen centre and the mouse cursor.

swid=screen width()
shig=screen height()
mwid=swid/2
mhig=shig/2

mx=mousex()
my=mousey()

dx#=mx-mwid
dy#=my-mhig

So DX# and DY# now contain the difference, now to work out the distance from that... and while were there, work out that angle too...

D#=sqrt((dx#*dx#)+(dy#*dy#))
A#=atanfull(dx#,dy#)

Now, to limit mx and my so that it can stay inside the circle, I would use a multiplier, lets assume your boundary circle is 128 pixels...

Rate#=D#/128.0
if D#>1.0
mx=mwid+sin(A#)*128.0
my=mhig+cos(A#)*128.0
endif

You could use vectors as well, like set the DX# and DY# to a 2D vector and normalize it, but that might be overkill, and would only account for the circle boundary, not working out the angle.

Health, Ammo, and bacon and eggs!
Posted: 11th Oct 2011 21:16
Awesome , thanks very much . I feel an update coming on ...

Posted: 12th Oct 2011 06:32

works quite nicely , the code is a media-less demo .
any suggestions of how to tidy-up the turn bits where ive used for/next commands ?
thanks .
Posted: 12th Oct 2011 22:20
Well, I've changed up a couple of things, but anyway I think you'll like this.

Quite a nice control scheme, I like it. I fixed the problem with Z rolling, by rotating the camera with object 1 instead of pointing towards it. I might dig out my old starsphere and add that, just for fun.

Health, Ammo, and bacon and eggs!
Posted: 12th Oct 2011 22:41
Hehe, space environments are cool.

Health, Ammo, and bacon and eggs!
Posted: 13th Oct 2011 11:38 Edited at: 13th Oct 2011 15:16
Thats cool , i spent about 3 hours drawing random 1 pixel dots for my sky sphere in my game (with 6 images)

the ridgid camera is better , and the smoother turn , good stuff
now how i really want the cursor to behave is to add drag/delay/inertia (which ever it is) so the X cursor laggs behind the actual mouse cursor as you move the mouse but it still traces your move .
Adding the physics to the cursor would add all direction inertia/drag in one go as opposed to coding the 4 turn directions (like i did in my game.) Fancy having a bash at that too ?

We should do a medialess space epic out of this
added a planet nav , toggle return
Posted: 13th Oct 2011 20:13
Yeah, added some more stuff, inertia movement, press space to airbrake, firing lasers, and draw command hud.

Health, Ammo, and bacon and eggs!
Posted: 14th Oct 2011 01:01
Ive updated my game files on my site , it plays much,much better !
Thanks Mr B !

Posted: 14th Oct 2011 01:39
Posted: 14th Oct 2011 13:25
Some coffee got me this far ...

Sorry its a mess ,but its working so i left it how it is for now .

Fear the Cone Spaw !

Some stuff is not working as i thought, lights dont always show when cones fire or when u hit them, cones go invisible at certain angles either the cone shape is not a closed prim' or the culling needs tweaking .
a missile would be nice ,i thought to target a missile you could make it so u need to line up all 3 cursors over the target for 3 seconds then a missile will fire off automaticly ,cone missiles vs the cone spaw hehe!! the ai movement will work for cool missiles,just need to play with the speed/turn speed to get a good missile. Anyway , another day maybe, i spent too much time on it last night
Posted: 14th Oct 2011 17:18
Cool, will get a play with it tonight. I know what you mean about spending too much time on it - you just kinda get sucked in, and want to add more and more stuff.

I will see if I have time to add missiles tonight. Also, I have a neat idea for medialess asteroids I'd like to try.

Health, Ammo, and bacon and eggs!
Posted: 15th Oct 2011 09:22
hehe FPS massacre its down to 11fps on my pc ,when i remove my AI it goes up to 112fps , its a too long for/next with 100 enemy.
Posted: 15th Oct 2011 12:50
Yeah, tried it on my laptop yesterday and it crawled. I'll have a good look tonight, see if I can claw back some fps.

Health, Ammo, and bacon and eggs!
Posted: 15th Oct 2011 15:00

added my version of asteroids and added if object inscreen to the cones , clawed back 6 or 7 fps , now runs on my pc at 17fps or so.
also made a few changes so the cones fire more often ect.
Posted: 15th Oct 2011 19:18
Cool, I was thinking about vertex modding the asteroids into more rock shapes, but I'll try that later.

I've changed everything to instanced objects, but I'm not sure how much of a performance gain that is. Also, added some space nebula .

Health, Ammo, and bacon and eggs!
Posted: 16th Oct 2011 01:52 Edited at: 16th Oct 2011 02:07
nice nebuli
im seeing a slight improvment sometimes up to 20 fps .
Im certain the beast is the lengthy for/next . Only solutions would be to have less ships but 100 isnt much I thought , or change the method , maybe some re-ordering might help but i cant see any obvious things to alter. its not the actual turn part with wrapvalues i took that out and ran with no change in fps so its what comes after there.

If you can make a nebula image then you could easily make simple textures id like to learn more about that . Im thinking some kind of texture like the nebula image ( or an electric sparky or flames image )scroling around a cube or cilinder attached to the underside of the cones would look cool and hide the gap in the cones geometry .

looking forward to your asteroid creation method , mine is just place holder, yours sound better already

could you make in in game ship designer out of the vertex thing you mentioned ? would be cool feature to design your ship somehow, or space stations or turrets . you spend points/resources per block and build the geometry from a 3dgrid adding cubes .The design could affect the stats of the finished ship .somehow.
have you ever played beyond protocol ? Its died now and is open source , anyway it had a very cool ship design and weapon design feature , the models were preset though,im thinking one step more.
Posted: 16th Oct 2011 13:07
Another little update, some planet textures, bad ones, but its a start.

Made the asteroids move and rotate as well. I was thinking that we could have the ships made from basic shapes, added as limbs, like in Evochron Mercenary (I think), you buy a bigger engine or bigger guns, then position them on the ship.
I think that there are too many enemies, if you start up then just leave it for a while, you get 100 enemies orbiting you!, maybe it only needs half of those, and just a dozen or so planets (like a solar system). I think that would be quite cool, each solar system could have randomly generated planets and enemies. Then the player has to wipe out a certain amount of enemies before moving to the next solar system, customizing their ship, buying more powerful weapons and engines. Also, would be really cool to destroy asteroids, big ones split into smaller ones, maybe leave some space credits to spend on your ship.

Health, Ammo, and bacon and eggs!
Posted: 17th Oct 2011 00:34 Edited at: 17th Oct 2011 02:09
Very nice , not bad far away but could use a higher res image closer up (as large as screen size should look fairly crisp right up to it).

Scale up the universe, the 100 planets become 100 stars ,no fogging , with a warp engine you could travel to the very distant stars when current system fully exploited/conquered.The solarsystem will load when its star is the closest one/hideing the last one.
Asteroid destruction and asteroid mining. I prefer the idea of collecting resources instead of credits.Perhaps refining them into building materials /or trade for credits at a space station or on planets.
Procedural asteroid fields aswell as some kind of random spaceparticle (like we have now which adds to the sensation of flying through otherwise empty space ) If there is a set pattern of asteroid field these could be destroyed ect and the game remembers not to draw that asteroid or how much resource has been gathered from it.
Enemy spawn in each solarsystem ther could be (upto) a certain number of Cone bases which churn out a constant number of ships
which could rally and attack your structures and planets or attack one by one depending on some random "director" , you must build defences to defend your spacestations (which you need to build things and refine) against a constant attack from the nearest cone base , which inturn will be defended with some cone structures , maybe you need to build a fleet of droid ships to help defeat the bases , you could give orders to the droids ,patrol , follow ,attack ,defend. Mining droids which go to asteroid fields you discover and mine and return with resources, you would have to defend the supply lines too .
theres a cool game in there ...breathes ...

i will test to find the highest number of enemy to stay avove 50 fps .

25 enemy i get 48 to 52 fps ! which leaves some fps to play with , bit disapointed with such a low number but atleast it still looks like a fleet .
Posted: 17th Oct 2011 10:30 Edited at: 17th Oct 2011 10:32
ive set out a basic structure to the universe ,added 1000 planets which are positioned near a random star, we now have sun nav and planet nav, planet nav will only show planets within solarsystem range planet nav +return , sun nav + shift
cones spawn at the closest sun.
Posted: 17th Oct 2011 21:45
while all the objects are being made before the main loop the load time is getting too long to test things so a way of making the distant planets only when needed would be alot better . Change the 1000 planets to 500 before you run it, that is more than enough really .Have a look see what you think .
Posted: 18th Oct 2011 12:03
Did i scare you away? Well I did say space Epic , i meant it lol..

a strange virus has wiped out 80% of the colonised universe . In the deluge a mysterious alien race has has moved in as the ancient human trade lines and space stations sit decaying in space .
What is left of civilisation lives on the planets now cut off from eachother , fearing the threat of the space virus re contaminating the population .
You wake up from statis sleep unaware of the demise of human civilisation , You are in your attack shuttle , a small craft with offencive capabilitys which also contains the statis pod , just part of the ensomble of the deepspace mining rig that you owned and worked on 150 years ago . The mothership ejected you in your sleep due to a malfunction , lucky , you drifted through space on the edges of cicilisation and beyond ,safe from the virus .
Now the enemy is closing in for the kill , to wipe out the last remnents of human life ! It has fallen on you to save the universe !
Using the equipment and resources avalable , you must rebuild the decaying space structures which once defended the universe , aquiring the use of larger facilitys to build more advanced systems which you will need to save each system and be able to travel on to the next .
So your drifting in space, you need to find your way back to your mining rig(a minni space station with refiner and limited fabrication capabilitys). then begin to collect resources to refine the materials needed to fix several structurers in space ,open up the mining routs to resupply the human colonists with remote automated droid mining craft (that you must build)perhaps finding alien tech along the way as you kill aliens ,then you need to collect resources to build a hyper drive for your craft (a one use warp of any distance) to get you to the next system .
Saving a system could benefit you in the future somehow perhaps supplying something you need to make more advanced robots and structures .

what do you think ?
Posted: 18th Oct 2011 14:19
Hehe not at all, just have to get some work done on my iOS game, I will get a look at this and get up to date tonight.

I like the plot so far tho, big fan of Aliens so the idea of waking up from cryostasis sounds great . I think we need to tidy up the source code a bit, otherwise things will get very complex before long.

Health, Ammo, and bacon and eggs!
Posted: 18th Oct 2011 16:02
Yes ,could try to just add things as seperate gosubs for each element . And we need an array for the universe creation ,the game will need to be saved and objects made and drawn as needed / where enemy spawn points are defeated/destroyed remembered ect.
an array for all player stuff , shiphp,resources,gameobjects,game time,?,?ect, and enemy array for the ai .
the first solarsystem could be pre set , the rest procedural(created the first time a game runs),enemy threat levels for each system could be the number of the star object(object 100 will have threat level 1% and should be the 1st system, object 200 will have the highest threat(100%) where the max ammount of enemy will be faced ,waves of 25 cones plus what ever other enemy we might create(some boss types ect). But the order of the next 99 stars is randomly placed(the game could stear you to the next threat level up or could leave it open ended and have the players luck decide the path , they might need to retreat from a high level until they can defeat it...or start again from the last save if the hyperdrive is a one use thing and retreat is not possible)
Posted: 18th Oct 2011 16:39 Edited at: 18th Oct 2011 21:25
The lack of media is getting to me , i just had to doodle , a diagram of game play attached

bundled the main loop into gosubs , added mouse wheel zoom,cut down number of planets to 250, running up to 45/50 fps .

#### Attachments

Posted: 19th Oct 2011 14:46 Edited at: 19th Oct 2011 15:12
Been thinking..again.. when you finnish a system and move to the next you set up a supply route and you could then get a steady boost of some resource from each finished system could just do it with numbers (boring!), Im thinking an actual vessle traveles between stars that delivers them , it would take 30 mins or so for it to travel but it would happen in real time and could endup getting attacked too . Anything to give the scale of the universe added layers .(which makes me think maybe you should eventually have free travel between stars ,or there is little point in having the awesome scale if its one way in one way out we may aswell make seperate levels, so it could be some tech you earn after a few systems are done the hard way "unlimited warp drive" .)
When you "die" your ship is lost but you are ejected in a pod which flys you back to the spacestation (in real time , enjoy the ride like the auto docking sequence in elite hehe ) pod could be a target which if killed you then die and need to start from the last save. you will need to rebuild your ship .
Posted: 20th Oct 2011 01:40
Sounds like you have a solid plan for this. I've added the vertex adjustment stuff for the asteroids, works pretty well, some nice rocky shapes now.

I've started on a library of texture creation tools, like animated particles, so we can make explosions and better planet textures. Maybe worth looking into a simple perlin noise system as well. But the main thing is I'll design it so that it's all just function calls, then it can be bolted on. Also I think that the direct draw plugin would be great, giving faster 2D lines and circles, plus smoother text, anti-aliasing, alpha, all that good stuff. Now that the asteroids have vertex mod stuff, I think it would be cool to add in some spaceship generation - like use a cube to make irregular shapes that are added as limbs, low poly spheres for cannopy's, that sort of thing. One cool possibility is that we could have the ships break apart when destroyed, because each bit would be stored as a mesh, we just have a bank of these meshes created as objects, then re-use them.

Health, Ammo, and bacon and eggs!
Posted: 20th Oct 2011 11:38
yea sorry, some ideas ive had swimming about in my head for years , Ive wanted to make an epic space game all along since i got dbp so years of thinking about what makes a space game great for me , Ive never strung the ideas together enough to make a full game but thats down to my limitations as a coder , though some of these specific ideas are just coming as i ponder about this project.

If you dont like any of my suggestions thats ok, thats all they are , ive just been typing as it comes. But , i know they are good ideas so im not shy hehe.

Interesting fact that i can't prove , CCP used some of my ideas for EVE , after some months of playing i met a dev ingame and discused several things with them. My ideas were to updaste drones so u have less (used to have 10 drones max ,v laggy i suggested 5 , 1 per skill level)and give them more power, difrent types of drone,ewar,sniper sentery drones ,jamming drones and attack drones. I also had an idea about a more luck influenced blueprint and creation method where the outcome of some of the blueprints was affected by skill and some luck resulting in a unique set of stats for the created item . a year later they had a major update with every single one of my ideas implimented .After the conversation with the dev ingame he did ask me if i wanted a job with ccp , i declined because id have had to move to iceland. (deeply wish i has accepted now though , circumstances at the time meant i couldnt move).But that year i got DBpro and became very interested in game design its all i want to do now .
So dont mind me , im seeing opportunity while its here, jumping at the chance to help create a very cool game with someone who knows his stuff . This game may be good enough to warrant making for real , and trying to sell.(dream hat on)
Posted: 20th Oct 2011 12:41
Wow, being a dev in Iceland would be pretty cool! - never know, maybe this game would be a good showcase if you wanted to try and get their interest.

But I know what you mean, I really like space environments, the atmosphere is really convincing with space games I think, maybe all those times I sat playing Elite on the spectrum wondering how the hell Braben did all that. I've always wanted to make a massive space game too, I even have a decent flight stick and VR headset (works with DBPro) B).

Health, Ammo, and bacon and eggs!
Posted: 20th Oct 2011 16:38
Quote: " One cool possibility is that we could have the ships break apart when destroyed, because each bit would be stored as a mesh, we just have a bank of these meshes created as objects, then re-use them."

Yea nice , if we have weapons as items or any equipment it could have a visual representation in the debris, some could be salvaged . If they are joined as limbs then its a simple case of scaling the limb offset for a nice explosion sequence(no gravity in space to make things more complicated)

texture creation tools sounds cool, I have plenty of time on my hands so i could use tools . Will it be a standalone app ? With a compiler in game kinda thing so you can design textures for anything and with a plug in use them in any game ? That would be a neat tool for the community .Same with the model builder .

Large asteroids would be more rounded due to gravity (for mineable asteroid fields), would craters and surphace features be a streatch too far? (textures would do i guess)

Weapons attached to the ship could aim and point to the cursor that is restricted , so the guns could fire and be accurate without lining up with the center cursor . If were mounting weapons it would be nice to see them move about . So then with the extra aim on guns and the line up with center missile we have a nice tidy combat system .
Posted: 21st Oct 2011 06:10 Edited at: 21st Oct 2011 06:11
Im having a go at the universe arrays and mineable asteroid field positions, something is wrong with it i cant figure out what right now , i will find it tomorow unless you get a chance to have a look b4 then . Its almost there
Posted: 21st Oct 2011 22:46 Edited at: 23rd Oct 2011 15:20
lol , found the problem ,the array was fine i just forgot to add the asteroid field position to the sun position .

minni version
edit: we need a better way to save the individual asteroid coords , there could be upto 30000 positions and other variables too. How about saving a text file and reading it as needed?
Posted: 25th Oct 2011 20:14

all ive done here is play about with the scale of the minni version . Still stuck on the individual positions .
Posted: 25th Oct 2011 22:15 Edited at: 27th Oct 2011 07:31
i guess it doesnt matter so much about unique positions, so this version uses the same position relative to the field center each time instead of a random position relative to the field center.(so in effect (field 1/sun 100) will be identical to (field 1 /sun 150)but the field itself will have a unique position ,ect)
arrowkeys move

colored suns and light

I may aswell keep the minni version going till the load/save bit is done then add the other stuff to it .

what are your 5 fave space games?
heres mine...
elite : the master of all space games
starglider : I played this on my old AtariST 520 awesome game where you flew seemlessly from planet into space with freedom of one whole solarsystem ,isometric 3d graphics
freelancer : the first game to offer a scale of universe to better that of elite , online too
eve online ; first proper space mmo , jaw dropping scale and graphics ,the culmination of all the good things
beyond protocol ; 3d mmo rts ,build fleets control solarsystems, build colonies , war on planet and in space , amazing research tree and a very indepth unit design aspects .
like the saying goes , theres not much that hasnt been done before , but i say there STILL isnt one that does it ALL
Posted: 27th Oct 2011 10:51
Yeah, makes sense to make sure your happy with it before adding it to the game proper. I should get some more time this weekend to work on the random ships and textures.

Fave space games...

1.Elite
2.Evochron Mercenary
3.Frontier
4.Star Wars Battlefront2 (the space battles are damn good fun in multiplayer)
5.Star Wars (vector based arcade cabinet)

I never got into Eve, or any of the more strategic space games - I mostly like sandbox style games, like Elite and Evochron - or epic space battles.

Health, Ammo, and bacon and eggs!
Posted: 27th Oct 2011 21:13 Edited at: 27th Oct 2011 21:15
Ok, i have to say i agree to the sandbox style game , even games with structure i try to play in a sandbox way (pure escapism) so lets scrap the restricting story for now and focus on making cool things to do in our universe, wiping out the population in space would lead to a very solitery feeling and trade ect becomes pointless . We can weave a story in later.
a universe buisy with npc's about their random busness would be cool .
Posted: 28th Oct 2011 11:04 Edited at: 28th Oct 2011 11:09
sneaky peek .. everything but the ai , justs needs the save function adding and the ai . Will do that next . Ive added a dead center to aid long journeys.And an fps based timer and when the navs are inactive they flicker on and off (mainly to make sure that the objects are dreawn when you change solarsystem but i like the effect with the text part still in there , for now.
I notice one thing i cant figure out , the object lighting doesnt line up with the light position . The light is positioned at the closest sun but the shadow side of the planets and asteroids does not coincide .
its looking quite nice now

Posted: 29th Oct 2011 14:12
lol what wasnt i thinking.. now the astF positions are unique so now im happy... And the array is saved or loaded too .. oh and i fixed the lighting issue , that pesky light (0) doesnt do what its told , light 1 works as intended.

I hate arrays , thats why i gave it a go i need practice . They get all convoluted easily and i find it hard to visualise what im doing with them , then i miss completly obvious stuff (laughs insanely!).

next i want to have a go at some traffic npc's (with less cpu demand than the enemy cone ai, i have a plan to use the rotating or turning in a very limited way for the space traffic)