Alien Movement In Space Invaders Game

Apr 13, 2014

I'm working on this space invaders game and I've been stuck trying to get the alien spaceships to move down in one group. The way we have to design the game is we have to implement at least these 3 classes. These classes are GameData,GamePanel, and Animator. GameData is all the action figures/models in the game. GamePanel draws all game action figures/ models on the screen. Animator updates periodicaly action figures positions,sizes, colors etc. I can get the aliens to move right but once they hit the end of the canvas I cannot figure out how to get them to move as a group down and then begin moving left. I tried to add alien objects to the GameFigures list and then have the update method in the Alien class be responsible for moving the alien ships, but I couldn't figure out how to make it work. So then I made an alienFigures list in the GameData class and I still cannot figure out what to do. Here is the GameData class

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

[code]....

View Replies


ADVERTISEMENT

Space Invaders Game - Collision Detection

Apr 19, 2014

I'm working on a space invaders game and I'm having problems with collision detection. My main issue is I'm having problems getting what the y value of the "missile" is as it goes up towards the top of the game. I have tried for many hours and tried to look at other people's space invaders game in an attempt to figure out how to figure out my problem. Also I'm not sure if I have the code for my collision detection in the correct spot. Right now I have the code in the keyPressed method. Below is the code for the main and missle classes ...

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Iterator;

[Code] ....

View Replies View Related

Array In Space Invaders Program

Mar 7, 2015

Java Code:

public synchronized boolean isHit (FilledRect missile) {
for (int col = 0; col < aliens[0].length; col++) {
for (int row = 0; row < aliens.length; row++) {
if (aliens[row][col]!= null && aliens[row][col].overlaps (missile)) {
aliens[row][col] = null;
return true;
}
return false;
}
}
} mh_sh_highlight_all('java');

And I get an error saying that it cannot find symbol method overlaps. So is there something wrong that I am doing?

View Replies View Related

How To Do Movement In Text Based Game

Feb 13, 2015

I'm relatively new to Java, I'm trying to create a text based game, like those old ones where you type "north" or "east" to move as such, and "look" to inspect the area. My only problem thus far has been trying to figure out just how I should... "structure?" the movement. As in, what's the best overall way to approach this? I've tried making a new method for every area and just passing a variable called "location," but along with passing the inventory and stat arrays, it's just become messy. Or is this a good way to do it? I have a separate method for when the player enters something, but then how will it know which description to give when the player types "look?"

View Replies View Related

Snake Game Movement Algorithm

Jun 16, 2014

I am working on replicating this project: [URL] ....

What is wrong with the moveSnake method and the for loop within it?

View Replies View Related

Maze Game - Tracking Objects / Limit Movement

Jan 26, 2015

I made a kind of maze game that includes the class keylistener and orients a object, i can't find where the program tracks this object (where its x and y coordinates are). So now my object can move freely through all walls and i want it to bounce back or at least something to happen when the object reaches a wall.

I want to find a way to limit my objects movement and because i cant find where the coordinates or variable for this object is i cannot limit its movement

View Replies View Related

Java Game - 3D Space / Camera Positioning

Jan 4, 2014

1: 3D space. How do i define the space where i will make my world? Is there a certain point that i will define as 0,0,0 or is there some other way.

2: Camera positioning. When i have the 3D space, how to i make it so that the camera will show that what i want it to show. Lets say il define its lokatios 30,50,100 and direction is NW, then how to i make it so that is see the SW direction from the point 30,50,100?

View Replies View Related

Create 2D Game That Has Realistic Space Simulation

Jul 31, 2014

I am attempting to create a 2d game that has a realistic space simulation. The map is supposed to be set so that you are looking from the top down. The problem I am having exists in my interaction between the sun and a planet. Simply put, the planet will only move in a single diagonal direction without ever changing direction. The formulas I am using are F=(G*M1*M2)/D^2 and A=F/M. The code below is simplified.

(inside planet Class)
double x;
double y;
double mass;
double xForce;
double yForce;
double xAccel;
double yAccel;

[Code] ....

Things I have already tried:
1. Setting G to negative
2. changing the order of the subtraction in determining D
3. some weird pythagorean theorem thing someone suggested

View Replies View Related

Mouse Movement Code

Feb 11, 2014

I have been working on this mouse movement code that detects which direction the mouse moves in hope to use it in a game. The only problem is that I can not figure out how to make it move to the other side of the screen so I could continue turning to the right or left without having to stop. How would I actually get the x and y coordinants of the mouse to change?

PHP Code: if(x == xscreen){
//set x to 0
}else if(x == 0){
//set x to xscreen
}else if(y == yscreen){
//set y to 0
}else if(y == 0){
//set y to yscreen
} mh_sh_highlight_all('php');

View Replies View Related

How To Make Smoother Movement

Jan 23, 2014

First, I have a figure that moves around the screen. It uses keylisteners and just subtracts or adds pixels. However, I notice the movement is not smooth at all. It is very rigid and laggy movement. How can I make it smoother movement?

Second, you get three lives in the game. The lives are subtracting correctly, but I want the game to say "GAME OVER" on a dialog box. How would I get this to happen? My JFrame and my life int are in separate classes. I know I should use an if statement, saying if lives are at or less than zero, open the box, but how do I open the box?

Third, I want to display the time on the screen. I have a swing timer, but how do I put it on the screen? DrawString is not working for me.

Fourth, I want to set an icon for the game, the code is running, but not doing anything.

Java Code: frame.setIconImage(Toolkit.getDefaultToolkit().getImage("/Users/MW/Downloads/petericon.jpg")); mh_sh_highlight_all('java');

View Replies View Related

Unexpected OpenGL Simple Movement

May 28, 2014

I am new to DreamInCode! I was creating a game using OpenGL (and slick for textures).

Using Vector3f, I make coordinates to where my camera is camera'ing (and rotation).

It was working... until I modified something. I only added shaders. When I took the shaders off I think I might of accidentally deleted something. Nonetheless the code looks perfect to me.

On the method "input()" everything runs. No errors are thrown anywhere. I have syso'd the hell outa my code. It shows no signs of breaks. I can, however, move elements I put into my program. I am 100% sure that no other class is breaking my game (soon to be).

What you should look out for: I am not really sure about the glLoadIdentity()'s and glMatrixMode(). I am, knowing a good part of, thinking it could be gluViewPort....

My problem: Can't move my camera even tho it was working before.

package com.Hydroque.OpenGlTest;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluPerspective;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;

[Code] ....

View Replies View Related

Limit Object Movement Within A Window

Aug 31, 2014

I just started to learn Java. In my program, I created a GRect(paddle) and I would like to move it on the x axis whenever the mouse is moved.

import acm.graphics.*;
import acm.program.*;
import acm.util.*;
import java.awt.*;
import java.awt.event.*;
public class BreakoutClass extends GraphicsProgram {
/** Width and height of application window in pixels */
private static final int WIDTH = 400;
private static final int HEIGHT = 600;

[code]....

In this case, whenever the paddle reaches the right edge of the screen, it doesn't move off the windows, but it stops moving (even if you move the mouse).

View Replies View Related

Matrix Icon / Button Movement

Apr 30, 2015

I'm working on making a game in JAVA. To be brief, the game is on a 6x6 matrix called "blocks[][]". The game has two players and the objective is to capture the enemies pieces by moving your piece onto there's. The players do this by moving one piece per turn either forward/backward (Vertically) or right/left (horizontal) movements. Essentially checkers without jumps.I'm not very far into the development process here. So far I have the game board created and the pieces load by clicking the "Start" button (handled by the refresh function). However I'm having a few problems... Namely moving the pieces effectively at the moment.

Right now there's a lot to do:

(1) - Implement a turn system,
(2) - Only allow a player to click their pieces (I've a validation function already in place to only permit valid moves [horizontal/vertical only]),
(3) - getting the pieces to actually "move" what I mean by this is a player selects the piece they want to move, then they select the spot they want to move to and the icon I have placed on the button is supposed to be added to the new square and the icon for its previous position is to be made null.

Please see the "actionPerformed" section to see exactly what I'm trying to do and hopefully as well see what I'm missing as to why it is not working at the moment... Also see under the Refresh function where I commented out the for loops to add the pieces. I did this because it was resulting in an ArrayOutofBounds error so I just wrote each spot out manually where I wanted them to start.

/* Ghosts *
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.border.*;
import java.io.*;

[code].....

View Replies View Related

Basic Sprite Character Movement

Aug 18, 2014

how I would go about having a moving sprite on a page, such as a virtual pet kind of thing. I've tried searching for it through the years and I've tried it with what I know on my own, but things just act up every time. Either:

A.) The sprite moves (respondent to key strokes, of course), but leaves a trail of its image behind itself.

B.) The background image writes, but for some reason the second image does not write, or is lost behind the background.

I'm sure these are simple issues for most of you, but I've tried going about this for a while now with no luck. What I'm trying to do I'm trying to write a virtual pet game, and I would eventually love to make it move around randomly like an A.I. that's pathfinding, but I've got ideas about that, just I need to know how to make it move period first, everything else I think I could figure out on my own.

View Replies View Related

Fading Trail And Random Movement Coding?

Oct 30, 2014

I need the following key controlled ellipse to leave a trail behind that vanishes after 10 frames. Also, I need to create a random moving ellipse not related to the preexisting one. How to separate the two ellipses ...

Current code:

boolean left, right, backward, forward;
boolean SPEED;
 PVector pos = new PVector(680, 400);
 void setup() {
size (680,400);
fill (0 ,0,0);
frameRate(100);
noCursor();

[Code] .....

View Replies View Related

Make Mouse Cursor Visible On Movement

Mar 25, 2014

I've been creating a digital clock using Java, and have made the mouse cursor invisible after a set period of time (40-seconds) and had the thought to make it visible again if mouse was moved.

Here's the code that makes it invisible:

ActionListener mouseTimeout = new ActionListener() {
public void actionPerformed(ActionEvent e) {
setCursor(blankCursor);
}
};
/* Make mouse cursor disappear after 40 seconds */
Timer mTimeout = new Timer(40000, mouseTimeout);
mTimeout.start();

And here is what I have so far for making it visible again:

MouseMotionListener mouse = new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e)
{
}
@Override
public void mouseMoved(MouseEvent e)
{
}
};

I have tried using "setCursor(DEFAULT_CURSOR)" but NetBeans says that it "cannot find symbol" .....

View Replies View Related

Swing/AWT/SWT :: Movement And Conversion Of GetText Input In OrderCalc Method

Mar 7, 2014

My OrderCalculator class is throwing an exception. The input from my HourPanel that is supposed to add to my OrderCalc is cooperating.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
public class OrderCalculator extends JFrame
{
private JobPanel jobs;
private HourPanel rate;

[Code] .....

View Replies View Related

JavaFX 2.0 :: Handle Table Column Re-position / Movement Event

Sep 4, 2014

How to catch the event when table view's column are re-positioned. Basically when the column is re-positioned from 1 position to 5 position ,  i want to do update the db.

View Replies View Related

Opoly Game - Goal Of The Game Is To Reach Or Exceed Reward Value 1000

Mar 12, 2015

Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.

Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.

In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.

Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:

**o******

means that the player is at location 2 on the board.

Here are the other Opoly game rules:

If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.

If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).

If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,

Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.

Here is the driver class for the game:

import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();

[Code] ....

heres the methods:

REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:

playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.

spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.

spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.

move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.

isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.

drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.

displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.

View Replies View Related

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

How To Ignore Numbers After Space

Feb 12, 2014

In c++, I'm aware that you can use the ignore function to ignore numbers after space, but in string how do I ignore a number after space is found for instance, "109 33" how would I ignore 33?

View Replies View Related

Finding Space In String

Jan 19, 2015

I have an assessment for college, the part of my code that im struggling with is the part where the user enter their first name followed by a space and then their second name. I m using ---------------fullname = JOptionPane.showInputDialog("enter your firstname followed by a space then your second name " ); ------------- to capture this. the issue is if the user only enter 1 name I need to output an error. the issue is I cant find a way to tell if the user entered a second name. This is what I have so far:

public void makename() {
// makes an inputbox to ask their name
fullname = JOptionPane.showInputDialog("enter your firstname followed by a space then your second name " );
 //separates the first and second name into 2 strings in order to make the username
 
[code]....

The problem is it accepts anything I type in without causing an error. What should I type in to stop this? ive tried anything but I cant find a way to tell if a surname has been entered or not.

View Replies View Related

How To Set Color When Space Is Pressed

Apr 11, 2014

The title says it all and i'm a fairly new java programmer but here is the code:

package TestVersion;
import java.awt.Color;
import java.awt.Graphics;

[Code]......

I think i need a variable or something oh and here is the 2 other classes, the keylistener one:

package TestVersion;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

[Code].....

View Replies View Related

Ending The Input With Space

Apr 2, 2014

Here is the question I'm having trouble with:

Write a program that reads a list of characters:

eg.ubccdddwfreshawbgtiijhktrocbfgrtwghdddguppgrkitt. etc.

inputted from the keyboard one character at a time starting with a vowel (The vowels are a, e, i, o, and u) until a blank {spacebar} character is issued. You do not press enter after each character. Any other sequence should return an error message and a way of entering it correctly.

Having read in the list (or during the reading of the list) the program is to find the longest continuous occurrence of consonants, outputting the vowels between which this occurs and the length of this string of consonants.

{In the example above, the output would be 13ou}

Check for input errors and respond accordingly.

I have done most of it, the problem being that I don't know how to end the scan with a space so that I don't have to press enter. I have done the bit that finds the biggest amount of consonants in a row. (I'm writing in netbeans)

View Replies View Related

Adding Space Between Each Element Of Array

Dec 8, 2014

I have been trying to space out output on a Java console window so that I have three columns with 6 rows of data from three different arrays. The code I have so far outputs the data with no problem however the spacing between the columns is uneven. My loop so far is made up as follows

for (int i = 0; i < printVotes.length; i++) {
System.out.println(printNames[i] + "
" + printVotes[i] + "
" + printPrecent[i] + "%");
}

As you can see I have been manually adding the space between each element of the array but this means that the space between each element is different because the size of each element is different if work out a loop that works out an even amount of space between the elements and then print this along with the elements ....

View Replies View Related

How To Hide A Panel But Preserve The Space

Mar 27, 2014

I have eight panels that are one above the other and are the full width of the frame.

I would like to hide some of them some of the time and then "bring them back".

If I use panel1.setVisible(false) panel1 will disappear but then all the panels below it move up to take panel1's place.

I don't want that to happen. I want just a blank area where panel1 was.

Is there a way to do that?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved