5 Replies - 3703 Views - Last Post: 18 December 2011 - 09:10 PM Rate Topic: -----

#1 carlstucky   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 09-December 11

Java Space Invaders

Posted 11 December 2011 - 09:49 AM

Well Here I am making a Space Invaders Clone in Java and I need a few answers.

1: I don't know how to make the player stop when he hits the frame.

2: I need help making Walls/Barriers.

Please answer soon I would like to get the game done by Christmas!

Sorry i am kinda new to this sort of thing :)

Is This A Good Question/Topic? 0
  • +

Replies To: Java Space Invaders

#2 DivideByZero   User is offline

  • D.I.C Addict
  • member icon

Reputation: 240
  • View blog
  • Posts: 551
  • Joined: 02-December 10

Re: Java Space Invaders

Posted 11 December 2011 - 10:21 AM

If you know the size of the frame, you could have an if statement that checks whether the ship's X and Y value is within the screen. If it is, run the movement code.

An example could be:
if (ship.Position.X < SCREEN_WIDTH && ship.Position.X > 0 &&
        ship.Position.Y < SCREEN_HEIGHT && ship.Position.Y > 0)
{
    // Run the code that move the ship when the user presses a button.
}


Was This Post Helpful? 0
  • +
  • -

#3 carlstucky   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 09-December 11

Re: Java Space Invaders

Posted 11 December 2011 - 10:44 AM

ok thx
Was This Post Helpful? 0
  • +
  • -

#4 carlstucky   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 09-December 11

Re: Java Space Invaders

Posted 11 December 2011 - 10:56 AM

nope that doesnt work :(
Was This Post Helpful? 0
  • +
  • -

#5 anonymous26   User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Java Space Invaders

Posted 11 December 2011 - 12:21 PM

You need to show us your code, we are not going to write your game for you.
Was This Post Helpful? 0
  • +
  • -

#6 Mr. House   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 30
  • Joined: 18-July 11

Re: Java Space Invaders

Posted 18 December 2011 - 09:10 PM

You would need to have some code to push the sprite back whenever it reaches the boundaries.

For example, say your screen is 300 pixels wide. You would need code to push your character back when it goes past 0 or 300 pixels.

Example

Your Sprite's movement function moves your sprite 10 pixels in either direction for a given time interval

if (Sprite.GetPosition().x > 300)
    Sprite.Move(-10,0);
else if (Sprite.GetPosition().x < 0)
    Sprite.Move(10,0);



This only covers X movement obviously.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1