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

2014/3/24

how to make space invaders stronger

FlyingGvirus FlyingGvirus

2014/3/24

#
i want to make my space invaders have more "HP" so the last row takes 3 shots to kill and the 2nd row 2 shots and so on but i cant seem to get it no matter what i try plz help
FlyingGvirus FlyingGvirus

2014/3/24

#
done it :P took a little bit of smoke coming out my ears but its done import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class invader here. * * @author (your name) * @version (a version number or a date) */ public class invader extends Actor { /** * Act - do whatever the invader wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ int count =10; public void act() { // Add your action code here. setLocation(getX() -1, getY() ); Actor a = getOneIntersectingObject(bullet.class); if (a != null) { count = count -1; getWorld().removeObject(a); } if (count == 0) { getWorld().removeObject(a); getWorld().removeObject(this); return; } } }
danpost danpost

2014/3/24

#
Please show what code you have at this point (as far as trying to assign number of hits allowed per row of invaders). Use the 'code' link below the 'Post a reply' box to insert your code. You should probably show the Invader class from line 1 up to and including the constructor and the 'addedToWorld' method (if you have one); plus, your world class where you create and add the Invader objects into the world.
FlyingGvirus FlyingGvirus

2014/3/24

#
danpost wrote...
Please show what code you have at this point (as far as trying to assign number of hits allowed per row of invaders). Use the 'code' link below the 'Post a reply' box to insert your code. You should probably show the Invader class from line 1 up to and including the constructor and the 'addedToWorld' method (if you have one); plus, your world class where you create and add the Invader objects into the world.
the code that i am using there is the actual invader code and how can i make my invaders slower than -1 so like -0.1 on the getX() -1 (doesnt allow doubles ) :(
danpost danpost

2014/3/24

#
FlyingGvirus wrote...
the code that i am using there is the actual invader code
Sorry, I was not initially up when I started my post. Still need the code mentioned in your subclass of World. Will deal with speed of invaders after resolving the HP issue.
FlyingGvirus FlyingGvirus

2014/3/24

#
danpost wrote...
FlyingGvirus wrote...
the code that i am using there is the actual invader code
Sorry, I was not initially up when I started my post. Still need the code mentioned in your subclass of World. Will deal with speed of invaders after resolving the HP issue.
i have sorted the HP issue with the code i posted but here is the world code
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
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
 
/**
 * Write a description of class Space here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class Space extends World
{
 
    /**
     * Constructor for objects of class Space.
     *
     */
    public Space()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(1000, 600, 1);
         
        Rocket myrocket;
        myrocket = new Rocket();
         
        invader myinvader;
        myinvader = new invader();
         
        invader myinvader1;
        myinvader1 = new invader();
         
        invader myinvader2;
        myinvader2 = new invader();
         
        invader myinvader3;
        myinvader3 = new invader();
         
        invader myinvader4;
        myinvader4 = new invader();
         
        invader myinvader5;
        myinvader5 = new invader();
         
        invader myinvader6;
        myinvader6 = new invader();
         
        invader myinvader7;
        myinvader7 = new invader();
         
        invader myinvader8;
        myinvader8 = new invader();
         
        addObject(myrocket, 55 , 300);
        addObject(myinvader, 980 , 50);
        addObject(myinvader2, 980 , 115);
        addObject(myinvader3, 980 , 180);
        addObject(myinvader4, 980 , 240);
        addObject(myinvader5, 980 , 300);
        addObject(myinvader6, 980 , 360);
        addObject(myinvader7, 980 , 420);
        addObject(myinvader8, 980 , 480);
        addObject(myinvader1, 980 , 540);
 
         
         
 
    }
}
danpost danpost

2014/3/24

#
FlyingGvirus wrote...
i have sorted the HP issue with the code i posted
Alright, I did not understand that being the case in your last post (I was not sure what 'it' was referring to). Add another int field to your invader class to count act cycles.
1
int acts = 0;
Then in your act method, if it is divisible by 10, have the invader move; then increment the counter:
1
2
if (acts%10 == 0) setLocation(getX()-1, getY());
acts = (acts+1)%10; // cycles act counter from 0 through 9
FlyingGvirus FlyingGvirus

2014/3/24

#
danpost wrote...
FlyingGvirus wrote...
i have sorted the HP issue with the code i posted
Alright, I did not understand that being the case in your last post (I was not sure what 'it' was referring to). Add another int field to your invader class to count act cycles.
1
int acts = 0;
Then in your act method, if it is divisible by 10, have the invader move; then increment the counter:
1
2
if (acts%10 == 0) setLocation(getX()-1, getY());
acts = (acts+1)%10; // cycles act counter from 0 through 9
how does this acts work i don't understand it 100%
danpost danpost

2014/3/24

#
If you do not want your invader to move 1 pixel every act method and you want it only to move 1 pixel every 10 act methods, then you need to count act cycles. This is what 'acts' whill hold -- the running count of act cycles. But we do not need it to run past 10, just need it to restart counting after it reaches 10 (that is what line 2 above does). The 'if' statement puts a condition on the movement code to execute only every 10th act (essentially, slowing down the invader). You can change the '10's in the two lines to any positive number as adjust the speed as wanted. The higher the number, longer the 'delay' between movements (or the slower the invader will move).
FlyingGvirus FlyingGvirus

2014/3/24

#
danpost wrote...
If you do not want your invader to move 1 pixel every act method and you want it only to move 1 pixel every 10 act methods, then you need to count act cycles. This is what 'acts' whill hold -- the running count of act cycles. But we do not need it to run past 10, just need it to restart counting after it reaches 10 (that is what line 2 above does). The 'if' statement puts a condition on the movement code to execute only every 10th act (essentially, slowing down the invader). You can change the '10's in the two lines to any positive number as adjust the speed as wanted. The higher the number, longer the 'delay' between movements (or the slower the invader will move).
awesome thanks again for the help
FlyingGvirus FlyingGvirus

2014/3/24

#
ummm i don't think i am using it properly here is the code for invader
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
public class invader extends Actor
{
    /**
     * Act - do whatever the invader wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    int acts = 0;
    int count = 3;
    public void act()
    {
         
        if (acts%10 == 0)
        {
        setLocation(getX()-1, getY()); 
        acts = (acts+1)%50; // cycles act counter from 0 through 9
        }
        Actor a = getOneIntersectingObject(bullet.class);
        if (a != null)
        {
        count = count -1
        getWorld().removeObject(a);
        }
        if (count == 0)
        {
            getWorld().removeObject(a);
            getWorld().removeObject(this);
            return;
            
        }
                if (getX() < 1)
        {
            getWorld().removeObject(this);
            Greenfoot.stop();
        }
    }   
}
danpost danpost

2014/3/24

#
No, you are not. Switch lines 15 and 16. The second line I gave must NOT be governed by the 'if' statement.
You need to login to post a reply.