Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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  Games Center / Tiny Game 2010 / Re: Game Titles on: 2010-04-18 18:11:46
I call 'Empire 4030'
2  Games Center / Tiny Game 2010 / Re: TinyGame Resources on: 2010-04-16 07:45:34
This is a half-finished framework I stiched together when I started on my entry.

EGAColor

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
[pre]package egalib.ega;

import java.awt.Color;

public final class EGAColor
{
    private static final int[] HEX_VALUES = new int[]{
      0x000000, 0x0000aa, 0x00aa00, 0x00aaaa, 0xaa0000, 0xaa00aa, 0xaaaa00, 0xaaaaaa,
      0x000055, 0x0000ff, 0x00aa55, 0x00aaff, 0xaa0055, 0xaa00ff, 0xaaaa55, 0xaaaaff,
      0x005500, 0x0055aa, 0x00ff00, 0x00ffaa, 0xaa5500, 0xaa55aa, 0xaaff00, 0xaaffaa,
      0x005555, 0x0055ff, 0x00ff55, 0x00ffff, 0xaa5555, 0xaa55ff, 0xaaff55, 0xaaffff,
      0x550000, 0x5500aa, 0x55aa00, 0x55aaaa, 0xff0000, 0xff00aa, 0xffaa00, 0xffaaaa,
      0x550055, 0x5500ff, 0x55aa55, 0x55aaff, 0xff0055, 0xff00ff, 0xffaa55, 0xffaaff,
      0x555500, 0x5555aa, 0x55ff00, 0x55ffaa, 0xff5500, 0xff55aa, 0xffff00, 0xffffaa,
      0x555555, 0x5555ff, 0x55ff55, 0x55ffff, 0xff5555, 0xff55ff, 0xffff55, 0xffffff
   };
   
   public static final EGAColor[] EGA_COLORS = new EGAColor[64];
   
   static
   {
       for (int x=0; x<64; x++)
       {
           EGA_COLORS[x] = new EGAColor(x);
       }
   }
   
   public final int index;
   
   public final Color awtColor;
   
   public EGAColor(int index)
   {
       this.index=index;
       this.awtColor = new Color(HEX_VALUES[index]);
   }
}
         
          [/pre]



EGAGraphics

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
[pre]package egalib.ega;

import java.awt.*;

public final class EGAGraphics
{
    private EGAColor[] palette = new EGAColor[16];
   
    private Graphics awt;
   
    private int cIndex;
   
    private static final Font
        F_BIG = new Font("SansSerif",Font.PLAIN,10),
        F_MED = new Font("SansSerif",Font.PLAIN,8),
        F_SMALL = new Font("SansSerif",Font.PLAIN,6);
       
    public static final byte BIG = 1, MED = 2, SMALL = 3;
   
    public EGAGraphics(Graphics g)
    {
        awt=g;
        for (int x=0; x<16; x++)
        {
            palette[x] = EGAColor.EGA_COLORS[x];
        }
        cIndex=0;
        awt.setColor(palette[cIndex].awtColor);
        awt.setFont(F_SMALL);
    }
   
    public void updatePalette(EGAColor color, int index)
    {
        palette[index]=color;
        if (cIndex==index)
            awt.setColor(palette[index].awtColor);
    }
   
    public void setPalette(EGAColor[] palette)
    {
        if (palette.length!=16)
            throw new RuntimeException("Palette must be an array of length 16!");
        for (int x=0; x<16; x++)
        {
            if (palette[x]==null)
                throw new NullPointerException("EGAColor in palette was null!");
            this.palette[x]=palette[x];
        }
    }
   
    public void setColor(int index)
    {
        cIndex=index;
        awt.setColor(palette[index].awtColor);
    }
   
    public void drawRect(int x, int y, int w, int h)
    {
        awt.drawRect(x,y,w,h);
    }
   
    public void fillRect(int x, int y, int w, int h)
    {
        awt.fillRect(x,y,w,h);
    }
   
    public void drawString(String string, int x, int y)
    {
        awt.drawString(string,x,y);
    }
   
    public void drawShape(Shape shape)
    {
        ((Graphics2D)awt).draw(shape);
    }
   
    public void fillShape(Shape shape)
    {
        ((Graphics2D)awt).fill(shape);
    }
   
    public void fontSize(byte _enum)
    {
        switch (_enum)
        {
            case BIG:
                awt.setFont(F_BIG);
                break;
            case SMALL:
                awt.setFont(F_SMALL);
                break;
            case MED:
                awt.setFont(F_MED);
                break;
        }
    }
}
   
    [/pre]


EGADisplay

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
[pre]package egalib.ega;

import java.applet.Applet;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;

public final class EGADisplay
{
    private Applet applet;
   
    private Canvas canvas;
   
    private BufferedImage buffer;
   
    private EGAGraphics graphics;
   
    public EGADisplay(Applet applet)
    {
        this.applet=applet;
       
        applet.setIgnoreRepaint(true);
        applet.setLayout(new BorderLayout());
       
        GraphicsConfiguration config =
            GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();
        canvas = new Canvas(config);
        canvas.setIgnoreRepaint(true);
        applet.add(canvas,BorderLayout.CENTER);
        buffer = config.createCompatibleImage(40,30,Transparency.OPAQUE);
        canvas.requestFocus();
        graphics = new EGAGraphics(buffer.getGraphics());
    }
   
    public EGAGraphics getGraphics()
    {
        return graphics;
    }
   
    public void show()
    {
        Graphics2D g = (Graphics2D)canvas.getGraphics();
        g.setTransform(AffineTransform.getScaleInstance(canvas.getWidth()/buffer.getWidth(),canvas.getHeight()/buffer.getHeight()));
        g.drawImage(buffer,0,0,null);
    }
   
    public void attachInput(EGAInput input)
    {
        canvas.addKeyListener(input);
        canvas.addMouseListener(input);
    }
}[/pre]


EGAInput

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
[pre]package egalib.ega;

import java.awt.event.*;

public final class EGAInput implements KeyListener, MouseListener
{
    private boolean[] keys = new boolean[256];
    private boolean[] mouse = new boolean[4];
    private int mx,my;
   
    public int mouseX()
    {
        return mx;
    }
   
    public int mouseY()
    {
        return my;
    }
   
    public boolean mouseFocus()
    {
        return mouse[3];
    }
   
    public boolean mouseDown(int button)
    {
        return mouse[button-1];
    }
   
    public boolean keyDown(int key)
    {
        return keys[key];
    }
   
    public void keyPressed(KeyEvent event)
    {
        int code = event.getKeyCode();
        if (code<256)
            keys[code]=true;
    }
   
    public void keyReleased(KeyEvent event)
    {
        int code = event.getKeyCode();
        if (code<256)
            keys[code]=false;
    }
   
    public void mousePressed(MouseEvent event)
    {
        mouse[event.getButton()-1]=true;
        mx = event.getX();
        my = event.getY();
    }
   
    public void mouseReleased(MouseEvent event)
    {
        mouse[event.getButton()-1]=false;
        mx = event.getX();
        my = event.getY();
    }
   
    public void mouseEntered(MouseEvent event)
    {
        mouse[3]=true;
        mx = event.getX();
        my = event.getY();
    }
   
    public void mouseExited(MouseEvent event)
    {
        mouse[3]=false;
        mx = event.getX();
        my = event.getY();
    }
   
    public void keyTyped(KeyEvent e){}
    public void mouseClicked(MouseEvent e){}
}
    [/pre]


EGAGame

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
[pre]package egalib.game;

import java.applet.Applet;
import egalib.ega.*;

public abstract class EGAGame extends Applet implements Runnable
{
    protected volatile EGADisplay ega_display;
   
    protected volatile EGAInput ega_input;
   
    protected volatile Thread ega_thread;
   
    public final void init()
    {
        ega_display = new EGADisplay(this);
        ega_input = new EGAInput();
        ega_display.attachInput(ega_input);
        ega_load();
    }
   
    public final void start()
    {
        ega_thread = new Thread(this);
        ega_thread.start();
    }
   
    public final void stop()
    {
        ega_thread.interrupt();
        ega_thread = null;
    }
   
    public final void destroy()
    {
       
    }
   
    public final void run()
    {
        while (!ega_thread.isInterrupted())
        {
            ega_update();
            ega_paint(ega_display.getGraphics());
            ega_display.show();
            try
            {
                Thread.sleep(30);
            }
            catch (Exception e){}
        }
    }
   
    public abstract void ega_update();
    public abstract void ega_paint(EGAGraphics g);
    public abstract void ega_load();
}[/pre]


Its not complete but maybe somebody can use it.[/code][/code]
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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (113 views)
2014-11-26 15:22:04

toopeicgaming1999 (100 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!