From 47badea54b5b544a34f5477a2aa792db7c907e2a Mon Sep 17 00:00:00 2001 From: Solargale Date: Sun, 29 Mar 2020 04:32:00 -0600 Subject: [PATCH] Added crosshair and wrote the coords of the mouse on the screen --- core/assets/crosshair.png | Bin 0 -> 1435 bytes core/assets/grass.png | Bin 558 -> 2970 bytes core/assets/man.atlas | 229 ++++++++++++++++++ core/assets/man.png | Bin 0 -> 1626 bytes core/assets/wood.png | Bin 0 -> 1624 bytes core/src/com/mygdx/game/Chunk.java | 5 + core/src/com/mygdx/game/GUI.java | 27 +++ core/src/com/mygdx/game/InputController.java | 63 +++-- core/src/com/mygdx/game/Main.java | 25 +- core/src/com/mygdx/game/Mouse.java | 50 ++++ core/src/com/mygdx/game/Player.java | 54 ++++- core/src/com/mygdx/game/Restrictions.java | 9 + core/src/com/mygdx/game/World.java | 11 +- core/src/com/mygdx/game/WorldRenderer.java | 28 ++- .../mygdx/game/desktop/DesktopLauncher.java | 3 + 15 files changed, 452 insertions(+), 52 deletions(-) create mode 100644 core/assets/crosshair.png create mode 100644 core/assets/man.atlas create mode 100644 core/assets/man.png create mode 100644 core/assets/wood.png create mode 100644 core/src/com/mygdx/game/Chunk.java create mode 100644 core/src/com/mygdx/game/GUI.java create mode 100644 core/src/com/mygdx/game/Mouse.java create mode 100644 core/src/com/mygdx/game/Restrictions.java diff --git a/core/assets/crosshair.png b/core/assets/crosshair.png new file mode 100644 index 0000000000000000000000000000000000000000..5635c25430c9af46a27007242fdb968d604e82c3 GIT binary patch literal 1435 zcmV;M1!Ve(P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=HGcH}4whTmDmECES?#Bwl~b7lv#{Q1GyNhO`` zBvTLb5K{&$Koa`6lByBioH zK`G~_r7iD}Gy3zE*R7{O9$zWSeK#DB4P`50+XgO++mO&{z_+caY(>J`ayY+_Z8>Gr z*HhTz{MhX)40zqlf+(k$NCWb~UNvRZjeStWt;IEv^BfnCOVQ)EySgIs%w0(Q%K7wC z&bQzdUqbO{coR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`0daD4Qgo3L?@J0TV!ZHpALre3c<(+yXq1^@cZ~yv z=~$^mT+U=y<(^lFh#&+BqRQ;*oT4NVSYP+lNp%vG zr#GD{=Y3*{6;+-1oOsNl3lcwaUGw>kbHQVQXG&H&HBT%N%Y_csI+ztLgLsNKsv9Qd z3mKnv&Rd*~a*eg_$zK@GnJdd&rxig0i&%mJ85(LRp$rEx+D%eyr06^z;2-w<3b{0L zmB7fcfC>z#o*(=Vet*x_&QDJGN#Quq{o=YGBS6nC(5$=e_p$3XPXO^5xH8-RN&}er zB)#6&qDR2MHgIv>*0ep~at9cCs;ZXiNg^#Fp9kL0=$o>@;4RR%=FhElj?)JqO|weg z00)P_Xo0fV1K!=+Ik$g%TJ!q>^Vf28W^bj#00009a7bBm0F&kj7zY6rC1D*or;`N< zCoTXONklYL*v>!_U}9hx)iA1IxM~0ZV=w^M$#(ZZ00000NkvXXu0mjf5d+PH diff --git a/core/assets/man.atlas b/core/assets/man.atlas new file mode 100644 index 0000000..ae74293 --- /dev/null +++ b/core/assets/man.atlas @@ -0,0 +1,229 @@ +man.png +size: 256, 128 +format: RGBA8888 +filter: Nearest,Nearest +repeat: none +man_Up + rotate: false + xy: 0,0 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 0 +man_Up + rotate: false + xy: 32,0 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 1 +man_Up + rotate: false + xy: 64,0 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 2 +man_Up + rotate: false + xy: 96,0 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 3 +man_Down + rotate: false + xy: 128,0 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 0 +man_Down + rotate: false + xy: 160,0 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 1 +man_Down + rotate: false + xy: 192,0 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 2 +man_Down + rotate: false + xy: 224,0 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 3 +man_Left + rotate: false + xy: 0,32 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 0 +man_Left + rotate: false + xy: 32,32 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 1 +man_Left + rotate: false + xy: 64,32 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 2 +man_Left + rotate: false + xy: 96,32 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 3 +man_Right + rotate: false + xy: 128,32 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 0 +man_Right + rotate: false + xy: 160,32 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 1 +man_Right + rotate: false + xy: 192,32 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 2 +man_Right + rotate: false + xy: 224,32 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 3 +man_UpLeft + rotate: false + xy: 0,64 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 0 +man_UpLeft + rotate: false + xy: 32,64 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 1 +man_UpLeft + rotate: false + xy: 64,64 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 2 +man_UpLeft + rotate: false + xy: 96,64 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 3 +man_UpRight + rotate: false + xy: 128,64 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 0 +man_UpRight + rotate: false + xy: 160,64 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 1 +man_UpRight + rotate: false + xy: 192,64 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 2 +man_UpRight + rotate: false + xy: 224,64 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 3 +man_DownLeft + rotate: false + xy: 0,96 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 0 +man_DownLeft + rotate: false + xy: 32,96 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 1 +man_DownLeft + rotate: false + xy: 64,96 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 2 +man_DownLeft + rotate: false + xy: 96,96 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 3 +man_DownRight + rotate: false + xy: 128,96 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 0 +man_DownRight + rotate: false + xy: 160,96 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 1 +man_DownRight + rotate: false + xy: 192,96 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 2 +man_DownRight + rotate: false + xy: 224,96 + size: 32,32 + orig: 32,32 + offset: 0,0 + index: 3 diff --git a/core/assets/man.png b/core/assets/man.png new file mode 100644 index 0000000000000000000000000000000000000000..aa2beb9f6e9c326b2a8d806264060f4ffb224ea3 GIT binary patch literal 1626 zcmdUvYgZFj6ow}ft`!1O5D^GyUA3ZupjNp@!9b-_EEShP1BfCZMpmpK6(#~o#VF8v zsUQR!7GkXgM8H%bRD=XAM4%WEg+MR^Bqow@Ny22N6R=;}U(oYm*531;ea@QwytB`L zwTEnOW^V=nfO$x8;9da0VIe>_F~Xi>4NZChN83x@0n~ImOaOq<$032Fh>RQW-t?TT zTxS{3Gh3rUDcxCbRqf zN7^Z#b_=jp@@wRFgti$t5)XPDhIyjGDdA?|mX1L(6ot)F2WQ(FQV02RH_#aD3#|A& z%!M40i`~Mf_*#uirBdO(#5slUg;s%pILl?A_oy!WW75GwVKxQflUkYEdpeM*lTakz5O(BaU83h%PaK*FG$vYMokJ z8ama^24D?%&Q5(0zDdM$l3n@!JVe8rFSVyW{~%p(^IZMa z!%re2uov6Fes_^~k4yE&HfQYSI;13@KA6Vi-Vbye#OqnfxbS4F0TdtBR6M!yo#dBT)QU`U(a^sC#$QjPZl}uZY2K01PJiEYrVX?V)W%7VybRP@5A45{QV}ypcA@cAZ@BiGXv1i_5i>~EF554 zbsMJ^XS3!r)`A7-32v?&)Of2)CAil~StqiQE4qFaAaC^Z@<*Q{B^Rlj#i-Yu`fxFt z%%`VE5zCn1A#PkiY+S)|BaT!%4#TeV7rqD5V-^&!zc)5L`a`I1E zaw>-AwC@g=t{2I>;#7iQB!`^Ngb(nj{B zRH`T)T}0Wxy?l(b%L|=8hU`JAuAMRS3w~~cv9|+fq^-FxNMhz+;I5O=a4J%zz{#RY z83d2_kT&s$GyWY!Eve{EV-8G{F~LWu`0XE_1&^6hri&3)Oe2WYr$$M4SV~CKlscGw zM!C1}|fhE`fI8`k@j4c6D$YecZfdk^h}B1f0Ohi;-!k l_Z`&aZc^+1zjSiwQ`EhQe=EKInUx+*NYI|ZnjNt@e*+y;VpsqG literal 0 HcmV?d00001 diff --git a/core/assets/wood.png b/core/assets/wood.png new file mode 100644 index 0000000000000000000000000000000000000000..78c96e1831d5819b07096f3d25933582b9493b26 GIT binary patch literal 1624 zcmV-e2B-OnP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+SQj^mfIiS-1-VB&B73HbO%CzjZ_hniRN#o@b z<~-A8{|Eza>JMk51Rpp$Je`;rLqc1{xQMtFKPF1*^Zc?ax_+m9sK6(wmaQ32*}Syd zopD<{1s1zRM!U9QBuS z_Pe4Rtb^T!<)DY>37UM`t-eEn{%Xlr#_U3LLW4s%iaQbr5omL9D!E1*OZ2uY}D z^pa2%+hRp76|%n2jE>f?v|J4qg}r{$61ih;W-h z^&`N0xxG493xa-xS+T%u7TQ!Sp8qA69iS}+deqw{=2)fzgb1cRoM8(BCb0D!;87Hb z%m}0cP=@Pboh%^0-b;a#;;apTgFOt}m=k#n6)&3@hoNi-(J68$ zd+VL|KKSU>C!d22eTRh*LqAn>w9!Q$LyS==rkK^LQ?EgzswT}zlEta(6ZT`$lv2(x znxQ#kcE*657g_A$7QcigF1jRI@{06X-Rjq{##Ps}<|4%w?BfzjELu{@l`B%Iy6S7F zv1&~6s#%{AXbi`2BGmJezZ>s@()8c%96NcDm7payA-y9(~diSNunOdJDv1T_#t zVs~an**WRtIx~|5yTS{c^c_y&P7DNHW$}#y= z&`TTYiF0%w`Ew`f$!>osQRzoV(Q9Y+ITobmBj1s`W902m8-3y{+g+n~zN(K8wh#Q0 z_}>*Z{2;@>arz4}%r1_u>RqS+00D$)LqkwWLqi~Na&Km7Y-IodD3N`UJxIeq9K~Nh zq#_kT3yO5eP@OD@ia2T&iclfc3avVrT>1q~8j=(jN5Qq=;KyRs!Nplu2UkH5`~Y!s zbW(JY691PJTEuv8+>dwn9(V5mf1|=wGdK>Ynq{Pu2_c(X6+*8FAc`RRF(@%ppA*Ft zJjd5Pe0;r&^DOUke~w-yZ!*9q5YIB*u!uK^r#CH~^FDEel_Z7uoOsNj3lcwaU3U46 zbJ1Zx&x{zE^gMBdSSWU|+`+75sKismF-6rV-=B3^;k?CJt<+fSp8SR3ytcB;b(&Em zv4|yz5Fn$5GAghTr&S}xM4I*!9{yp+FOo|pR~d{P3#dYcGif2I|BN)fs5<5Chq~4JHXJBE*X*| z1!(#U1>pURz9|O`+yXsoZf~u9oIU^<>MC^u92^3pMao|Hcz1VaZ~vZY_4flPFLH@g z73^dH000SaNLh0L04^f{04^f|c%?sf00007bV*G`2jl}B1Qa=H%$7m`000?uMObu0 zZ*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}0001cNklycmDx9Jh&ZkJQwn5{FT!TN! z?=b?WRzxw023Qj9DhbW_Tm#qwOa>gZqpf6L!>Yi63(5bbN~j+p{Q*(B^z**HLlZB9 W2rr0K)za4h0000?5I literal 0 HcmV?d00001 diff --git a/core/src/com/mygdx/game/Chunk.java b/core/src/com/mygdx/game/Chunk.java new file mode 100644 index 0000000..9b4ad8a --- /dev/null +++ b/core/src/com/mygdx/game/Chunk.java @@ -0,0 +1,5 @@ +package com.mygdx.game; + +public class Chunk { + +} diff --git a/core/src/com/mygdx/game/GUI.java b/core/src/com/mygdx/game/GUI.java new file mode 100644 index 0000000..cff7127 --- /dev/null +++ b/core/src/com/mygdx/game/GUI.java @@ -0,0 +1,27 @@ +package com.mygdx.game; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector3; + +public class GUI { + private BitmapFont font = new BitmapFont(); + private Mouse mouse; + private OrthographicCamera cam; + + public GUI(Mouse mouse, OrthographicCamera cam) { + this.font = new BitmapFont(); + this.mouse = mouse; + this.cam = cam; + } + + public void render(SpriteBatch batch){ + font.draw(batch, "x: "+ mouse.getTileX(cam) + "y: " + mouse.getTileY(cam),-10, 0); + } + + public void dispose(){ + font.dispose(); + } +} diff --git a/core/src/com/mygdx/game/InputController.java b/core/src/com/mygdx/game/InputController.java index 20c21f0..dc1b002 100644 --- a/core/src/com/mygdx/game/InputController.java +++ b/core/src/com/mygdx/game/InputController.java @@ -3,42 +3,61 @@ package com.mygdx.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; -public class InputController { +public class InputController implements Restrictions { private OrthographicCamera cam; + private Player player; + private Animation animation; + float pressTime, unpressTime; + int i = 0; - public InputController(OrthographicCamera cam) { + public InputController(OrthographicCamera cam, Player player) { this.cam = cam; + this.player = player; } public void handleInput() { + i++; + if (Gdx.input.isKeyPressed(Input.Keys.A)) { - cam.zoom += 0.02; + cam.zoom += 1; } if (Gdx.input.isKeyPressed(Input.Keys.Q)) { - cam.zoom -= 0.02; - } - if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) { - cam.translate(-3, 0, 0); - } - if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) { - cam.translate(3, 0, 0); - } - if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) { - cam.translate(0, -3, 0); - } - if (Gdx.input.isKeyPressed(Input.Keys.UP)) { - cam.translate(0, 3, 0); + cam.zoom -= 1; } - cam.zoom = MathUtils.clamp(cam.zoom, 0.1f, 100/cam.viewportWidth); + if (Gdx.input.isKeyPressed(Input.Keys.LEFT) && i > KEY_DELAY) { + i = 0; + directionAnimation("Left"); + player.addX(-MOVEMENT_SPEED); + cam.translate(-MOVEMENT_SPEED,0); + } + if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)&& i > KEY_DELAY) { + i = 0; + directionAnimation("Right"); + player.addX(MOVEMENT_SPEED); + cam.translate(MOVEMENT_SPEED,0); + } + if (Gdx.input.isKeyPressed(Input.Keys.DOWN)&& i > KEY_DELAY) { + i = 0; + directionAnimation("Down"); + player.addY(-MOVEMENT_SPEED); + cam.translate(0,-MOVEMENT_SPEED); + } + if (Gdx.input.isKeyPressed(Input.Keys.UP)&& i > KEY_DELAY) { + i = 0; + directionAnimation("Up"); + player.addY(MOVEMENT_SPEED); + cam.translate(0,MOVEMENT_SPEED); + } + cam.update(); + } - float effectiveViewportWidth = cam.viewportWidth * cam.zoom; - float effectiveViewportHeight = cam.viewportHeight * cam.zoom; - cam.position.x = MathUtils.clamp(cam.position.x, effectiveViewportWidth / 2f, 100 - effectiveViewportWidth / 2f); - cam.position.y = MathUtils.clamp(cam.position.y, effectiveViewportHeight / 2f, 100 - effectiveViewportHeight / 2f); + public void directionAnimation(String direction) { + player.setAnimation(new Animation<>(1 / 4f, player.getTextureAtlas().findRegions(player.getSpriteName() + "_" + direction))); } } diff --git a/core/src/com/mygdx/game/Main.java b/core/src/com/mygdx/game/Main.java index 91b4703..f8e3e49 100644 --- a/core/src/com/mygdx/game/Main.java +++ b/core/src/com/mygdx/game/Main.java @@ -3,36 +3,45 @@ package com.mygdx.game; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.GL30; +import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import static com.mygdx.game.Restrictions.*; + public class Main extends ApplicationAdapter { private SpriteBatch batch; private WorldRenderer worldRenderer; + private GUI gui; + private Mouse mouse; + private OrthographicCamera cam; @Override public void create () { - batch = new SpriteBatch(); - World world = new World(); - Player player = new Player(0, 0); - - worldRenderer = new WorldRenderer(world, player); + mouse = new Mouse(player); + cam = new OrthographicCamera(VIEWPORT_WIDTH,VIEWPORT_HEIGHT); + cam.translate(TILE_SIZE/2,TILE_SIZE/2); + cam.zoom = 25f; + worldRenderer = new WorldRenderer(world, player, mouse,cam); + batch = new SpriteBatch(); + gui = new GUI(mouse,cam); } @Override public void render () { - Gdx.gl.glClearColor(0, 0, 0, 1); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - + Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); batch.begin(); worldRenderer.render(batch); + gui.render(batch); batch.end(); } @Override public void dispose () { worldRenderer.dispose(); + gui.dispose(); batch.dispose(); } } diff --git a/core/src/com/mygdx/game/Mouse.java b/core/src/com/mygdx/game/Mouse.java new file mode 100644 index 0000000..bf61281 --- /dev/null +++ b/core/src/com/mygdx/game/Mouse.java @@ -0,0 +1,50 @@ +package com.mygdx.game; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector3; + +import static java.lang.Math.round; + +public class Mouse implements Restrictions { + Player player; + Texture crosshair = new Texture("core/assets/crosshair.png"); + + public Mouse(Player player) { + this.player = player; + } + + public void selectedTile(SpriteBatch batch, OrthographicCamera cam){ + Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0); + cam.unproject(mousePos); + batch.draw(crosshair, getSelectedX(mousePos), getSelectedY(mousePos)); + } + + public int getSelectedX(Vector3 mousePos) { + return round((mousePos.x-8)/16)*16; + } + + public int getSelectedY(Vector3 mousePos) { + return round((mousePos.y-8)/16)*16; + } + + public int getTileX(OrthographicCamera cam){ + Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0); + cam.unproject(mousePos); + return (getSelectedX(mousePos) + player.getX()/2)/TILE_SIZE; + } + + public int getTileY(OrthographicCamera cam){ + Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0); + cam.unproject(mousePos); + return (getSelectedY(mousePos) + player.getY()/2)/TILE_SIZE; + } + + + public void render(SpriteBatch batch, OrthographicCamera cam) { + selectedTile(batch,cam); + System.out.println("X = " + getTileX(cam) + " Y = "+ getTileY(cam)); + } +} diff --git a/core/src/com/mygdx/game/Player.java b/core/src/com/mygdx/game/Player.java index cdfaef8..abf0e3c 100644 --- a/core/src/com/mygdx/game/Player.java +++ b/core/src/com/mygdx/game/Player.java @@ -1,13 +1,29 @@ package com.mygdx.game; -import javafx.util.Pair; +import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.utils.Array; -public class Player { +public class Player implements Restrictions { private int x,y = 0; + private String spriteName; + private TextureAtlas textureAtlas; + private Animation animation; - public Player(int x, int y) { - this.x = x; - this.y = y; + Player(int x, int y) { + this.x = 0; + this.y = 0; + this.spriteName = "man"; + this.textureAtlas = new TextureAtlas("core/assets/" + spriteName + ".atlas"); + Array keyFrames = textureAtlas.findRegions(spriteName + "_Down"); + float frameDuration = 1 / 4f; + this.animation = new Animation<>(frameDuration, keyFrames); + } + + public void render(Batch batch){ + float elapsedTime = 1f; + batch.draw(getAnimation().getKeyFrame(elapsedTime, true), getX(), getY(), TILE_SIZE, TILE_SIZE); } public int getX() { @@ -25,4 +41,32 @@ public class Player { public void setY(int y) { this.y = y; } + + public void addX(int x){ + this.x += x; + } + + public void addY(int y){ + this.y += y; + } + + String getSpriteName() { + return spriteName; + } + + public void setSpriteName(String tempSpriteName) { + spriteName = tempSpriteName; + } + + TextureAtlas getTextureAtlas() { + return textureAtlas; + } + + Animation getAnimation() { + return animation; + } + + void setAnimation(Animation animation) { + this.animation = animation; + } } diff --git a/core/src/com/mygdx/game/Restrictions.java b/core/src/com/mygdx/game/Restrictions.java new file mode 100644 index 0000000..79384c7 --- /dev/null +++ b/core/src/com/mygdx/game/Restrictions.java @@ -0,0 +1,9 @@ +package com.mygdx.game; + +public interface Restrictions { + int TILE_SIZE = 16; + float VIEWPORT_HEIGHT = 9/2f; + float VIEWPORT_WIDTH = 16/2f; + int MOVEMENT_SPEED = 16; + int KEY_DELAY = 20; +} diff --git a/core/src/com/mygdx/game/World.java b/core/src/com/mygdx/game/World.java index 8703036..b089bf3 100644 --- a/core/src/com/mygdx/game/World.java +++ b/core/src/com/mygdx/game/World.java @@ -6,7 +6,7 @@ import javafx.util.Pair; import java.util.HashMap; import java.util.Map; -public class World { +public class World implements Restrictions{ Map,Block> blocks; public World(HashMap, Block> blocks) { @@ -31,8 +31,11 @@ public class World { } public void fillWorld(){ - this.addTile(1,1,new Block("grass")); - this.addTile(0,0,new Block("grass")); + for(int x = -10; x< 10;x++){ + for(int y = -10; y<10;y++){ + this.addTile(x,y,new Block("grass")); + } + } + this.addTile(1,1 , new Block("wood")); } - } diff --git a/core/src/com/mygdx/game/WorldRenderer.java b/core/src/com/mygdx/game/WorldRenderer.java index 3337be0..a6182f7 100644 --- a/core/src/com/mygdx/game/WorldRenderer.java +++ b/core/src/com/mygdx/game/WorldRenderer.java @@ -1,42 +1,44 @@ package com.mygdx.game; import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector3; -public class WorldRenderer { - private Texture texture; +public class WorldRenderer implements Restrictions { + private Mouse mouse; private OrthographicCamera cam; private World world; private Player player; private InputController inputController; - public WorldRenderer(World world, Player player) { + public WorldRenderer(World world, Player player, Mouse mouse, OrthographicCamera cam) { this.player = player; this.world = world; - - cam = new OrthographicCamera(10, 7); - inputController = new InputController(cam); + this.mouse = mouse; + this.cam = cam; + inputController = new InputController(this.cam,this.player); } - public void render(Batch batch){ + public void render(SpriteBatch batch){ + drawWorld(batch, player); inputController.handleInput(); batch.setProjectionMatrix(cam.combined); - drawWorld(batch, player); cam.update(); + mouse.render(batch,cam); + player.render(batch); } private void drawWorld(Batch batch,Player player) { - for(int x = player.getX()-10; x