void CPlayer::Jump()
{
if((KEY_DOWN(KEY_JUMP)) && (this->YPos==this->GroundLevel))
{
this->YVel = 150 * Clock.FrameTime/100;
this->Acceleration = 10 * Clock.FrameTime/100;
this->Jumping = 1;
}
if (this->Jumping==1)
{
this->Acceleration = 10 * Clock.FrameTime/100;
this->YVel -= this->Acceleration;
this->YPos -= this->YVel;
}
if (this->YPos >= this->GroundLevel)
{
this->YPos = this->GroundLevel;
this->Jumping = 0;
}
}
is there any way i could round off the velocity and acceleration, so they would be pretty much the same with each call?
or what?
ok, 2nd question:
im currently just drawing one screen at a time, comprised of 20x13 tiles
my question:
how should i keep track of where i am on the map, so i know where to draw, and how do i implement smoothe scrolling?
i could just update which tile to start at, but that would move in jolts of 32 pixels (1 tile = 32 pixels wide)
and question # 3:
how should i keep track of all the enemies on the screen?
if i have a class CEnemy should i just create an array of enemies and then draw whatever ones i need to, or should i use new and delete to dynamically allocate enemies when they are located on the map
if anyone could answer any of these questions at all, i would be extremely happy
i hope i made them all clear enough, tell me if you dont understand any of the questions...
thx
a few questions on 2d side scroller...
im making a 2d side scroller and have run into a few problems..
1) instead of locking the frame rate, im calculating how much time it takes to render a frame and then working out how much to move each object based on this. it works fine for movement, but when i call Jump(), the object jumps a different amount each time.
my jump function looks like this:
Not sure about question 1.
For question 2, I keep track of position something like this...
bigX=5 (current tile position)
smallX=13 (offset within tile)
so, for this, move over 5 tiles, render on to buffer, then when you blit to screen, offset by smallX pixels. When smallX gets to 32, make it 0 and increase bigX. (bigX and smallX could be the same variable, with smallX precision. Divide by 32 to get bigX and modulus by 32 to get smallX)
Anyway, that''s the way I do it. It works, but there might be much better ways.
For question 3, in my opinion I would use a linked-list to hold the enemies, but this could be done with an array. Once you have the linked-list structure up and running correctly, it will be easier than the array.
For question 2, I keep track of position something like this...
bigX=5 (current tile position)
smallX=13 (offset within tile)
so, for this, move over 5 tiles, render on to buffer, then when you blit to screen, offset by smallX pixels. When smallX gets to 32, make it 0 and increase bigX. (bigX and smallX could be the same variable, with smallX precision. Divide by 32 to get bigX and modulus by 32 to get smallX)
Anyway, that''s the way I do it. It works, but there might be much better ways.
For question 3, in my opinion I would use a linked-list to hold the enemies, but this could be done with an array. Once you have the linked-list structure up and running correctly, it will be easier than the array.
I just a quick look at your code, but isn''t your initial y velocity dependent on the time between frames? Well, you may not want to do that. If you want your hero to reach about the same height after every jump, have a constant initial y velocity. Also, do you need the acceleration declaration in the first if statement? In the second if, you redefine it any way.
I read at a website somewhere that in order to make the jump height independant of the framerate, you should go
I still haven''t quite figured out how it works... It has something to do with integrals, and I haven''t read about that yet... Though I''m not sure if this is your problem!
Concerning the other two questions, I really don''t have anything to add... They''ve pretty much summed up my conclusions too...
//Ksero, who is also doing a 2d-scroller, but with Allegro/DJGPP
this->Acceleration = 10 * Clock.FrameTime/100;this->YVel -= this->Acceleration/2;this->YPos -= this->YVel;this->YVel -= this->Acceleration/2;
I still haven''t quite figured out how it works... It has something to do with integrals, and I haven''t read about that yet... Though I''m not sure if this is your problem!
Concerning the other two questions, I really don''t have anything to add... They''ve pretty much summed up my conclusions too...
//Ksero, who is also doing a 2d-scroller, but with Allegro/DJGPP
QUANTUM, STOP AND LISTEN!!
You are updating your objects every frame which is a very bad idea. This is due to the fact that if your framerate is not static, then your game is going to execute in an unpredicatable way, as you have said.
Wouldn't it be easier if you were updating your game objects say every 100th of a second? Have you ever noticed how no matter what the framerate in Quake 3, the rockets always fly around at a consistent speed. How do you do it then???
Use a thread function.. look up CreateThread in the Platform SDK. This will allow you to fire off a windows thread. Oh what the heck - here's some code:
//----------------------------------
#include windows.h
#include stdio.h
#define UPDATE_INTERVAL 10
HANDLE UpdateThread;
DWORD UpdateThreadID;
DWORD StartTime = GetTickCount();
DWORD WINAPI UpdateFunction(LPVOID lpParameter) {
DWORD CurrentTime;
while(1) {
CurrentTime = GetTickCount();
if(CurrentTime >= StartTime + UPDATE_INTERVAL) {
printf("==== Update tings ====\n");
StartTime = CurrentTime;
}
}
ExitThread(0);
return 0;
}
int main(int argc, char* argv[]) {
UpdateThread = CreateThread(NULL, 0, UpdateFunction, NULL, 0, &UpdateThreadID);
while(1) {
printf("Draw tings\n");
// blah blah
}
return 0;
}
Edited by - NBGH on September 18, 2000 11:10:25 AM
You are updating your objects every frame which is a very bad idea. This is due to the fact that if your framerate is not static, then your game is going to execute in an unpredicatable way, as you have said.
Wouldn't it be easier if you were updating your game objects say every 100th of a second? Have you ever noticed how no matter what the framerate in Quake 3, the rockets always fly around at a consistent speed. How do you do it then???
Use a thread function.. look up CreateThread in the Platform SDK. This will allow you to fire off a windows thread. Oh what the heck - here's some code:
//----------------------------------
#include windows.h
#include stdio.h
#define UPDATE_INTERVAL 10
HANDLE UpdateThread;
DWORD UpdateThreadID;
DWORD StartTime = GetTickCount();
DWORD WINAPI UpdateFunction(LPVOID lpParameter) {
DWORD CurrentTime;
while(1) {
CurrentTime = GetTickCount();
if(CurrentTime >= StartTime + UPDATE_INTERVAL) {
printf("==== Update tings ====\n");
StartTime = CurrentTime;
}
}
ExitThread(0);
return 0;
}
int main(int argc, char* argv[]) {
UpdateThread = CreateThread(NULL, 0, UpdateFunction, NULL, 0, &UpdateThreadID);
while(1) {
printf("Draw tings\n");
// blah blah
}
return 0;
}
Edited by - NBGH on September 18, 2000 11:10:25 AM
quote: Original post by NBGH
You are updating your objects every frame which is a very bad idea. This is due to the fact that if your framerate is not static, then your game is going to execute in an unpredicatable way, as you have said.
Wouldn''t it be easier if you were updating your game objects say every 100th of a second? Have you ever noticed how no matter what the framerate in Quake 3, the rockets always fly around at a consistent speed. How do you do it then???
AFAIK, if you update your objects based on how much time has elapsed since the last update, it works just as well. All you need is a high-res timer...
I believe the two ways are equally good...
//Ksero
Ksero, I''ll ask you this (i''m sure just as every newcommer to these forums might), how do you set up those quote boxes, and how do you use code boxes. I know its HTML, but what are the markup strings - if I never ask, I''ll never know :-)
Any other markup strings that are fun would also be a bonus. cheers mate!
Any other markup strings that are fun would also be a bonus. cheers mate!
They can be found in the FAQ, there''s a link to it in the upper-right corner...
[ source ]
[ /source ]
[ qoute ]
Be sure to remove the spaces around the tags!
Also, I think you can only use one source-block. Another thing about the forums is that you can''t write #includes properly... You have to make a blankspace like this:
#include < allegro.h >
//Ksero
[ source ]
Which becomes like this, C-style formatted.
[ /source ]
<br><pre><br>This becomes really small and difficult to read <img src="smile.gif" width=15 height=15 align=middle><br>It''s for large blocks of code...<br> </pre> <br>
[ qoute ]
quote:
This is a quote... If you click on the small "reply to post"-icon found on the same line as the date of each message, that text will be included in your post in a quote-block.
Be sure to remove the spaces around the tags!
Also, I think you can only use one source-block. Another thing about the forums is that you can''t write #includes properly... You have to make a blankspace like this:
#include < allegro.h >
//Ksero
I had a post exactly the same as Ksero, and when I started it Ksero had not posted yet, but he finished before I did, so I have now deleted the redundant information.
------------------------------
#pragma twice
------------------------------
#pragma twice
sharewaregames.20m.com
Edited by - furby100 on September 18, 2000 12:10:48 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement