|
Post by Tedmilk on Dec 6, 2007 13:46:50 GMT
Hello everyone, this is my first post here. I've been a massive Tyrian fan ever since I first played the demo on a PC Format coverdisk all those years ago.
Like many, I have a flash project on the go. While I am not seeking to 'port' tyrian to flash, I am currently using it's art assets until I have my engine finished. Since I have been teaching myself actionscript up to this point, and after noticing that Tyrian is opensource, I decided to take a peek at the code to try and figure out how certain things are done in the engine to help with my own code.
However, after scouring the files for hours there are some things I either don't understand or can't find reference to in the code, namely:
How player movement is calculated How enemies are added/removed from an array
and the one that's really been baking my noggin:
HOW are the turning animations for the player ship calculated?
That is, how does the game determine when to change the sprite?
If any of you excellent porters could help me out, that'd be fantastic. I will try to do my part with regards to bug reporting.
And finally, WELL DONE on your work so far - you are all brilliant!
Cheers
|
|
|
Post by yuriks on Dec 6, 2007 16:23:04 GMT
First: Don't look at the Tyrian source if you want any coding examples. Please, don't. It's a mess. Second: All you asked is obvious, just think for a while.
|
|
|
Post by Tedmilk on Dec 6, 2007 17:45:08 GMT
Thanks for replying. I know they should seem obvious to me (I'm at least intelligent enough to implement an A* algorithm from a tutorial), but I just can't grasp the concepts.
Ship turning animations, for example. Now I know it's easy to say "if the player presses left, show the 'left' sprite), but what about when there are two frames for each direction as with Tyrian? The frames also change far slower than Tyrian's global framerate, which surely means there's something to do with the duration of the keypress...
Any help? Oh, and I was in super arcade mode on Opentyrian and found that if you destroy some bosses prematurely (The big brain on gyges comes to mind), the level will scroll indefinately and you won't be able to finish it. If you know about this one, sorry!
|
|
|
Post by Mindless on Dec 6, 2007 21:19:10 GMT
for the ship movement, implement velocity, acceleration and movement resistance. the ship's velocity determines the frame that's displayed, the keypresses cause acceleration, and resistance to cause the ship to slow down when the keys have been released
|
|
|
Post by Tedmilk on Dec 6, 2007 21:41:14 GMT
Hey, thanks! I think I understand - is that how it's done in Tyrian? So far I've been using an inertia variable, along with additional x & y coordinates to make the ship 'follow' what would otherwise be strictly digital control (like the sideships follow your own ship in the game).
The only problem I've been having is that when reaching the edges of the screen, the ship will slow down and stop at the edge, rather than flying fullspeed to the edge and then stopping.
I think I've got it working nicely now though. Thanks fine fellows!
Now about that turning animation math.... ;-)
|
|
|
Post by Mindless on Dec 6, 2007 22:23:57 GMT
you'll find all the math you could ever need in JE_playerMovement() ... if you can figure out what's going on ;P
|
|
|
Post by Tedmilk on Dec 6, 2007 22:36:31 GMT
Hehe ... I'll search for that and see what I can see!
Thanks for all your help! I can appreciate how dull it must be when people come on here asking for programming tips.
|
|
|
Post by yuriks on Dec 7, 2007 1:19:20 GMT
And I'm sorry for being so unhelpful at times. =P
Yeah, for the ship frames, you basically check, if the velocity is above some threshold, display frame 2, if not frame 1, and if the ship is stopped, frame 0 (or something similar).
For enemies, you should probably use a linked list instead.
|
|
|
Post by Tedmilk on Dec 7, 2007 13:33:05 GMT
It's OK - you're doing a great job! And hey, it's voluntary... we're all lucky to have you all porting Tyrian and helping us out.
I'd figured the turning animations were probably done in a way such as that. The only dificulty comes when trying to incorprate it when your method of moving the ship is different. I'll keep at it though!
I don't believe I've heard of a 'linked list' before... care to elaborate on the principle? Thanks!
|
|
|
Post by yuriks on Dec 7, 2007 16:10:13 GMT
It's a pretty... very common concept. I suggest you Google or read Wikipedia a bit.
|
|
|
Post by Tedmilk on Dec 7, 2007 19:27:26 GMT
Ahh... maybe it's a technique not used much by inexperienced Flash programmers! I've researched it now though, and I think I get it.
A double-linked list, using enemies' movie clip instances as nodes, each containing two variables to specify their neighbouring nodes? I'm beginning to see the benefits now - simplicity, and speedier adding/removing of bad guys.
Cheers! I'll have a go at implementing this tonight.
|
|
|
Post by Tedmilk on Dec 10, 2007 14:07:04 GMT
OK, since my last post I've been pulling my hair out trying to get a linked list to work. I'd love some help - if someone can tell me what's wrong with the code below I'd really appreciate it. Basically, once the first enemy is removed, enemies created thereafter are set as the head AND the tail, and enemies created before the first one is removed are ignored. function newEnemy(link,q,a) { //Creates a head node if it's first, or adds a tail node to the end of the list var e = id(); if (!h) { h = t = attachMovie(link,"e" + e, e); } else { t.next = attachMovie(link,"e" + e, e); m = t; t = t.next; t.prev = m; } t._x = q; t._y = a; }
function killEnemy(r) { if (h = r) { h = r.next; if (h = t) { trace(h); delete h,t; } } else { r.prev.next = r.next; } if (t = r) { t = r.prev; if (t = h) { delete h,t; } } else { r.next.prev = r.prev; } removeMovieClip(r); } ----------------------------- If this is too off-topic, can anyone suggest an appropriate forum? Thanks guys! Edit by Mindless: code box
|
|
|
Post by Mindless on Dec 10, 2007 22:55:50 GMT
it'd be helpful to have more detailed variable names, I can't figure out what's going on
|
|
|
Post by Tedmilk on Dec 11, 2007 16:14:31 GMT
Sorry! It's quite simple really (except that it doesn't work!)...
h is a reference to the head node, t is a reference to the tail node. id() just saves a sequential number in the 'e' variable (at the beginning there) for attaching the enemy movieclip.
Each movieclip has a 'next' and 'prev' variable containing its adjacent nodes (at least, it's supposed to!).
Thanks for helping... I STILL can't figure out what's wrong with it!
|
|
|
Post by Mindless on Dec 11, 2007 19:17:45 GMT
does flash use == for comparison?
|
|