I AM IN!!!!!!!!!!!

Im in for ludum dare 29 its my 3 ludum and you not the saying 3 time luckie ? (hope)…

i have made a very basic java thing (cant really call it a engine) and i hope to use it in the compo so here it is ….

import java.awt.Color;

import net.babbster.rain.Game;

public class Screen {

private int width;
private int height;
public int RED = 0xFF0000;
public int BLACK= 0x000000;
public int BLUE = 0x0f92bd;
public int GREEN = 0x00FF00 ;
public int WHITE =0xeeeeee ;

public int[] pixels;

// objects//
int[][] Player = new int[][] {
//0 = black
//1 = white
//2 = blue
//3 = red
//4 = green
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 1, 2, 2, 1, 0, 0, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 1, 0, 1, 1, 1, 1, 0, 1, 0 },
{ 0, 2, 0, 1, 1, 1, 1, 0, 2, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 },
{ 0, 0, 2, 2, 0, 2, 2, 0, 0, 0 } };
int[][] Player2 = new int[][] {
//0 = black
//1 = white
//2 = blue
//3 = red
//4 = green
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 1, 2, 2, 1, 0, 0, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 1, 0, 1, 1, 1, 1, 0, 1, 0 },
{ 0, 2, 0, 1, 1, 1, 1, 0, 2, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 },
{ 0, 0, 0, 2, 2, 0, 2, 2, 0, 0 } };
int[][] Player3 = new int[][] {
//0 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 1, 1, 2, 1, 0, 0 },
{ 0, 0, 0, 1, 2, 2, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 } };
int[][] object2 = new int[][] {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 1, 2, 2, 2, 2, 1, 0, 0 },
{ 0, 0, 1, 2, 1, 1, 2, 1, 0, 0 },
{ 0, 0, 1, 2, 1, 1, 2, 1, 0, 0 },
{ 0, 0, 1, 2, 2, 2, 2, 1, 0, 0 },
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }};
int[][] object3 = new int[][] {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 2, 2, 1, 0, 0, 0 },
{ 0, 0, 1, 2, 1, 1, 2, 1, 0, 0 },
{ 0, 1, 2, 1, 2, 2, 1, 2, 1, 0 },
{ 0, 1, 2, 1, 2, 2, 1, 2, 1, 0 },
{ 0, 0, 1, 2, 1, 1, 2, 1, 0, 0 },
{ 0, 0, 0, 1, 2, 2, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 } };
int time = 0;
int counter = 0;

public Screen(int width, int height) {
this.width = width;
this.height = height;
pixels = new int[width * height];
}

public void clear() {

for (int i = 0; i < pixels.length; i++) {
pixels[i] = 0;
}

}

public void render() {

counter++;

if (counter % 100 == 0) {
time++;
}

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {

try {
if(y < 100){
//112

}else{
pixels[( x) + ( y) * width] = 0x0f92bd;
}
//pixels[x + y * width] = 0xff00ff;
if(Game.STNCE == 1){
if (Player[x][y] == 0) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = BLACK;
}
if (Player[x][y] == 1) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = WHITE;
}
if (Player[x][y] == 2) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = BLUE;
}
}
if(Game.STNCE == 2){
if (Player2[x][y] == 0) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = BLACK;
}
if (Player2[x][y] == 1) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = WHITE;
}
if (Player2[x][y] == 2) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = BLUE;
}
}
if(Game.STNCE == 3){
if (Player3[x][y] == 0) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = BLACK;
}
if (Player3[x][y] == 1) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = WHITE;
}
if (Player3[x][y] == 2) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = BLUE;
}
}
if(Game.STNCE == 4){
if (Player3[x][y] == 0) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = BLACK;
}
if (Player3[x][y] == 1) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = WHITE;
}
if (Player3[x][y] == 2) {
pixels[(Game.PlayerX + y) + (Game.PlayerY + x) * width] = BLUE;
}
}
if(Game.STATE == 1){
if (object1[x][y] == 0) {
pixels[(Game.object1X + y) + (Game.object1Y + x) * width] = BLACK;
}
if (object1[x][y] == 1) {
pixels[(Game.object1X + y) + (Game.object1Y + x) * width] = WHITE;
}
if (object1[x][y] == 2) {
pixels[(Game.object1X + y) + (Game.object1Y + x) * width] = BLUE;
}
}

if(Game.STATE == 2){
if (object2[x][y] == 0) {
pixels[(Game.object1X + y) + (Game.object1Y + x) * width] = BLACK;
}
if (object2[x][y] == 1) {
pixels[(Game.object1X + y) + (Game.object1Y + x) * width] = WHITE;
}
if (object2[x][y] == 2) {
pixels[(Game.object1X + y) + (Game.object1Y + x) * width] = BLUE;
}
}

//if (level1[x][y] == 1) {

//pixels[x + (10) + y + (10) * width] = 0xff00ff;
//}
} catch (Exception exp) {
time = 0;
}
}
}
}

}

package net.babbster.rain;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.util.Arrays;

import javax.swing.JFrame;

import net.babbster.rain.graphics.Screen;

public class Game extends Canvas implements Runnable, KeyListener {
private static final long serialVersionUID = 1L;
public static int width = 200;
public static int height = width / 16 * 9;
public static int scale = 5;
///////////
//players//
///////////
public static int PlayerX = 50;
public static int PlayerY = 50;
public static int STNCE = 2;
public static int vol = 0;
public static int grav = 3;
public static int Acc = 0;
////////////
//objects//
////////////
public static int object1X = 100;
public static int object1Y = 91;
public static int STATE = 1;
int F = 0;
private Thread thread;
private JFrame frame;
private boolean running = false;

private Screen screen;

/* IMAGES */
//BufferedImage is a raster storage class
private BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

//CTRL + SHIFT + O will import a missing package
//this pulls the pixels out of the BufferedImage so that we can manipulate them
private int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();

/**
* Constructor
*/
public Game() {
Dimension size = new Dimension(width * scale, height * scale);

this.setPreferredSize(size);
screen = new Screen(this.width, this.height);
frame = new JFrame();

}

/**
* Start game thread
*/
public synchronized void start() {
running = true;
thread = new Thread(this, “Game”);
thread.start();
}

/**
* Stop game thread
*/
public synchronized void stop() {
running = false;
try {
thread.join();
} catch (InterruptedException error) {
error.printStackTrace();
}
}
double interpolation = 0;
final int TICKS_PER_SECOND = 24;
final int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
final int MAX_FRAMESKIP = 5;
public void run() {
// Game loop
while (running) {
double next_game_tick = System.currentTimeMillis();
int loops;

while (true) {
loops = 0;
while (System.currentTimeMillis() > next_game_tick
&& loops < MAX_FRAMESKIP) {

update();
render();
if(PlayerY + 10 + vol < 100){
vol ++;
}else{
vol = 0;
if(STNCE == 1){
}else{
if(STNCE == 2){
}else{
STNCE = 1;
}
}

}
if( F > 3){
if(STATE == 2){
STATE = 1;
}else{
STATE = 2;
}
F = 0;
}else{F ++;}
if(PlayerX >190){
Acc = -10;
}
if(PlayerX < 10){
Acc = +10;
}
PlayerX += Acc;
if(Acc > 0){
Acc –;
}
if(Acc < 0){
Acc ++;
}
PlayerY += vol;
object1X -= 3;

//PlayerX ++;

next_game_tick += SKIP_TICKS;
loops++;
//System.out.println();
}

interpolation = (System.currentTimeMillis() + SKIP_TICKS – next_game_tick
/ (double) SKIP_TICKS);
// display_game(interpolation);
}
}
}

/**
* render – all drawing work
*/
public void render(){
//create the back buffer
BufferStrategy buffer = this.getBufferStrategy();
if(buffer == null){
//the 3 represents triple buffering
this.createBufferStrategy(3);
return;
}

//clear and render the backbuffer
screen.clear();
screen.render();

for(int i = 0; i < pixels.length; i++){
this.pixels[i] = screen.pixels[i];
}
//gets the non-rendered drawing buffer for modification
Graphics g = buffer.getDrawGraphics();

g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);

//release resources
g.dispose();
//and show the back buffer
buffer.show();

}

/**
* update – game logic
*/
public void update(){

}

/**
* Entry point
*
* @param args
*/
public static void main(String[] args) {
Game game = new Game();
game.addKeyListener(game);
game.frame.setResizable(false);
game.frame.setTitle(“Rain”);
game.frame.add(game);
game.frame.pack();
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.frame.setLocationRelativeTo(null);
game.frame.setVisible(true);
game.start();
}

public void keyPressed(KeyEvent e) {
int keycode = e.getKeyCode();
if (keycode == KeyEvent.VK_LEFT) {
Acc -=2;
STNCE = 1;
}

if (keycode == KeyEvent.VK_RIGHT) {
Acc += 2;
STNCE = 2;
}

if (keycode == KeyEvent.VK_UP) {
if(STNCE == 2){
STNCE = 3;
vol = -10;
}
if(STNCE == 1){
STNCE = 4;
vol = -10;
}

}

if (keycode == KeyEvent.VK_DOWN) {

}
}

@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub

}

@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub

}
}

Comments

Newbie97
25. Apr 2014 · 20:12 UTC
please add a ‘read more’ to your post dude.