Jump to content
  • Advertisement

imontheverge

Member
  • Content Count

    13
  • Joined

  • Last visited

Community Reputation

168 Neutral

About imontheverge

  • Rank
    Member

Personal Information

  • Interests
    Art
  1. Im trying to create a simple " give order to Sprite, make Sprite do thing" game much like rimworld or oxygen not included. So far I have two controllers type objects, on for the player and one for each Sprite. When a Sprite is selected, the player controller takes a reference of the Sprite and sets a Boolean variable hasMoveOrder to true when the player clicks on a spot. My code right now is filled with if/else statements in order to get this to work. Once I add more work orders like digging, building, etc, a thousand if statements starts to get sloppy. The question is what kind of data structure or algorithms can I use to make this more efficient? Would an enumeration of the Sprite states be fine and just switch through them when the Sprite gets a new work order? Or would something more complex like a state machine make sense?
  2. I've never heard of catmull rom but it looks like what I need! Thanks :)
  3. Nope but that's a favorite of mine! It's an older series.
  4. To start off, the reason I'm creating this journal is because this will be my first "complete" game I've made. Years ago I made a shell of a survival game in XNA and that was the closest I ever got to a finished project. My goal for this post and future posts is to hopefully share some knowledge about LibGDX and get feedback about terrible my programming practices :P Lets jump right into it! The premise of this game is pretty simple. You play as some dude whose image is based off of a character in one of my favorite books. +10 to anyone who can guess which book. There really isn't a story yet, although the goal of the game is to journey through 7 dungeons, or the 7 layers of hell, defeat the bosses, and then kill satan possibly? I haven't thought of an ending yet. When you first start off in the town area, youll notice all the NPCs are ghosts and you can't interact with them, the exception being a single priest in the giant tower. As you finish each dungeon, more and more NPCs return to their original form. Although this sounds fairly linear, I'm trying to move away from it by incorporating a "purgatory" system when the player dies. Instead of a game over, the player is sent to purgatory where he has the option to descend the layers of hell with the current skills available, or return to the surface via rising from a grave to acquire better skills and potions. Weapon and armor equips won't be a part of the game at this point. I have much love for the way the Witcher 3 handles their potion system, so I'm using inspiration from that to make the player stronger. As the player defeats monsters, items will be picked up. At the end of the day you have an option to make camp and create and consume up to 2 or 3 potions which buff you for the whole day afterwards. Obviously a lot of this hasn't been implemented yet, but it's nice to have goals to work on. The title of the post says two months worth of development, it may be more like 4 or 5. It's only been 2 months since I've put my project onto Github. I was wanting to start a journal earlier, but the artwork was so terrible that I felt too ashamed to share it. Look at these awesome slimes! So far my biggest struggle is moving forward has been the artwork. I am by no means a good artist, and to make things worse I chose to use pixel style art. But I've limited myself to a maximum of 2 hours a day working on the art so I don't get frustrated and give up. The world feels bland and boring without trees and bushes, so wandering around at this point is useless. The map at this point right now is huge, maybe too huge. You can see the areas I've outlined as different biomes and areas for the dungeons. My greatest challenge I feel will be to make this world feel alive and vibrant. Now on to code things. I've used LibGDX before for smaller projects like your basic pong and breakout clones, but this is the first time I've delved so far into the library. Right now I have something like 15 enemies planned for the world, and I use a class called EnemyFactory for creation. public Enemy createEnemy(EnemyType type, Vector2 position){ Enemy enemy = null; String id; switch (type){ case SLIME: id = "slime" + idNumber; enemy = new Enemy(position, id); enemy.isEnemy = true; enemy.sprite = new Sprite(new Texture("slime.png")); enemy.createBody(position, enemy.sprite.getTexture()); enemy.health = 10; enemy.enemyType = EnemyType.SLIME; enemy.itemToDrop = Item.SLIME_GOO; enemy.attackCount = 0; enemy.attackTimer = 0.2f; Eventually this will be put into a json or xml file, but I don't know anything about those languages yet so this works for now. Enemies are spawned using tiled map objects like so:for(MapObject object : tiledMap.getLayers().get("SpawnLayer").getObjects().getByType(RectangleMapObject.class)){ Rectangle rect = ((RectangleMapObject)object).getRectangle(); if(object.getProperties().containsKey("slime")){ mapEntities.add(MainGame.enemyFactory.createEnemy(Enemy.EnemyType.SLIME, new Vector2(rect.getX() / MainGame.PPM, rect.getY() / MainGame.PPM))); } This was one of my biggest reasons for using LibGDX. Using tiled map data has made things like teleporting to different maps and spawning enemies so much easier. Another reason for using this library is Box2D. I hate math and hard-coding values for collisions, so Box2D was a godsend for what I needed. In LibGDX you have a class called ContactListener which handles all collisions in your world. public void beginContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); Player player; Entity entity; Projectile projectile; if(fixtureA == null || fixtureB == null)return; if(fixtureA.getBody().getUserData() == null || fixtureB.getBody().getUserData() == null)return; if(isProjectileHitEnemy(fixtureA, fixtureB)){ entity = fixtureB.getBody().getUserData() instanceof Entity ? (Enemy)fixtureB.getBody().getUserData() : (Enemy)fixtureA.getBody().getUserData(); projectile = fixtureA.getBody().getUserData().equals(Statics.PLAYER_PROJECTILE) ? (Projectile)fixtureA.getUserData() : (Projectile)fixtureB.getUserData(); subject.notify(projectile, entity, Event.ENEMY_DAMAGE);// projectile.isActive = false; System.out.println("PROJECTILE HIT ENEMY"); } This is nice because it allows you to use the user data from a Box2D body to see what is hitting what. A day/night cycle has been implemented as well. Box2DLights is another great option that LibGDX offers. With dynamic hard and soft shadows, you really can't go wrong with it. public void updateLight(DayNightCycle dayNightCycle, Camera camera){ if(dayNightCycle.getHours() == 6){ ambientB = 0.3f; ambientR = 0.8f; ambientG = 0.35f; } if(dayNightCycle.getHours() == 7){ ambientG = 0.65f; ambientR = 0.9f; ambientB = 0.01f; } if(dayNightCycle.getHours() == 8){ ambientB = 1; ambientG = 1; ambientR = 1; } if(dayNightCycle.getHours() == 17){ ambientR = 1; ambientG = 0.8f; ambientB = 0; } if(dayNightCycle.getHours() == 19){ ambientR = 1; ambientG = 0.5f; ambientB = 0; } if(dayNightCycle.getHours() == 20){ ambientR = 1; ambientB = 0.3f; ambientG = 0.3f; } if(dayNightCycle.getHours() == 21){ ambientG = 0.2f; ambientB = 0.7f; ambientR = 0.3f; } if(dayNightCycle.getHours() == 22){ ambientR = 0.2f; ambientG = 0.15f; ambientB = 0.4f; ambientA = 0.3f; } rayHandler.setAmbientLight(ambientR, ambientG, ambientB, ambientA); playerLight.setPosition(MainGame.player.sprite.getX(), MainGame.player.sprite.getY()); rayHandler.setCombinedMatrix(camera.combined); rayHandler.updateAndRender(); } Holy if statements! Maybe one day I'll figure out how to make a smooth transition from daylight to darkness, but it is not this day. There really isn't anything more to Box2DLights than the initialization of the light and the update method! How great is that? Here are a couple of gifs of the lighting and combat system in action: http://imgur.com/unkOjMK http://imgur.com/QIqmgax I'll try to make more frequent posts as I implement more of my ideas into this project, and hopefully with better artwork so there's something nice to look at. Feel free to give advice or ask questions! I feel like a have a decent understanding of LibGDX at this point and I highly recommend it to anyone who wants to make a game in Java :)
  5. imontheverge

    Create random biome shape

    I want to create a random polygon shape for my biomes in a tile map. The tile map is created using perlin noise, so on top of that I want maybe two or three polygons which I can use to set the tiles of the map to the correct biome. Has someone come up with a way to make a 4 sided random polygon in monogame? Or is there maybe a better way to create random biomes using colors in the person noise?
  6. imontheverge

    Collision Detection error

    Collision Rectangle is just a rectangle with a getter method public Rectangle CollisionRectangle { get { return new Rectangle( (int)g_WorldPosition.X, (int)g_WorldPosition.Y, g_Texture.Width, g_Texture.Height); } } unless I'm using it wrong? I'll put it in the update method and see if that changes anything
  7. imontheverge

    Collision Detection error

    I have a list of game objects I'm trying to check collision against. I've used the Debug class to write to the console and it seems that i'm getting a collision where there is none. private bool Intersects(Rectangle player, Rectangle other, CollisionDirection direction, out Vector2 depth) { if (direction == CollisionDirection.Vertical) { depth = new Vector2(0, GetVerticalIntersectionDepth(player, other)); } else depth = new Vector2(GetHorizontalIntersectionDepth(player, other)); return depth.Y != 0 || depth.X != 0; } public float GetHorizontalIntersectionDepth(Rectangle rectA, Rectangle rectB) { float halfWidthA = rectA.Width / 2; float halfWidthB = rectB.Width / 2; float centerA = rectA.Left + halfWidthA; float centerB = rectB.Left + halfWidthB; float distanceX = centerA - centerB; float minDistanceX = halfWidthA + halfWidthB; if (Math.Abs(distanceX) >= minDistanceX) return 0; return distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX; } public float GetVerticalIntersectionDepth(Rectangle rectA, Rectangle rectB) { float halfWidthA = rectA.Height / 2; float halfWidthB = rectB.Height / 2; float centerA = rectA.Top + halfWidthA; float centerB = rectB.Top + halfWidthB; float distanceX = centerA - centerB; float minDistanceX = halfWidthA + halfWidthB; if (Math.Abs(distanceX) >= minDistanceX) return 0; return distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX; } private void CheckCollisions(CollisionDirection direction, List<GameObject> objects) { foreach(GameObject obj in objects) { Vector2 depth; if(Intersects(CollisionRectangle, obj.g_CollisionRectangle, direction, out depth)) { g_WorldPosition += depth; Debug.WriteLine("true"); if (direction == CollisionDirection.Horizontal) g_Velocity.Y = 0; else g_Velocity.X = 0; } } } And in my update method. .... if(ks.IsKeyDown(Keys.S)) { g_WorldPosition.Y += 10f; playerFacing = Direction.DOWN; CheckCollisions(CollisionDirection.Vertical, objectList); } if(ks.IsKeyDown(Keys.A)) { g_WorldPosition.X -= 10f; playerFacing = Direction.LEFT; CheckCollisions(CollisionDirection.Horizontal, objectList); } ... In the CheckCollision method the Debug line is writing true to the output even when i'm not colliding with anything. I know the g_CollisionRectangle is being set correctly because I have lines being drawn around the outside of each collidable object. What happens is my player kinda moves sporadically because I'm getting collisions in places where I shouldnt. Can anyone see where I'm going wrong here? I realize that g_Velocity is not being used in my update method, but I don't think that it should effect what is happening at this point. From what I can tell, my GetVertical and GetHorizontal methods are wrong somewhere because of the Debug line in the CheckCollision method.
  8. imontheverge

    Tilemap Chunk Generation

    So say I set the coordinate to the center of the chunk, being chunkwidth *tilewidth /2 and chunkheight *tileheight /2. Then in the hashtable, I check which chunk the player is in and then using an offset I check if the chunk has loaded chunks on the side and if not I load them. Maybe this would work?
  9. I have a class TileChunk which at it's most basic contains a rectangle that surrounds the chunk, and four bools isLeftLoaded, isTopLoaded, etc. Using the rectangle I can determine which chunk the player is in. What I want to do is create some kind of method which checks the current chunk the player is in, and if nothing is loaded then create new chunks that surround the sides that haven't been loaded. The problem I'm coming across is that using the four bool variables doesn't seem to work correctly. At initialization, I create 9 chunks to make a 3x3 starting area but some of the bool variables aren't being set correctly. My question is how should I write a method which determines what chunks have loaded chunks adjacent to them? Every chunk is stored in a List, but other than using the bool variables I'm not sure what is the best way to do this.
  10. imontheverge

    Updating game world every new day

    Im gonna guess a global would be kinda like a static variable in Java? But I get what you're saying. Also I do have several listener classes since I'm trying the entity component design so I figure that would make the most sense to fit my game.
  11. Im looking to create a class that will update things like quests after my character sleeps or a new day has started. I currently have a single class that updates my game clock and current day. My first idea was to create a class that will run an update quest method every time a new day has started, in other words after the clock hits midnight. I think this may work but I am curious as to how other people have gone about this?
  12. imontheverge

    box2d pixels per meter scaling

    You're completely correct. Now I need to figure out how to get the values from setScale.   Edit: Never mind, figured it out. Had to multiply by the conversion 0.01f and divide by 2.
  13. imontheverge

    box2d pixels per meter scaling

    When I tried scaling before, I had an issue with the sprite texture ending up too big. I couldn't get it to scale down to the size I wanted either. I hadn't considered this but would a 54x74 size texture cause some issues? I don't really know why I didnt use 64x64 or something like that but now that I think about it, that may have something to do with my sprite scaling problems.   Edit: So what I have so far is this: camera = new OrthographicCamera(); viewport = new FitViewport(5, 9, camera); viewport.apply(); camera.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2, 0); player = new Sprite(img); player.setPosition(viewport.getScreenWidth() / 2, viewport.getScreenHeight() / 2); player.setOrigin(img.getWidth() / 2, img.getHeight() / 2); player.setScale(1/100f); Is this going to give me the correct result? Whenever I set my box2d shape to the sprite, it's way too big. This line gives me the issue square.setAsBox(player.getWidth() / 2, player.getHeight() / 2);
  14. I've been having a hard time figuring out how the whole box2d pixels to meter thing works.  I've read a bunch of things on google trying to understand the logic behind this, but I just can't grasp it :P here is the code right now. SpriteBatch batch; Texture img; Sprite player; Body playerBody; OrthographicCamera camera; int FRUSTUM_WIDTH = 500; // 5 blocks 100 pixels wide int FRUSTUM_HEIGHT = 900; int PIXELS_TO_METERS = 100; World world; Box2DDebugRenderer debugRenderer; @Override public void create () { batch = new SpriteBatch(); img = new Texture("player.png"); player = new Sprite(img); player.setPosition(220 * PIXELS_TO_METERS, 300 * PIXELS_TO_METERS); player.setOrigin(img.getWidth() / 2, img.getHeight() / 2); camera = new OrthographicCamera(FRUSTUM_WIDTH, FRUSTUM_HEIGHT); camera.position.set(FRUSTUM_WIDTH / 2, FRUSTUM_HEIGHT / 2, 0); world = new World(new Vector2(0, -98), true); debugRenderer = new Box2DDebugRenderer(); setUpBox2D(); } private void setUpBox2D() { BodyDef bodyDef1 = new BodyDef(); bodyDef1.type = BodyDef.BodyType.DynamicBody; bodyDef1.position.set((player.getX() + player.getWidth() / 2) / PIXELS_TO_METERS, (player.getY() + player.getHeight() / 2) / PIXELS_TO_METERS); playerBody = world.createBody(bodyDef1); PolygonShape square = new PolygonShape(); square.setAsBox(player.getWidth() / 2, player.getHeight() / 2); FixtureDef fixtureDef1 = new FixtureDef(); fixtureDef1.shape = square; fixtureDef1.density = 0.1f; fixtureDef1.friction = 1f; fixtureDef1.restitution = 0f; Fixture fixture1 = playerBody.createFixture(fixtureDef1); BodyDef groundBodyDef = new BodyDef(); groundBodyDef.type = BodyDef.BodyType.KinematicBody; groundBodyDef.position.set(new Vector2(0, 100)); Body groundBody = world.createBody(groundBodyDef); PolygonShape groundBox = new PolygonShape(); groundBox.setAsBox(camera.viewportWidth, 1.0f); groundBody.createFixture(groundBox, 0); } @Override public void render () { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); drawScene(); updateScene(); } private void drawScene() { debugRenderer.render(world, camera.combined); camera.update(); batch.setProjectionMatrix(camera.combined); batch.begin(); player.draw(batch); batch.end(); world.step(1/60f, 6, 2); } private void updateScene() { if(Gdx.input.isKeyPressed(Input.Keys.LEFT)) { playerBody.setLinearVelocity(-100, 0); } if(Gdx.input.isKeyPressed(Input.Keys.RIGHT)) { playerBody.setLinearVelocity(100, 0); } player.setPosition(playerBody.getPosition().x, playerBody.getPosition().y); } Before I go any further with the program, I am wondering if I am doing this the right way?    
  15. imontheverge

    specific set of tutorials c++

    Perfect :D also it doesnt have to be SDL. Any other recommendations are appreciated
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!