Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*The problem is how to track the fly miles of the craft. If the user press the key
- but there is a collision so the crast is not moving the miles should not increase*/
- //when the character is C Craft craft = new Craft();
- class Craft extends Entity {
- int fuel = 10;
- //how many enemies in the game? health value should be less than the enemy
- int health = 5;
- //health = 0 means live = false
- boolean live;
- // images with different directions are loaded
- String rotated_image = new String("craft-up.png");
- Craft(int x, int y, int h, int w)
- {
- super(x, y, h, w);
- showImage(rotated_image);
- }
- void display()
- {
- stroke(255);
- fill(175);
- if(keyPressed)
- {
- keyPressed();
- if(acceleration.x == 0 && acceleration.y == -3) rotated_image = "craft-up.png";
- if(acceleration.x == 0 && acceleration.y == 3) rotated_image = "craft-down.png";
- if(acceleration.x == 3 && acceleration.y == 0) rotated_image = "craft-right.png";
- if(acceleration.x == -3 && acceleration.y == 0) rotated_image = "craft-left.png";
- if( (int) acceleration.x != 0 || (int) acceleration.y != 0)
- {
- if( ! sound.isPlaying("engine") ) sound.play("engine", random(0.9, 1.2) );
- }
- }
- if( (int) acceleration.x == 0 && (int) acceleration.y == 0 )
- {
- if( sound.isPlaying("engine") ) sound.stop("engine");
- }
- showImage(rotated_image);
- // checkBoundaryCollision();
- move();
- keyReleased();
- }
- void keyPressed()
- {
- if(keyPressed || key == CODED)
- {
- if(keyCode == UP)
- {
- acceleration.y = -3;
- }
- if(keyCode == DOWN)
- {
- acceleration.y = 3;
- }
- if(keyCode == LEFT)
- {
- acceleration.x = -3;
- }
- if(keyCode == RIGHT)
- {
- acceleration.x = 3;
- }
- }
- }
- void keyReleased()
- {
- if(key == CODED)
- {
- if(keyCode == UP)
- {
- velocity.y = 0;
- acceleration.y = 0;
- }
- if(keyCode == DOWN)
- {
- velocity.y = 0;
- acceleration.y = 0;
- }
- if(keyCode == LEFT)
- {
- velocity.x = 0;
- acceleration.x = 0;
- }
- if(keyCode == RIGHT)
- {
- velocity.x = 0;
- acceleration.x = 0;
- }
- //if(keyCode == UP || keyCode == DOWN || keyCode == LEFT ||
- }
- }
- //check window's boundary
- void checkBoundaryCollision()
- {
- if(location.x > width - w/2)
- {
- location.x = width - w/2;
- }
- else if(craft.location.x < 0)
- {
- location.x = 0;
- }
- else if(craft.location.y > height - h/2)
- {
- location.y = height - h/2;
- }
- else if (craft.location.y < 0)
- {
- location.y = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement