Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / [DarkGDK/MS,VC++] HELP! Creating a smooth 2d shooter

Author
Message
GameGeek
12
Years of Service
User Offline
Joined: 24th Nov 2011
Location:
Posted: 25th Nov 2011 00:33
Ok here's the basics I have to create a space invaders game for my college project and have ample amount of time however I have made an early start and have already ran into an issue.

One of the first things I wanted out of the way was the background, which I want to scroll vertically.

So here's my issue(s):

A) I cant get the background to scroll smoothly. i.e in just jumps up one pixel at a time which looks horrid.

B) I can't get the background to scroll faster either.

Here's what I have so far:



Im not really sure where to continue from here Im really just looking for a way to make the game run smoothly and look good.
Wizz
14
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 27th Nov 2011 00:13 Edited at: 27th Nov 2011 09:06
There are two things I see that are wrong with your code. First of all try not to use dbLoadImage in the while loop. You only need to load the image once. Putting that into the while loop makes the program constatly load the image and that makes the game slower. So put that part before the loop.

The reason your background doesn't flow smoothly is that you clear the screen every time the loop begins. You dont need to clear the screen. The dbSprite function moves the sprite if you change the coordinates.

like this:


GameGeek
12
Years of Service
User Offline
Joined: 24th Nov 2011
Location:
Posted: 1st Dec 2011 15:08
Ok thanks a tonne for the help it works beatifully I have now ran into another problem. I created a function to neaten up thr program and keep it more modular. Now the program is error free and runs the function that controls background scrolling however the sprites seem to have frozen and will no longer run. I was wondering if you could take another look and see if im missing something obious? Thanks again!

Wizz
14
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 1st Dec 2011 19:13 Edited at: 1st Dec 2011 19:16
Well first of all you are loading sprites in the game loop again. load the sprites right after you set the display mode (you only want the sprites to load once, otherwise the game will lag). Second of all, keep the dbSync(); in the game loop. don't put it into the functions, it's impracticle. Also you have a line of code in the DarkGDK function "void ScrollingBG(int &, float, float, float, float, float&);" Delete that it does nothing. Your problem is that you are copying the values of your variables into the scrollingBG function in every frame and in every frame the values of the variables are the same. One way to fix this would be to put a reference to every variable, so the values change and don't always stay the same. But the better way to do this would be to make those variables global and turn the scrollBG function into a function that takes zero arguments. (if the variables are global you can use them in any function).

Take a look at the code I fixed it for you a bit.
Also try to put the dbLoadImage stuff back to where you had it before and see the difference, just so you know what i'm talking about.



GameGeek
12
Years of Service
User Offline
Joined: 24th Nov 2011
Location:
Posted: 2nd Dec 2011 19:06 Edited at: 2nd Dec 2011 19:39
Awesome thanks man, it hadn't occured to me to make a global function. Ive actually gotten quite substantially into the program without functions so i went back through and its all tidy now So UBER thanks to you and Thanks again!

I have another question this one is more sort of a logic puzzle if you will Im trying to get my SpaceShip to shoot however when I shhot the bullet i follows the spaceship (since i used it to obtain the bullets starting x/y coords. So whats the easiest way to stop it following the ship?

Heres what Ive been using:



BulletY is the variable for resseting and keeping control of the y coord
Ship1x is responsible for keeping track of ship number 1's x coords
firing is a identifier to tell the game if its shooting or not.

I think i have to create a way of assigning the ships x coords to a static value once spacebar is hit so that it no longer follows it not sure how though :L
Wizz
14
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 3rd Dec 2011 22:53 Edited at: 3rd Dec 2011 22:54
You can't use the same variables for the ship and the bullet. Make seperate variables for the bullet and when the bullet is supposed to be fired just put down bulletX=shipX when you start firing. And then when you want to move the bullet bulletX=bulletX+10; and shipX remains the same.

Also I suggest you to think about your problem for a day or two before posting it here. In programing you usually figure problems out when you're not sitting next to the computer and thinking about it. And figuring it out on your own is the best and most satisfying way to learn. Trust me, alot of times the solution will just pop up when you're taking a shower the next day or something like that.

GameGeek
12
Years of Service
User Offline
Joined: 24th Nov 2011
Location:
Posted: 4th Dec 2011 12:36
Cool thanks man youve been a tonne of help.

Login to post a reply

Server time is: 2024-04-16 10:39:26
Your offset time is: 2024-04-16 10:39:26