Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 902 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: 283
Projects: 12
Exp: 12 years - 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. - 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:
long powerUpCount = 20*1000; //miliseconds

private loop (long deltaT)
powerUpCount = powerUpCount - deltaT;
if (powerUpCount >0)

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  

EgonOlsen (73 views)
2018-06-10 19:43:48

EgonOlsen (54 views)
2018-06-10 19:43:44

EgonOlsen (73 views)
2018-06-10 19:43:20

DesertCoockie (253 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (153 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (807 views)
2018-03-24 14:43:53

Solater (171 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

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 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‑
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!