Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (531)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Little problem  (Read 686 times)
0 Members and 1 Guest are viewing this topic.
Offline DancingDevil

Junior Newbie





« Posted 2007-11-18 17:31:29 »

Image (donut) doesnt drop normally... but if i press buttons it drops little bit in every press

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  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
     package org.me.hello;

     import java.applet.*;
     import java.awt.*;
     import java.awt.event.*;
         
     public class peli extends Applet implements KeyListener,Runnable {
         
     Font fontti = new Font("Helvetica", Font.BOLD,  20);    
     
     Image homer;
     Image homerv;      
     Image sydan;
     Image donut;
     
     int aika=0;
     int aks;
     int x,y;
     int pisteet,livet;
   
     public boolean oikee;
     public boolean vasen;
     public boolean tippuu;
     public boolean focus;
         
     private Thread thread =new Thread(this);
                 
     public void run(){            
                     
     while (true) {
         
     try{                    
     
     Thread.currentThread().sleep(20);
     }catch(InterruptedException e){
     }    
     
     repaint();
         
     }    
     }
     
     public void init(){  
     this.aks=(int)(4*Math.random()*100+4);      
     addKeyListener(this);
     setBackground(Color.BLACK);
     donut = getImage(getDocumentBase(),"donutti.png");
     homer = getImage(getDocumentBase(),"homer.png");
     homerv = getImage(getDocumentBase(),"homerv.png");
     sydan = getImage(getDocumentBase(),"sydan.png");    
     resize(600,400);
     livet = 4;
     x=175;
     y=-70;
     }
             
     public void keyPressed(KeyEvent e) {
   
          if (e.getKeyCode() == KeyEvent.VK_ENTER) {
             tippuu = true;            
          }
         
          if (e.getKeyCode() == KeyEvent.VK_LEFT) {
             vasen = true;
          }
         
         
          if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
             oikee = true;
          }
         
     if(oikee == true){
     if(x<350)x = x+10;
     }
             
         
     if(vasen == true){
     if(x>0)x = x-10;
     }
         
     if(tippuu==true)y = y +5;    
         
     repaint();
     }
     
     public void keyReleased(KeyEvent e) {
     
          if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
              oikee = false;
          }
         
          if (e.getKeyCode() == KeyEvent.VK_LEFT) {
              vasen = false;
          }                      
     }
           
    public void actionPerformed(ActionEvent e) {}
   
     public void alas(){
               
     }
     
     public void paint(Graphics g) {
     
     g.setColor(Color.red);
     g.drawRect(450,1,5,1000);
     g.setFont(fontti);
     g.drawString("Lives:",470,50);
     
     if(livet > 1){
     g.drawImage(sydan,470,65,30,30,this);
     }
     
     if(livet > 2){
     g.drawImage(sydan,500,65,30,30,this);
     }
     
     if(livet > 3){
     g.drawImage(sydan,530,65,30,30,this);
     }
     
     g.drawString("Points:"+pisteet+"",470,130);
         
     if(vasen==false){    
     g.drawImage(homer,x,313,83,100,this);
     }
   
     if(vasen==true){
     g.drawImage(homerv,x,313,83,100,this);              
     }
     
     g.drawImage(donut,aks,y,50,50,this);
     }
     
    public void keyTyped(KeyEvent e) {
    }
    }

Offline alexxz4

Junior Member


Projects: 1



« Reply #1 - Posted 2007-11-18 21:29:26 »

ok, i suppose u want the donut to start moving down if u press down? I dont quiet get the meaning of "oikee", "vasen" and "tippuu", but the idea is this:
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  
int speed=0,x,y;
...
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN)speed=5;
...
}
...
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN)speed=0;
...
}
public void run(){
while (true) {
y+=speed;
     try{                    
     Thread.currentThread().sleep(20);
     }catch(InterruptedException e){
     }    
     repaint();
     }    
}
...
public void paint(Graphics g){
g.drawImage(donut,x,y,null,this);
...
}

[ Motherload Unlimited looking for programmers ] [ Solitaire ]
Offline Jackal von ÖRF

Junior Member





« Reply #2 - Posted 2007-11-18 23:01:05 »

ok, i suppose u want the donut to start moving down if u press down? I dont quiet get the meaning of "oikee", "vasen" and "tippuu", but the idea is this:
Short introduction to the Finnish language:

sydan (sydän) = heart
aika = time
aks (akseli?) = axis
pisteet = points
livet (English word "live/life" in Finnish plural, the real Finnish word is "elämät") = lives
oikee (slang for "oikea") = right
vasen = left
tippuu = [it] falls
alas = down

PS: It's better to write all code in English. Then more people can read the code and the code will look more consistent, because every library you will use is also written in English. And even though Java supports Unicode characters in variable and method names, that does not mean that you should use them there. (I once tried writing method names with Chinese characters just to see that it was possible. It might be good for obfuscation job security, though. Wink)

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DancingDevil

Junior Newbie





« Reply #3 - Posted 2007-11-19 19:11:32 »

Short introduction to the Finnish language:

sydan (sydän) = heart
aika = time
aks (akseli?) = axis
pisteet = points
livet (English word "live/life" in Finnish plural, the real Finnish word is "elämät") = lives
oikee (slang for "oikea") = right
vasen = left
tippuu = [it] falls
alas = down

PS: It's better to write all code in English. Then more people can read the code and the code will look more consistent, because every library you will use is also written in English. And even though Java supports Unicode characters in variable and method names, that does not mean that you should use them there. (I once tried writing method names with Chinese characters just to see that it was possible. It might be good for obfuscation job security, though. Wink)

Thanks jackal for that crarification...
ill try ty remember to use english in codes...

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (13 views)
2014-07-24 01:59:36

Riven (13 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (14 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (39 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (35 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!