Skip to content

Commit

Permalink
CWT Game - Checking Tires
Browse files Browse the repository at this point in the history
Preparing for menu functionality, so have to make sure all the classes 
are cleaned up for both architectures

- Improved the flexibility of the draw classes [J/JS]
- Split up a part of JSlix into its own module [JS]
- Made a MainGame class for testing purposes [J/JS]
- Shortened some code lingo for the screen size [J]
- Updated and cleaned code for all the changes [J/JS]
  • Loading branch information
ctomni231 committed Jan 4, 2021
1 parent c4c7138 commit f2b7fb5
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 491 deletions.
2 changes: 1 addition & 1 deletion cwtactics.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function boot() {

// Let's test some screens
screenlib.addTrait(main)
//screenlib.addTrait(battle)
//screenlib.addTrait(testbed)

screenlib.run()

Expand Down
420 changes: 420 additions & 0 deletions engine/js/gif.js

Large diffs are not rendered by default.

471 changes: 24 additions & 447 deletions engine/js/jslix.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/com/cwt/screen/BattleScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void init() {
public void update(int timePassed) {
// TODO Auto-generated method stub

if(sx != scr_width || sy != scr_height) {
imgLib.setImageSize((scr_width/2)-(basize+5), scr_height-((basize+5)*2));
if(sx != scrx || sy != scry) {
imgLib.setImageSize((scrx/2)-(basize+5), scry-((basize+5)*2));
imgLib.addImage(1, imgLib.getImage(1));

imgLib.setImageSize((scr_width/2)-(basize+5), scr_height-((basize+5)*2));
imgLib.setImageSize((scrx/2)-(basize+5), scry-((basize+5)*2));
imgLib.setFlipX();
imgLib.addImage(2, imgLib.getImage(1));

Expand All @@ -58,16 +58,16 @@ public void render(Graphics2D g, Component dthis) {
//g.drawImage(imgLib.getImage(0), 0, 0, dthis);

g.setColor(Color.BLACK);
g.fillRect(basize, basize, scr_width-(basize*2), scr_height-(basize*2));
g.fillRect(basize, basize, scrx-(basize*2), scry-(basize*2));
g.setColor(Color.WHITE);
g.fillRect(basize+5, basize+5, scr_width-((basize+5)*2), scr_height-((basize+5)*2));
g.fillRect(basize+5, basize+5, scrx-((basize+5)*2), scry-((basize+5)*2));

g.drawImage(imgLib.getImage(1), basize+5, basize+5, dthis);
g.drawImage(imgLib.getImage(2), scr_width/2, basize+5, dthis);
g.drawImage(imgLib.getImage(2), scrx/2, basize+5, dthis);

g.setColor(Color.BLACK);
g.setStroke(new BasicStroke(2f));
g.drawLine(scr_width/2, basize+2, scr_width/2, scr_height-basize-2);
g.drawLine(scrx/2, basize+2, scrx/2, scry-basize-2);
}


Expand Down
4 changes: 2 additions & 2 deletions src/com/cwt/screen/MainGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void update(int timePassed) {

@Override
public void render(Graphics2D g, Component dthis) {
g.drawImage(imgLib.getImage(0), 0, 0, scr_width, scr_height, dthis);
//g.drawImage(imgLib.getGIFImage("./image/background/AWDoRBattle.gif"), 0, 0, scr_width, scr_height, dthis);
g.drawImage(imgLib.getImage(0), 0, 0, scrx, scry, dthis);
//g.drawImage(imgLib.getGIFImage("./image/background/AWDoRBattle.gif"), 0, 0, scrx, scry, dthis);
}

}
4 changes: 2 additions & 2 deletions src/com/jslix/JSlix.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ private void drawJava(Graphics2D g2, int w, int h){
tempScreen = ScreenLibrary.scrOrder.get(i);
tempScreen.scr_mouseScroll = KeyPress.mouseScroll;
tempScreen.scr_index = i;
tempScreen.scr_width = w;
tempScreen.scr_height = h;
tempScreen.scrx = w;
tempScreen.scry = h;
tempScreen.scr_sysTime = getTime();
if(i == 0)
tempScreen.update(-100);
Expand Down
4 changes: 2 additions & 2 deletions src/com/jslix/Screen.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public abstract class Screen {
/**
* Holds the width of the screen
*/
public int scr_width = 0;
public int scrx = 0;
/**
* Holds the height of the screen
*/
public int scr_height = 0;
public int scry = 0;
/**
* Holds the clicks of the mouse wheel
*/
Expand Down
52 changes: 22 additions & 30 deletions src/com/jslix/image/ImgLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -653,44 +653,37 @@ public Color getColor(Color color, int alpha){
//DRAW FUNCTIONS
//-----------------

//public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)
//public abstract boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
//public abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
//public abstract boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
//public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
//public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)

/**
* This function places an image on a destination screen. Used
* primarily for drawing items to the screen quickly.
* @param g The Java2D Graphics Object
* @param index The index of the image in ImgLibrary
* @param img The Java2D image to draw to location
* @param dlx The destination (screen) x-axis location of the image
* @param dly The destination (screen) y-axis location of the image
* @param dthis The Component to draw the image to
*/
public void placeImg(Graphics2D g, int index, int dlx, int dly,
public void placeImg(Graphics2D g, Image img, int dlx, int dly,
Component dthis){
g.drawImage(getImage(index), dlx, dly, dthis);
g.drawImage(img, dlx, dly, dthis);
}

/**
* This function draws the image on a destination screen. Used
* for drawing items to the screen and allowing for scaling of the
* destination image on the fly
* @param g The Java2D Graphics Object
* @param index The index of the image in ImgLibrary
* @param img The Java2D image to draw to location
* @param dlx The destination (screen) x-axis position of the image
* @param dly The destination (screen) y-axis position of the image
* @param dsx The destination (screen) horizontal width of the image
* @param dsy The destination (screen) vertical height of the image
* @param dthis The Component to draw the image to
*/
public void drawImg(Graphics2D g, int index, int dlx, int dly,
public void drawImg(Graphics2D g, Image img, int dlx, int dly,
int dsx, int dsy, Component dthis){
dlx = (dsx < 0) ? dlx-dsx : dlx;
dly = (dsy < 0) ? dly-dsy : dly;
g.drawImage(getImage(index), dlx, dly, dsx, dsy, dthis);
g.drawImage(img, dlx, dly, dsx, dsy, dthis);
}

/**
Expand All @@ -702,17 +695,17 @@ public void drawImg(Graphics2D g, int index, int dlx, int dly,
* like the function placeImg
*
* @param g The Java2D Graphics Object
* @param index The index of the image in ImgLibrary
* @param img The Java2D image to draw to location
* @param dlx The destination (screen) x-axis position of the image
* @param dly The destination (screen) y-axis position of the image
* @param slx The source (picture) x-axis cut position of the image
* @param sly The source (picture) y-axis cut position of the image
* @param dthis The Component to draw the image to
*/
public void placeCropImg(Graphics2D g, int index, int dlx, int dly,
public void placeCropImg(Graphics2D g, Image img, int dlx, int dly,
int slx, int sly, Component dthis){
g.drawImage(getImage(index), dlx, dly, dlx+getX(index), dly+getY(index),
slx, sly, slx+getX(index), sly+getY(index), dthis);
g.drawImage(img, dlx, dly, dlx+img.getWidth(dthis), dly+img.getHeight(dthis),
slx, sly, slx+img.getWidth(dthis), sly+img.getHeight(dthis), dthis);

}

Expand All @@ -726,7 +719,7 @@ public void placeCropImg(Graphics2D g, int index, int dlx, int dly,
* like the function drawImg
*
* @param g The Java2D Graphics Object
* @param index The index of the image in ImgLibrary
* @param img The Java2D image to draw to location
* @param dlx The destination (screen) x-axis position of the image
* @param dly The destination (screen) y-axis position of the image
* @param dsx The destination (screen) horizontal width of the image
Expand All @@ -735,12 +728,12 @@ public void placeCropImg(Graphics2D g, int index, int dlx, int dly,
* @param sly The source (picture) y-axis cut position of the image
* @param dthis The Component to draw the image to
*/
public void drawCropImg(Graphics2D g, int index, int dlx, int dly,
public void drawCropImg(Graphics2D g, Image img, int dlx, int dly,
int dsx, int dsy, int slx, int sly, Component dthis){
dlx = (dsx < 0) ? dlx-dsx : dlx;
dly = (dsy < 0) ? dly-dsy : dly;
g.drawImage(getImage(index), dlx, dly, dlx+dsx, dly+dsy,
slx, sly, slx+getX(index), sly+getY(index), dthis);
g.drawImage(img, dlx, dly, dlx+dsx, dly+dsy, slx, sly,
slx+img.getWidth(dthis), sly+img.getHeight(dthis), dthis);
}

/**
Expand All @@ -754,7 +747,7 @@ public void drawCropImg(Graphics2D g, int index, int dlx, int dly,
* placed like the function placeImg
*
* @param g The Java2D Graphics Object
* @param index The index of the image in ImgLibrary
* @param img The Java2D image to draw to location
* @param dlx The destination (screen) x-axis position of the image
* @param dly The destination (screen) y-axis position of the image
* @param slx The source (picture) x-axis cut position of the image
Expand All @@ -763,9 +756,9 @@ public void drawCropImg(Graphics2D g, int index, int dlx, int dly,
* @param ssy The source (picture) y-axis height slice of the image
* @param dthis The Component to draw the image to
*/
public void placeCutImg(Graphics2D g, int index, int dlx, int dly,
public void placeCutImg(Graphics2D g, Image img, int dlx, int dly,
int slx, int sly, int ssx, int ssy, Component dthis){
g.drawImage(getImage(index), dlx, dly, dlx+ssx, dly+ssy,
g.drawImage(img, dlx, dly, dlx+ssx, dly+ssy,
slx, sly, slx+ssx, sly+ssy, dthis);
}

Expand All @@ -779,6 +772,7 @@ public void placeCutImg(Graphics2D g, int index, int dlx, int dly,
* drawn like the function drawImg
*
* @param g The Java2D Graphics Object
* @param img The Java2D image to draw to location
* @param dlx The destination (screen) x-axis position of the image
* @param dly The destination (screen) y-axis position of the image
* @param dsx The destination (screen) horizontal width of the image
Expand All @@ -789,11 +783,11 @@ public void placeCutImg(Graphics2D g, int index, int dlx, int dly,
* @param ssy The source (picture) y-axis height slice of the image
* @param dthis The Component to draw the image to
*/
public void drawCutImg(Graphics2D g, int index, int dlx, int dly, int dsx,
public void drawCutImg(Graphics2D g, Image img, int dlx, int dly, int dsx,
int dsy, int slx, int sly, int ssx, int ssy, Component dthis){
dlx = (dsx < 0) ? dlx-dsx : dlx;
dly = (dsy < 0) ? dly-dsy : dly;
g.drawImage(getImage(index), dlx, dly, dlx+dsx, dly+dsy,
g.drawImage(img, dlx, dly, dlx+dsx, dly+dsy,
slx, sly, slx+ssx, sly+ssy, dthis);
}

Expand Down Expand Up @@ -1494,7 +1488,7 @@ private void addTextImage(int index, String str, int row, int limit) {
int posy = (int)Math.floor(tmplps / tmpslx);

System.out.println("Canvas - Letter: "+str.charAt(i)+" ("+posx+","+posy+")");
placeCutImg(g, index, tmppx+((i-back)*letsx), tmppy+(drop*(letsy+1)), posx*letsx, posy*letsy, letsx, letsy, this);
placeCutImg(g, getImage(index), tmppx+((i-back)*letsx), tmppy+(drop*(letsy+1)), posx*letsx, posy*letsy, letsx, letsy, this);
}
}
addImage(pimg);
Expand Down Expand Up @@ -1576,9 +1570,7 @@ private String normalizeStr(int index, String str, int row, int limit) {
String[] strArr = newstr.split("\n");
newstr = (row < strArr.length) ? strArr[row].trim() : "";
}
}

}
return newstr;

}
}

0 comments on commit f2b7fb5

Please sign in to comment.