You can help CodeWalrus stay online by donating here. | New CodeWalrus | Old (dark mode) | Old (light) | Discord server

Walrus Kingdom (former PocketWalrus) [PC] [Windows] [Java] [Walrus]

b/[Completed] Walrii Games (TI/HP/PC/2600) Started by p2, September 21, 2016, 09:23:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

u/Dream of Omnimaga April 11, 2017, 10:32:24 PM
Good luck. I hope this doesn't kill the project or require a full rewrite again o.o

Little dinosaur walrii at the bottom of the screen would be sad D:
u/p2 April 11, 2017, 11:11:40 PM
nah it just means that all plans to maybe rewrite parts of the code aren't possible. So I'll stick with my current engine.
Still I have to add lots of map data, new tiles and add all of the story line stuff >.<
I even have to add NPCs first, they don't exist yet <--- major code change

Edit:
*which is hard spending almost all the time on pxls.space x.x
So I won't have tome to work on it atm :/
u/Dream of Omnimaga April 12, 2017, 04:28:35 AM
Yeah I hoped you won't spend all your time on pxl.space especially since it's gonna be reset at one point or another. Wod suck to lose you in the same style we lost active members to Freecodecamp D: @p2 (eg alexgt)
u/p2 April 15, 2017, 06:52:42 AM
Nah don't worry u got me addicted to this site a long time ago <3 no way I'm gonna leave ^^
Guess as soon as I find the time, I'll take my first approach on adding smooth scrolling x.x
Just hope I do t break everything xD

Buuut then I'll have to handle the line of tiles touching the border completely different which requires major changes to the rendering thingy... so I guess that might take some time ^^
u/Dream of Omnimaga April 15, 2017, 08:38:21 PM
Yeah for smooth scrolling you need to draw an extra row and column and maybe you need two extra variables
u/c4ooo April 15, 2017, 08:42:29 PM
Store x and y position in pixels. Then, loop through each tile, and render each tile at (tileX * tileSize -playerX + (windowWidth / 2), tileY * tileSize - playerY + (windowHeight / 2)). Once you do that, it shouldn't be hard to use two nested for loops to only render the tiles around the player.
Last Edit: April 15, 2017, 08:47:19 PM by c4ooo
u/p2 April 16, 2017, 02:07:15 PM
It's a bit more complicated:

Forst I calculate the top-left position of the screen in the map:
screenTop = General.getBetween(0, Map.getHeight()-getHeight(), Player.getYPos()-Math.round(getHeight()/2));
screenLeft = General.getBetween(0, Map.getWidth()-getWidth(), Player.getXPos()-Math.round(getWidth()/2));
// getWidth() returns the width of the screen in tiles
// Map.getWidth() returns the map dimensions


I do this to get the currently relevant map data, which is then copied to a second matrix: ScreenMatrix[_x][_y]
It basically is a screen-sized region of the map centered around the walrus, but one that cannot leave the map (so the walrii is only centered if it isn't too close to the edge).

starting from this point, I have the following methods (sorry for bad readability):
public static void renderBackground(boolean ForceUpdate) {
// Renders background layer *obviously*
for(int _y=0;_y<getHeight();_y++) {
for(int _x=0;_x<getWidth();_x++) {
double data = ScreenMatrix[_x][_y]; // load raw data
double dataOld = ScreenMatrixOld[_x][_y];
if (data!=dataOld | ForceUpdate == true) { // Player moved
int _background = Map.getBackgroundID(data); // extract background data
TilesDrawn++;
TileArea.drawTile(tiles, TileSource.getXPos(_background), TileSource.getYPos(_background), window.blocksize*_x, window.blocksize*_y); // render background layer
} else { // To prevent area around the character to be rendered twice (messes up partially transparent tiles in the menu plus slows down)
if (General.isCloseToChar(_x, _y)) { // prevent shadows when close to the edge on in ScrollLock regions
int _background = Map.getBackgroundID(data); // extract background data
TilesDrawn++;
TileArea.drawTile(tiles, TileSource.getXPos(_background), TileSource.getYPos(_background), window.blocksize*_x, window.blocksize*_y); // render background layer
}
}
}
}
}
public static void renderForeground(boolean ForceUpdate) {
// Renders foreground layer *obviously*
for(int _y=0;_y<getHeight();_y++) {
for(int _x=0;_x<getWidth();_x++) {
double data = ScreenMatrix[_x][_y]; // load raw data
double dataOld = ScreenMatrixOld[_x][_y];
if (data!=dataOld | ForceUpdate == true) { // Update to map data or player moved
int _foreground = Map.getForegroundID(data); // extrace foreground data
if(_foreground>0 && General.isCloseToChar(_x, _y)==false) { // To prevent area around the character to be rendered twice (messes up partially transparent tiles in the menu plus slows down)
TilesDrawn++;
TileArea.drawTile(tiles, TileSource.getXPos(_foreground), TileSource.getYPos(_foreground), window.blocksize*_x, window.blocksize*_y);
}
}
if (General.isCloseToChar(_x, _y)) { // prevent shadows when close to the edge on in ScrollLock regions
int _foreground = Map.getForegroundID(data); // extrace foreground data
if(_foreground>0) {
TilesDrawn++;
TileArea.drawTile(tiles, TileSource.getXPos(Map.getForegroundID(data)), TileSource.getYPos(Map.getForegroundID(data)), window.blocksize*_x, window.blocksize*_y);
}
}
}
}
}
public static void renderWalrus() {
for(int _y=0;_y<getHeight();_y++) {
for(int _x=0;_x<getWidth();_x++) {
if (scrollLocked==false) {
if(General.getBetween(0, Player.getXPos()-Math.round(getWidth()/2), Map.getWidth()-getWidth())+_x == Player.getXPos() && General.getBetween(0, Player.getYPos()-Math.round(getHeight()/2), Map.getHeight()-getHeight())+_y == Player.getYPos()) {
int _background = Map.getBackgroundID(ScreenMatrix[_x][_y]); // extract background data
TilesDrawn++;
TileArea.drawTile(tiles, TileSource.getXPos(_background), TileSource.getYPos(_background), window.blocksize*_x, window.blocksize*_y); // render background layer
PlayerTile = Player.getCurrentTile()+Player.TileChangeWhileWalking;
TilesDrawn++;
TileArea.drawTile(tiles, TileSource.getXPos(PlayerTile), TileSource.getYPos(PlayerTile), window.blocksize*_x, General.getMax(window.blocksize*_y-window.blocksize/4, 0)); // render char
Player.newLastXPos = _x;
Player.newLastYPos = _y;
int _foreground = Map.getForegroundID(ScreenMatrix[_x][_y]); // extrace foreground data
if(_foreground>0) {TileArea.drawTile(tiles, TileSource.getXPos(_foreground), TileSource.getYPos(_foreground), window.blocksize*_x, window.blocksize*_y);} // add foreground layer

}
} else { //This disables the automated screenscrolling for special areas on the map (like in huge gardens) so only the y-axis scrolls. Similar to behavior close to map's edges
if(Player.getXPos()-screenLeft==_x && General.getBetween(0, Player.getYPos()-Math.round(getHeight()/2), Map.getHeight()-getHeight())+_y == Player.getYPos()) {
int _background = Map.getBackgroundID(ScreenMatrix[_x][_y]); // extract background data
TilesDrawn++;
TileArea.drawTile(tiles, TileSource.getXPos(_background), TileSource.getYPos(_background), window.blocksize*_x, window.blocksize*_y);
PlayerTile = Player.getCurrentTile()+Player.TileChangeWhileWalking;
TilesDrawn++;
TileArea.drawTile(tiles, TileSource.getXPos(PlayerTile), TileSource.getYPos(PlayerTile), window.blocksize*_x, General.getMax(window.blocksize*_y-Math.round(getZoom()/4), 0)); // render char
Player.newLastXPos = _x;
Player.newLastYPos = _y;
int _foreground = Map.getForegroundID(ScreenMatrix[_x][_y]); // extrace foreground data
if(_foreground>0) {TileArea.drawTile(tiles, TileSource.getXPos(_foreground), TileSource.getYPos(_foreground), window.blocksize*_x, window.blocksize*_y);} // add foreground layer
}
}
}
}
}
public static void render(boolean ForceUpdate) {
// main class that does all the rendering
renderBackground(ForceUpdate);
renderWalrus();
renderForeground(ForceUpdate);
Trigger.trigger(Player.getXPos(), Player.getYPos());
if(Trigger.get(Player.getXPos(), Player.getYPos())==0.0 && forceUpdateNextTime==true) { // To prevent left over fragments from popups
forceUpdateNextTime = false;
render(true);
}
Player.lastXPos = Player.newLastXPos;
Player.lastYPos = Player.newLastYPos;
System.out.println(TilesDrawn+" Tiles updated");
TilesDrawn = 0;
}


ld;dr: it's a lot more complicated x.x
u/c4ooo April 18, 2017, 01:27:45 AM
You can get rid of Math.round() and just cast to int ;)
Anyways, are you using openGL or Graphics2D?
I *might* be able to advise on how to optimize.

Also, if (data!=dataOld | ForceUpdate == true)  could be:  if (data!=dataOld || ForceUpdate).
u/p2 July 28, 2017, 08:27:28 PM
me has officially continued work on the Walrus Kingdom project.
Buuut I first have to work a bit with my code again (havent looked at it for a while) so I'm now going for savegame and stuff like that, maybe also tools and more key functionality.
Will (if at all) do graphic updates like smooth scrolling laaaaaaaaaaaater :)

WALRUSES <3
u/Dream of Omnimaga July 30, 2017, 05:14:44 PM
Glad to hear. The p2 Walrii on caffeine on this page was starting to feel lonely with so few updates :P

Hopefully you don't have too much trouble understanding your old code ^^
u/p2 July 30, 2017, 06:48:37 PM
I began working on the savegame and besides the basic vars like current map and player position there's almost no reference to the old code necessary. So I have Time to Review the rest of the code before having to work with it ^^
u/Dream of Omnimaga September 01, 2017, 03:12:57 AM
I'm looking forward for this ^^
u/p2 September 03, 2017, 08:03:06 PM
Now featuring: A huge fat house  :thumbsup:
This will probably be the town library, or at least it was planned as such.
Even tho I'm still not sure how to implement a library in the game's story...
(Maybe just a place to scroll through all the lame dialogues you skipped earlier?)
u/WholeWheatBagels September 03, 2017, 10:55:02 PM
That'd be an interesting idea, like you click through something but you want to go read it later, I like that.

Could also be like a display hall or something for all the different :walrii: you've encountered
u/Dream of Omnimaga September 05, 2017, 05:53:09 PM
You should make inns like this ^^
Website statistics


MyCalcs | Ticalc.org | Cemetech | Omnimaga | TI-Basic Developer | MaxCoderz | TI-Story | Casiocalc.org | Casiopeia | The Museum of HP Calculators | HPCalc.org | CnCalc.org | Music 2000 Community | TI Education | Casio Education | HP Calcs | NumWorks | SwissMicros | Sharp Calculators
Powered by EzPortal