The Ur-Quan Masters Home Page Welcome, Guest. Please login or register.
Did you miss your activation email?
December 10, 2024, 12:18:17 pm
Home Help Search Login Register
News: Celebrating 30 years of Star Control 2 - The Ur-Quan Masters

+  The Ur-Quan Masters Discussion Forum
|-+  The Ur-Quan Masters Re-Release
| |-+  General UQM Discussion (Moderator: Death 999)
| | |-+  Asteroid Melee
« previous next »
Pages: [1] 2 Print
Author Topic: Asteroid Melee  (Read 5482 times)
harth1026
*Many bubbles*
***
Offline Offline

Gender: Male
Posts: 142



View Profile WWW
Asteroid Melee
« on: July 29, 2005, 09:33:55 pm »

In my quest to add an SC1-style tactical campaign to UQM, I have made a wrong turn and ended up making something different.  This new thing I'm making doesn't not use any UQM code as I started it from scratch.  Currently, there is no music, no sounds, no AI controls, and the graphics suck.  But the framework for the combat engine is pretty much complete which I believe was the toughest part for me to figure out.  Although, putting in the AI sounds like it'll be fun.  The idea is simple, take Star Control's Melee mode and add environmental obstacles.  Lots of asteroids that do damage on contact, nebulas that have random effects on ships and weapons, debris from destroyed ships, etc.  And of course, the other ship that's trying to kill you.

Now I'm adding in some ships.  In the tradition of Star Control, I want a lot of ships, I want them to all be unique, I want them all to be fun to use, and I want each one to have a chance at being someone's favorite.  That being said, I want your opinion on what kind of ship you would like to see in a game like this.
Logged
Elerium
Guest


Email
Re: Asteroid Melee
« Reply #1 on: July 29, 2005, 09:40:55 pm »

We, and possibly many others would agree that we should have, and this would be a really good thing to have, if we had a...

Taalo Ship Wink

(Based on the artwork that someone did)
Logged
Mr._Jiggles
*Many bubbles*
***
Offline Offline

Gender: Male
Posts: 208


Get Down!


View Profile
Re: Asteroid Melee
« Reply #2 on: July 30, 2005, 01:24:01 am »

The orz in their actual true form  Cheesy
Logged
Dean
Guest


Email
Re: Asteroid Melee
« Reply #3 on: July 30, 2005, 01:00:36 pm »

Harth, willing to share the source? I'm making a new SC from scratch too, and the only thing I can't figure out is the damn vector addition physics (if your travelling in one direction and turn&thrust in another, the ship should slowly change direction).

Also, could I nick some of the graphics for my own game? I'll share the code of mine with everyone once it's done, don't worry Wink.

- Dean
Logged
Arne
Enlightened
*****
Offline Offline

Gender: Male
Posts: 520


Yak!


View Profile WWW
Re: Asteroid Melee
« Reply #4 on: July 30, 2005, 04:35:52 pm »

Dean, I think a (quick and dirty) vector thrust system would work like this:

Code:
if thrusting
  xAdd=xAdd+sin(shipAngle)*enginePower
  yAdd=yAdd+-cos(shipAngle)*enginePower
end if

// Add friction
xAdd=xAdd*0.99
yAdd=yAdd*0.99

// Add to ship position
xPos=xPos+xAdd
yPos=yPos+yAdd


Making sinus and cosinus array tables will speed things up a tad, but it also means you have to worry more about staying inside the array etc. It could also be cool to use acceleration for turning the ship.

If you want the friction to be more accurate the shape of the ship will have to be checked. A long ship will be harder to spin than a spherical ship I guess. Also, if you spin a long ship 90 degrees it will braodside the air and slow in faster than if it's going with the spear tip forward.
Logged
Dean
Guest


Email
Re: Asteroid Melee
« Reply #5 on: July 30, 2005, 05:10:51 pm »

Arne, can I nick you art for the moment?

As for the code, believe me i've spent a lot of time figuring things out. Being 16 years old does has it's drawbacks with limited physics knowege! I've already added that, the problem is:

Say you thrust at a 45 degree angle from "north". Your ship is travelling north at MAX_ACCELERATION. You then turn to 180 degrees and hold the thrust button again. I need to figure out how to make the ship turn correctly via vector addition.

Incidentally, the sin/cos/tan tripped me up for a day....until I realised the &^%& computer wanted the degrees in RADIANS. I can give you a VERY crude demo of what i've done Arne if you want to see - believe me it's certainly not much from the end-user point of view but i've spent ages getting all the engine to work right.

- Dean
Logged
meep-eep
Forum Admin
Enlightened
*****
Offline Offline

Posts: 2847



View Profile
Re: Asteroid Melee
« Reply #6 on: July 30, 2005, 06:29:40 pm »

There are a few different concepts you need to incorporate:
position (x): just the coordinates of the object
speed (v): the speed the object is travelling in
acceleration (a): speed increase per time unit
force (F): the force that is excerted on the object.
Each of these are vectors.
There's also the mass (m) of the object (which is a scalar, not a vector).

Each cycle you update these like this:
a = F * m
v += a * delta_time
x += v * delta_time
delta_time is the number of time units since the last update.

In SC2/UQM the speed you can get to through your trusters is capped, and there's also an absolute maximum that you cannot get past by through gravity whipping.

You'll use the direction to determine the force vector. You can take the direction as a vector with length 1 and multiply it by a force determined by the engine strength for instance.
(You can calculate the direction vector in 2 dimensions from the angle: (x, y) = (cos(alpha), sin(alpha)) )
The simplest way to add rotation to this (the way SC2/UQM does it) is by taking a constant angle, multiplying that by the delta_time, and add that to your old angle. In SC2, this angle is capped by the maximum turning rate for the object. For more natural turning rate, you'd need to do something similar to the movement, so that the ship has a turning velocity. The formulas for that are slightly more difficult, and I'd have to look them up (or try to reconstruct them from).

« Last Edit: July 30, 2005, 06:33:20 pm by meep-eep » Logged

“When Juffo-Wup is complete
when at last there is no Void, no Non
when the Creators return
then we can finally rest.”
Dean
Guest


Email
Re: Asteroid Melee
« Reply #7 on: July 30, 2005, 06:34:51 pm »

(Insert bug-eyed smiley here). Well, i've got most of that already, though not one-after-another like that. All's peachy, cept for the two vectors. I think I have a cheapo's way out of doing that, but I'm after a more elegant solution. If anyone wants to take a look at my code and make suggestions, i'll post it. Just be gentle if it's crap.

- Dean
Logged
Dean
Guest


Email
Re: Asteroid Melee
« Reply #8 on: July 30, 2005, 06:41:34 pm »

Ok, source at http://home.pacific.net.au/~sthelena/General/src.zip. I haven't included any of the libraries or images because they're unimportant at the moment. Arne, you're creditied in the intro for the moment cause i've nicked a ship pic as a test. Comments welcome.

- Dean
Logged
meep-eep
Forum Admin
Enlightened
*****
Offline Offline

Posts: 2847



View Profile
Re: Asteroid Melee
« Reply #9 on: July 30, 2005, 07:19:23 pm »

I've got no specific remarks regarding the physics (I'm not quite sure what you're doing), but I've got some general coding remarks:
Calling something "VECT" which isn't a vector is confusing.
Making the coordinates dependant on the zoom level is a bad idea. You should just use absolute coordinates, which are used everywhere, and afterwards transform them for your zoom level. It simplifies your code, and it makes the backend independant of the representation.
I suggest you either rename your .cpp files to .c, or start using the C++ features. Using classes for vectors etc. could clean up your code a lot.
You don't have to specify characters as a number. You can an exclamation mark as '!' (with the single quotes included). That makes some parts of your code self-documenting.
While inline documentation is good, don't comment obvious things. Superfluous comments just cost your time, and the time of the reader of the code (who will expect comments to add something, and hence be worth reading). It will only make the important comments less obvious.
Use "const" whenever a function argument is not supposed to be changed by the function. That way the compiler can help you find some type of bugs.

Btw, a good resource for game math and physics is http://www.gamedev.net/reference/list.asp?categoryid=28
Logged

“When Juffo-Wup is complete
when at last there is no Void, no Non
when the Creators return
then we can finally rest.”
Arne
Enlightened
*****
Offline Offline

Gender: Male
Posts: 520


Yak!


View Profile WWW
Re: Asteroid Melee
« Reply #10 on: July 31, 2005, 04:42:09 am »

Hehe, I'm not much of a coder, but the code I wrote should work for gradually altering the speed of the ship. I use it in my Asteroids clone and a lot of games. It does not use maxSpeed. enginePower and Friction weighs the max speed limit naturally. Listen to meep-eep though, he's a real coder. Using delta_time is a good idea.

Now I'm not sure what you mean. You mentioned turning so... If you want to find out the difference between two angles, and the direction in which to turn, this function will work as long as the angles are 0 to <360
Code:
; ----------------------------------------------------------------
; Calculate the difference between 2 angles and direction
; Stores in rotate_dir (-1 or 1) and diff_ang (abs 0 to 180)
; ----------------------------------------------------------------
Function rotate_check(source_ang,dest_ang)

If source_ang<>dest_ang
  diff_ang = Abs(source_ang - dest_ang) : rotate_dir=1 ;// Get absolute diff between angles. Set rotation angle to CW.
  If diff_ang > 180 : rotate_dir=-rotate_dir : diff_ang = diff_ang-180 : EndIf
  If source_ang > dest_ang : rotate_dir=-rotate_dir : EndIf
EndIf

End Function


; ----------------------------------------------------------------
; Make sure angles are =>0 and <360
; ----------------------------------------------------------------
Function angle_cap1(ang#)
ang=ang Mod(360)
If ang<0 Then ang=360+ang
capang=ang#  ; uh... this is probably a transfer to a global variable rather than using return()
End Function


; ----------------------------------------------------------------
; Calculate sprite frame 0-15 (up is 0-11.25 to 11.25)
; ----------------------------------------------------------------
Function spriteframe(ang#)
ang=ang+11.25
ang=ang Mod(360)
If ang<0 Then ang=360+ang

Return (Floor(ang/22.5))
End Function

Btw. this is written in BASIC syntax, and it's not optimized. I used this code for a kid icarus clone where you aim with the mouse, like in Soldat etc.
( ; = // )

If you want to find out the angle when you have x,y vectors, use Atan or Atan2

Logged
Dean
Guest


Email
Re: Asteroid Melee
« Reply #11 on: July 31, 2005, 05:02:26 am »

Thanks both of you for your replies.

Arne, I know BASIC quite well (I'm a VB and C programmer) so what you wrote makes sense. Apparently i've go about the physics the wrong way; it works so far but I want to get it right. In any case, i'll spend this week getting all the physics - and placement - code right.

Meep-meep, thanks for the link. I've actually been doing vector physics in, well, physics class for the past two weeks so what you said made sense.

Ok, ignoring the physics for the moment. Wht about the rest of the code. Is wiriting an generic engine which calls the routines of the selected ship (via function pointers) a good idea? It allows me a LOT of flexibility, because that way all the code to make a ship behave in a non-standard way is only in the ship file rather than the engine.

I'm aware that consts can be used for both values and ASCII characters, after all ASCII is a char number. Where have I used a number instead of a character assignment? The const is a good idea, kudos.

And yes, I'll need to change the "int"s to "short"s for all you folk with wierd int sizes to prevent memory wastage. I'm using the world's slowest IDE (C++.net), which spares me the agony of having to continuously alter the makefile) which is why all my files are .cpp. This will be fixed in the release.


You lot've been suprisingly gentle. This is my first attempt at a proper game and I was expecting a lot more harsh comments. In any case, it's all helping me to refine my techniques.

- Dean
Logged
Arne
Enlightened
*****
Offline Offline

Gender: Male
Posts: 520


Yak!


View Profile WWW
Re: Asteroid Melee
« Reply #12 on: July 31, 2005, 06:59:39 am »

Ian Bell has some pages on vector stuff here.
Logged
meep-eep
Forum Admin
Enlightened
*****
Offline Offline

Posts: 2847



View Profile
Re: Asteroid Melee
« Reply #13 on: July 31, 2005, 03:21:39 pm »

Ok, ignoring the physics for the moment. Wht about the rest of the code. Is wiriting an generic engine which calls the routines of the selected ship (via function pointers) a good idea? It allows me a LOT of flexibility, because that way all the code to make a ship behave in a non-standard way is only in the ship file rather than the engine.
That's a good way to design code in general, making a general engine, and keep the specifics separate. Function pointers will keep things clear, and I use them often myself in C, but there are other ways. In C++ you could use virtual methods. They may be slower though, so you don't want them in time critical code.

Quote
I'm aware that consts can be used for both values and ASCII characters, after all ASCII is a char number. Where have I used a number instead of a character assignment?
"consts can be used for both values and ASCII characters"? You lost me there. Anyhow, what I meant was statements like this (from images.cpp):
     case 33: // "!"
You could have just put
     case '!':
there. The same goes for
    if (Text[Pos] > 96)
which could be
    if (Text[Pos] >= 'a')
Self documenting code.

Quote
And yes, I'll need to change the "int"s to "short"s for all you folk with wierd int sizes to prevent memory wastage.
Actually, chances are that the same amount of memory will be used for shorts if you compile for speed. Unless you're using a great number of them, I wouldn't worry about them on today's systems.

Quote
You lot've been suprisingly gentle. This is my first attempt at a proper game and I was expecting a lot more harsh comments. In any case, it's all helping me to refine my techniques.
From what I've seen, you are on the right track. Ofcourse I have only been browsing the code.

I've seen a couple of coding style issues too, but I didn't mention them because everyone develops his own style. But there's one that almost everyone will do after a while, so let me comment on that one:
    if (something) return;
is a lot less readable than
    if (something)
        return;
The latter will allow you to browse through the code a lot faster.

Another one that a lot (but not all) experienced coders will do: always put the name of the function on the first line in function definitions. It will help you find your functions a lot quicker if you're browsing through your code. So instead of
    static unsigned int *doSomething(void) {
        ....
You do
    static unsigned int *
    doSomething(void) {
        ....

Logged

“When Juffo-Wup is complete
when at last there is no Void, no Non
when the Creators return
then we can finally rest.”
Blackarz
Zebranky food
*
Offline Offline

Posts: 1



View Profile
Re: Asteroid Melee
« Reply #14 on: July 31, 2005, 05:00:06 pm »

why doesn't soomeone make a mod for UQM. It could be the Star Wars mod?
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!