Added parallax, started documentation

master
John 2022-06-03 13:44:38 -04:00
parent bcd896ed45
commit ca97774204
2 changed files with 31 additions and 7 deletions

25
doc/index.md Normal file
View File

@ -0,0 +1,25 @@
# Function Overview
This document intended to assist developers who seek to extend the game by modifying source code in src/.
## Classes
### BackgroundImage
Its constructor takes the following arguments:
`int x, int y, BufferedImage backgroundImage, int width, int height, int parallaxRatio`
Draws a background image that moves one pixel every `parallaxRatio` pixels when `BackgroundImage.draw()` is called.
### Camera
placeholder
## Utility Functions
These functions are located in the `public final` class UtilityFunction; please note that the UtilityFunction constructor is private to prevent initialization.
### readFromFile
placeholder

View File

@ -4,22 +4,21 @@ import java.awt.image.BufferedImage;
public class BackgroundImage {
public int x, y;
public int width, height;
public int parallaxRatio;
public BufferedImage backgroundImage;
public BackgroundImage(int x, int y, BufferedImage backgroundImage, int width, int height) throws SpriteException {
int compressionRatio;
public BackgroundImage(int x, int y, BufferedImage backgroundImage, int width, int height, int parallaxRatio) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.backgroundImage = backgroundImage;
// compressionRatio = Math.max(backgroundImage.getWidth() / width, backgroundImage.getHeight() / height);
// this.backgroundImage = backgroundImage.getSubimage((backgroundImage.getWidth() - width)/2,
// (backgroundImage.getHeight() - height)/2, width, height);
this.parallaxRatio = parallaxRatio;
}
public void draw(Graphics g){
g.drawImage(backgroundImage, x, y, width, height, null);
g.drawImage(backgroundImage, x-GamePanel.camera.x/parallaxRatio % width, y, width, height, null);
// added to prevent the background image from disappearing
g.drawImage(backgroundImage, x-GamePanel.camera.x/parallaxRatio % width + width - 1, y, width, height, null);
}
}