Alternatively, join us on Discord.

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

Started by p2, September 21, 2016, 09:23:42 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DJ Omnimaga

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:

p2

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 :/
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

DJ Omnimaga

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)

p2

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 ^^
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

DJ Omnimaga

Yeah for smooth scrolling you need to draw an extra row and column and maybe you need two extra variables

c4ooo

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.

p2

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
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

c4ooo

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).

p2

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
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

DJ Omnimaga

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 ^^

p2

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 ^^
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

DJ Omnimaga


p2

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?)
Anyway war sucks. Just bring us your food instead of missiles  :P ~ DJ Omnimaga (11.10.2016 20:21:48)
if you cant get a jframe set up, draw stuff to it, and receive input, i can only imagine how horrible your game code is _._   ~ c4ooo (14.11.2016 22:44:07)
If they pull a Harambe on me tell my family I love them ~ u/Pwntear37d (AssangeWatch /r/)
make Walrii great again ~ DJ Omnimaga (28.11.2016 23:01:31)
God invented the pc, satan the smartphone I guess ~ p4nix (16.02.2017 22:51:49)

WholeWheatBagels

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
Living in another world to you.



Also in case you were wondering Frankie did go to Hollywood

DJ Omnimaga


Powered by EzPortal