Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (813)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Pong power ups  (Read 712 times)
0 Members and 1 Guest are viewing this topic.
Offline hansielneff

Senior Newbie


Exp: 1-3 months



« Posted 2015-04-30 13:27:23 »

I just finished my Pong game and now I would like to add some power ups. I would like for some of them to be active for only a certain amount of seconds (fx. the ball moving faster for 20 seconds).

I'm not sure how to go about it. Should I make a thread for it? Is that what "multi-threading" is? I've heard about it, but I'm not sure what it is, so please explain! Smiley
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 262
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #1 - Posted 2015-04-30 13:31:14 »

This does not sound like a reason to use threads.

Threads are *basically* a way to make the computer do two things at once- in reality, the computer is simply switching between two different things. An example would be loading a file while updating a progress bar- one thread would load the file, another thread would draw the progress bar.

Most games use a single game loop thread, that way they don't have to worry about a bunch of synchronization.

One approach to your problem would be to simply store the "start" time of and temporary objects, then remove them when the elapsed time exceeds the time limit. No need for threads there.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline teletubo
Global Moderator

JGO Wizard


Medals: 75
Projects: 4
Exp: 8 years



« Reply #2 - Posted 2015-04-30 13:32:31 »

No, no threads in your game loop.

You just add a counter that is decreased at each iteration, until it reaches 0. Something like:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
long powerUpCount = 20*1000; //miliseconds

private loop (long deltaT)
{
...
powerUpCount = powerUpCount - deltaT;
if (powerUpCount >0)
 applyPowerUp();
...
}


Where deltaT is the time passed from the last iteration.




Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hansielneff

Senior Newbie


Exp: 1-3 months



« Reply #3 - Posted 2015-04-30 13:58:28 »

I see. Thank you!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
cybrmynd (138 views)
2017-08-02 12:28:51

cybrmynd (159 views)
2017-08-02 12:19:43

cybrmynd (153 views)
2017-08-02 12:18:09

Sralse (169 views)
2017-07-25 17:13:48

Archive (646 views)
2017-04-27 17:45:51

buddyBro (766 views)
2017-04-05 03:38:00

CopyableCougar4 (1300 views)
2017-03-24 15:39:42

theagentd (1264 views)
2017-03-24 15:32:08

Rule (1237 views)
2017-03-19 12:43:22

Rule (1312 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!