/**
* Credits:
* Base Images Courtesy of LoL member Fox Force
* Game written by LoL member Trivial Fate
* Code Formatted by Sven Bomer
*
* Feel free to stream your favorite music in the background!
* Please make sure you downloaded the images and did not change their
* names to ensure full game functionality.
*
* Instructions:
* - Press Q to enter Powerball, and protect yourself from super minions.
* - Press W to activate Defensive Curl, shielding yourself from towers.
* Points are awarded for time spent alive.
* Using both abilities at the same time will in some situations be required,
* but an excess use will result in a 50% point deduction.
* If a super minion or turret catches you unprotected, you will lose a life.
* You start with 3 lives and will not have an opportunity to get another.
* Lives are located in the top left corner, have fun!
*
* ==========================================================================
* © Daniel Koohmarey 2011
* Thanks Mr. Sacco for teaching me the skills necassary to create this game!
* ==========================================================================
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class RammusRun extends JPanel implements ActionListener, KeyListener {
private Timer myTimer;
private Image background;
private Image rammusImage;
private Image turretImage;
private Image minionImage;
private Image turretSlain;
private Image minionSlain;
private Image turretDestroyed;
private Image dc;
private Image qDC;
private Image gameOverScreen;
private Image startScreen;
private Image livesRemaining;
private Image scoreScroll;
private Image instructions;
private boolean qPressed, wPressed, spacePressed, iPressed, bPressed;
private int currentTime;
private int animationValue;
private int qAnimationValue;
private int wAnimationValue;
private int width;
private int height;
private int scroll;
private int scrollAmount;
private int score;
private int turretEncounter;
private int superMinionEncounter;
private int secondSuperMinionEncounter;
private int secondMinionLocation;
private int turretLocation;
private int minionLocation;
private boolean turretSpawned, minionSpawned, secondMinionSpawned;
private boolean turretAlive, minionAlive, secondMinionAlive;
private int lives;
private boolean gameOver;
private boolean lostLifeM, lostLifeT, lostLifeSM;
private boolean battledM, battledT, battledSM;
private int qwAbuse;
private boolean startMenu, iMenu;
public RammusRun() {
startMenu=true;
iMenu = false;
animationValue = 0;
qAnimationValue = 1;
wAnimationValue = 1;
width = 1000;
height = 300;
scroll = 0;
scrollAmount = 25;
score = 8900;
turretSpawned = false;
minionSpawned = false;
secondMinionSpawned = false;
turretAlive = false;
minionAlive = false;
secondMinionAlive = false;
turretLocation = width;
minionLocation = width;
secondMinionLocation = width;
lives = 3;
this.setPreferredSize(new Dimension(width,height));
currentTime = 50;
myTimer = new Timer(currentTime, this);
myTimer.start();
background = Toolkit.getDefaultToolkit().getImage(getClass().getResource("background.jpg"));
gameOverScreen = Toolkit.getDefaultToolkit().getImage(getClass().getResource("go.png"));
this.setFocusable(true);
this.addKeyListener(this);
requestFocus();
}
public void paintComponent(Graphics g) {
/** In Development */
if(spacePressed)
startMenu=false;
iMenu=false;
if(!startMenu && !iMenu){
/** Check for Game Over */
if(lives>0){
g.drawImage(background, scroll,0, 3052, height, null);
/** Rammus animation system */
if(animationValue == 5)
animationValue = 1;
if(qAnimationValue == 4)
qAnimationValue = 1;
if(wAnimationValue == 4)
wAnimationValue = 1;
if(qPressed && wPressed)
qwAbuse++;
else
qwAbuse--;
if(qwAbuse <0)
qwAbuse = 0;
if(qwAbuse >=15){
score = score-(score/2);
if(score==2)
score = 0;
}
if(qAnimationValue ==1 && qPressed){
rammusImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("Powerball"+qAnimationValue+".png"));
g.drawImage(rammusImage, width/3-25, height/2-70, null);}
else if(qAnimationValue ==2 && qPressed){
rammusImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("Powerball"+qAnimationValue+".png"));
g.drawImage(rammusImage, width/3-25, height/2-70, null);}
else if(qAnimationValue ==3 && qPressed){
rammusImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("Powerball"+qAnimationValue+".png"));
g.drawImage(rammusImage, width/3-25, height/2-70, null);}
else
{
rammusImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/resource/rr"+animationValue+".png"));
g.drawImage(rammusImage, width/3, height/2, null);
}
if(wAnimationValue ==1 && wPressed && !qPressed)
{
dc = Toolkit.getDefaultToolkit().getImage(getClass().getResource("dc"+wAnimationValue+".png"));
g.drawImage(dc, width/3-65, height/2-75, null);
}
else if(wAnimationValue ==2 && wPressed && !qPressed){
dc = Toolkit.getDefaultToolkit().getImage(getClass().getResource("dc"+wAnimationValue+".png"));
g.drawImage(dc, width/3-65, height/2-75, null);}
else if(wAnimationValue ==3 && wPressed && !qPressed){
dc = Toolkit.getDefaultToolkit().getImage(getClass().getResource("dc"+wAnimationValue+".png"));
g.drawImage(dc, width/3-65, height/2-75, null);}
else if(wAnimationValue ==1 && wPressed && qPressed){
qDC = Toolkit.getDefaultToolkit().getImage(getClass().getResource("qdc"+wAnimationValue+".png"));
g.drawImage(qDC, width/3+90, height/2+15, null);}
else if(wAnimationValue ==2 && wPressed && qPressed){
qDC = Toolkit.getDefaultToolkit().getImage(getClass().getResource("qdc"+wAnimationValue+".png"));
g.drawImage(qDC, width/3+90, height/2+15, null);}
else if(wAnimationValue ==3 && wPressed && qPressed){
qDC = Toolkit.getDefaultToolkit().getImage(getClass().getResource("qdc"+wAnimationValue+".png"));
g.drawImage(qDC, width/3+90, height/2+15, null);}
/** Graphical Life Display */
livesRemaining = Toolkit.getDefaultToolkit().getImage(getClass().getResource("life"+lives+".png"));
g.drawImage(livesRemaining, 0, 0, null);
/** Score Display */
scoreScroll = Toolkit.getDefaultToolkit().getImage(getClass().getResource("score.png"));
g.drawImage(scoreScroll, 790, 5, null);
g.setColor(Color.BLACK);
if(score<9000) {
Font font = new Font("Lucida Sans Bold Oblique", Font.BOLD, 18);
g.setFont(font);
g.setColor(Color.GREEN);
g.drawString("Current Score: "+score, 800, 37);
}
else {
Font font = new Font("Lucida Sans Bold Oblique", Font.BOLD, 15);
g.setFont(font);
g.setColor(Color.GREEN);
g.drawString("Current Score: Over 9000!!!", 800,37);
}
/** Enemy spawning system */
turretEncounter = (int)(Math.random()*10);
superMinionEncounter = (int)(Math.random()*10);
secondSuperMinionEncounter = (int)(Math.random()*10);
if((turretEncounter ==9 && !turretSpawned) || turretAlive)
{
turretImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("tr.png"));
g.drawImage(turretImage, turretLocation, 0, null);
turretSpawned = true;
turretAlive = true;
}
if((superMinionEncounter >=9 && !minionSpawned) || minionAlive)
{
minionImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("sm.png"));
g.drawImage(minionImage, minionLocation, height/2, null);
minionSpawned = true;
minionAlive = true;
}
if((secondSuperMinionEncounter >=9 && !secondMinionSpawned) || secondMinionAlive)
{
minionImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("sm.png"));
g.drawImage(minionImage, secondMinionLocation, height/2, null);
secondMinionSpawned = true;
secondMinionAlive = true;
}
/** Combat System */
if(wPressed && turretLocation <= width/3+40 && turretAlive) {
turretSlain = Toolkit.getDefaultToolkit().getImage(getClass().getResource("ts.png"));
g.drawImage(turretSlain, turretLocation, 0, null);
turretAlive = false;
}
if(!wPressed && turretLocation <=width/3+40 && turretAlive && !battledT)
lostLifeT = true;
if(qPressed && minionLocation <= width/3+75 && minionAlive){
minionSlain = Toolkit.getDefaultToolkit().getImage(getClass().getResource("sms.png"));
g.drawImage(minionSlain, minionLocation, height/2+25, null);
minionAlive = false;
}
if(!qPressed && minionLocation <= width/3+75 && minionAlive && !battledM)
lostLifeM = true;
if(qPressed && secondMinionLocation <= width/3+75 && secondMinionAlive){
minionSlain = Toolkit.getDefaultToolkit().getImage(getClass().getResource("sms.png"));
g.drawImage(minionSlain, secondMinionLocation, height/2+25, null);
secondMinionAlive = false;
}
if(!qPressed && secondMinionLocation <= width/3+75 && secondMinionAlive && !battledSM)
lostLifeSM = true;
if(!turretAlive) {
turretDestroyed = Toolkit.getDefaultToolkit().getImage(getClass().getResource("td.png"));
g.drawImage(turretDestroyed, turretLocation, height/2+10, null);
}
if(!minionAlive) {
minionSlain = Toolkit.getDefaultToolkit().getImage(getClass().getResource("sm2.png"));
g.drawImage(minionSlain, minionLocation, height/2+25, null);
}
if(!secondMinionAlive) {
minionSlain = Toolkit.getDefaultToolkit().getImage(getClass().getResource("sm2.png"));
g.drawImage(minionSlain, secondMinionLocation, height/2+25, null);
}
}
/** Game Over Screen */
else {
gameOver = true;
g.setColor(Color.BLACK);
g.fillRect(0,0,1000,300);
turretImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("tr.png"));
g.drawImage(turretImage, 25, 0, null);
g.drawImage(gameOverScreen, width/2-135, height/3-30, null);
minionImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("sm.png"));
g.drawImage(minionImage, (width/5)*4-25, height/2-25, null);
Font font = new Font("Lucida Sans Bold Oblique", Font.BOLD, 30);
g.setFont(font);
g.setColor(Color.GREEN);
//g.drawString("GAME OVER", width/2-80, height/3);
g.drawString("Your final score: "+score,width/2-133,height/2+40);
/** Play Again feature still in development */
g.drawString("Press Space to Play Again", width/2-175,height/2+90);
if (score>=9000)
g.drawString("YOU ARE EPIC!", width/2-100,height/2+75);
}
}/** In Development Menu */
else {
startScreen = Toolkit.getDefaultToolkit().getImage(getClass().getResource("main.png"));
g.drawImage(startScreen, 0, 0, null);
if(iPressed) {
instructions = Toolkit.getDefaultToolkit().getImage(getClass().getResource("i.png"));
g.drawImage(instructions, 0, 0, null);
}
}
}
public void actionPerformed(ActionEvent e) {
animationValue++;
if(qPressed)
qAnimationValue++;
if(wPressed)
wAnimationValue++;
scroll = scroll -scrollAmount;
if(scroll == -1525)
scroll = 0;
/** Life Update System */
if(minionLocation<width/3-50 && lostLifeM && !battledM) {
lives--;
lostLifeM = false;
battledM = true;
}
if(secondMinionLocation<width/3-50 && lostLifeSM && !battledSM) {
lives--;
lostLifeSM = false;
battledSM = true;
}
if(turretLocation<width/3-50 && lostLifeT && !battledT) {
lives--;
lostLifeT = false;
battledT = true;
}
/** Enemy Update System */
if(minionSpawned)
minionLocation = minionLocation -scrollAmount;
if(secondMinionSpawned)
secondMinionLocation = secondMinionLocation -scrollAmount;
if(turretSpawned)
turretLocation = turretLocation -scrollAmount;
if(minionLocation<=-130){
minionSpawned = false;
minionAlive = false;
battledM = false;
minionLocation = 1000;
}
if(secondMinionLocation<=-130){
secondMinionSpawned = false;
secondMinionAlive = false;
battledSM = false;
secondMinionLocation = 1000;
}
if(turretLocation<=-250){
turretSpawned = false;
turretAlive = false;
battledT = false;
turretLocation = 1000;
}
/** Enemy Stack Prevention System */
if(Math.abs(turretLocation-minionLocation) <=200)
turretLocation = turretLocation +(scrollAmount*2);
if(Math.abs(secondMinionLocation-minionLocation) <=200)
secondMinionLocation = secondMinionLocation +(scrollAmount*2);
/** Score System */
if(lives >0 && !startMenu)
score++;
if(!qPressed && !wPressed && !startMenu)
score++;
/** Still in Development */ if(spacePressed) {
gameOver=false;
score = 0;
lives = 3;
}
if(!gameOver)
repaint();
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.add(new RammusRun());
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void keyPressed(KeyEvent k) {
int key = k.getKeyCode();
switch(key) {
case KeyEvent.VK_Q: qPressed = true; break;
case KeyEvent.VK_W: wPressed = true; break;
case KeyEvent.VK_SPACE: spacePressed = true; break;
case KeyEvent.VK_I: iPressed = true; break;
case KeyEvent.VK_B: bPressed = true; break;
}
}
public void keyReleased(KeyEvent k) {
int key = k.getKeyCode();
switch(key) {
case KeyEvent.VK_Q: qPressed = false; break;
case KeyEvent.VK_W: wPressed = false; break;
case KeyEvent.VK_SPACE: spacePressed = false; break;
case KeyEvent.VK_I: iPressed = false; break;
case KeyEvent.VK_B: bPressed = false; break;
}
}
public void keyTyped(KeyEvent k) {
}
}
/** Feel free to use this code for games of your own! Redirect to your own image files and create an entire new game experience!
* If you do, please include this in the header:
* ==================================================================================================== =========================
* Original Game Written by Daniel Koohmarey
* Questions/Comments?
cccypher@gmail.com
* ==================================================================================================== =========================
*/