This site requires JavaScript, please enable it in your browser!
Greenfoot back
Unlimited
Unlimited wrote ...

2018/12/26

Game Creation: Directional Idle, Shooting and Jumping.

1
2
3
4
5
Unlimited Unlimited

2018/12/27

#
However, now neither gravity nor hit detection work and only the standing animation plays, movment animations do not play.
danpost danpost

2018/12/27

#
I missed a set of lines to be removed: * lines 179 through 214 (not to be replaced) * line 167 and line 173 (to be replaced later by setting the animation sets) Other things that should be removed: * lines 62 through 69 (jumping and falling deal with vertical movement) * lines 73 through 78 or lines 88 through 113 (one or the other -- both add horizontal movement by direction of key pressing) No key should be checked more than once in your code. I count 3 times where you check the "right" key in your original code and 4 times in your badly revised code. Please start back with original code remove and replace appropriate codes and post the entire class for review and further changes to be made. Prayerfully, it will at least compile at that point.
danpost danpost

2018/12/27

#
Unlimited wrote...
However, now neither gravity nor hit detection work and only the standing animation plays, movment animations do not play.
Correct, animations are incomplete at this point -- we will get to that. As far as gravity and hit detection, let's hold off on those changes as yet -- stay with original codes for that until animating is done. One thing at a time is always best.
Unlimited Unlimited

2018/12/27

#
The lines to be removed are still in the first post yes?
danpost danpost

2018/12/27

#
Unlimited wrote...
The lines to be removed are still in the first post yes?
Yes. The code you put in the onGround method is the entire vertical movement code (should replace jump, fall, onGround and any other methods, dealing with vertical movement). You can put that code in a method called moveVertically and call it from the act method. But, like I already said, we can deal with that later.
Unlimited Unlimited

2018/12/27

#
So im not sure if i removed the correct lines but here is what i have now.
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * This class is just an example. You can delete it or change the code.
 * It's not necessary for the scrolling system.
 */
public class Azure extends ScrollingActor
{
    private int vSpeed = 0;
    private int acceleration = 1;
    private boolean jumping;
    private int jumpStrength = 20;
     
     
     
     
  
     
     
    private static GreenfootImage[] standAnim = new GreenfootImage[9];
    private static GreenfootImage[] rightAnim = new GreenfootImage[11];
    private static GreenfootImage[] leftAnim = new GreenfootImage[11];
     
    static
    {
        for (int i=0; i<standAnim.length; i++) standAnim[i] = new GreenfootImage("Stand_0"+(i+1)+".png");
        for (int i=0; i<rightAnim.length; i++) rightAnim[i] = new GreenfootImage("Walk-A_"+(i < 10 ? "0" : "")+(i+1)+".png");
        for (int i=0; i<rightAnim.length; i++) leftAnim[i] = new GreenfootImage("WalkLeft-A_"+(i < 10 ? "0" : "")+(i+1)+".png");
    }
     
     
    private int frame = 1;
    // with the following fields
    private int animCount; // counter for animations
    private int animDelay = 6; // initially set for standing animation (frame rate field)
  
    // this method might help
    private void setAnim(GreenfootImage[] anim, int frameRate)
    {
        animSet = anim;
        animCount = -1; // prepares to set first image when incremented
        animDelay = frameRate;
        animate(); // calls a method to set a frame of this newly set animation
    }
    private int Counter = 0;
     
     
    private GreenfootImage[] animSet = standAnim;
     
     
     
     
    /**
     * Here you can tell your actor what he has to do.
     */
    public void act() {
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
        animate();
        move();
        Counter();
         
         
        ceiling();
         
    }
     
     
    
 
    public void Counter()
    {
         
        if(Greenfoot.isKeyDown("right"))
        Counter = 0;
         
        if(Greenfoot.isKeyDown("left"))
        Counter = 1;
    }
     
    public void move()
    {
        int y = getY();
        int x = getX();
        if(Greenfoot.isKeyDown("right") ) x+=6;
        
         
         
        if(Greenfoot.isKeyDown("left") ) x-=6;
        
         
        setLocation(x,y);
    }
     
     
     
    public void fall()
    {
        setLocation(getX(), getY() +vSpeed);
         
        {
            vSpeed = vSpeed + acceleration;
        }
        jumping = true;
    }
     
    public void onGround()
    {
         boolean onGround = false;
         // assume in air
       vSpeed += acceleration; // apply gravity
       setLocation(getX(), getY()+vSpeed); // fall
       Actor actor = getOneIntersectingObject(Actor.class);
       if (actor != null)
       { // colliding with another actor
           int vDir = (int)Math.signum(vSpeed); // vertical direction of movement
           vSpeed = 0; // kill vertical speed
           if (vDir > 0) onGround = true; // landing and not bopping head
           setLocation(getX(), actor.getY()-vDir*(actor.getImage().getHeight()+getImage().getHeight())/2+30); // assigning stop location
        }
        if (onGround && Greenfoot.isKeyDown("space")) vSpeed = -20; // initiate a jump
    }
         
         
         
         
         
     
     
     
     
    public boolean ceiling()
    {
        int spriteHeight = getImage().getHeight();
        int yDistance = (int) (spriteHeight/-2-30);
         
        Actor ceiling = getOneObjectAtOffset(0, yDistance, Highway.class);
         
        if(ceiling != null)
        {
            vSpeed =1;
             
            return true;
        }
         
    }
     
     
     
     
    public void moveToGround(Actor ground)
    {
        int groundHeight = ground.getImage().getHeight();
        int newY = ground.getY() - (groundHeight + getImage().getHeight())/2+30;
         
        setLocation(getX(), newY);
        jumping = false;
         
    }
     
     
     
    public void jump()
    {
        vSpeed = vSpeed - jumpStrength;
        jumping = true;
        fall();
         
         
        
    }
     
     
         
         
     
     
     
     
    private void animate()
    {
        animCount = (animCount+1)%(animSet.length*animDelay);
        if (animCount%animDelay == 0) setImage(animSet[animCount/animDelay]);
    }
}
Unlimited Unlimited

2018/12/27

#
I guess i am to remove the counter() as well right?
danpost danpost

2018/12/27

#
Unlimited wrote...
I guess i am to remove the counter() as well right?
Yes. Remove lines 11, 32, 45, 75, 78, 85 through 93, 111 through 119 and lines 146 through 185. Change the name of your onGround method (line 121) to moveVertically and add the following line to your act method:
1
moveVertically();
Unlimited Unlimited

2018/12/27

#
Alright.
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
138
139
140
141
142
143
144
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * This class is just an example. You can delete it or change the code.
 * It's not necessary for the scrolling system.
 */
public class Azure extends ScrollingActor
{
    private int vSpeed = 0;
    private int acceleration = 1;
     
    private int jumpStrength = 20;
     
     
     
     
  
     
     
    private static GreenfootImage[] standAnim = new GreenfootImage[9];
    private static GreenfootImage[] rightAnim = new GreenfootImage[11];
    private static GreenfootImage[] leftAnim = new GreenfootImage[11];
     
    static
    {
        for (int i=0; i<standAnim.length; i++) standAnim[i] = new GreenfootImage("Stand_0"+(i+1)+".png");
        for (int i=0; i<rightAnim.length; i++) rightAnim[i] = new GreenfootImage("Walk-A_"+(i < 10 ? "0" : "")+(i+1)+".png");
        for (int i=0; i<rightAnim.length; i++) leftAnim[i] = new GreenfootImage("WalkLeft-A_"+(i < 10 ? "0" : "")+(i+1)+".png");
    }
     
     
     
     
    private int animCount; // counter for animations
    private int animDelay = 6; // initially set for standing animation (frame rate field)
  
     
    private void setAnim(GreenfootImage[] anim, int frameRate)
    {
        animSet = anim;
        animCount = -1; // prepares to set first image when incremented
        animDelay = frameRate;
        animate(); // calls a method to set a frame of this newly set animation
    }
     
     
     
    private GreenfootImage[] animSet = standAnim;
     
     
     
     
    /**
     * Here you can tell your actor what he has to do.
     */
    public void act() {
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
        animate();
        move();
         
         
        moveVertically();
         
         
    }
     
     
    
 
     
     
    public void move()
    {
        int y = getY();
        int x = getX();
        if(Greenfoot.isKeyDown("right") ) x+=6;
        
         
         
        if(Greenfoot.isKeyDown("left") ) x-=6;
        
         
        setLocation(x,y);
    }
     
     
     
     
     
    public void moveVertically()
    {
         boolean onGround = false;
         // assume in air
       vSpeed += acceleration; // apply gravity
       setLocation(getX(), getY()+vSpeed); // fall
       Actor actor = getOneIntersectingObject(Actor.class);
       if (actor != null)
       { // colliding with another actor
           int vDir = (int)Math.signum(vSpeed); // vertical direction of movement
           vSpeed = 0; // kill vertical speed
           if (vDir > 0) onGround = true; // landing and not bopping head
           setLocation(getX(), actor.getY()-vDir*(actor.getImage().getHeight()+getImage().getHeight())/2+30); // assigning stop location
        }
        if (onGround && Greenfoot.isKeyDown("space")) vSpeed = -20; // initiate a jump
    }
         
         
         
         
         
     
     
     
     
    
     
     
         
         
     
     
     
     
    private void animate()
    {
        animCount = (animCount+1)%(animSet.length*animDelay);
        if (animCount%animDelay == 0) setImage(animSet[animCount/animDelay]);
    }
}
danpost danpost

2018/12/27

#
Jumping should work properly now, correct? Bopping head? and landing?
Unlimited Unlimited

2018/12/27

#
Am no, when i try to jump i teleport under the platform, however i asume that is because ive added +30 to this line: setLocation(getX(), actor.getY()-vDir*(actor.getImage().getHeight()+getImage().getHeight())/2+30); I did that so i am not on top of the platform but a little inside and in front of it to give it this somewhat 3 Dimensinal feeling. Is there a way to keep that or would i have to change it back?
danpost danpost

2018/12/27

#
Unlimited wrote...
Am no, when i try to jump i teleport under the platform, however i asume that is because ive added +30 to this line: setLocation(getX(), actor.getY()-vDir*(actor.getImage().getHeight()+getImage().getHeight())/2+30); I did that so i am not on top of the platform but a little inside and in front of it to give it this somewhat 3 Dimensinal feeling. Is there a way to keep that or would i have to change it back?
Remove the '+30'. Maybe you can draw the top part of the platform on the background image so it is not part of an actor to intersect with.
Unlimited Unlimited

2018/12/27

#
Well i have a scrolling background as well so i dont think that would work that well. I guess i can remove it for now but i would like to keep it. Also ramps, these would also be a goal of mine but for now i just want to get the game working.
danpost danpost

2018/12/27

#
Unlimited wrote...
Well i have a scrolling background as well so i dont think that would work that well.
Why not? It should scroll along with the platform (unless you are trying to add a 3D effect with the background also).
Unlimited Unlimited

2018/12/27

#
I was thinking about adding parallax yes however i will probably not considering i am not able to that much. either way, what do i have to do to get the colison and animations done, afterall i have still a couple more animations i want to do. So what do i have to do now? Also are there other ways to work around the problem with the plattforms? As you could probably asume im trying to create a game like megaman x or gunvolt.
There are more replies on the next page.
1
2
3
4
5