[gameprogrammer] Re: 2d side scroller
- From: Nick Howes <nickhowes@xxxxxxxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Mon, 07 Nov 2005 18:54:06 +0000
Yes it's best to do rendering and logic in two separate loops. The
looping itself isn't intensive so you won't get any slowdown from that
(until you have massive numbers of entities). The extra advantage of
this is you don't necessarily have to render each time you update the
world. They could even be separate threads running at their own speed
(provided everything is thread-safe). You could control the frame rate
without affecting the actual running speed of the game world.
Alan Wolfe wrote:
Thats a good point. I was trying to be more efficient by taking
advantage of loops as they happened, ie instead of looping through all
enemies and doing movement/physics/logic and then looping through them
all again later to do the drawing, i tried to make it all part of the
same loop.
Guess that's not the best idea eh? :P
Thanks for pointing that out, that probably explains some wierdness I
was having with the moving platforms.
On 11/7/05, *Ken Johnson* <johnsk16@xxxxxxxxx
<mailto:johnsk16@xxxxxxxxx>> wrote:
One thing that I noticed is that I would render the screen as the
last operation. You render enemies/player before you test if an
enemy may have been killed by a players bullet and you also render
the player before you test if he needs to be moved from a moving
platform.
On 11/7/05, *Alan Wolfe* < alan.wolfe@xxxxxxxxx
<mailto:alan.wolfe@xxxxxxxxx> > wrote:
Hey everybody!
I'm working on a 2d side scroller in SDL/OpenGL and this is
the first actual one i have ever made. Because of that, I
have found some things I did which were not the most efficient
way to do things and have changed them, but I have found other
things which i know must not be the best way, but am unsure of
what the best way would be.
Here is my order of operations in my game loop:
1) Check which keys are down and move the player accordingly
or spawn bullets etc. (movement checks that there are no
blocks in the way, as well as checks if they touch spikes
etc). This section also figures out which frame of animation
to draw for the main character whether he looks like he is
jumping running shooting etc.
2) Handle gravity and other physics for player, moving as necesary
3) Handle the scrolling of the camera to keep player on screen
(the game uses mouse look so the screen really scrolls based
on mouse coordinates.
4) Draw paralax layers that are behind the map
5) Draw the map
6) Draw the main character
7) Draw and handle enemies - draws enemies as well as handles
enemy physics and logic (AI)
8) Draw projectiles - both enemy and player projectiles.
Draws them and does physics and logic, also checks to see if
friendly bullets have hit enemies (if so take away life from
the enemy it hit) and checks to see if enemy bullets have hit
the player (if so take away life from the player).
9) Draw game objects such as powerups etc. Does physics and
logic as well for each.
10) Draw moving platforms (along with path logic as well -
such as if it moves in a circle, it will move it the next
step). This part also checks to see if each moving platform is
going to hit the player when it moves. If so, it pushes the
player out of the way (checking to make sure it doesnt push
the player through a wall or anything like that).
11) Draw paralax layers that are in front of the map
12) Draw game GUI such as lives left etc
13) see if the player has touched any bad guys. If so, take
away life and mark the player as being in the "injured"
animation state.
14) see if the player has touched any power ups. If so, give
them energy, extra life, or whatever.
Does anyone see anything sticking out which might be optomized
or done in a better way?
A secondary question is how is the best way to program moving
platforms? I am in the middle of implementing them and right
now my tactic is this...
-----
Loop through each moving platform...
If the player is on the current platform, move them the same
amount as the platform is moving (this makes sure if they are
standing on a platform that it carries the player with it) -
(taking into account other walls etc so you don't push them
into space etc)
Move the platform.
If the player wasnt on a platform but is now, move the player
the same amount as the platform is moving (taking into account
other walls etc so you don't push them into space etc)
-----
I know this isnt the best way because this makes the player
"float" slightly above the platform at times and rarely, the
player will get stuck inside the platform.
Is there a better way to do this?
Thanks!
Alan
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: 2d side scroller
- From: Josh Stewart
- References:
- [gameprogrammer] 2d side scroller
- From: Alan Wolfe
- [gameprogrammer] Re: 2d side scroller
- From: Ken Johnson
- [gameprogrammer] Re: 2d side scroller
- From: Alan Wolfe
Other related posts:
- » [gameprogrammer] 2d side scroller
- » [gameprogrammer] Re: 2d side scroller
- » [gameprogrammer] Re: 2d side scroller
- » [gameprogrammer] Re: 2d side scroller
- » [gameprogrammer] Re: 2d side scroller
- » [gameprogrammer] Re: 2d side scroller
- » [gameprogrammer] Re: 2d side scroller
Guess that's not the best idea eh? :P
Thanks for pointing that out, that probably explains some wierdness I was having with the moving platforms.
On 11/7/05, *Ken Johnson* <johnsk16@xxxxxxxxx <mailto:johnsk16@xxxxxxxxx>> wrote:
One thing that I noticed is that I would render the screen as the
last operation. You render enemies/player before you test if an
enemy may have been killed by a players bullet and you also render
the player before you test if he needs to be moved from a moving
platform.
On 11/7/05, *Alan Wolfe* < alan.wolfe@xxxxxxxxx <mailto:alan.wolfe@xxxxxxxxx> > wrote:
Hey everybody!
I'm working on a 2d side scroller in SDL/OpenGL and this is
the first actual one i have ever made. Because of that, I
have found some things I did which were not the most efficient
way to do things and have changed them, but I have found other
things which i know must not be the best way, but am unsure of
what the best way would be.Here is my order of operations in my game loop:
1) Check which keys are down and move the player accordingly
or spawn bullets etc. (movement checks that there are no
blocks in the way, as well as checks if they touch spikes
etc). This section also figures out which frame of animation
to draw for the main character whether he looks like he is
jumping running shooting etc.2) Handle gravity and other physics for player, moving as necesary
3) Handle the scrolling of the camera to keep player on screen
(the game uses mouse look so the screen really scrolls based
on mouse coordinates.4) Draw paralax layers that are behind the map
5) Draw the map
6) Draw the main character
7) Draw and handle enemies - draws enemies as well as handles
enemy physics and logic (AI)8) Draw projectiles - both enemy and player projectiles. Draws them and does physics and logic, also checks to see if
friendly bullets have hit enemies (if so take away life from
the enemy it hit) and checks to see if enemy bullets have hit
the player (if so take away life from the player).
9) Draw game objects such as powerups etc. Does physics and
logic as well for each. 10) Draw moving platforms (along with path logic as well -
such as if it moves in a circle, it will move it the next
step). This part also checks to see if each moving platform is
going to hit the player when it moves. If so, it pushes the
player out of the way (checking to make sure it doesnt push
the player through a wall or anything like that).11) Draw paralax layers that are in front of the map
12) Draw game GUI such as lives left etc
13) see if the player has touched any bad guys. If so, take
away life and mark the player as being in the "injured"
animation state. 14) see if the player has touched any power ups. If so, give
them energy, extra life, or whatever. Does anyone see anything sticking out which might be optomized
or done in a better way? A secondary question is how is the best way to program moving
platforms? I am in the middle of implementing them and right
now my tactic is this... -----
Loop through each moving platform... If the player is on the current platform, move them the same
amount as the platform is moving (this makes sure if they are
standing on a platform that it carries the player with it) -
(taking into account other walls etc so you don't push them
into space etc)Move the platform.
If the player wasnt on a platform but is now, move the player
the same amount as the platform is moving (taking into account
other walls etc so you don't push them into space etc)
----- I know this isnt the best way because this makes the player
"float" slightly above the platform at times and rarely, the
player will get stuck inside the platform.Is there a better way to do this?
Thanks!
Alan--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- [gameprogrammer] Re: 2d side scroller
- From: Josh Stewart
- [gameprogrammer] 2d side scroller
- From: Alan Wolfe
- [gameprogrammer] Re: 2d side scroller
- From: Ken Johnson
- [gameprogrammer] Re: 2d side scroller
- From: Alan Wolfe