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

2013/10/23

Need an object fixed to the screen, not the map.

1
2
3
4
SPower SPower

2013/10/28

#
1) Did you really copy the code exactly?? (with getWorld().getCameraX() instead of getCameraX()) 2) Is it really in a subclass of ScrollActor --- 3) You could fix it by expanding your background, however, this would mean that the background would also scroll, so you're going to see what you added, and it is just using more memory for something that can be fixed this easily --- 4) Do you have any code where you actually move the world's camera up?
Tavi Tavi

2013/10/29

#
) Did you really copy the code exactly?? (with getWorld().getCameraX() instead of getCameraX()) I Copied the code :) yes, 2) Is it really in a subclass of ScrollActor It REALLY is a subclass of actor --- 3) You could fix it by expanding your background, however, this would mean that the background would also scroll, so you're going to see what you added, and it is just using more memory for something that can be fixed this easily That's correct, sir. --- 4) Do you have any code where you actually move the world's camera up? No, not that i am aware of . i just copied the scroll world, adjusted my map, and last, adjusted my character like so : ScrollWorld :
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
import greenfoot.*;
import java.util.ArrayList;
 
/**
 * A world which has the possibility to scroll
 * over a really big area. That big area is called
 * the big space, It scrolls over it using a camera.
 * The camera's location starts as x=half width, y=half height
 * of the world. It can't get outside of the big space.<p>
 *
 * The background is always scrolling, you don't have
 * to do anything for it. Just make a background like you
 * always do in your scenarios, and this scenario will
 * scroll over it. The only note is that the method
 * {@link setBackground} is replaced by {@link
 * setNewBackground}.<p>
 *
 * The world supports adding ScrollActors in 2 ways:
 * <Li>
 * Adding it in the regular way, which means that it can
 * go off screen and come back on screen.
 * </Li><Li>
 * Adding a camera follower, which means that it will
 * move just as much as the camera does. So if you add it
 * to the center of the screen, it will always be there
 * (except for when you change it yourself).
 * </Li>
 * <b>IMPORTANT NOTE:</b> if your Actor isn't a subclass of ScrollActor, it
 * will looklike it is a camera follower.
 *
 * @author Sven van Nigtevecht
 * @version 2.1.2
 */
public abstract class ScrollWorld extends World
{
    private final int width, height, cellSize;
    private final ArrayList<ScrollActor> objects;
    private final ArrayList<ScrollActor> camFollowers;
    private final int fullWidth, fullHeight;
     
    private int camX, camY, camDir;
     
    public final GreenfootImage bigBackground, back;
    public int scrollPosX, scrollPosY;
     
    /**
     * Create a new ScrollWorld.
     * @param width The width of the scroll world in cells.
     * @param height The height of the scroll world in cells.
     * @param cellSize The size of the cells (in pixels).
     * @param fullWidth The total width of the world.
     * That means, objects can't move further than this limit.
     * @param fullHeight The total height of the world.
     * That means, objects can't move further than this limit.
     * @throws IllegalArgumentException If one of the arguments
     * is smaller or equal to 0.
     */
    public ScrollWorld(int width, int height, int cellSize, int fullWidth, int fullHeight)
    {
        super(width, height, cellSize, false);
        this.back = getBackground();
        this.width = back.getWidth();
        this.height = back.getHeight();
        this.cellSize = cellSize;
        this.fullWidth = fullWidth;
        this.fullHeight = fullHeight;
        if (fullWidth <= 0)
            throw new IllegalArgumentException("The width of the big space ("+fullWidth
            +") can't be smaller then the width of the world ("+width+")");
        if (fullHeight <= 0)
            throw new IllegalArgumentException("The height of the big space ("+fullHeight
            +") can't be smaller then the height of the world ("+height+")");
         
        objects = new ArrayList<ScrollActor>();
        camFollowers = new ArrayList<ScrollActor>();
         
        camX = getWidth() /2;
        camY = getHeight() /2;
        camDir = 0;
         
        scrollPosX = 0;
        scrollPosY = 0;
         
        bigBackground = new GreenfootImage(width+width, height+height);
        setNewBackground(back);
    }
     
     
     
    /** EXTRA METHODS: */
     
    /**
     * Sets the background of the world. This will also initialize
     * everything to make the background scroll, something the
     * normal {@link setBackground} method doesn't.
     */
     public void setNewBackground(GreenfootImage background) 
    
        bigBackground.clear(); 
        if (background.getWidth() == bigBackground.getWidth() && 
            background.getHeight() == bigBackground.getHeight()) { 
            bigBackground.drawImage(background, 0,0); 
            back.clear(); 
            back.drawImage(bigBackground, scrollPosX,scrollPosY); 
            return
        
           
        bigBackground.drawImage(background, 0,0); 
        bigBackground.drawImage(background, background.getWidth(),0); 
        bigBackground.drawImage(background, 0,background.getHeight()); 
        bigBackground.drawImage(background, background.getWidth(),background.getHeight()); 
           
        back.clear(); 
        back.drawImage(bigBackground, scrollPosX,scrollPosY); 
    
     
    /** ADDING + REMOVING OBJECTS: */
     
    /**
     * Adds an object which will follow the camera.
     * The location is seen from the camera, not from the
     * big space.
     * @param cameraFollower The object that will be added to the world
     * as a camera follower.
     * @param x The x coördinate seen from the camera where the object
     * will be added.
     * @param y The y coördinate seen from the camera where the object
     * will be added.
     * @see #addObject(ScrollActor, int, int)
     */
    public void addCameraFollower(ScrollActor cameraFollower, int x, int y)
    {
        super.addObject(cameraFollower, getWidth() /2 +x, getHeight() /2 +y);
        camFollowers.add(cameraFollower);
        cameraFollower.setIsCameraFollower(true);
    }
     
    /**
     * Adds an object to the the world. If the given object
     * is a ScrollActor or a subclass of it, the x and y
     * coördinates are in the big space.
     *
     * @param object The object that will be added to the world.
     * @param x The x coördinate in the world where the object
     * will be added.
     * @param y The y coördinate in the world where the object
     * will be added.
     * @see #addCameraFollower(ScrollActor, int, int)
     */
    public void addObject(Actor object, int x, int y)
    {
        if (object instanceof ScrollActor) {
            if (x >= fullWidth)
                x = fullWidth -1;
            else if (x < 0)
                x = 0;
            if (y >= fullHeight)
                y = fullHeight -1;
            else if (y < 0)
                y = 0;
            ScrollActor sa = (ScrollActor) object;
            super.addObject(sa, x -(camX -getWidth() /2), y -(camY -getHeight() /2));
            objects.add(sa);
            sa.setIsCameraFollower(false);
        } else
            super.addObject(object,x,y);
    }
     
    /**
     * Removes an object from the world.
     * @param object The object that will be removed
     * from the world. This can either be a camera follower,
     * or just a regular object.
     */
    public void removeObject(Actor object)
    {
        super.removeObject(object);
        if (object instanceof ScrollActor) {
            ScrollActor a = (ScrollActor) object;
            objects.remove(a);
            camFollowers.remove(a);
            a.setIsCameraFollower(false);
        }
    }
     
    /** RETURN VALUES: */
     
    /**
     * Returns the camera's x coördinate in big space.
     * @see #getCameraY
     */
    public int getCameraX()
    {
        return camX;
    }
     
    /**
     * Returns the camera's y coördinate in big space.
     * @see #getCameraX
     */
    public int getCameraY()
    {
        return camY;
    }
     
    /**
     * Returns the width of the big space.
     * @see #getFullHeight
     */
    public int getFullWidth()
    {
        return fullWidth;
    }
     
    /**
     * Returns the height of the big space.
     * @see #getFullWidth
     */
    public int getFullHeight()
    {
        return fullHeight;
    }
     
    /** CAMERA MOVEMENT + ROTATION: */
     
    /**
     * Moves the camera to a particular location.
     * Note that this is a location in the big space.
     * @param x The new x coördinate of the camera.
     * @param y The new y coördinate of the camera.
     */
    public void setCameraLocation(int x, int y)
    {
        if (camX == x && camY == y) return;
        if (x > fullWidth -getWidth() /2)
            x = fullWidth -getWidth() /2;
        else if (x < getWidth() /2)
            x = getWidth() /2;
        if (y > fullHeight -getHeight() /2)
            y = fullHeight -getHeight() /2;
        else if (y < getHeight() /2)
            y = getHeight() /2;
        int dx = x -camX;
        int dy = y -camY;
        camX = x;
        camY = y;
        for (ScrollActor a : objects)
            a.setLocation(a.getX() -dx, a.getY() -dy);
        for (ScrollActor a : camFollowers)
            a.setLocation(a.getX(), a.getY());
        moveBackgroundRight(dx *cellSize);
        moveBackgroundUp(dy *cellSize);
    }
     
    /**
     * Sets the direction the camera is facing.
     * It doesn't change anything you see, but it makes
     * it possible to use the {@link moveCamera} method.
     * @param degrees The new rotation in degrees.
     * @see #turnCamera(int)
     * @see #moveCamera(int)
     */
    public void setCameraDirection(int degrees)
    {
        if (degrees >= 360) {
            if (degrees < 720)
                degrees -= 360;
            else
                degrees %= 360;
        } else if (degrees < 0) {
            if (degrees >= -360)
                degrees += 360;
            else
                degrees = 360 +(degrees %360);
        }
        if (camDir == degrees) return;
        camDir = degrees;
    }
     
    /**
     * Turns the camera.
     * It doesn't change anything you see, but it makes
     * it possible to use the {@link moveCamera} method.
     * @param amount The number of degrees the camera will
     * turn clockwise. If this is negative, it will turn
     * counter-clockwise.
     * @see #setCameraDirection(int)
     * @see #moveCamera(int)
     */
    public void turnCamera(int amount)
    {
        setCameraDirection(camDir +amount);
    }
     
    /**
     * Moves the camera forward to the direction
     * it's facing (to go backwards, enter a negative number).
     * @param amount The number of cells the camera will move.
     * When this is negative, the camera will move forward.
     */
    public void moveCamera(int amount)
    {
        if (amount == 0) return;
        double radians = Math.toRadians(camDir);
        double dx = Math.cos(radians) *amount;
        double dy = Math.sin(radians) *amount;
        setCameraLocation((int)(camX +dx +0.5), (int)(camY +dy +0.5));
    }
     
    /** MOVING BACKGROUND: */
     
    /**
     * All the honor for this goes to Busch2207 from
     * greenfoot.org
     */
    private void moveBackgroundUp(int amount) 
    
        if (amount == 0) return
        int height = getHeight(); 
        scrollPosY -= amount; 
        /*while (scrollPosY < 0)
            scrollPosY += height;
        scrollPosY %= height;*/ 
        if (scrollPosY < -fullHeight) { 
            scrollPosY = -fullHeight; 
        
        getBackground().drawImage(bigBackground, scrollPosX,scrollPosY); 
    }
     
    /**
     * All the honor for this goes to Busch2207 from
     * greenfoot.org
     */
    private void moveBackgroundRight(int amount) 
    
        if (amount == 0) return
        int width = getWidth(); 
        scrollPosX -= amount; 
        /*while (scrollPosX < 0)
            scrollPosX += width;
        scrollPosX %= width;*/ 
        if (scrollPosX < -fullWidth) { 
            scrollPosX = -fullWidth; 
        
        getBackground().drawImage(bigBackground, scrollPosX,scrollPosY); 
    
    
}
TrainingGround World
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Sky here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class TrainingGround extends ScrollWorld
{
     
    private Rogue theRogue;
    private int xValueRogue = 500;
    private int yValueRogue = 70;
    private int spawnTimer = 300;
    GreenfootSound trainingGround = new GreenfootSound("TrainingGround.wav");
    /**
     * Constructor for objects of class Sky.
     *
     */
    public TrainingGround()
    {  
       super(800, 600, 1, 2000, 1100);
        prepare();
 
    }
    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        //RibbonPig ribbonpig = new RibbonPig(xpbar);
        CouragiousLamb couragiouslamb = new CouragiousLamb();
        //addObject(ribbonpig, 734, 299);
        Portal portal = new Portal(2);
        addObject(portal, 206, 338);
        setBackground("lvl1.png");
 
        /**
         * GUI
         *
         */
        //Level
        LevelCounter levelcounter = new LevelCounter();
        addObject(levelcounter, 100, 30);
        //XP
        XpBar xpbar = new XpBar();
        addObject(xpbar, 450, 30);
        //Mesos
        MesoCounter mesocounter = new MesoCounter();
        addObject(mesocounter, 100, 80);
        //HP
        LifeBar lifebar = new LifeBar();
        addObject(lifebar, 100, 125);
        //Character
        addCameraFollower(new Rogue(levelcounter, mesocounter, lifebar, xpbar), 0, 0);
         
         
         
 
        //blokje rechtsonder
        addObject (new platform(), 800  , 585);
        addObject (new platform(), 850  , 585);
 
        addObject (new platform(), 900  , 585);
        addObject (new platform(), 950  , 585);
        addObject (new platform(), 1000  , 585);
        addObject (new platform(), 1050  , 585);
        addObject (new platform(), 1100  , 585);
        addObject (new platform(), 1150  , 585);
        addObject (new platform(), 1200  , 585);
        addObject (new platform(), 1250  , 585);
        addObject (new platform(), 1300  , 585);
        addObject (new platform(), 1328  , 585);
 
        //NaastPortal
        addObject (new platform(), 700, 525);
        addObject (new platform(), 650, 525);
        addObject (new platform(), 600, 525);
        addObject (new platform(), 550, 525);
        addObject (new platform(), 500, 525);
        addObject (new platform(), 450, 525);
        addObject (new platform(), 400, 525);
        addObject (new platform(), 350, 525);
 
        //blokje links
        addObject (new platform(), 175, 465);
        addObject (new platform(), 225, 465);
        addObject (new platform(), 275, 465);
 
        //blok rechts
        addObject (new platform(), 1425, 525);
        addObject (new platform(), 1475, 525);
        addObject (new platform(), 1510, 525);
 
        //TOP - 1
        addObject (new platform(), 375, 345);
        addObject (new platform(), 425, 345);
        addObject (new platform(), 475, 345);
        addObject (new platform(), 525, 345);
        addObject (new platform(), 575, 345);
        addObject (new platform(), 625, 345);
        addObject (new platform(), 675, 345);
        addObject (new platform(), 725, 345);
        addObject (new platform(), 775, 345);
        addObject (new platform(), 825, 345);
        addObject (new platform(), 875, 345);
        addObject (new platform(), 925, 345);
        addObject (new platform(), 975, 345);
        addObject (new platform(), 1025, 345);
        addObject (new platform(), 1075, 345);
        addObject (new platform(), 1125, 345);
        addObject (new platform(), 1175, 345);
        addObject (new platform(), 1225, 345);
        addObject (new platform(), 1240, 345);
 
        //HooiBlokken
        addObject (new platform(), 1080, 285);
        addObject (new platform(), 1130, 285);
        addObject (new platform(), 1180, 285);
        addObject (new platform(), 1230, 285);
 
        addObject (new platform(), 1130, 228);
        addObject (new platform(), 1180, 228);
 
        //Blok rechts
        addObject (new platform(), 1340, 285);
        addObject (new platform(), 1390, 285);
        addObject (new platform(), 1440, 285);
        addObject (new platform(), 1490, 285);
        addObject (new platform(), 1508, 285);
 
        //TOP
        addObject (new platform(), 450, 170);
        addObject (new platform(), 500, 170);
        addObject (new platform(), 550, 170);
        addObject (new platform(), 600, 170);
        addObject (new platform(), 650, 170);
        addObject (new platform(), 700, 170);
        addObject (new platform(), 750, 170);
        addObject (new platform(), 800, 170);
        addObject (new platform(), 850, 170);
        addObject (new platform(), 900, 170);
        addObject (new platform(), 950, 170);
        addObject (new platform(), 1000, 170);
        addObject (new platform(), 1050, 170);
        addObject (new platform(), 1100, 170);
        addObject (new platform(), 1150, 170);
        addObject (new platform(), 1200, 170);
        addObject (new platform(), 1240, 170);
 
        //LinksOnder
        addObject (new platform(), 0, 642);
        addObject (new platform(), 50, 642);
        addObject (new platform(), 100, 642);
        addObject (new platform(), 150, 642);
        addObject (new platform(), 200, 642);
        addObject (new platform(), 250, 642);
        addObject (new platform(), 300, 642);
        addObject (new platform(), 350, 642);
 
        //Links Trap
        addObject (new platform(), 400, 702);
        addObject (new platform(), 440, 702);
 
        //Bodem
        addObject (new platform(), 490, 760);
        addObject (new platform(), 540, 760);
        addObject (new platform(), 590, 760);
        addObject (new platform(), 640, 760);
        addObject (new platform(), 690, 760);
        addObject (new platform(), 740, 760);
        addObject (new platform(), 790, 760);
        addObject (new platform(), 840, 760);
        addObject (new platform(), 890, 760);
        addObject (new platform(), 940, 760);
        addObject (new platform(), 990, 760);
        addObject (new platform(), 1040, 760);
        addObject (new platform(), 1090, 760);
        addObject (new platform(), 1140, 760);
        addObject (new platform(), 1190, 760);
        addObject (new platform(), 1240, 760);
        addObject (new platform(), 1290, 760);
        addObject (new platform(), 1340, 760);
        addObject (new platform(), 1380, 760);
 
        //RechterBlok
        addObject (new platform(), 1430, 700);
        addObject (new platform(), 1480, 700);
        addObject (new platform(), 1530, 700);
        addObject (new platform(), 1580, 700);
         
        //SPAWN CHARACTER
        //addObject (new Rogue(levelcounter, mesocounter, lifebar), 205, 420);
 
        //MUSIC
        //trainingGround.playLoop();
        RibbonPig ribbonpig2 = new RibbonPig(xpbar);
        addObject(ribbonpig2, 1502, 670);
        RibbonPig ribbonpig3 = new RibbonPig(xpbar);
        addObject(ribbonpig3, 847, 723);
        RibbonPig ribbonpig4 = new RibbonPig(xpbar);
        addObject(ribbonpig4, 1211, 542);
        RibbonPig ribbonpig5 = new RibbonPig(xpbar);
        addObject(ribbonpig5, 1121, 306);
        //ribbonpig.setLocation(574, 305);
        //ribbonpig.setLocation(553, 312);
        ribbonpig5.setLocation(1112, 309);
        RibbonPig ribbonpig6 = new RibbonPig(xpbar);
        addObject(ribbonpig6, 624, 485);
        ribbonpig6.setLocation(615, 491);
        RibbonPig ribbonpig7 = new RibbonPig(xpbar);
        addObject(ribbonpig7, 1301, 718);
        ribbonpig7.setLocation(1307, 721);
        ribbonpig3.setLocation(672, 712);
        RibbonPig ribbonpig8 = new RibbonPig(xpbar);
        addObject(ribbonpig8, 911, 542);
 
        Liane liane = new Liane(10, 150);
        addObject(liane, 238, 515);
 
        Liane liane2 = new Liane(10, 150);
        addObject(liane2, 336, 205);
        liane2.setLocation(500, 229);
        Liane liane3 = new Liane(10, 150);
        addObject(liane3, 308, 185);
        liane3.setLocation(376, 399);
        Liane liane4 = new Liane(10, 150);
        addObject(liane4, 796, 543);
        liane4.setLocation(848, 637);
        Liane liane5 = new Liane(10, 150);
        addObject(liane5, 1080, 466);
        liane5.setLocation(1330, 638);
        Liane liane6 = new Liane(10, 150);
        addObject(liane6, 1438, 388);
        liane6.setLocation(1524, 580);
        Liane liane7 = new Liane(10, 250);
        addObject(liane7, 1290, 257);
        liane7.setLocation(1284, 357);
        Liane liane8 = new Liane(10, 300);
        addObject(liane8, 1510, 197);
        liane8.setLocation(1360, 413);
        removeObject(liane7);
         
        MutantFireBoar mutantfireboar = new MutantFireBoar(xpbar);
        addObject(mutantfireboar, 150, 100);
    }
 
 
    public void act()
    {
        respawn(spawnTimer);
        spawnTimer--;
        spawnTimeCheck();
    }
 
    public void spawnTimeCheck()
    {
        if (spawnTimer <= 0)
        {
            spawnTimer = spawnTimer + 1500;
        }
    }
 
    public void setXValueRogue(int xValueRogue){
        this.xValueRogue = xValueRogue;
    }
 
    public int getXValueRogue(){
        return xValueRogue;
    }
 
    public void setYValueRogue(int yValueRogue){
        this.yValueRogue = yValueRogue;
    }
 
    public int getYValueRogue(){
        return yValueRogue;
    }
 
    public void respawn(int spawnTimer)
    {
        if(spawnTimer == 1)
        {
           /*
            RibbonPig ribbonpig2 = new RibbonPig(xpbar);
            addObject(ribbonpig2(), 1502, 670);
            RibbonPig ribbonpig3 = new RibbonPig();
            addObject(ribbonpig3, 847, 723);
            RibbonPig ribbonpig4 = new RibbonPig();
            addObject(ribbonpig4, 1211, 542);
            RibbonPig ribbonpig5 = new RibbonPig();
            addObject(ribbonpig5, 1121, 306);
            ribbonpig5.setLocation(1112, 309);
            RibbonPig ribbonpig6 = new RibbonPig();
            addObject(ribbonpig6, 624, 485);
            ribbonpig6.setLocation(615, 491);
            RibbonPig ribbonpig7 = new RibbonPig();
            addObject(ribbonpig7, 1301, 718);
            ribbonpig7.setLocation(1307, 721);
            ribbonpig3.setLocation(672, 712);
            RibbonPig ribbonpig8 = new RibbonPig();
            addObject(ribbonpig8, 911, 542);
            */
        }
    }
 
}
ScrollActor Class
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import greenfoot.*;
 
/**
 * An actor which ca be in a ScrollWorld.
 * It has 3 types of locations:
 * <Li>
 * A location where it really is. That means, the
 * location the space the camera is moving over.
 * This is the most important one. Access it by
 * the {@link getGlobalX} and the {@link getGlobalY}
 * methods.
 * </Li><Li>
 * A location seen from the camera. This means when
 * it's at {@link 0,0}, it is at the center of what
 * you see. Access it by the {@link getXFromCamera}
 * and the {@link getYFromCamera} methods.
 * </Li><Li>
 * A location on screen. This is what you would do in
 * your usual scenarios, so {@link 0,0} is the top left
 * corner. With this library, it is the least important
 * one. Access it by the usual {@link getX} and {@link
 * getY} methods.
 * </Li>
 *
 * @author Sven van Nigtevecht
 * @version 2.1.2
 */
public abstract class ScrollActor extends Player
{
    private int camX, camY;
    private int globalX, globalY;
    private boolean isCameraFollower;
    private ScrollWorld world;
     
    /**
     * Create a new ScrollActor.
     */
    public ScrollActor()
    {
        camX = 0;
        camY = 0;
        globalX = 0;
        globalY = 0;
        isCameraFollower = false;
        world = null;
    }
     
    /** LOCATIONS: */
     
    /**
     * Returns the x coordinate where you're really
     * standing.
     */
    public int getGlobalX()
    {
        if (getWorld() == null)
            throw new IllegalStateException("Actor not in world. Either is hasn't"+
            " been inserted, or it has been deleted.");
        return globalX;
    }
     
    /**
     * Returns the y coordinate where you're really
     * standing.
     */
    public int getGlobalY()
    {
        if (getWorld() == null)
            throw new IllegalStateException("Actor not in world. Either is hasn't"+
            " been inserted, or it has been deleted.");
        return globalY;
    }
     
    /**
     * Returns your x coördinate seen from the camera.
     */
    public int getXFromCamera()
    {
        if (getWorld() == null)
            throw new IllegalStateException("Actor not in world. Either is hasn't"+
            " been inserted, or it has been deleted.");
        return camX;
    }
     
    /**
     * Returns your y coördinate seen from the camera.
     */
    public int getYFromCamera()
    {
        if (getWorld() == null)
            throw new IllegalStateException("Actor not in world. Either is hasn't"+
            " been inserted, or it has been deleted.");
        return camY;
    }
     
    /**
     * Sets your location seen from the world
     * (regular location).
     * That means that a negative location is off
     * screen, and bigger than the world's size is
     * also off screen.
     */
    public void setLocation(int x, int y)
    {
        if (getX() == x && getY() == y) return;
        super.setLocation(x,y);
        int halfWorldWidth = world.getWidth() /2;
        int halfWorldHeight = world.getHeight() /2;
        camX = x -halfWorldWidth;
        camY = y -halfWorldHeight;
        globalX = x +(world.getCameraX() -halfWorldWidth);
        globalY = y +(world.getCameraY() -halfWorldHeight);
    }
     
    /**
     * Sets your location seen from the camera.
     */
    public void setLocationFromCamera(int x, int y)
    {
        if (camX == x && camY == y) return;
        setLocation(x +world.getCameraX(), y +world.getCameraY());
    }
     
    /**
     * Sets your location in the big space (the
     * space where the camera is moving over).
     */
    public void setGlobalLocation(int x, int y)
    {
        if (globalX == x && globalY == y) return;
        int subX = world.getCameraX() -world.getWidth() /2;
        int subY = world.getCameraY() -world.getHeight() /2;
        setLocation(x -subX, y -subY);
    }
     
    /** OTHER METHODS: */
     
    /**
     * Returns the ScrollWorld you're in.
     * If you're not in a world, this will return null.
     */
    public ScrollWorld getWorld()
    {
        return world;
    }
     
    /**
     * Moves the scroll actor forward a specified amount.
     * To go backwards, enter a negative number.<p>
     * This will affect all the locations of the
     * scroll actor.
     * @param distance The number of cells the scroll
     * actor will move forward.
     */
    public void move(int distance)
    {
        if (distance == 0) return;
        double radians = Math.toRadians(getRotation());
        double sin = Math.sin(radians);
        double cos = Math.cos(radians);
        int dx = (int)Math.round(cos *distance);
        int dy = (int)Math.round(sin *distance);
        setGlobalLocation(getGlobalX() +dx, getGlobalY() +dy);
    }
     
    /**
     * Turns towards a location in the big space.
     * @param x The x coördinate of the location.
     * @param y The y coördinate of the location.
     */
    public void turnTowardsGlobalLocation(int x, int y)
    {
        if (x == globalX && y == globalY) return;
        double a = Math.atan2(y -globalY, x -globalX);
        int newRotation = (int)Math.round(Math.toDegrees(a));
        setRotation(newRotation);
    }
     
    /**
     * Turns towards a location seen from the camera.
     * @param x The x coördinate of the location.
     * @param y The y coördinate of the location.
     */
    public void turnTowardsCameraLocation(int x, int y)
    {
        if (x == camX && y == camY) return;
        double a = Math.atan2(y -camY, x -camX);
        int newRotation = (int)Math.round(Math.toDegrees(a));
        setRotation(newRotation);
    }
     
    /**
     * Returns you're a camera follower or not.
     * If you're not in a world, this will throw an
     * exception.
     */
    public boolean isCameraFollower()
    {
        if (getWorld() == null)
            throw new IllegalStateException("Actor not in world. Either is hasn't"+
            " been inserted, or it has been deleted.");
        return isCameraFollower;
    }
     
    /**
     * Used by the system: don't touch!
     */
    void setIsCameraFollower(boolean value)
    {
        this.isCameraFollower = value;
        this.world = (ScrollWorld) super.getWorld();
    }
}
And 2 more classes are important.. Mover Class
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
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
 
/**
 * A Mover is an actor that also has 'move' and 'turn' ability. Both moving and turning
 * are relative to its current position. When moving, the Mover will move in the direction
 * it is currently facing.
 *
 * Both 'move' and 'turn' methods are available with or without parameters.
 *
 * The 'Mover' class is a subclass of Actor. It can be used by creating subclasses, or
 * copied into scenarios and edited inline.
 *
 * The initial direction is to the right. Thus, this class works best with images that
 * face right when not rotated.
 *
 * This class can also check whether we are close to the edge of the world.
 *
 * @author Michael Kolling
 * @version 1.0 (July 2007)
 */
public class Mover extends Actor
{
    private static final double WALKING_SPEED = 5.0;
     
    /**
     * Turn 90 degrees to the right (clockwise).
     */
    public void turn()
    {
        turn(90);
    }
     
 
    /**
     * Turn 'angle' degrees towards the right (clockwise).
     */
    public void turn(int angle)
    {
        setRotation(getRotation() + angle);
    }
     
 
    /**
     * Move a bit forward in the current direction.
     */
    public void move()
    {
        move(WALKING_SPEED);
    }
 
     
    /**
     * Move a specified distance forward in the current direction.
     */
    public void move(double distance)
    {
        double angle = Math.toRadians( getRotation() );
        int x = (int) Math.round(getX() + Math.cos(angle) * distance);
        int y = (int) Math.round(getY() + Math.sin(angle) * distance);
         
        setLocation(x, y);
    }
 
     
    /**
     * Test if we are close to one of the edges of the world. Return true is we are.
     */
    public boolean atWorldEdge()
    {
        if(getX() < 20 || getX() > getWorld().getWidth() - 20)
            return true;
        if(getY() < 20 || getY() > getWorld().getHeight() - 20)
            return true;
        else
            return false;
    }
}
And my Character class, Rogue
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Char here.
 *
 * @author (Patrick van Kralingen)
 * @version (0.14  19OKT2013)
 */
public class Rogue extends ScrollActor
{
    //Verticale snelheid en acceleratie
    private int vSpeed = 0;
    private int acceleration = 1;
    private boolean jumping;
    private int jumpStrength = -15;
 
    //Loop variabelen
    private int speed = 24;
    //Frame float
    public float frame = 0;
    long lastAdded = System.currentTimeMillis();
    // init sequence
    private int sequence = 0;
    //richting
    public int richting = 2;
 
    //CHAR Eigenschappen
    private int mesos = 0;
    public int level = 1;
    public int hp = 120;
    private LevelCounter currentlevel;
    private MesoCounter currentmeso; 
    private LifeBar currenthp;
    private int newHP;
    private int oldHP;
    private XpBar currentXp;
     
     
     
    private int xValue;
    private int yValue;
 
    //Richting aanval
    public double throwingDirection = 10.0;
 
    //Shoot interaction
    private int reloadDelayCount;  
    private int throwReloadTime;  
 
    // Levelup
    private LevelUp levelUp;
    private Thombstone thombstone;
 
    // CLAW & STER
    public int claw = 0 ;
    public int throwingStar = 0;
     
    /****
       *
        *SCROLL WORLD VARIABELEN
         *
          *
           *
            ********/
    /** The number of cells we move forward and backword */
    private static final int MOVE_AMOUNT = 5;       
             
             
    /**
     * SPRITES INLADEN
     **/
    //links lopen
    GreenfootImage[] walkLeft = new GreenfootImage[]
        {
            new GreenfootImage("Rogue_Walk_left_1_0.png"),
            new GreenfootImage("Rogue_Walk_left_1_1.png"),
            new GreenfootImage("Rogue_Walk_left_1_2.png"),
            new GreenfootImage("Rogue_Walk_left_1_3.png")
        }; 
    //rechts lopen
    GreenfootImage[] walkRight = new GreenfootImage[]
        {
            new GreenfootImage("Rogue_Walk_right_1_0.png"),
            new GreenfootImage("Rogue_Walk_right_1_1.png"),
            new GreenfootImage("Rogue_Walk_right_1_2.png"),
            new GreenfootImage("Rogue_Walk_right_1_3.png")
        };
    //Idle links
    GreenfootImage [] alertLeft = new GreenfootImage []
        {
            new GreenfootImage("Rogue_Alert_left_0.png"),
            new GreenfootImage("Rogue_Alert_left_1.png"),
            new GreenfootImage("Rogue_Alert_left_2.png"),
            new GreenfootImage("Rogue_Alert_left_3.png"),
            new GreenfootImage("Rogue_Alert_left_4.png")
        };
    //Idle rechts
    GreenfootImage [] alertRight = new GreenfootImage []
        {
            new GreenfootImage("Rogue_Alert_right_0.png"),
            new GreenfootImage("Rogue_Alert_right_1.png"),
            new GreenfootImage("Rogue_Alert_right_2.png"),
            new GreenfootImage("Rogue_Alert_right_3.png"),
            new GreenfootImage("Rogue_Alert_right_4.png")
        };
    //Aanvallen links
    GreenfootImage [] attackLeft = new GreenfootImage []
        {
            new GreenfootImage("Rogue_Attack_left_0.png"),
            new GreenfootImage("Rogue_Attack_left_1.png"),
            new GreenfootImage("Rogue_Attack_left_2.png"),
            new GreenfootImage("Rogue_Attack_left_3.png"),
            new GreenfootImage("Rogue_Attack_left_4.png"),
            new GreenfootImage("Rogue_Attack_left_5.png"),
            new GreenfootImage("Rogue_Attack_left_6.png"),
            new GreenfootImage("Rogue_Attack_left_7.png"),
            new GreenfootImage("Rogue_Attack_left_8.png"),
        };
 
    GreenfootImage [] attackRight = new GreenfootImage []
        {
            new GreenfootImage("Rogue_Attack_right_0.png"),
            new GreenfootImage("Rogue_Attack_right_1.png"),
            new GreenfootImage("Rogue_Attack_right_2.png"),
            new GreenfootImage("Rogue_Attack_right_3.png"),
            new GreenfootImage("Rogue_Attack_right_4.png"),
            new GreenfootImage("Rogue_Attack_right_5.png"),
            new GreenfootImage("Rogue_Attack_right_6.png"),
            new GreenfootImage("Rogue_Attack_right_7.png"),
            new GreenfootImage("Rogue_Attack_right_8.png"),
        };
         
        GreenfootImage [] climb = new GreenfootImage []
        {
            new GreenfootImage("rope_0.png"),
            new GreenfootImage("rope_1.png")
        };
 
    //SPRINGEN
    GreenfootImage [] jumpLeft = new GreenfootImage []
        {
            new GreenfootImage("Rogue_Jump_left_0.png")
        };
    GreenfootImage [] jumpRight = new GreenfootImage []
        {
            new GreenfootImage("Rogue_Jump_right_0.png")
        };
 
    // Rogue constructor
    public Rogue(LevelCounter levelCounter, MesoCounter mesocounter, LifeBar lifebar, XpBar xpbar)
    {
        //throwReloadTime = 22;
        throwReloadTime = 3;
        reloadDelayCount = 0;
        currentlevel = levelCounter;
        currentmeso = mesocounter;
        currenthp = lifebar;
        currenthp.add(hp);
        currentXp = xpbar;
         
    }
 
    public void act()
    {
        checkFall();
        checkKey();
        //checkRightWalls();
        //checkLeftWalls();
        animate(sequence);
        timer();
        reloadDelayCount++;
        checkForPortal(); 
        checkLiane();
        checkForItem();
        System.out.println("CURRENT HP = " + hp);
        System.out.println("OLD HP = " + oldHP);
        System.out.println("NEW HP = " + newHP);
    }
     
 
    /**
     * CONTROLS
     **/
    public void checkKey()
    {
        if(Greenfoot.isKeyDown("space") && jumping == false)
        {
            sequence = 1;
            jump();
        }
 
        if (Greenfoot.isKeyDown("right"))
        {
            sequence = 2;
            richting = 1;
            //moveRight();
            getWorld().moveCamera(MOVE_AMOUNT);
        }
        if (Greenfoot.isKeyDown("left"))
        {
            sequence = 3;
            richting = 2;
            //moveLeft();
            getWorld().moveCamera(-MOVE_AMOUNT);
            /*
            if (getCameraX() == 0) { // if in the middle of the screen 
               if (getWorld().getCameraX() == cx)
               
                    move(-MOVE_AMOUNT); 
               
            } else { 
                // not in the middle of the screen, so we need to move back to the middle 
                // and don't move the camera 
                move(-MOVE_AMOUNT); 
            }
            */
        ////////////////////////
        }
        if ("a".equals(Greenfoot.getKey()))
        {
            sequence = 4;
            luckySeven(richting);
        }
        if (getWorld().getObjects(LevelUp.class).isEmpty() && Greenfoot.isKeyDown("u")){
            levelUp();
        }
 
        // Tijdelijk wordt de thombstone opgevangen middels een key
        // Deze moet straks worden geactiveerd als hij dood gaat.
        if (getWorld().getObjects(Thombstone.class).isEmpty() && Greenfoot.isKeyDown("y")){
            thombstone = new Thombstone();
             getWorld().addObject(thombstone, getX(), -200);
        }
    }
 
    public void checkLiane(){
        Actor lianeActor = getOneIntersectingObject(Liane.class);
 
        yValue = getY();
 
        if(lianeActor != null && Greenfoot.isKeyDown("up")){
            System.out.println(yValue);
            System.out.println("Ik probeer te klimmen.");
            climbInLiane();
            sequence = 5;
        }
    }
 
    public void climbInLiane(){
        // Vallen uitschakelen
        vSpeed = 0;
 
        // Rogue X value gelijk stellen aan die van Liane
        // System.out.println(getWorld().getObjects(Liane.class));
 
        yValue = getY();
        // Vreemd.... bij waarde yValue = 5 klimt ie niet meer....
        yValue -= 2;
        // Nog Gelijk stellen aan X van Liane
 
        Liane liane = (Liane) getOneIntersectingObject(Liane.class); 
 
        setLocation(liane.getX(), yValue); 
        // Stil hangen in touw verwerken
    }
 
    // Toevoeving Portal
    public void checkForPortal(){
        Portal portal = (Portal) getOneObjectAtOffset(10, 10, Portal.class);
        // Te lang op de portal geeft andere effecten
        // opvangen met getKey (indien mogelijk)
        // NOG TE DOEN: OP GOEDE PLEK TERECHT LATEN KOMEN,,,
        // MISSCHIEN MET GETTER AND SETTERS.
        // Proberen te verwerken in portal --> ding voor later
        if(portal != null && Greenfoot.isKeyDown("up")){
            // Description of cases
            // Case 1: Portal to TrainingGround
            // Case 2: Portal to Questmap
            // Case 3: Portal to map3
            // Case 4: Portal to mapTransition1
            // Case 5: Portal to mapTransition2
            // Case 6: Portal to IronBoarLand
            // Case 7: Portal to BossMap
            Greenfoot.playSound("Portal.wav");
            switch (portal.getOurWorld()){
                case 1:
                Greenfoot.setWorld(new TrainingGround());
                break;
 
                case 2:
                Greenfoot.setWorld(new Questmap());
                break;
 
                case 3:
                Greenfoot.setWorld(new map3());     
                break;
 
                case 4:
                Greenfoot.setWorld(new mapTransition1());
                break;
 
                case 5:
                Greenfoot.setWorld(new mapTransition2());
                break;
                 
                case 6:
                Greenfoot.setWorld(new IronBoarLand());
                break;
                 
                case 7:
                Greenfoot.setWorld(new BossMap());
                break;
                
                default:
                break;
            }
        }
    }
 
    /*************
     *
     *
     *
     *
     *PHYSYCS & MOVEMENT
     *
     *
     *
     **********/
      
     /*
     public void moveToLeftEdge()
    {
        // new movement to the left: 
        if (getCameraX() == 0) { // if in the middle of the screen 
            int cx = getWorld().getCameraX(); 
            getWorld().moveCamera(-MOVE_AMOUNT); 
           
            // if the camera couldn't move: 
            if (getWorld().getCameraX() == cx) { 
                move(-MOVE_AMOUNT); 
            
        } else { 
            // not in the middle of the screen, so we need to move back to the middle 
            // and don't move the camera 
            move(-MOVE_AMOUNT); 
        
         
    }
      
     */
 
    //Naar links kunnen bewegen
    public void moveLeft()
    {
        setLocation(getX()-speed, getY());
        //moveToLeftEdge();
    }
 
    //Dit is het hoofd-onderdeel dat ervoor zorgt dat char valt wanneer hij de grond raakt.
    public void fall()
    {
        setLocation (getX(), getY() +vSpeed);
        if (vSpeed <=9)
        {
            //elke pixel dat hij valt, word er +1 extra pixel bijgevoegd (exponentieel)
            vSpeed = vSpeed + acceleration;
        }
        jumping = true;
    }
    //Eerst controleren of ons character op de grond staat.
    public boolean onGround()
    {
        //Uitrekenen hoe hoog de sprite is.
        int spriteHeight = getImage().getHeight();
        // Dit pakt de sprite hoogte, en deelt deze door 2, ook vind conversie plaats en worden er 5 extra pixels gegeven.
        int lookForGround = (int)(spriteHeight/2) + 5;
        //Hier word er gezocht naar de grond, en er word direct naar beneneden gekeken.
        Actor ground = getOneObjectAtOffset(0, lookForGround, platform.class);
        //als er niets onder hem is, false, als er wel iets onder zn voeten is, true
        if (ground == null)
        {
            jumping = true;
            return false;
        }
        else
        {
            moveToGround(ground);
            return true;
        }
 
    }
 
    public boolean checkRightWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int)(spriteWidth/2);
 
        Actor rightWall = getOneObjectAtOffset(xDistance, 0, platform.class);
 
        if (rightWall == null)
        {
            return false;
        }
        else
        {
            stopByRightWall(rightWall);
            return true;
        }
    }
 
    public void stopByRightWall (Actor rightWall)
    {
        int wallWidth = rightWall.getImage().getWidth();
        int newX = rightWall.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX - 2, getY());
    }
 
    //niet door LINKER muur heenlopen
    public boolean checkLeftWalls()
    {
        int spriteWidth = getImage().getWidth();
        int xDistance = (int)(spriteWidth/2);
 
        Actor leftWall = getOneObjectAtOffset(xDistance, 0, platform.class);
 
        if (leftWall == null)
        {
            return false;
        }
        else
        {
            stopByLeftWall(leftWall);
            return true;
        }
    }
 
    public void stopByLeftWall (Actor leftWall)
    {
        int wallWidth = leftWall.getImage().getWidth();
        int newX = leftWall.getX() +(wallWidth + getImage().getWidth())/2;
        setLocation(newX + 2, getY());
    }
 
    //Dit plaatst het character precies met zn voeten op de grond  
    public void bopHead (Actor ceiling)
    {
        int ceilingHeight = ceiling.getImage().getHeight();
        int newY = ceiling.getY() + (ceilingHeight + getImage().getHeight()) / 2;
        //Dit plaatst hem werkelijk  
        setLocation(getX(), newY);
    }
 
    //Dit plaatst het character precies met zn voeten op de grond  
    public void moveToGround (Actor ground)
    {
        int groundHeight = ground.getImage().getHeight();
        int newY = ground.getY() - (groundHeight + getImage().getHeight()) / 2;
        //Dit plaatst hem werkelijk  
        setLocation(getX(), newY);
        //hier is hij weer klaar om te springen
        jumping = false;
    }
    //als hij op de grond staat, vSpeed word naar 0 gezet, zo niet word de fall methode aangeroepen
    public void checkFall()
    {
        if(onGround())
        {
            vSpeed =0;
        }
        else
        {
            fall();
        }
    }
 
    public void jump()
    {
        Greenfoot.playSound("Jump.wav");
        vSpeed = vSpeed = jumpStrength;
        jumping = true;
        fall();
    }
 
    /*************
     *
     *
     *
     *
     *Animaties
     *
     *
     *
     **********/
    public void animate(int sequence) {
        switch(sequence)
        {
            case 0:
            idle(richting);
            break;
            case 1:
            animateJump(richting);
            break;
            case 2:
            animateRight();
            break;
            case 3:
            animateLeft();
            break;
            case 4:
            animateAttack(richting);
            break;
            case 5:
            animateClimb();
            break;
            case 6:
            break;
            default:
            break;
        }
    }
 
    public void timer()
    
        long curTime  = System.currentTimeMillis(); 
        if (curTime >= lastAdded + 150) //5000ms = 5s 
        
            frame++;
            lastAdded  = curTime; 
        
    
 
    public void idle (int richting)
    {
        if(richting == 2)
        {
            animateAlertLeft();
        }
        if (richting == 1)
        {
            animateAlertRight();
        }
    }
 
    public void animateAlertRight()
    {
        if(frame == 1)
        {
            setImage(alertRight[0]);
        }
        else if (frame == 2)
        {
            setImage(alertRight[1]);
        }
        if(frame == 3)
        {
            setImage(alertRight[2]);
        }
        else if (frame == 4)
        {
            setImage(alertRight[3]);
            frame = 0;
            return;
        }
 
    }
 
    public void animateAlertLeft()
    {
        if(frame == 1)
        {
            setImage(alertLeft[0]);
        }
        else if (frame == 2)
        {
            setImage(alertLeft[1]);
        }
        if(frame == 3)
        {
            setImage(alertLeft[2] );
        }
        else if (frame == 4)
        {
            setImage(alertLeft[3]);
            frame = 0;
            return;
        }
 
    }
 
    //Naar rechts kunnen bewegen
    public void moveRight()
    {
        setLocation(getX()+speed, getY());
    }
 
    //animatie rechts lopen
    public void animateRight()
    {
        if(frame == 1)
        {
            setImage(walkRight[0]);
        }
        else if (frame == 2)
        {
            setImage(walkRight[1]);
        }
        if(frame == 3)
        {
            setImage(walkRight[2] );
        }
        else if (frame == 4)
        {
            setImage(walkRight[3]);
            frame = 0;
            sequence = 0;
            return;
        }
    }
 
    //animatie links lopen
    public void animateLeft()
    {
        if(frame == 1)
        {
            setImage(walkLeft[0]);
        }
        else if (frame == 2)
        {
            setImage(walkLeft[1]);
        }
        if(frame == 3)
        {
            setImage(walkLeft[2]);
        }
        else if (frame == 4)
        {
            setImage(walkLeft[3]);
            frame = 0;
            sequence = 0;
            return;
        }
    }
 
    public void animateJump(int richting)
    {
        if(richting == 2)
        {          
            setImage(jumpLeft[0]);
            frame = 0;
            return;
 
        }
        if (richting == 1)
        {
            setImage(jumpRight[0]);
            frame = 0;
            return;
        }
 
    }
 
    //FIRE ZE MISSILES!
    public void animateAttack(int richting)
    {
        if(richting == 2)
        {
            if(frame == 1)
            {
                setImage( attackLeft [0]);
            }
            if(frame == 2)
            {
                setImage( attackLeft [1]);
            }
            if(frame == 3)
            {
                setImage( attackLeft [2]);
            }
            if(frame == 4)
            {
                setImage( attackLeft [3]);
            }
            if(frame == 5)
            {
                setImage( attackLeft [4]);
            }
            if(frame == 6)
            {
                setImage( attackLeft [5]);
            }
            if(frame == 7)
            {
                setImage( attackLeft [6]);
            }
            if(frame == 8)
            {
                setImage( attackLeft [7]);
                frame = 0;
                sequence = 0;
                return;
            }
        }
        if(richting == 1)
        {
            if(frame == 1)
            {
                setImage( attackRight [0]);
            }
            if(frame == 2)
            {
                setImage( attackRight [1]);
            }
            if(frame == 3)
            {
                setImage( attackRight [2]);
            }
            if(frame == 4)
            {
                setImage( attackRight [3]);
            }
            if(frame == 5)
            {
                setImage( attackRight [4]);
            }
            if(frame == 6)
            {
                setImage( attackRight [5]);
            }
            if(frame == 7)
            {
                setImage( attackRight [6]);
            }
            if(frame == 8)
            {
                setImage( attackRight [7]);
                frame = 0;
                sequence = 0;
                return;
            }
        }
    }
            public void animateClimb()
            {
                if(frame == 1)
                    {
                        setImage(climb[0]);
                    }
                    else if (frame == 2)
                    {
                       setImage(climb[1]);
                       frame = 0;
                       sequence = 1;
                       return;
                    }
 
            }
 
    /*************
     *
     *
     *
     *
     *USER ACTIONS
     *
     *
     *
     **********/
      
     // Checks if the Rogue is in range of an item
    public void checkForItem(){
        // Actor voor item.
        Meso meso = (Meso)getOneIntersectingObject(Meso.class);
 
        if(meso != null){
            // Probeer iets met getKey
            if(Greenfoot.isKeyDown("z")){
                // Item verdwijning is in de item class verwerkt
                meso.checkIfPickedUp();
                currentmeso.add(100);
                // Tel punten er bij op.
            }           
        }
    }
     
     
     
    public void levelUp()
    {
        oldHP = hp ;
        hp =(int) (hp * 1.26);
        newHP = hp;
        currenthp.add(newHP - oldHP);
        currentlevel.add(1);
        Greenfoot.playSound("LevelUp.wav");
        levelUp = new LevelUp();
        getWorld().addObject(levelUp, getX(), getY());//-181+70);
         
         
    }
 
    public void luckySeven(int richting)
    {
        if(richting == 1)
        {
            throwRight();
        }
        if(richting == 2)
        {
            throwLeft();
        }
    }
 
    public void throwRight()
    {
        if(reloadDelayCount >= throwReloadTime)
        {
            Tobi throwingstar = new Tobi();
            getWorld().addObject(throwingstar, getX(), getY());
            throwingDirection = 10.0;
            Greenfoot.playSound("Throw.wav");
            reloadDelayCount = 0;
            throwingstar.move(40.0);
        }
 
    }
 
    public void throwLeft()
    {
        if (reloadDelayCount >= throwReloadTime)
        {
            Tobi throwingstar = new Tobi();
            getWorld().addObject(throwingstar, getX(), getY());
            throwingDirection = -10.0;
            throwingstar.setRotation(180);
            Greenfoot.playSound("Throw.wav");
            reloadDelayCount = 0;
            throwingstar.move(30.0);
        }
 
    }
 
    public void setGunReloadTime(int reloadTime)
    {
        throwReloadTime = reloadTime;
    }
 
}
If you want to see how my classes are ranked, just let me know and i'll create a Jpeg :) .. I Hope you guys can figure out why this isnt working yet :( Deadline is coming soon im afraid.. Thank you in advance !
danpost danpost

2013/10/29

#
Is the ScrollActor class supposed to extend the Player class?
Tavi Tavi

2013/10/29

#
Well i divided my classes like this, i needed the mover class for my throwingstars and attacks from my boss :) .. I Hope this makes sense. You can Copy the URL and see the full image, this one is scaled down.. http://s17.postimg.org/f5q617aov/Classes.jpg
danpost danpost

2013/10/29

#
Can't you have Player and Mover extend ScrollActor and subclass them with your throwingstars and attacks from your boss?
Tavi Tavi

2013/10/29

#
Well i tried, nothing really changed.. except i cant throw throwingstars anymore,, regardless of my X position, it won't move ... ( It does measure my Y position ) I Feel bad now :( ... im really trying but this scrollworld is hard to implement somehow, or my code isnt written well.. (Arrows are thrown from left to right now) However, my biggest problem still is the Y scroll of the map.. EDIT : I really fear the worst at this point :( . Kinda losing hope on my big project. please help out.
danpost danpost

2013/10/30

#
This is really something that the maker of ScrollWorld would be able to help more with (being he wrote it and understands how it works a lot more than I).
Tavi Tavi

2013/10/30

#
Ok so i rearranged my classes again, and im hoping the maker will be available soon.. Thanks :) .
SPower SPower

2013/10/30

#
Well, here I am, coming to the rescue! XD And I indeed made some mistakes, I haven't worked with my Scrolling World engine in a long time :) This should be the new movement code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (Greenfoot.isKeyDown("left")) 
        
            sequence = 3
            richting = 2;
            int cx = getWorld().getCameraX();
            getWorld().moveCamera(-MOVE_AMOUNT); 
            if (getXFromCamera() == 0) { // if in the middle of the screen  
               if (getWorld().getCameraX() == cx) {  
                    move(-MOVE_AMOUNT);  
               }  
            } else {  
                // not in the middle of the screen, so we need to move back to the middle  
                // and don't move the camera  
                move(-MOVE_AMOUNT);  
            
        }
And this for the right:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (Greenfoot.isKeyDown("right")) 
        
            sequence = 3
            richting = 2;
            int cx = getWorld().getCameraX();
            getWorld().moveCamera(MOVE_AMOUNT);
            if (getXFromCamera() == 0) {
               if (getWorld().getCameraX() == cx) {
                    move(MOVE_AMOUNT);  
               }  
            } else {
                move(MOVE_AMOUNT);
            }
        }
which has the same principle, but then with MOVE_AMOUNT instead of -MOVE_AMOUNT And for the camera moving up and down: as you said, you haven't got any code telling the camera to move up. So the camera will never move up. To write it, you first need to consider when you want it to move up. I think it is useful to make a constant:
1
private static final int MAX_UP_DIST = 100;
which tells you how much you may be away from the bottom or the top of the screen before the camera starts to move up. Maybe this value is wrong: it's just a matter of experimenting with different values. This would be some code:
1
2
3
4
5
6
7
8
private void checkCameraUpMovement() // i know, a bit of a long name :)
{
    if (getY() < MAX_UP_DIST) { // if too close to the top
        getWorld().setCameraLocation(getWorld().getCameraX(), getWorld().getCameraY() -MOVE_AMOUNT);
    } else if (getY() >= getWorld().getHeight() -MAX_UP_DIST) { // if too close to the bottom
        getWorld().setCameraLocation(getWorld().getCameraX(), getWorld().getCameraY() +MOVE_AMOUNT);
    }
}
which should work (again, if I don't make any mistakes). Just add a call to this method at the bottom of the act method:
1
2
3
4
5
public void act()
{
    // other stuff
    checkCameraUpMovement();
}
I hope this works, and I just want to thank you for using my Scrolling World engine in such a big way! (en spreek je trouwens Nederlands? Dat zou wat makkelijker zijn, omdat je misschien niet perfect Engels spreekt :) En ik zag dat je richting in je code had staan, dat is direction in het Engels :) )
SPower SPower

2013/10/30

#
And if you still have some problems after this, please make another video about it: it makes it very easy to see what's wrong :) And you don't need to post the ScrollWorld and ScrollActor classes anymore, since I know how they work :)
Tavi Tavi

2013/10/30

#
Spower :) You're back ! Awsome ! It's ALMOST working now,, sometimes it unlocks now, and the screen goes faster then the character can walk.. However :) i will post a video later tonight.. Thanks again :) And Yes, i do speak dutch ( En ik spreek inderdaad Nederlands, maar op deze manier kunnen we misschien ook mensen helpen die geen Nederlands spreken :) .. )
SPower SPower

2013/10/30

#
Goed punt :)
Tavi Tavi

2013/10/30

#
Here it is :) http://www.youtube.com/watch?v=ixpAFAlueJ4
JetLennit JetLennit

2013/10/31

#
(Made it eaisier to view)
SPower SPower

2013/10/31

#
I think I'm coming close to cracking the nuts!
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
if (Greenfoot.isKeyDown("left"))   
        {   
            sequence = 3;   
            richting = 2;
            if (getXFromCamera() == 0) {
                move(-MOVE_AMOUNT);
            } else {
                int cx = getWorld().getCameraX(); 
                getWorld().moveCamera(-MOVE_AMOUNT);
               if (getWorld().getCameraX() == cx) {
                    move(-MOVE_AMOUNT);
               }
            }
        }
 
]if (Greenfoot.isKeyDown("right"))   
        {   
            sequence = 3;   
            richting = 2;
            if (getXFromCamera() == 0) {
                move(MOVE_AMOUNT);
            } else {
                int cx = getWorld().getCameraX(); 
                getWorld().moveCamera(-MOVE_AMOUNT);
               if (getWorld().getCameraX() == cx) {
                    move(MOVE_AMOUNT);
               }
            }
        }
And maybe you need to change the MAX_UP_DIST constant to be 50 or something, since 100 seems too big.
There are more replies on the next page.
1
2
3
4