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 / Struct Boxes always move !help!

Author
Message
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 10th Jan 2012 20:20 Edited at: 11th Jan 2012 13:49
okai... now im trying to get the boxes to always move at a certain speed with struct "ohh and its 2d-sidescroller" but i just can't get it to work. It just generate boxes every where on the on the x-axis.
Please Help



Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 10th Jan 2012 23:24
There is one thing I noticed that is extra code. Here is the concept. You only need to make one (1) bullet sprite before the while ( LoopGDK ( ) ), then hide it. Whenever you want to show any number of bullets, just use dbPasteSprite(..) at the x,y coordinates for that bullet.

Here is the problem you are experiencing:

This ,I assume, is your "shoot" section.
The first part "while ((Box[i].active)&&(i<500)) i++;" is practically useless where it is. Actually, let me show you my method for shooting:

The way you had your code, it would make up to 500 bullets on the screen no matter what you did.

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 11th Jan 2012 13:50
But it's not a bullet

he is gonna jump over the boxes that comes along the x axis i just want them to move along the x-axis but i can't figure out how to do it.

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 11th Jan 2012 14:50 Edited at: 22nd Jan 2012 19:52
OH....

You want boxes that appear on the screen and move to the left?

If you want them to move, loop each one and if it's active move it:


The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 11th Jan 2012 15:39
Thanks Hawkblood

Beginner In the Language.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 11th Jan 2012 18:57 Edited at: 12th Jan 2012 14:47
But it's only moving 1 box, and its only generating 2 boxes
whats wrong?



Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Jan 2012 15:11
dbPasteSprite(i,Box[i].x,Box[i].y);

You are not making multiple sprites, you are "pasting" the same sprite multiple times.

you also need this before your LoopGDK()


You also don't have any "generation" code for the boxes.

I'm assuming you want the boxes to start on the right side of the screen and move to the left. Your player is to jump over them. Right? If so, you want to have some generation code inside your loop:


The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 12th Jan 2012 19:16
Please show me The timer solution

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Jan 2012 19:26
#include "time.h"

declare some globals:
long oldTime,newTime;
float fTBF;//this is the time between frames. Make it a float because the math works better that way

At the beginning of your loop:
newTime=clock();
fTBF=newTime-oldTime;//this gets you the time between frames
oldTime=newTime;// so that when your machine lags slightly or speeds up slightly, the objects still move the same pace

Now, whenever you have movement such as the blocks or the character, do something like this:
Box[i].x-=fTBF/1000.0;//instead of 0.1

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 12th Jan 2012 19:42
Okai, i just can't get it to move... and it doesn't generate anything



Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Jan 2012 22:41 Edited at: 22nd Jan 2012 19:52
Fix this:

It should be:


The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 13th Jan 2012 17:10
Still doesn't work

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 13th Jan 2012 18:28
Show me all your code as it is right now. I will try to fix it and annotate where you went wrong.

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 22nd Jan 2012 15:25
Sorry vacation. heres the code:


Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jan 2012 17:22 Edited at: 22nd Jan 2012 17:23
Here is your problem:
Nowhere are you actually telling the box to move. You are just making the sprite appear one pixil to the left of the box's location.


The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 22nd Jan 2012 18:17
Okai now they are moving but they doesn't generate always

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jan 2012 19:51 Edited at: 22nd Jan 2012 19:51
Change this:

to:


You have no "destroy box" functionallity. It will only generate a max of 1000 and they will go to the left side of the screen. Once the 1000th box has been generated, there will be no more. Add something like this to your update code:

Here is the entire updated code:


The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 22nd Jan 2012 20:07 Edited at: 22nd Jan 2012 20:19
That fixed it.

but what if i want to make a time based generater fx:



i can't get it to work

@Edit I got it to work just edited


Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jan 2012 20:18
I'm not sure you would be worried about game speed, but if you are:
//global

//just before starting loop

//in your loop

//in your "update" code. (where you move the boxes)

//in your "generate" code

//the "else" (where you count down the timer)


The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 22nd Jan 2012 20:27
Thanks for everything Hawkblood

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 22nd Jan 2012 20:28
np

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 24th Jan 2012 16:12
Hey Hawkblood, i got another question, if i want to make if my boxes touches with my player then game end, i can't figure out on where to place it? it just go black when i place it in i & g loop.

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 24th Jan 2012 18:57
A way to do it is:

make a normal "in-game" funtion that handles all the input for normal play. this would include any animation changes, moving boxes and the player.

make a "dead" funtion that shows the "you are dead" stuff and gives a simple menu for "restart" or "end" and anything else you want like maybe shows the score and maybe gives top score and rankings stuff.... whatever you want.

*** in your game loop ****
**************************

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 24th Jan 2012 19:52
Thanks Hawkblood.

Beginner In the Language.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 24th Jan 2012 20:28
1 more question how do you delete Text as dbText();???

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 24th Jan 2012 22:19
Just don't print it.

Give a specific example of what you want to show and then the condition that you want it not to show anymore......

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 24th Jan 2012 22:24
if i want to make a play Button just with text, and then if i click it, it should go to the game.

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 24th Jan 2012 23:56
That's a menu. You could make the menu as simple or as complicated as you like. If your game is a simple game, I suggest making the menu simple as well-- don't add stuff to change the resolution for instance.

There are a few ways to make the "Play" button. You could make a sprite and place text over top of it. When the player clicks, check the bounds (is the mouse within the box of the sprite or text). If it is, then do the funtion for that menu item (in this case play the game).

If you want more functionallity, I have a GUI that you can use. It comes with an editor and I will give support for it. It's not something you will want to use if you just want a "Play" button.

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 25th Jan 2012 07:55
Then i think i will go the sprite way, and keep it simple

Thanks.

Beginner In the Language.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 25th Jan 2012 17:05
Now i got a simple menu in but now the generate part doesn't work.



Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Jan 2012 17:21

When you "generate" you are looking for a non-active box starting at index 0. When you go to update, you start your index at 7.
Decide the number you want to use 1,000 or 10,000.

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 25th Jan 2012 17:49
i changed it, but no different

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Jan 2012 21:04
Post it all.

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 25th Jan 2012 21:42


Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Jan 2012 21:46

Here is the corrected code:


The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 25th Jan 2012 22:02
Thanks Hawkblood, such a little error

Beginner In the Language.
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Jan 2012 23:49
The little errors are the hardest to prevent.

The fastest code is the code never written.
Blackout1471
7
Years of Service
User Offline
Joined: 21st Dec 2011
Location: Visual C++ Express
Posted: 26th Jan 2012 18:28
True

Beginner In the Language.

Login to post a reply

Server time is: 2019-12-13 21:10:02
Your offset time is: 2019-12-13 21:10:02