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.

DarkBASIC Professional Discussion / help with a 2d space game

Author
Message
TheMeq
13
Years of Service
User Offline
Joined: 5th Sep 2012
Location: Nottingham
Posted: 13th Sep 2012 00:04
Hello. I'm having a really hard time trying to figure out how I can do this.

In my code, I have a spaceship in the center of the screen which faces the position of the mouse.

At first, I had it so that the backdrop would move reverse of the position of the mouse, so if the mouse was in the top left, the backdrop would move towards the bottom right. It would move at the speed of how far away the mouse was from the center. This caused a few inconsistencies with the positioning of the backdrop and also it seemed hard to keep the X & Y position of the ship (say if this was to become multiplayer which is my plan eventually).

Secondly, I had it so that the ship just faced in the direction of the mouse and the arrow keys moved the backdrop around, this worked relatively well, apart from the movement didn't look natural.

My final idea is so that the spacebar raises the speed of the ship and it will fly towards the mouse. This way if the mouse moves, the ship still has to turn around more naturally to start heading towards the mouse.

Now I know this really doesn't have anything to do with the ship, as all it does is rotate in the center of the screen, it's mainlt to do with the backdrop and keeping the players relative X & Y position.

What do you think would be the best method of doing this? I'm really scratching my head about it.




Is all I really have at the moment. I just can't figure out what to do next...

Help!

Thanks

10 PRINT "Hello World"
20 GOTO 10
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 15th Sep 2012 03:04
Have you thought about texturing a plane object with the background and then scrolling the texture (or altering the UV coords), that shouldn't give you any problems with inconsistencies.

New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 15th Sep 2012 09:58 Edited at: 15th Sep 2012 10:00
are you doing making this in 2d or 3d (i understand it's top down, but even that cooould be easier to make in 3d)? And if 2d-do you have a tile system? because if you don't then you will have issues when you try to fly out of the area that is covered by your background image...

I would make it in 3d and use either 3d models or plains textured with the ships (with transparency). The advantages would be the follwoing:
- you could actually and easily fly around in the x and z axis. Positioning the camera over the player's ship and looking down at it ensures that you both have actual x and z coordinates AND always have the ship at the center of the screen (or move the camera around for cutscenes etc)
- you could have one big textured plain covering the entire screen below the ship, ALWAYS MOVING along with the ship, so that it seems to remain static on screen: that's because extremely far away nebulae and stars wouldn't appear to move very much if you fly around in space.
- you could add small dust particles or whatever in different heights (y axis) which then automatically move around on the screen and give the impression of flight.

The thing about movement: You need to consider what kind of physics you want. Do you want friction? This would be unrealistic, but most space shooters have some kind of friction that automatically slows the ships down when they dont have their thrusters on.. Makes gameplay a bit more familiar and easeier, I think...


I recently made a (fairly) simple code demo for sb else on the foruma and expanded it a bit...

Note that it doesn't have any physics, really... all ships move by default in the direction they are pointing (control with arrow-keys, afterburners with shift, shoot with space).
A better system of physics would be something along the lines of (pseudo code, won't actually work like this):


so here's my example demo.. i stopped documenting the controls at some point, unfortunately maybe it'll help a bit anywhow..)



hope this helped a bit.

[EDIT: Note, all of this can ofcourse also be done completely in 2d. I just like to use 3d.. it's all personal preference I guess..]
TheMeq
13
Years of Service
User Offline
Joined: 5th Sep 2012
Location: Nottingham
Posted: 17th Sep 2012 02:50
I managed to solve this using the following code:



Thanks for your help

10 PRINT "Hello World"
20 GOTO 10

Login to post a reply

Server time is: 2026-07-08 10:16:17
Your offset time is: 2026-07-08 10:16:17