here is the code that i have so far and it is not doing what it needs to do so far, this is not my code it is from a tutorial that i am following on youtube. i am just rebuilding it to learn how to make a game in java.
this is the first class-----
package com.ryan.doomed;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import javax.swing.JFrame;
import com.ryan.doomed.graphics.Screen;
public class Doomed extends Canvas implements Runnable{
private static final long serialVersionUID = 1L;
public static int width = 300;
public static int height = width / 16 * 9;
public static int scale = 3;
private Thread thread;
private JFrame frame;
private boolean running = false;
private Screen screen;
private BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
private int pixels[] = ((DataBufferInt)image.getRaster().getDataBuffer()) .getData();
public Doomed(){
Dimension size = new Dimension(width * scale, height * scale);
setPreferredSize(size);
screen = new Screen(width, height);
frame = new JFrame();
}//ends game
public synchronized void start(){
running = true;
thread = new Thread(this, "Display");
thread.start();
}//ends start
public synchronized void stop(){
running = false;
try{
thread.join();
}catch(InterruptedException e){
e.printStackTrace();
}
}//ends stop
public void run(){
while (running){
update();
render();
}
}//ends run
public void update(){
}//ends update
public void render(){
BufferStrategy bs = getBufferStrategy();
if (bs == null){
createBufferStrategy(3);
return;
}
screen.render();
for (int i = 0; i > pixels.length; i++){
pixels[i] = screen.pixels[i];
}//ends for
Graphics g = bs.getDrawGraphics();
// g.setColor(Color.BLACK);
// g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(image, 0, 0, getHeight(), getWidth(), null);
g.dispose();
bs.show();
}//ends render
public static void main(String[] args){
Doomed game = new Doomed();
game.frame.setResizable(false);
game.frame.setTitle("Doomed");
game.frame.add(game);
game.frame.pack();
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON _CLOSE);
game.frame.setLocationRelativeTo(null);
game.frame.setVisible(true);
game.start();
}//ends main
}//ends Doomed
this is the 2nd class---
package com.ryan.doomed.graphics;
public class Screen {
private int width, height;
public int pixels[];
public Screen(int width, int height){
this.width = width;
this.height = height;
pixels = new int [width * height];
}//ends constructor
public void render(){
for (int y = 0; y < height; y++) {
for (int x = 0; x < height; x++){
pixels[x + y * width] = 0xfe34ab;
}//ends second for
}//ends first for
}//ends render
}//ends screen
-----------------------------------
the code is supposed to have the full size of the screen the color specified but it is all messed up. i think that it is in the screen class but i can't pin point the error.