Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map: Draw tile spritesheet onto window #15

Open
2 tasks
BlastWind opened this issue Oct 14, 2021 · 3 comments
Open
2 tasks

Map: Draw tile spritesheet onto window #15

BlastWind opened this issue Oct 14, 2021 · 3 comments
Assignees
Labels

Comments

@BlastWind
Copy link
Member

BlastWind commented Oct 14, 2021

Produce:

  • A class named MapLoader with the following methods
loadMap(filePath) 
draw(window) // note, we should draw map only once, might need a boolean flag  
  • Map data specification (I'll elaborate this below)

Links to #16

@BlastWind BlastWind added the code label Oct 16, 2021
@BlastWind BlastWind self-assigned this Oct 16, 2021
@BlastWind
Copy link
Member Author

BlastWind commented Oct 16, 2021

  1. Gonna self assign myself to this one. Harder than I think. Here's an example problem we need to consider:
  2. On map data specification
    If the background is completely tile based, here's one way to represent map data:
    demoLevel1Data.txt:
// 2D int array where each int maps to a specific asset
0 0 0 0 
0 1 2 0 
0 1 2 0 
0 1 1 0 

In the draw(window) function specified in the issue description, we specify which asset does each int map to:

switch(integerValue){
 case 0: 
  // dealing with dungeon wall 
  // so draw the damn dungeon wall 
 case 1: 
  // dealing with torches 
 case 2: 
 // dealing with statues
 ...
}

However, what if one asset spans longer than two tiles? What if we want to specify which way the asset is facing in the data? Then, a 2d int array might not suffice. However, we can probably still model the data with a 2d array, just not with a single integer.

Aside: We want to use the flyweight design pattern so that, for example, when we are rendering 100 dungeon basic floor tiles, they are pointing to (and not storing) the same asset in the spritesheet.

@BlastWind BlastWind added this to the Basic Framework milestone Oct 16, 2021
@BlastWind BlastWind changed the title Map Map: Draw tile spritesheet onto window Oct 16, 2021
@aaronamk
Copy link
Member

Very good article you have there, I like the flyweight idea.

@BlastWind
Copy link
Member Author

Splitting task into smaller tasks:

  • Create Base map class
  • Draw tile sprites onto screen using map class
  • Base sprite type enum
  • Set up observer system
  • Set up contact collision system (subclass of observer)
  • Draw tile sprites onto screen using a file with columns: |TILE|ID|x|y|layer|solid|
  • Implement collision behaver based on tile sprite solidness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants