Game Logic

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

36 Replies - 5827 Views - Last Post: 09 January 2013 - 02:55 PM Rate Topic: -----

#1 Silver1992  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 13-August 12

Game Logic

Posted 22 December 2012 - 04:28 PM

Hey! I'm another one of those people who wants to make a game for "Insert random reason here" and I've run into some logic problems.

1) I've implemented a collision detection system that works. But I read somewhere here that Collision detection should not be used for game mechanics. To elaborate. I'm making a 2D game with a tile map system. Part of the map will consist of lets say water. One game mechanic is that the player can turn on a special ability that allows him/her to run ontop of water. This will drain a resource. But my question is how would you go around to implementing such a thing? Is that a collision detection mechanic or are we making our water some kind of entity?

2) I'm trying to figure out how to add stuff like stones/trees/water to my world. Should they just be simple tiles or should I add them as some kind of entity? I know its a very open question but every bloody tutorial you read suggest different methods of implementing everything.

3) Can anyone link me towards some tutorials on making a login system against a database?

4) How would one go around on implementing a small stat system. Lets say my player class should have a variable called "str" which is the strength. I also want it so that when I press A he is to attack and if there is a scarecrow infront of him then str should be incremented. In other words he gets stronger?

I'm aware some of these questions are bad. But I'm trying to get so much information its hard to know where to start. I'll do my best to answer any questions about my questions.

Is This A Good Question/Topic? 0
  • +

Replies To: Game Logic

#2 Silver1992  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 13-August 12

Re: Game Logic

Posted 22 December 2012 - 05:16 PM

Something to add towards question 2)

Should everything in-game be an entity? As in should I make all the tiles an entity? (As in the grass aswell?)
Was This Post Helpful? 0
  • +
  • -

#3 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Game Logic

Posted 22 December 2012 - 06:44 PM

Your questions show that you haven't thought through how you are going to represent the terrain. How are you going to do that?
Was This Post Helpful? 0
  • +
  • -

#4 Silver1992  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 13-August 12

Re: Game Logic

Posted 22 December 2012 - 07:32 PM

I think most of my ideas on how to represent the game world (terrain) are morphed tutorials.
Since I don't have a firm grasp on what an entity is just yet this idea might not work but going to see if I cant type it out.

For this little thought project our game map is 40 x 40 tiles. Each tile is 32x32 pixel.

The game map consist mainly of grass except for a small 4x4 lake in the middle.

If I understand it correctly I could just load the base terrain (As in the lower layer of tiles into an array. This array has no "Empty" values. Every tile is to be drawn) Then I could create 2 classes that inherits from my entity class. One called Grass (Which has the value CollideAble = false) and Water (Which for the purpose of this example has CollideAble = true) meaning our character cannot move on this tile.

Then I'll just loop through this array (And using some code/math I have yet to look into) draw each entity in its respective place.

The downside with this seems to be that I'll have shit-loads of objects of the type Grass which I cant see a point for. The upside seems to be that seeing how all of the game world is now an object of some kind I can easily alter it. Like have a collision-check on the grass with the player and if he has fire-boots on then grass should change graphics or whatnot.

And now if I wanted to draw trees or stones on-top of this. (Or spawn, power-ups, trigger tiles) then I'll just load another file into an array which allows 0 (Aka there is nothing special with this tile position) then draw this afterwards. That way it will come on-top of the prev tiles.

Not even sure if that answers your question. Is there something wrong with my logic here? Anything I should read up on or change?
Was This Post Helpful? 0
  • +
  • -

#5 BlueMelon  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 187
  • Joined: 27-April 10

Re: Game Logic

Posted 22 December 2012 - 08:54 PM

For this type of tile system I would have each type of tile have an ID, then create functions.
For example:
Map.onWater(x,y), Map.onWall(x,y)
player.onWater(), player.onWall()

All depends on how you create your system, its up to you.
In your movement system you would do a check
if player is on water -> Swim sprite?
if player is on water AND has active power up -> Walk sprite?

As for the trees and stones, they can be wall tiles (blocking tiles)

In one of my projects I had the following functions:
Map.tiletype(x,y) // 1- walk-able 2- swim 3- blocking
Map.onWater(x,y)
Map.onWall(x,y)

Thats just one of many ways to look at it.

3) What language?
4) Yes, your player could have a strength variable and it can increment when he kills/destroys whatever. Its up-to you.

This post has been edited by BlueMelon: 22 December 2012 - 08:54 PM

Was This Post Helpful? 0
  • +
  • -

#6 Silver1992  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 13-August 12

Re: Game Logic

Posted 23 December 2012 - 07:18 AM

3) C++

And thanks for the good reply. Got the feeling I'm just one minor step away from understanding it.

If I understand you correctly then I should create one object our of each tile type then redraw it where I need it? Then make myself a Map class that will handle all the drawing of the map + have the functions to test different x,y positions?
Was This Post Helpful? 0
  • +
  • -

#7 Silver1992  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 13-August 12

Re: Game Logic

Posted 23 December 2012 - 07:35 AM

3) C++

Thanks for a detailed reply. I don't understand everything yet but its somewhere to begin.

So the structure you are proposing is something like this. (This might be completely off but I have to start somewhere)

In this thought out project we have 3 Tiles we want to draw. 1 = Grass, 2 = Water and 3 = Stone (This will be drawn on-top of Grass. Might add another tile later that will simply be a stone but for this stone I want you to see what kind of tile is under)

So if I were to make a base class called "Tile" which would have some basic features like which Texture and what part of the image of the texture it should draw. (I have a Texture manager in my game and then you create an Image out of that texture)

Should I then at the base level add some kind of integer/bool value that will represent if the block is dense or? Also perhaps I should add some way for the Tile object to be aware of its own coordinates? (This would be for the future when I'm making more special Tiles like a spawn place or a trigger)

Then I make 3 classes that inherit from the Tile class. One Grass, Water and Stone.

Grass will inherit everything without changing anything.
Water will inherit everything and have the default constructor saying that it's dense
Stone will inherit everything and be dense.

But how would I go on from there? Do you perhaps have some example 2D game source I could look at?

Perhaps have a Map class which would handle the drawing of the map and then this class would have the functions you speak off? (I'm still reading through every article I can find on 2D games logic and dev.
Was This Post Helpful? 0
  • +
  • -

#8 BlueMelon  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 187
  • Joined: 27-April 10

Re: Game Logic

Posted 23 December 2012 - 08:31 AM

How do you want to load your map and render it? From a file?

Say we used 5x5 map in a .txt file
1 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1

If we took 1- Grass 2- Water 3- Stone
We would have some sort of field, with water in the middle and a stone in the middle of the water.

The way I would do it is to load the txt file into the map class. Then you would render it accordingly.
Lets say you went ahead with tile types, Map.tiletype(3,3) would return 3

There are other ways of doing it just lookup different tile engine source codes
Was This Post Helpful? 1
  • +
  • -

#9 Silver1992  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 13-August 12

Re: Game Logic

Posted 23 December 2012 - 08:35 AM

Yes. I'm loading from a file. But I don't understand when you say Tile types? Are you then referring to a function that finds the 3,3 position in an array and return the integer value that it holds?

Or are we talking about some Tile object I have to make?

P.S: I imagine trying to explain this is like teaching math to a 3 year old so I understand if you cant take the time man. You've already given me alot to start on.

This post has been edited by Silver1992: 23 December 2012 - 08:42 AM

Was This Post Helpful? 0
  • +
  • -

#10 BlueMelon  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 187
  • Joined: 27-April 10

Re: Game Logic

Posted 23 December 2012 - 08:50 AM

I don't see why you would create an object for each tile...
If you have a type of tile for each tile you are rendering (I took grass water stone as an example)

The same thing would be
1- Walk able 2- Swim 3- Blocking
Which you would then integrate into your movement system.

Coming back to your original question, no you don't need to create an "entity" for your water/trees/stones. Using tile types, you would just check to see if the player is standing over a specific tile, like water.
Was This Post Helpful? 1
  • +
  • -

#11 Silver1992  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 13-August 12

Re: Game Logic

Posted 23 December 2012 - 09:46 AM

Ok, let me rephrase it. You keep saying "Tile Type" What does that mean?
Was This Post Helpful? 0
  • +
  • -

#12 BlueMelon  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 187
  • Joined: 27-April 10

Re: Game Logic

Posted 23 December 2012 - 12:28 PM

View PostSilver1992, on 23 December 2012 - 04:46 PM, said:

Ok, let me rephrase it. You keep saying "Tile Type" What does that mean?


When I say tile type its simply the type of tile you are placing down. Is the tile walk able? Is the tile a water tile? Is it a wall tile? When your player is moving around, what type of tile is he standing on?
If he is standing on water (collides with a water tile) surely you want to display a swimming type animation? Maybe reduce the players speed? That's up-to you.
Was This Post Helpful? 0
  • +
  • -

#13 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Game Logic

Posted 23 December 2012 - 01:50 PM

I think that the missing word here is 'attribute'. This is just a specific field holding a value of some kind that would identify what the tile is.
Was This Post Helpful? 0
  • +
  • -

#14 Silver1992  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 13-August 12

Re: Game Logic

Posted 23 December 2012 - 01:52 PM

But how do I connect the correct attribute with the right tile?
Was This Post Helpful? 0
  • +
  • -

#15 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Game Logic

Posted 23 December 2012 - 01:59 PM

It was already explained here in the simplest terms possible.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3