Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java 2D / Re: Java game, what can I fix. on: 2011-11-15 00:56:24
http://www.mediafire.com/?5osfzjbpa264awc

The Jar.
2  Java Game APIs & Engines / Java 2D / Re: Java game, what can I fix. on: 2011-11-15 00:54:01
Im not really sure on your error. Mine compiles fine with no problem, Im using blueJ right now.
3  Java Game APIs & Engines / Java 2D / Re: Java game, what can I fix. on: 2011-11-14 21:11:02
/*
 * Elude
 * By Tylor
 *
 *
 *
 */
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.io.PrintStream;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Toolkit;
import java.applet.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;

public final class JGame extends JFrame
{
    Grid grid;
    GameLoop gLoop;
    public static boolean p_up = false;
    public static boolean p_down = false;
    public static boolean p_left = false;
    public static boolean p_right = false;
    static Player player;
    static BufferedImage img;

    public JGame()
    {
        super("Eludë 0.1");
        this.grid = new Grid();
        add(this.grid);

        setDefaultCloseOperation(3);
        this.gLoop = new GameLoop(this);
        this.gLoop.start();

    }

    public void Menu()
    {

    }

    public static void main(String[] args)
    {

        int a = 2;
        int b = "DSU".hashCode() % 3000;
        int c = "WXC".hashCode() % 3000;
        for (int i = 0; i <= c; i++)
        {
            a = (a ^ i) % b;
        }
        System.out.println(a);
        JGame fm = new JGame();
        fm.setVisible(true);
        fm.setResizable(false);
        fm.setExtendedState(fm.MAXIMIZED_BOTH);
        fm.pack();
        fm.show();
    }
}
class Player
implements KeyListener
{
    int x;
    int buildings;
    Grid grid;

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    int y;
    int clevel = 1;
    String level = "Level: " + this.clevel;
    String version = "Eludë 0.1";
    String user = "Player.gif";

    boolean p_up = false;
    boolean p_down = false;
    boolean p_left = false;
    boolean p_right = false;
    int loop = 400;
    int startloop = 0;
    int backgroundx = 50;
    int backgroundy = 50;
    int backgroundx2 = 50;
    int backgroundy2 = 50;
    int backgroundx3 = 50;
    int backgroundy3 = 50;
    int backgroundx4 = 50;
    int backgroundy4 = 50;

    BufferedImage image;

    static int followx = 400;
    static int followy = 400;
    static boolean morex = false;
    static boolean morey = false;

    public Player(int i, int a)
    {
        this.x = i;
        this.y = a;
        try
        {
            image = ImageIO.read(Player.class.getResource(this.user));
        }
        catch (IOException e)
        {
            System.out.println("Image Not In Root");
        }
    }

    public void draw(Graphics g)
    {
        int gamespeed = 5;
        boolean boxagro = false;

        g.fillRect(followx, followy, 20, 20);

        g.drawString("Player", this.x - 2, this.y - 5);
        g.drawString(this.level, 0, screenSize.height - 25);
        g.drawString(this.version, screenSize.width - 90, screenSize.height - 25);
        //while ( startloop < loop)
        //{
        Random generator = new Random();
        backgroundx = generator.nextInt(screenSize.width);
        // System.out.println("backgroundX: " + backgroundx);
        backgroundy = generator.nextInt(screenSize.height);
        backgroundx2 = generator.nextInt(screenSize.width);
        //System.out.println("backgroundX2: " + backgroundx2);
        backgroundy2 = generator.nextInt(screenSize.height);
        backgroundx3 = generator.nextInt(screenSize.width);
        //System.out.println("backgroundX3: " + backgroundx3);
        backgroundy3 = generator.nextInt(screenSize.height);
        backgroundx4 = generator.nextInt(screenSize.width);
        backgroundy4 = generator.nextInt(screenSize.height);
        //}
        g.fillRect(backgroundx,backgroundy,5,5);
        g.fillRect(backgroundx2,backgroundy2,5,5);
        g.fillRect(backgroundx3,backgroundy3,5,5);
        g.fillRect(backgroundx4,backgroundy4,5,5);

        g.drawImage(image, this.x, this.y, null);
        int ydiff = this.y - followy;
        int xdiff = this.x - followx;
        //System.out.println("Xdiff" + xdiff);
        //System.out.println("Ydiff" + ydiff);
        if (ydiff < 300 || (xdiff < 300))
        {
            boxagro = true;
        }
        if (ydiff > 300 || (xdiff > 300) || (xdiff < -300) || (ydiff < -300))
        {
            boxagro = false;
            //System.out.println(boxagro);
        }
        if (boxagro == true)
        {
            if ( this.y < followy)
            {
                if (followy > 0 )
                {
                    followy--;followy--;
                }
            }
            if ( this.y > followy )
            {
                if (followy < screenSize.height - 30)
                {
                    followy++; followy++;
                }
            }
            if ( this.x > followx)
            {
                if (followx > 0 )
                {
                    followx++;followx++;
                }
            }
            if ( this.x < followx)
            {
                if (followy < screenSize.width )
                {
                    followx--;followx--;
                }
            }
        }

        if ((this.p_up == true) && (this.y > 25))
        {
            this.y -= gamespeed;

        }
        if ((this.p_down == true) && (this.y < screenSize.height - 55))
        {
            this.y += gamespeed;

        }
        if ((this.p_left == true) && (this.x > 10))
        {
            this.x -= gamespeed;

        }
        if ((this.p_right == true) && (this.x < screenSize.width - 35))
        {
            this.x += gamespeed;

        }
    }

    public void keyPressed(KeyEvent ke)
    {
        if ((ke.getKeyCode() == 38) &&
        (this.y > 15))
        {
            //System.out.println("Y: " + this.y);
            this.p_up = true;
            //System.out.println("FollowY" + followy);

        }
        if ((ke.getKeyCode() == 40) &&
        (this.y < screenSize.height - 45))
        {
            //System.out.println("Y: " + this.y);
            this.p_down = true;
            //System.out.println("FollowY" + followy);

        }
        if ((ke.getKeyCode() == 37) &&
        (this.x > 5))
        {

            //System.out.println("X: " + this.x);
            this.p_left = true;
            //System.out.println("FollowX" + followx);
        }
        if ((ke.getKeyCode() == 39) &&
        (this.x < screenSize.width - 35))
        {
            //System.out.println("X: " + this.x);
            this.p_right = true;
            //System.out.println("FollowX" + followx);

        }
        if (ke.getKeyCode() == 16)
        {
            this.clevel += 1;
            this.level = ("Level: " + this.clevel);
        }
    }

    public void keyReleased(KeyEvent ke)
    {
        if (ke.getKeyCode() == 38)
        {
            this.p_up = false;
        }
        if (ke.getKeyCode() == 40)
        {
            this.p_down = false;
        }
        if (ke.getKeyCode() == 37)
        {
            this.p_left = false;
        }
        if (ke.getKeyCode() == 39)
        {
            this.p_right = false;
        }
    }

    public void keyTyped(KeyEvent ke)
    {
    }
}
class Grid extends JPanel
{
    Player player;

    public Grid()
    {
        setFocusable(true);
        requestFocus();
        setBackground(Color.pink);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(0,0,screenSize.width, screenSize.height);
        setPreferredSize(new Dimension(screenSize.width, screenSize.height));

        this.player = new Player(16, 16);
        addKeyListener(this.player);
    }

    @Override
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        this.player.draw(g);
    }
}

class GameLoop extends Thread
{

    //int gamespeed = 1;
    JGame game;
    public GameLoop(JGame g)
    {
        this.game = g;
    }

    @Override
    public void run()
    {
        Player player;
        Grid grid;
        while (true)
        {
            this.game.repaint();
            try
            {
                Thread.sleep(15L);

            }
            catch (Exception e)
            {
                System.out.println("Error @ Thread.Sleep");
            }
        }
    }
}
4  Java Game APIs & Engines / Java 2D / Java game, what can I fix. on: 2011-11-14 21:09:07
I have been working on this project mainly for the hell of It and I wanted to know what I could do better because I know just how bad I am at coding. Pay no attention to my imports. Cheesy

http://www.mediafire.com/?84fuk47hub9qqf4
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (16 views)
2014-04-15 18:08:23

BurntPizza (14 views)
2014-04-15 03:46:01

UprightPath (27 views)
2014-04-14 17:39:50

UprightPath (12 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (51 views)
2014-04-10 04:04:31

BurntPizza (110 views)
2014-04-08 23:06:04

tom_mai78101 (211 views)
2014-04-05 13:34:39

trollwarrior1 (179 views)
2014-04-04 12:06:45

CJLetsGame (185 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!