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 / Need help with time.

Author
Message
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 10th Aug 2009 00:40
Hi. I am a beginner so i am making a simple game-like thingy just for laughs. I put an image of some guy as the background and on the bottom a little ship sprite that shoots lasers. When you hit the guy into the left or right eye every three times, the program adds a sprite of blood to it, until the eyes explode. That's about all i have for now, but a game isn't a game if it isn't a chalenge. What i want to do is to make a laser shoot out of his eyes every second.
Example a laser shoots out of left eye, a second later a laser shoots out of the right eye and so on.

I have no idea how to make the game wait for a second until it does something. I tried to use dbTimer and i can't even make it shoot a single laser after it waits for 5 seconds. I set dbTimer and then "if (dbTimer==5000){ [shoot laser code]} and that didn't even work so i have no idea what i'm doing wrong, please help!

here's the code:


Thank you!
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Aug 2009 00:56
I haven't followed your shooting code yet but I'd like to comment on some unnecessary code going on.

Every time through the loop you're calling create_player(). That function then proceeds to size the sprite, set an offset and set priority. For any given sprite this need only be done once, preferably outside the loop, unless something changes on any of them.

Call create_player() before you enter the look and don't call it after. Put a dbSprite(a, x, y, b) call in your move_player () function after you've determined the new position. If there is no change there's no need to call dbSprite().

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 10th Aug 2009 01:04 Edited at: 10th Aug 2009 01:05
dbTimer returns the current system time. So you could define a constant of 3 seconds which we know is and int of 3000.

the first loop iteration would store the system time into two variables called current, and last.

(these variables are outside your main loop)
const int wait = 3000;
int current = dbTimer();
int last = dbTimer();

inside the main loop, every iteration you would update current. then you would check to see if the wait time has past.

if((last - current) >= wait)
{
last = current;
shootLazer();
}

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 10th Aug 2009 01:05 Edited at: 10th Aug 2009 01:06
oh thanks lilith (i fell real stupid now)

I just love the smell of code in the morning...
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 10th Aug 2009 01:07
I cant beleive you keep beating me to the posts Lil. XD I am starting to check more often.

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 10th Aug 2009 01:11
Isn't last minus current always zero? they both equal dbTimer... they both have the same values don't they?

I just love the smell of code in the morning...
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Aug 2009 01:28
last would be a value you store to compare it to the one that you're reading in the current iteration of the loop. You take the difference, do what you need with it then replace last with the current value to use as the last in the next pass through the loop. By that time current should be something different. Rinse. Repeat.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 10th Aug 2009 01:28
No. Each time you call the function dbTimer() it will return the current system time in milliseconds. Meaning it will incrument by one every 1/1000th of a second.

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 10th Aug 2009 01:30
AH got me again Lil!

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 10th Aug 2009 01:41
so i put int last = dbTimer outside the main loop

and int current = dbTimer inside the main loop?

if this is the case... you have to do current - last not last - current correct?

I just love the smell of code in the morning...
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 10th Aug 2009 05:33 Edited at: 10th Aug 2009 05:34
Right. My code uses 3000 for 3 secconds if you want five increase wait to 5000. Pretty simple.

Sample Code:


The reason I do it this way is so that I get a positive number to compare to wait. There are a few different ways this can be implemented though. There is always more than one way to skin a cat.

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 10th Aug 2009 10:59
Oh thank you so much. I've been thinking ma head off with this problem. Just one last question. Why is it necessary to make int current twice? Wouldn't it be just the same if the code was like this?



I just love the smell of code in the morning...
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 10th Aug 2009 15:36 Edited at: 10th Aug 2009 15:37
*sigh* Did exactly as you said, it doesn't work. What am i doing wrong here?


I just love the smell of code in the morning...
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 10th Aug 2009 17:32 Edited at: 10th Aug 2009 17:33
You only need to define 'current' as a local variable (inside the function).

Change time_ray1() to this:



(You switched around the 'last = current' part, so 'last' always stayed the same and current always increases)

And don't forget to remove the line where you define 'current' at the top.

Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 10th Aug 2009 23:03
technically you don't even have to define the current variable at all I was just using it to illistrate the code. You could just use the dbTimer() function alone.

if((dbTimer() - last) >= wait)

Bran flakes is right about the time ray function.

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 11th Aug 2009 01:30
Omg! I totaly forgot that mattered... in my head i just tough "equalize the two variables" oh boy... all works perfectly! Thank god for geniuses like you! Thanks so much!

I just love the smell of code in the morning...
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 11th Aug 2009 01:30
/thread

I just love the smell of code in the morning...
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 11th Aug 2009 04:43
Sweet. Glad I could be of assistance. Your game sounds like it fun. If you build a release I would love to give it a shot.

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 11th Aug 2009 17:07
Haha it's totally boring. I'm just making it cause it's the best i can do. It's the first thing i made that i can actually call a game. Also i have a problem with compiling in release mode. I get some kind of error... nobody seems to know what's wrong.

I just love the smell of code in the morning...
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 11th Aug 2009 17:12 Edited at: 11th Aug 2009 17:16
No its great. All to often you have beginers trying to create the next world of warcraft or something right off the bat. The little stuff is the building blocks of everything.

Hit me with it. I will give figuring that out it a shot too.

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 13th Aug 2009 16:34
haha Ok! Where and how can i upload this? I'll just zip and upload the debug folder than. After i'm done, i'm still working on some details like sounds etc. I'll also give you the full code then maybe you can see whats wrong. Maybe you will be able to compile it, perhaps it's just my computer, i don't see any other reasons for this error. Thanks for all the support dude!

I just love the smell of code in the morning...
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 13th Aug 2009 22:04
At the bottom of the post editor is a field for attaching files. Handy.

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 13th Aug 2009 23:48
Ok, here it is. I've attached the debug folder. The media is in the media folder. Note that this game was intended for a few friends of mine and for me to practice, so the gameplay makes little sense. I will also add the whole code so please see if you are able to compile it in release mode.


I just love the smell of code in the morning...

Attachments

Login to view attachments
Amnzero
15
Years of Service
User Offline
Joined: 1st Aug 2009
Location:
Posted: 15th Aug 2009 02:34
Here check out the attachment I compiled in release and did one better as well.

if(enemy == Amnzero) runAway();
Amnzero->WebSite = L"http://neovance.com/";

Attachments

Login to view attachments
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 15th Aug 2009 11:30
So my system is to blame. I can't run those files you sent me. I can run the first setup file but can't run the exe later. And i can't even run the second setup file. Also can't run the exe that's added. It just crashes always, well it gets to the first three sprites, the menu, the story and instructions but when i press space, the music starts playing ut the game crashes.I'm getting a new computer real soon so no problem. Except if you know what's wrong.
You misspelled the name by the way. The guy's last name is Čakić so Cakic. It's a Serbian last name. (I'm from Slovenia tho).
Also, you made a huge mistake by sending me a setup file. Cos i'm gonna force you to teach me how to make it myself :3
It's so awesome i wanna learn it!
Thanks!

I just love the smell of code in the morning...
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 15th Aug 2009 20:11
Oh and does anyone have any suggestions on how to fix the problem? Can this also be the cause of my video game performance extremely decreasing a month ago? I appreciate the help, ty.

I just love the smell of code in the morning...
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 17th Aug 2009 14:55
nobody knows what's wrong?

I just love the smell of code in the morning...

Login to post a reply

Server time is: 2024-11-20 17:48:11
Your offset time is: 2024-11-20 17:48:11