Initial Commit of my Asteroids game clone.
I have started this project, to betterunderstand basic game development. This commit contains Most of the frame work for the game. Currently the ship can be flown around the screen. Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
72
Asteroids/src/com/RickBarrette/asteroids/Display.java
Normal file
72
Asteroids/src/com/RickBarrette/asteroids/Display.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Display.java
|
||||
* @date Mar 31, 2012
|
||||
* @author ricky barrette
|
||||
* @author Twenty Codes, LLC
|
||||
*
|
||||
* Copyright 2012 Richard Barrette
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package com.RickBarrette.asteroids;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
* This display panel will be used to display the game's object's and their world
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class Display extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = -9105117186423881937L;
|
||||
private AsteroidGame mGame;
|
||||
private Container mContainer;
|
||||
|
||||
/**
|
||||
* Creates a new Dispay
|
||||
* @param c
|
||||
* @param g
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public Display(Container c, AsteroidGame g) {
|
||||
mGame = g;
|
||||
mContainer = c;
|
||||
this.setBackground(new Color(0, 0, 0));
|
||||
mContainer.add(this, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
/*
|
||||
* Draw the world's objects
|
||||
*/
|
||||
for (Object item : mGame.getWorld()) {
|
||||
if (item instanceof Ship) {
|
||||
Ship s = (Ship) (item);
|
||||
s.move(getHeight(), getWidth());
|
||||
s.draw(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user