ok, first of all
thrump: yay i think i understand how to get that working, seems pretty simple after all
to the third from last anon: thx, that did help a bit, i realised it would help if i was recalculating everything each time a frame passed.
to everyone who said something about mistakes in my code, or somewhere where i could have left this out or done that instead:
i was just playing around with different values for everything, it was not final
so i''ve pretty much fixed question 1 by using constant values for velocity and acceleration and then recalculating how much to move by each frame, worked out question 2 by using what thrump said, but i have no idea how to implement a linked-list.
so if anyone knows of sites, tutorials, anything, i would be grateful
a few questions on 2d side scroller...
quote: Original post by Antknei
I believe that you are right Anonymous that there was an attempt to make a better integrator in Ksero''s post, but his code snippet is not correct.
Yeah... It was, but I read it some time ago... So I''m probably remembering incorrectly. How should it have been? Like one of the anonymous posters said?:
if(jumping){for (i = 0, newtimestep = timestep/4; i < 4; i++) {Yposition += newtimestep * Yvelocity;Yvelocity += newtimestep * Yacceleration;}
Linked lists are hard to wrap your head around at first. Pictures really, really help. (then when your really good, you can draw the pictures in your head )
Anyway, here''s a big site on programming C. I''m sure you''ll find it in there somewhere.
http://www.cs.cf.ac.uk/Dave/C/CE.html
Anyway, here''s a big site on programming C. I''m sure you''ll find it in there somewhere.
http://www.cs.cf.ac.uk/Dave/C/CE.html
Sorry, I guess you''re programming in C++, so you may want to use new/delete. I''ve never done an implementation with those (although it should be a tiny bit easier).
(are there any linked lists built into C++? I don''t know, I haven''t done much with it. I think there is for Java, but then it has a very extensive SDK.)
Anyway, you''re bound to find a tutorial on C++ with linked lists in it. But if not, can somebody else help him out?
(are there any linked lists built into C++? I don''t know, I haven''t done much with it. I think there is for Java, but then it has a very extensive SDK.)
Anyway, you''re bound to find a tutorial on C++ with linked lists in it. But if not, can somebody else help him out?
I have written a short document about integrating the gravity correctly so that it would no longer be an approximation (like it is in Quake games, for example).
CLICK HERE to read it!
So this is an approximation:
But this is the exact formula and even faster to calculate:
-Hans {home page} {e-mail}
Edited by - Hans on September 19, 2000 11:08:37 AM
CLICK HERE to read it!
So this is an approximation:
if(jumping){for (i = 0, newtimestep = timestep/4; i < 4; i++){Yposition += newtimestep * Yvelocity;Yvelocity += newtimestep * Yacceleration;}
But this is the exact formula and even faster to calculate:
if(jumping){Yvelocity += newtimestep * Yacceleration / 2;Yposition += newtimestep * Yvelocity;Yvelocity += newtimestep * Yacceleration / 2;}
-Hans {home page} {e-mail}
Edited by - Hans on September 19, 2000 11:08:37 AM
Ksero, I am sorry that I said that your code snippet was incorrect. I was just misreading it. You know how the eyes can get fuzzy when you glance at code?
Anyway, if you are going to break up the time segment into pieces, why not go all out and make an adaptive time step routine?
Here you would use the original time step in a frame, do the calculations and see where it gets you, then cut the time step in half and redo the calculation and compare it to the first calculation. If the error is greater then some error value, cut the time step in half again and recalculate. You can go into more details and calculate the error in each segment that just got divided or you can just calculate the final error. If you have just gravity at work you should be able to just look at the final value.
Anyway, if you are going to break up the time segment into pieces, why not go all out and make an adaptive time step routine?
Here you would use the original time step in a frame, do the calculations and see where it gets you, then cut the time step in half and redo the calculation and compare it to the first calculation. If the error is greater then some error value, cut the time step in half again and recalculate. You can go into more details and calculate the error in each segment that just got divided or you can just calculate the final error. If you have just gravity at work you should be able to just look at the final value.
Here's how you would make a linked list in C++.
It's a little long, so bear with me
Reading the list is also easy.
All you do is make a pointer to the head of the list.
And go through the items.
ECF_LINKED_LIST *temp = Head;
and you go through the list:
while (temp != NULL) // While it's not the end of the list
{
temp = temp->next; // go to next item
}
EDIT: Forgot to mention, remember to: delete node; at the end of your app. Otherwise you will have a nice little memory leak
- Goblineye Entertainment
The road to success is always under construction
Edited by - Tornado on September 20, 2000 5:58:25 AM
It's a little long, so bear with me
typdef struct LINKED_LIST_TYPE // this is the structure that we are going to use{ int x,y; // This is the data of this structure LINKED_LIST_TYPE *next; // This pointer points to the next item in list} LINKED_LIST;LINKED_LIST *Head=NULL; // This is the head of our listLINKED_LIST *Tail=NULL; // This is the tail of our listint Add_Item(void) // Let's add an item!{node = new LINKED_LIST; // We allocate room for this itemnode->x = x; // put some value in herenode->y = y; // ""node->next = NULL; // Make the pointer to the next item as NULL for nowif (Head == NULL) // If the item is empty { Head = Tail = node; // Life is easy, just add it in first return(1); }else if ((Head != NULL) && (Head == Tail)) // We got 1 item in there { Head->next = node; // Add the item as second Tail = node; // Update the tail return(1); }else // We got more than 2 items { Tail->next = node; // Make the next item in tail point to this item Tail = node; // Make the tail point to this item return(1); } return(1);}int Remove_Item(int x,int y){LINKED_LIST *curr_ptr = Head, // Make pointer to list *prev_ptr = Head;if (Head == NULL) // If the list is empty return(-1); while (1) // Here we go through the list{if ((x >= curr_ptr->x) && (x <= curr_ptr->x) && (y >= curr_ptr->y) && (y <= curr_ptr->y)) break; // If this is the item we want to delete prev_ptr = curr_ptr; curr_ptr = curr_ptr->next; if (curr_ptr == NULL) break;}if (curr_ptr == NULL) // If it's the end of the list and item was not found return(-1);if (Head==Tail) // If it's the only item in list Head=Tail=NULL; // zero out listelse if (curr_ptr == Head)Head=Head->next;else if (curr_ptr == Tail){ prev_ptr->next = NULL; Tail = prev_ptr; }else prev_ptr->next = curr_ptr->next; return(1);}
Reading the list is also easy.
All you do is make a pointer to the head of the list.
And go through the items.
ECF_LINKED_LIST *temp = Head;
and you go through the list:
while (temp != NULL) // While it's not the end of the list
{
temp = temp->next; // go to next item
}
EDIT: Forgot to mention, remember to: delete node; at the end of your app. Otherwise you will have a nice little memory leak
- Goblineye Entertainment
The road to success is always under construction
Edited by - Tornado on September 20, 2000 5:58:25 AM
Goblineye EntertainmentThe road to success is always under construction
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement