Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
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  
  Timers and image switching - re: Kevin's Space Invaders  (Read 805 times)
0 Members and 1 Guest are viewing this topic.
Offline gladwda

Junior Newbie





« Posted 2011-10-04 15:10:42 »

Hi there Smiley
New to the forum and Java! It's rather lovely on here so thought I would sign up.
I've spent a couple of weeks mulling over tutorials online and I even bought a SAM's teach yourself java and think I've cracked the basics.
However I've started writing wee games now. After a couple of really simple projects I happened upon the Space Invaders tutorial and thought I'd play with that.
It went successfully, and i've since added a few weapons to the game, created a 'boss character' as well that takes 10 shots to kill with a specific weapon that can be acquired after shooting a passing alien/ufo style thing.
However. Despite this I have absolutely no idea how to implement a means of the aliens/boss shooting back.

I figured I needed to set up a timer, and then allow to randomly fire back based on a 1-100 random number allocated to each alien, and based on this timer.
No idea where to start though?
Could anyone point me in the right direction regarding this?

My other issue, is that when shooting at the aliens, I want the shots to change .gif files every alternate shot. So for example calling shot 1 a, and shot 2 b, then looping round from a to b as the rounds are fired in rapid succession. Anyone got a notion of how to do this?

I'm sure it is all very easy but I'm unaware of what statement I should be devising in order to do this.

Hope somebody can help! Thanks Smiley
Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2011-10-04 18:43:44 »

I figured I needed to set up a timer, and then allow to randomly fire back based on a 1-100 random number allocated to each alien, and based on this timer.

That's certainly a reasonable way to do it.  If you allocate the per-alien number randomly, then just have them fire when the timer reaches their number, that'll let them fire in a pattern that the player can predict, which is actually a good thing for this sort of game (it adds to the "hypnotic" factor). 

My other issue, is that when shooting at the aliens, I want the shots to change .gif files every alternate shot. So for example calling shot 1 a, and shot 2 b, then looping round from a to b as the rounds are fired in rapid succession. Anyone got a notion of how to do this?

Just use separate textures.  Or use different texture coords inside a single texture, which is a technique known as "texture atlasing".  How you keep track of which one to use, that's basic programming: just store it anywhere that makes sense.

Offline gladwda

Junior Newbie





« Reply #2 - Posted 2011-10-05 10:54:11 »

Thanks for the reply, that's brilliant. I've googled texture atlasing for a bit of a walkthrough and that's going to be rather helpful.
I couldn't work out how to have each shot pic alternating textures as I wasn't sure how the coding would work. But it's good to know it is all rather logical.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gladwda

Junior Newbie





« Reply #3 - Posted 2011-10-05 12:09:21 »

Thought I'd share a link actually - in case somebody else is starting out and has a bit of trouble with this - found a wee tutorial that's absolutely fantastic:

http://rbwhitaker.wikidot.com/texture-atlases-1

Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (17 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
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!