Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  Systematic Instrucations in Java?  (Read 1013 times)
0 Members and 1 Guest are viewing this topic.
Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Posted 2012-10-29 15:11:36 »

How could I make a set of systematic instrucations? like so after one thing is done the next thing works?

like in this example;
1  
2  
3  
4  
derpX += .04;
derpY -= .5;
derpX += .3;
//these variables are x and y values for a moving image


Like I want these operations to work one at a time, not like the normally would (as they normally operate all at the same time) how could i do this?

Offline ReBirth
« Reply #1 - Posted 2012-10-29 15:17:09 »

There're lot ways to achieve sequence execution, ranging from putting while() after each statement, to create your own callback listener.

Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #2 - Posted 2012-10-29 15:19:15 »

could you show me an example? sorry for my noobish java skills

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

Senior Member


Medals: 4
Projects: 2



« Reply #3 - Posted 2012-10-29 15:24:16 »

They already do run one after another, not all at the same time?

The world is big, so learn it in small bytes.
Offline ReBirth
« Reply #4 - Posted 2012-10-29 15:25:19 »

1  
2  
3  
4  
float targetX = derpX + .4;
derpX += .4
while (derpX != targetX);
derpY -= .5;

The last statement will be executed after derpX meets the target.
I can't provide callback examples, too much classes and interfaces needed. Try to google it.

Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #5 - Posted 2012-10-29 15:26:13 »

They do, but the first one will still be operating while the last one is. And thats the problem. I would want these to operate one at a time

Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #6 - Posted 2012-10-29 15:49:36 »

I dont see how I can use this for many sets of instruction.. Sad

Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #7 - Posted 2012-10-29 19:39:23 »

Guys just saying this is how i finally got it to work. Thanks for any tips though.
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  
         if (move01 == true) {
            homelessX += .04f;
            if (homelessX > 700) {
               move01 = false;
               move02 = true;
            }
         }
         if (move02 == true) {
            homelessY += .04f;
            if (homelessY > 900) {
               move02 = false;
               move03 = true;
            }
         }
         if (move03 == true) {
            homelessX += .04f;
            if (homelessX > 800) {
               move03 = false;
               move04 = true;
            }
         }
         if (move04 == true) {
            homelessY += .04f;
            if (homelessY > 1000) {
               move04 = false;
               move05 = true;
            }
         }
         if (move05 == true) {
            homelessX -= .04f;
            if (homelessX < 675) {
               move05 = false;
               move06 = true;
            }
         }
         if (move06 == true) {
            homelessY += .04f;
            if (homelessY > 1100) {
               move06 = false;
               move07 = true;
            }
         }
         if (move07 == true) {
            homelessX -= .04f;
            if (homelessX < 600) {
               move07 = false;
               move08 = true;
            }
         }
         if (move08 == true) {
            homelessY -= .04f;
            if (homelessY < 743) {
               move08 = false;
               move01 = true;
            }
         }
//homelessX and homelessY are the x and y cordinates of the image

Offline ReBirth
« Reply #8 - Posted 2012-10-30 07:59:40 »

Great then.

Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-10-31 00:44:43 »

Hot damn dude, that's too much!

Here's a better (and scalable) example:
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  
class Action {
    enum Conditions {
        LESS_THAN, GREATER_THAN;
       
        public boolean test(float v1, float v2) {
            switch(this) {
                case LESS_THAN: return v1 < v2;
                case GREATER_THAN: return v1 > v2;
            }
        }
    }
   
    private boolean doneX, doneY;
    private Condition cond;
    private float condValue;
   
    private float dx, dy;
   
    public Action(float dx, float dy) {
        this.dx = dx;
        this.dy = dy;
    }
   
    public void act(Player player) {
        player.x += dx;
        player.y += dy;
    }
   
    public Action doneWhenX(Condition cond, float condValue) {
        doneX = true; doneY = false;
        this.cond = cond;
        this.condValue = condValue;
        return this;
    }
   
    public Action doneWhenY(Condition cond, float condValue) {
        doneY = true; doneX = false;
        this.cond = cond;
        this.condValue = condValue;
        return this;
    }
   
    public boolean isDone(Player player) {
        if(cond == null)
            throw new IllegalArgumentException("No condition specified.");
       
        if(doneX)
            return cond.test(player.x, condValue);
        if(doneY)
            return cond.test(player.y, condValue);
    }
}

public class MyClass {
    public static void main(String[] args) {
        PriorityQueue<Action> actions = new PriorityQueue<>();
        actions.add(new Action(0.04f,0).doneWhenX(Action.Condition.GREATER_THAN, 700));
        //...
       
        Action curAction = null;

        // gameloop
       while(true) {
            //...
           
            if(curAction == null || curAction.isDone())
                curAction = actions.poll();
           
            if(curAction != null)
                curAction.act(player);
           
            //...
       }
    }
}


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.

CogWheelz (12 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

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

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

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

Riven (30 views)
2014-07-23 20:56:16
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!