Jump to content

Pasha

Members
  • Content count

    10
  • Joined

  • Last visited

About Pasha

  • Rank
    New Member

OCC

  • Computer Specs
    Mac

Profile Information

  • Location
    California

Social

  • Facebook
    my brother is the manager of it
  1. Hi guys this is a project I'm working on... A java car game. Right now it has no objective, like no point and there are some bugs but I'm working on it (: Bugs: Stops you if you try to go thru the wall (can't move after) and some other minor ones well heres the code: // Made By: Pasha Kravtsov (c) // nVidia_Freak, Flibo hehehe import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.lang.Math; import java.util.Random; import java.util.List; import java.util.ArrayList; import java.util.Iterator; public class Game extends Applet implements KeyListener, Runnable { final String author = "Pasha"; int car_x,car_y,width,height,car_width,car_height,speedx,speedy; int direction = 0; boolean started; Thread t,t1; Graphics bufferGraph; Image bufferImg; List<Wall> walls; public void run(){ t1 = Thread.currentThread(); while(t1 == t){ updateSpace(); try{ t1.sleep(150); // SLEEP FOR 100 MILLISECONDS }catch(InterruptedException e){} } } public void init() { setSize(1000,1000); width = getSize().width; height = getSize().height; setBackground(Color.black); bufferImg = createImage(width,height); bufferGraph = bufferImg.getGraphics(); speedx = 15; speedy = 15; car_x = 500; car_y = 500; car_height = 30; car_width = 20; addKeyListener(this); t = new Thread(this); t.start(); walls = new ArrayList<Wall>(); //middle wall //walls.add(new Wall(530,390,5,100)); //horizontal 1 "street/curb(s)" walls.add(new Wall(290,45,5,240)); walls.add(new Wall(330,90,5,150)); //horizontal 2 "street/curb(s)" walls.add(new Wall(340,795,5,155)); walls.add(new Wall(295,840,5,245)); //first "street/curb" walls.add(new Wall(290,45,795,5)); walls.add(new Wall(330,95,710,5)); //second "street/curb(s)" walls.add(new Wall(490,95,710,5)); walls.add(new Wall(530,55,795,5)); } public void updateSpace() { //1 = up, 2 = right, 3 = down, 4 = left if (direction == 1 && !checkWallCollision(car_x,car_y,car_height,car_width)) { car_width = 20; car_height = 30; int temp_y = car_y - speedy; if (temp_y >= 0) { car_y -= speedy; } } if (direction == 2 && !checkWallCollision(car_x,car_y,car_height,car_width)) { car_width = 30; car_height = 20; int temp_x = (car_x + car_width) + speedx; if (temp_x <= width) { car_x += speedx; } } if (direction == 3 && !checkWallCollision(car_x,car_y,car_height,car_width)) { car_width = 20; car_height = 30; int temp_y = (car_y + car_width) - speedy; if (temp_y <= height - 60) { car_y += speedy; } } if (direction == 4 && !checkWallCollision(car_x,car_y,car_height,car_width)) { car_width = 30; car_height = 20; int temp_x = (car_x + car_width) + speedx; if (temp_x >= 0) { car_x -= speedx; } } Font font1 = new Font("Arial", Font.BOLD, 18); Font font2 = new Font("Arial", Font.BOLD,40); bufferGraph.clearRect(0,0,width,height); bufferGraph.setFont(font1); bufferGraph.setColor(Color.red); bufferGraph.drawString("Author: " + author,22,40); bufferGraph.setColor(Color.blue); for (Iterator<Wall> iter = walls.iterator(); iter.hasNext() { iter.next().Paint(bufferGraph); } if (started) { bufferGraph.setColor(Color.white); bufferGraph.fillRect(car_x,car_y,car_width,car_height); } else { bufferGraph.setFont(font2); bufferGraph.setColor(Color.green); bufferGraph.drawString("Hit The Walls And Fail!",270,300); bufferGraph.setFont(font1); bufferGraph.drawString("Press 's' to start",400,400); } repaint(); } public boolean checkWallCollision(int x,int y,int height, int width) { for (Iterator<Wall> iter = walls.iterator(); iter.hasNext() { Wall wall = iter.next(); if (x >= wall.x && x <= (wall.x + wall.width) && y >= wall.y && y <= (wall.y + wall.height) ) { return true; } } return false; } public void paint(Graphics g) { g.drawImage(bufferImg,0,0,this); } public void keyPressed(KeyEvent e) { if (e.getKeyChar() == 's') { started = true; t1.start(); } switch (e.getKeyCode()) { case KeyEvent.VK_RIGHT: direction = 2; break; case KeyEvent.VK_UP: direction = 1; break; case KeyEvent.VK_LEFT: direction = 4; break; case KeyEvent.VK_DOWN: direction = 3; break; } } public void keyTyped(KeyEvent e) { } public void keyReleased(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_RIGHT: direction = 0; break; case KeyEvent.VK_UP: direction = 0; break; case KeyEvent.VK_LEFT: direction = 0; break; case KeyEvent.VK_DOWN: direction = 0; break; } } private class Wall { protected int x,y,height,width; public Wall(int x,int y,int height,int width) { this.x=x - (x % speedx); this.y=y - (y % speedy); this.height=height; this.width=width; } protected void Paint(Graphics g) { g.fillRect(x,y,width,height); } } }
  2. yea i know but for now... with my projects being soo small its alright... right now i'm working on a game so expect that to be posted later today soo yea
  3. you can also just run main() ... lol
  4. d: took me like 4 hours ;x I failed like 3 times ;D well yea also i don't want eclipse... can't figure it out and i'm happy with just BlueJ
  5. i'm not sure why your running it in FireFox cause when i run it it runs in AppletViewer.... lol i have no idea why it does that 'cause it works perfectly for me
  6. hahaha its ok (: i would recommend the software "BlueJ" as its very easy to use... its free too when you've downloaded that goto file -> new project then look for new/make class then double click it paste code then compile it and then right click on the class and do "Run Applet"
  7. Pasha

    help with visual basic

    you can't get it anymore :x its warez sorry heh
  8. what compiler are you using?
  9. run Applet (: its ok i'm a noob too
  10. Hello everyone!, This is my first post and I just wanted to share this little code that I made in time for Christmas It's currently unfinished as you can see if you run it, the "ornaments" are all over the screen. Not concentrated on the tree I was thinking about using Pixel Grabber to move and regulate the "ornaments" Well, Here you go (by the way, I'm still learning Java...so its not like a perfect program) // Made By: Pasha Kravtsov (c) 2010 // nVidia_Freak,Darius,Flibo,bowtie import java.awt.image.BufferedImage; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*; import java.util.List; import java.util.Iterator; import javax.swing.*; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class ChristmasTree extends Applet implements MouseListener, Runnable { int width = 500,height = 500; BufferedImage bufferImg; Graphics bufferG; BufferedImage tree; Thread t,t1; JFrame F; MyCanvas C; Random r = new Random(); List<Lights> lights; public ChristmasTree() { F = new JFrame("Christmas Tree "); F.setSize(width,height); C = new MyCanvas(); C.setSize(width,height); C.setVisible(true); C.addMouseListener(this); F.add(C); F.setVisible(true); F.setResizable(false); F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String path = "images/tree.jpg"; File file = new File(path); try { tree = ImageIO.read(file); }catch(IOException e) { e.printStackTrace(); } bufferImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); bufferG = bufferImg.getGraphics(); lights = new ArrayList<Lights>(10); for (int i = 0; i <= 10; i++) { lights.add(new Lights(r.nextInt(width),r.nextInt(height))); } t = new Thread(this); t.start(); } public static void main() { ChristmasTree T = new ChristmasTree(); } public void run() { t1 = Thread.currentThread(); while(t1 == t){ updateSpace(); try{ t1.sleep(200); // SLEEP FOR 150 MILLISECONDS }catch(InterruptedException e){ e.printStackTrace(); } } } public void updateSpace() { bufferG.clearRect(0,0,width,height); bufferG.drawImage(tree,0, 0,width,height,this); for (Iterator<Lights> iter = lights.iterator(); iter.hasNext() { Lights L = iter.next(); L.paint(bufferG); } bufferG.setColor(Color.black); bufferG.drawString("Made by Pasha!!! :x",15,15); C.repaint(); } public void mouseExited(MouseEvent me) { } public void mouseEntered(MouseEvent me) { } public void mouseReleased(MouseEvent me) { } public void mousePressed(MouseEvent me) { lights.add(new Lights(me.getX(),me.getY())); } public void mouseClicked(MouseEvent me) { } private class Lights { Color[] ornaments = { Color.red, Color.green, Color.blue, Color.yellow }; Color lightColor; Random r = new Random(); int x,y; int width = 6,height = 6; public Lights(int x,int y) { this.x=x; this.y=y; lightColor = ornaments[r.nextInt(ornaments.length)]; } public void paint(Graphics g) { lightColor = ornaments[r.nextInt(ornaments.length)]; g.setColor(lightColor); g.fillOval(x,y,width,height); } } private class MyCanvas extends Canvas { public MyCanvas() { super(); } public void paint(Graphics g) { g.drawImage(bufferImg,0,0,this); } } }
×