Skip to content
Permalink
Browse files

Added Menu with MouseInput (click the star in the bottom right for

Padraic Single Player)
  • Loading branch information
tpg13002 committed Apr 26, 2016
1 parent 357f052 commit e9798ff6b6cdd5e4c9c32a74168ca3abd0c69d24
Showing with 145 additions and 43 deletions.
  1. +59 −42 src/main/Game.java
  2. +27 −0 src/main/Menu.java
  3. +58 −0 src/main/MouseInput.java
  4. +1 −1 src/main/Skins.java
@@ -23,7 +23,7 @@
private static final long serialVersionUID = 1L;
public static final int Width = 800;
public static final int Height = 600;
public final String Title = "Star Wars";
public final String Title = "spaaaaaace";

private boolean gameon = false;
private Thread thread;
@@ -43,7 +43,12 @@
public LinkedList<EntityTypeB> eb;
public LinkedList<EntityTypeC> ec;
public LinkedList<EntityTypeD> ed;


public static enum STATE {
MENU,
GAME
};
public static STATE State = STATE.MENU;

Random r = new Random();

@@ -54,8 +59,9 @@
private Player2 p2;
private Controller c;
private Skins tp;
private int numberOfPlayers = 2;
private boolean padraicmode = false;
private Menu menu;
public static int numberOfPlayers = 2;
public static boolean padraicmode = false;

public void init()
{
@@ -70,8 +76,10 @@ public void init()
e.printStackTrace();
}
addKeyListener(new KeyboardInput(this));
this.addMouseListener(new MouseInput());
tp = new Skins(this);
c = new Controller(tp, this);
menu = new Menu();

if(numberOfPlayers == 2){
p2 = new Player2(300, 300, tp, this, c);
@@ -135,6 +143,7 @@ public void run() {
int frames = 0;
long timer = System.currentTimeMillis();
while(gameon){
tp.getTextures();
long now = System.nanoTime();
delta += (now - lasttime) / ns;
lasttime = now;
@@ -159,10 +168,12 @@ public void run() {


private void tick() {
p.tick();
c.tick();
if(numberOfPlayers == 2){
p2.tick();
if(State == STATE.GAME){
p.tick();
c.tick();
if(numberOfPlayers == 2){
p2.tick();
}
}
if(kills >= enemy_count){
if (enemy_count == 10){
@@ -188,10 +199,14 @@ private void render(){
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
g.drawImage(background, 0,0, null);
//g.drawImage(player, 100, 100, this);
p.render(g);
c.render(g);
if(numberOfPlayers == 2){
p2.render(g);
if(State == STATE.GAME){
p.render(g);
c.render(g);
if(numberOfPlayers == 2){
p2.render(g);
}
}else if(State == STATE.MENU){
menu.render(g);
}
/////////////////
g.dispose();
@@ -200,37 +215,39 @@ private void render(){
}
public void keyPressed(KeyEvent e){
int key = e.getKeyCode();
if(key == KeyEvent.VK_RIGHT){
p.setVelX(6);

} else if(key == KeyEvent.VK_LEFT){
p.setVelX(-6);
} else if(key == KeyEvent.VK_DOWN){
p.setVelY(6);
} else if(key == KeyEvent.VK_UP){
p.setVelY(-6);
} else if(key == KeyEvent.VK_L ){
if(is_shooting == 3){
is_shooting = 0;
}
if(is_shooting == 0){
c.addEntity(new Laser(p.getX(),p.getY(), tp, this));}
is_shooting++;
} else if(key == KeyEvent.VK_A){
p2.setVelX(-4);
} else if(key == KeyEvent.VK_D){
p2.setVelX(4);
}else if(key == KeyEvent.VK_S){
p2.setVelY(4);
}else if(key == KeyEvent.VK_W){
p2.setVelY(-4);
}else if(key == KeyEvent.VK_SPACE ){
if(is_shooting2 == 4){
is_shooting2 = 0;
if(State == STATE.GAME){
if(key == KeyEvent.VK_RIGHT){
p.setVelX(6);

} else if(key == KeyEvent.VK_LEFT){
p.setVelX(-6);
} else if(key == KeyEvent.VK_DOWN){
p.setVelY(6);
} else if(key == KeyEvent.VK_UP){
p.setVelY(-6);
} else if(key == KeyEvent.VK_L ){
if(is_shooting == 3){
is_shooting = 0;
}
if(is_shooting == 0){
c.addEntity(new Laser(p.getX(),p.getY(), tp, this));}
is_shooting++;
} else if(key == KeyEvent.VK_A){
p2.setVelX(-4);
} else if(key == KeyEvent.VK_D){
p2.setVelX(4);
}else if(key == KeyEvent.VK_S){
p2.setVelY(4);
}else if(key == KeyEvent.VK_W){
p2.setVelY(-4);
}else if(key == KeyEvent.VK_SPACE ){
if(is_shooting2 == 4){
is_shooting2 = 0;
}
if(is_shooting2 == 0){
c.addEntity(new Laser(p2.getX(),p2.getY(), tp, this));}
is_shooting2++;
}
if(is_shooting2 == 0){
c.addEntity(new Laser(p2.getX(),p2.getY(), tp, this));}
is_shooting2++;
}

}
@@ -0,0 +1,27 @@
package main;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Font;

public class Menu {

public void render(Graphics g){
Font title_font = new Font("comic sans ms", Font.BOLD, 100);
g.setFont(title_font);
g.setColor(Color.white);
g.drawString("spaaaaaace", 145, 150);

Font single_font = new Font("comic sans ms", Font.BOLD, 50);
g.setFont(single_font);
g.drawString("single player", 265, 275);

Font multi_font = new Font("comic sans ms", Font.BOLD, 50);
g.setFont(multi_font);
g.drawString("multiplayer", 285, 375);

Font quit_font = new Font("comic sans ms", Font.BOLD, 50);
g.setFont(quit_font);
g.drawString("quit", 365, 475);
}

}
@@ -0,0 +1,58 @@
package main;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MouseInput implements MouseListener{

public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub

}

public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub

}

public void mousePressed(MouseEvent e) {
int mx = e.getX();
int my = e.getY();

if(mx >= 265 && mx <= 535 && my >= 225 && my <= 275)
{
Game.numberOfPlayers = 1;
Game.padraicmode = false;
Game.State = Game.STATE.GAME;
}
else if(mx >= 285 && mx <= 515 && my >= 325 && my <= 375)
{
Game.numberOfPlayers = 2;
Game.padraicmode = false;
Game.State = Game.STATE.GAME;
}
else if(mx >= 365 && mx <= 435 && my >= 425 && my <= 475)
{
System.exit(1);
}
else if(mx >= 610 && mx <= 650 && my >= 540 && my <= 580)
{
Game.numberOfPlayers = 1;
Game.padraicmode = true;
Game.State = Game.STATE.GAME;
}


}

public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub

}

}
@@ -25,7 +25,7 @@ public Skins(Game game) {
getTextures();

}
private void getTextures(){
public void getTextures(){
if(game.getPadraic()){
player = ss.grabimage(2, 2, 64, 64);
laser = ss.grabimage(3, 2, 64, 64);

0 comments on commit e9798ff

Please sign in to comment.
You can’t perform that action at this time.