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 / Having trouble with simple Dark GDK coding [HELP]

Author
Message
Pheelbert
7
Years of Service
User Offline
Joined: 12th Feb 2012
Location:
Posted: 12th Feb 2012 08:31
First of all I want to say thank you to whoever is going to take the time to read all of this, I really don't know what the source of the problem is.

[Bug Reports
1.Whenever I turn after accelerating, I seem to lose the 'decelerating' effect too much, when I want it to have this 'slippery' kind of feel.
2.If I press SPACE by itself, it stops the ship. Also, when I let go of it again, it seems to have kept it's momentum and goes back to it's speed without re-accelerating.
3.I was using dbLeftKey() and dbRightKey() before but the Left wouldn't work for some reason, why?
4.After going backwards, if I keep pressing right or left and then decide to press up, the ship won't move forwards.


JTK
9
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 12th Feb 2012 16:00
1) This has to do with the order of your conditional checks. First, you are checking for acceleration and immediately after you have a deceleration check; both of which will be true and cancel each other out. However, the third check checks for acceleration again and re-applies it.



Can you see in your code how you first check for the UP key, then the RIGHT key and then the UP and RIGHT key? That is the source of this issue.

2) You don't have a handler for when just a SPACE key is pressed. As such, any current speed/acceleration will remain and be increased/decreased as soon as you meet one of the other conditional checks (ie: instant speed-up you're seeing).

3) This could be a keyboard mapping issue. U.S vs Korean vs Japanese vs ... I would need more info on this one.

4) This is related to #1 above. Same thing is happening, order of your checks are canceling each other out.


Here's a code-snippet of how I would go about handling the keyboard input. It may seem a bit complicated at first, but it greatly simplifies the entire process:



It's quite a large snippet, I know but I was trying to customize the approach to your code above...

Hope this helps,

JTK
Pheelbert
7
Years of Service
User Offline
Joined: 12th Feb 2012
Location:
Posted: 12th Feb 2012 21:30
To begin with, I want to make you aware of how thankful I am for the amount of effort you are putting into helping me out, so thanks again!

By the way, I'm currently studying in Computer Science so please don't consider me as a script kiddie of some sort, I'm here to learn and I've already spent a lot of time into trying to make all of this work out.

1. 'rotation_adjustment' : undeclared identifier
'speed_adjusment' : undeclared identifier
I had the same problem with (w, a, s, d) but I defined them as their appropriate KeyState values.

2. Could you explain me the " |= " and the " ? IsSpaceKey : 0 "
curr_state |= (dbSpaceKey() == 1) ? IsSpaceKey : 0


3. All I have to add in now is the SpriteFrames? Is that going to be complicated to do since I have a different one for UP+LEFT, UP+RIGHT, UP alone, UP+LEFT+SPACE...etc.

Also I'm planning on making my ship shoot bullets, I'm having trouble with making the bullet come out of the right place on my space ship since I'd need to follow the x, y of the front of the ship and I'm trying to figure that out...

Also also, I'm making multiple screens to the game but I won't start posting those snippets now.

D:! I'll go work on that now!
Pheelbert
7
Years of Service
User Offline
Joined: 12th Feb 2012
Location:
Posted: 12th Feb 2012 23:51
Alright, so I fixed all the problems I had by following your instructions about the conditional checks. It took me some time but with a little luck I was able to make it work after all!

Now I'd like to know how you would make a 2 by 3 map, where every time I get to the limit of a screen, it changes the background (and other components) and lets me go from screen to screen in my virtual map :o.. Not too sure if that made sense but here's what I did.

background.h



test_pos() (in my player1.h)


Basically what I do is I have (or will have) six different screens, the way i'll make the game know whether it is screen #x or not is that i'll change the number in the 'Screen' variable every time I get to the extremes of the screens.

[what works now/and doesn't]:
FYI:Screen variable is initiated in main.cpp, outside the loop.
My first screen's left and bottom borders work fine.
When I go to the top, it'll put me into a screen that seems to not have been programmed with any borders but I clearly wrote 'Screen = 2' ... So I have no idea what's wrong.

Thanks again oh god s:
JTK
9
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 13th Feb 2012 15:41
Quote: "
1. 'rotation_adjustment' : undeclared identifier
'speed_adjusment' : undeclared identifier
I had the same problem with (w, a, s, d) but I defined them as their appropriate KeyState values.
"


The snippet above was meant to be a snippet. That entire block of code should be contained within its on function block. There's no guarantee of complete syntactic correctness with snippets.

Quote: "
2. Could you explain me the " |= " and the " ? IsSpaceKey : 0 "
curr_state |= (dbSpaceKey() == 1) ? IsSpaceKey : 0
"


|= Bitwise Inclusive OR Assignment Operator.
?: Conditional Operator.

Quote: "
3. All I have to add in now is the SpriteFrames? Is that going to be complicated to do since I have a different one for UP+LEFT, UP+RIGHT, UP alone, UP+LEFT+SPACE...etc.
"


Not really, a simple switch() statement would do. You already have the keystates to work with:





Regarding your world-map:

First, let me just say that this is a completely different issue than what you were having at first. No problem with that except that it should be posted in its own seperate thread so that other users can have a better chance of finding it in future searches...

Now, your approach is certainly workable but as you can tell by the code you are supplying - its highly error prone (what if you mis-code an if condition?)

One way to approach it will remove ALL of those if-checks and replace them with a couple of 3 or 4 math calculations.

Let's assume for a moment that each of your "background" images are sized 800x600 (any size will do so long as they are the same).

So, your world-map consists of (800x3)=2400 units accross and (600x2)=1200 units down.

By keeping track of your character's World-Coordinates, you can determine which background screen is displayed by:

tmpx=char_world_x / 800;
tmpy=char_world_y / 600;

And to access the background, use the tmpx and tmpy values to access an array of values:

background_id = Backgrounds[tmpx][tmpy];

I hope this helps,

JTK
Pheelbert
7
Years of Service
User Offline
Joined: 12th Feb 2012
Location:
Posted: 14th Feb 2012 03:07
Thank you!
I'll be trying that out until I get it right.
If I don't answer it either means I'm preoccupied
or that I didn't fail!

Login to post a reply

Server time is: 2019-12-15 07:22:01
Your offset time is: 2019-12-15 07:22:01