Saturday, December 20, 2014

2015 for Johnny...

2015 is about to come and, realistically I hope the following goals will be met:
1) revenue comes in on time for a change...
2) I settle down in a job and learn to do better programming as it is tough
3) I become more independent
4) I lose some fat as I cannot fit into any of my old clothes
5) I become more social as I have become a loner, although I do not really wish to do this I am fine with being a loner, really, this was just the doctor's suggestion at my apparent quick change of moods.
6) I want to make some money and buy a few things that I need
7) No big goals for this year, the world seems like a mess for now...except for funding a business.

Friday, December 19, 2014

The game which does not draw a robot...

package kiloboltgame; public class Robot { private int CenterX = 100; private int CenterY = 382; private boolean jumped = false; private int speedX = 0; private int speedY = 1; public void update() { //moves character or scrolls background if (speedX < 0) {CenterX += speedX;} else if (speedX == 0) { System.out.println("Do not scroll in the background");} else { if (CenterX <= 150) {CenterX += speedX;} else { System.out.println("Scroll background here"); } } //updates Y position if (CenterY + speedY >= 382) {CenterY = 382;} else {CenterY += speedY;} //handle jumping if (jumped == true) { speedY += 1; if ((CenterY + speedY) >= 382) { CenterY = 382; speedY = 0; jumped = false; } } //prevents going beyond the coordinate of zero if (CenterX + speedX <= 60) { CenterX = 61; } } public void moveRight() {speedX = 6;} public void moveLeft() {speedX = -6;} public void stop() {speedX = 0;} public void jump() { if (jumped == false) { speedY = -15; jumped = true; } } public int getCenterX() { return CenterX; } public int getCenterY() { return CenterY; } public boolean isJumped() { return jumped; } public void setJumped(boolean jumped) { this.jumped = jumped; } public int getSpeedX() { return speedX; } public void setSpeedX(int speedX) { this.speedX = speedX; } public int getSpeedY() { return speedY; } public void setSpeedY(int speedY) { this.speedY = speedY; } } package kiloboltgame; import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.color.*; import java.awt.Frame; import java.awt.event.*; import java.awt.image.BufferedImage; import java.awt.Graphics; import java.awt.Image; import java.net.*; @SuppressWarnings({ "unused" }) public class StartingClass extends Applet implements Runnable, KeyListener { /** * Demo game developed as per tutorial at http://www.kilobolt.com/day-4-enter-the-robot. */ private static final long serialVersionUID = -6721512236300497716L; private Robot r; private URL base; @Override public void init() { super.init(); setSize(800,480); setBackground(Color.BLACK); setFocusable(true); Frame f = (Frame) this.getParent().getParent(); f.setTitle("Q-Bot Alpha"); try { base = getDocumentBase(); } catch (Exception e) { e.printStackTrace(); } //image setups character = getImage(base, "img/robot.jpg"); addKeyListener(this); } @Override public void start() { //TODO: write implementation code super.start(); Thread t = new Thread(); t.start(); Robot r = new Robot(); } @Override public void stop () { //TODO: write implementation code super.stop(); } @Override public void destroy() { //TODO: write implementation code super.destroy(); } private final int DELAY = 20; public void run() { while (true) { repaint(); try { Thread.sleep(DELAY); } catch (InterruptedException e) { e.printStackTrace(); } } } @Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: break; case KeyEvent.VK_DOWN: break; case KeyEvent.VK_LEFT: break; case KeyEvent.VK_RIGHT: break; case KeyEvent.VK_SPACE: break; } } @Override public void keyReleased(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_UP: break; case KeyEvent.VK_DOWN: break; case KeyEvent.VK_LEFT: break; case KeyEvent.VK_RIGHT: break; case KeyEvent.VK_SPACE: break; } } @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } private Image image; private Graphics second; public void update (Graphics g) { if (image == null) { image = createImage(this.getWidth(), this.getHeight()); second = image.getGraphics(); } second.setColor(getBackground()); second.fillRect(0, 0, getWidth(), getHeight()); second.setColor(getForeground()); } Image character; public void paint (Graphics g) { //TODO: fix this bug g.drawImage(character, r.getCenterX() - 61, r.getCenterY() - 63, this); } }