GithubHelp home page GithubHelp logo

cytopiateam / cytopia Goto Github PK

View Code? Open in Web Editor NEW
1.9K 1.9K 100.0 144.18 MB

:deciduous_tree::house_with_garden::office::evergreen_tree: A city building simulation game

Home Page: https://www.cytopia.net

License: GNU General Public License v3.0

C++ 82.28% CMake 15.79% HTML 0.06% C 0.07% Shell 0.59% AngelScript 0.06% JavaScript 0.73% Python 0.41%
city-builder pixel-art sdl

cytopia's People

Contributors

9p4 avatar adct-the-experimenter avatar anotherfoxguy avatar bangboomboomboom avatar bitigchi avatar bogi79 avatar ceeac avatar comradekingu avatar dalerank avatar danielmowitz avatar dependabot[bot] avatar gamedev-mario avatar iaguozhi avatar kingtut10101 avatar kollix avatar lizzyd710 avatar mograbi avatar paragoumba avatar racerbg avatar renovate-bot avatar renovate[bot] avatar restyled-commits avatar restyled-io[bot] avatar rezaalmanda avatar simplyliz avatar syanush avatar tcoyvwac avatar transifex-integration[bot] avatar weblate avatar yukyduky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cytopia's Issues

[Feature] Rework event handling and support more mouse events

The event handling is fragmented now. There is the eventHandler class, which currently only handles mouse clicks for the UI and the old eventhandler code in game.cxx in the gameloop.

  • This needs to be reworked.
  • Mouse drag events are needed for terrain editing
  • Mouse over events are needed for showing tooltips in the UI.
  • Mouse over events can also be used for coloring the tile that's beneath the mouse when the game is in edit mode

Complex Resources Class

The Resources class has many responsibilities, maintains multiple global variables, and provides many different functions. It would be nice to refactor these into separate modules.

For example, there is no reason for convertIsoToScreenCoordinates to be a part of the Resources class. It can simply be a free function. The current design is much closer to Java than C++.

It also seems a little strange that zoom level, the SDL window, the camera offset, etc. are considered "resources". Typically, the resource system in a game engine has to do with the resources loaded from the file system (e.g., the 2D images for tiles).

I think the class should be split up into separate modules (not necessarily classes - free functions are appropriate here too) to simplify the design.

Add placement mode for zones

RCI Zones should be placable in rectangular zones.
When a tile is clicked and the mouse button is being held down, draw a rectangular zone to the end position when the mouse button is released.

The tiles in the zone should also be highlighted during the mousebutton held down event.

Add a splashscreen

Add "showSplashscreen" variable to settings and show a splashscreen when the image is done.

This need #51 as a prerequiste

[User Interface] Add function to draw a frame

Draw a rectangle with with a nice border (by drawing multime rects with offsets?)

The rectangle could either have a solid background (for a button menu) or have just the frame (to lay over other stuff like a solidrect (button without image))

Attributes:

  • Border color
  • Thickness

Improve the logging framework

The Log class is a little difficult for me to understand at first. Right now, the constructor creates a string stream and logs a timestamp and any additional information (e.g., ERROR), then the ostream operator outputs the message to the stringstream, then the destructor outputs the stringstream to std::cout.

This is pretty complex, and doesn't really fit idiomatic C++. I was thinking of one of two alternatives:

  1. SDL_Log - SDL2 already has facilities for logging. While they are not overly advanced, they are well-designed and consistent. You can override the output function of SDL_Log calls with SDL_LogSetOutputFunction, which would allow you to include the timestamp information that is currently shown in the log.

  2. Use a library - There are multiple libraries out there that can do logging. For example, spdlog's default output format is similar to the one currently in the engine. The format can be even further customized. It is much more advanced than SDL_Log, but would require us to introduce another dependency in the ThirdParty folder.

[User Interface] Implement button callback functions

Ui Elements should provide a registerCallbackFunction(std::function<void()) function.
This function should connect the cb function to a signal, that is emitted when the button is clicked.

It's enough to provide a mechanism for void() functions. If other function signatures are needed, it still can be expanded.

Change how isometric coordinates are calculated

Currently each of the elements are checked if the pixel color is transparent at the the clicked coordinates (with camera offsets and zoomlevel taken into account and if it's not, it's iso coordinates are returned.

It takes between 2 and 3 ms to calculate the isometric coordinates at a given screen coordinate this way and this is not viable. And certainly not for getting the current mouse over iso coordinates.

First attempt to improve performance.
Check all elements for SDL_PointInRect which should be way cheaper. If a collision occurs, check for pixel-alpha collision. If it's not the correct tile, use the next one in the list.

Further investiagtion showed that the performance penalty comes from iterating through all the tiles. Find a smarter way to do this.

Cannot open arcadeclassics font

The current engine crashes at runtime when trying to load a font. The resources/fonts directory contains a file named ARCADECLASSIC.TTF. Meanwhile, the uiElement class tries to load resources/fonts/arcadeclassics.ttf. Note the difference in case (one is ALL_CAPS) and the missing "s" before the extension.

The case should be the same to avoid issues with case-sensitive operating system. In addition, the filename should be fixed, though I'm not sure which one is correct (arcadeclassic vs arcadeclassics).

[User Interface] Add a settings menu dialog

Add a settings menu dialog.
The settings menu can be opened by a button in the game menu (reached by pressing the ESC key).

  • When the settings menu is opened, the game menu dialog should be closed.
  • When the settings menu is closed, the game menu should be displayed again.
  • Pressing ESC should close the menu that's currently opened. (or open the game menu)

Maybe an attribute for the parent - children relation should be added.

Modernize/Fix CMakelists.txt

The README states that CMake version 3.9 is required. However, the CMakelists.txt provided in the repo uses the very old (now discouraged) style for CMake. For example, the use of include_directories instead of target_include_directories.

There will also be issues with compiling on Windows because the find_package calls are confined only to Unix-based operating systems. Ideally, find_package should be used regardless of the operating system.

There are many blog posts online if you search "modern CMake". Here is one that is well done: https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/

[Feature] Procedural terrain generation

Implement procedural terrain generations.

Use https://github.com/utilForever/PolyMapGenerator library for that.

Considerations:

  • Height difference between two tiles must not be greater then one tile.
  • an option to define how high the map should be (huge mountains, flat valleys)
  • water - continent style, rivers, and so on
  • max height difference between lowest and highest (flat maps, mountains, ravines? take map size into account)

[User Interface] Add event handling functions to ui elements

Virtual functions for events should be provided by the UIElement base class, with a ref to SDL_Event as parameter:

  void onMouseButtonUp(const SDL_Event &event) override;
  void onMouseButtonDown(const SDL_Event &event) override;
  void onMouseEnter(const SDL_Event &event) override;
  void onMouseLeave(const SDL_Event &event) override;

Texture / Button states should be handled within these functions instead of an external function

[User Interface] Implement UI scaling factor

Add a scaling factor (1x, 1,5x, 2x, ...) for the UI to support different resolutions.

This scaling factor should be configurable in an ui dialog in settings.
The intension behind this is, so user could double / half the size of ui elements, in case someone wants a bigger / smaller ui.

This should be independent from the ui scale that is applied when resizing the game window

SDL2 Initialization Error

The current code for initializing SDL2 is incorrect:

  if ( SDL_Init(SDL_INIT_VIDEO != 0) )
  {
    LOG(LOG_ERROR) << "Failed to Init SDL\nSDL Error:" << SDL_GetError();
    return 0;
  }

I'm pretty sure you mean: if(SDL_Init(SDL_INIT_VIDEO) != 0). Note the bracket placement.

Change color of hovered tile when selection mode is active

Add a selection mode variable (bool). If its value is true, the tile beneath the mouse cursor should change it's color to something grey-ish.

Use SDL_SetTextureColorMod() to accomplish that.

As the rendering of each mapnode is handled in the sprite object, the coloring should go there too.
Add a function to tint the textures in the mapnode class, so it could be colored via the map class or the engine class.

Simplifying the Point class

Currently the Point class contains getters and setters for x, y, z, and height. However, it doesn't really do anything other than store data. This is fine - but it can be simplified into simply having all public data members to avoid code bloat. For example:

struct Point {
  int x;
  int y;
  int z;
  int height;
};

I have omitted the _ prefix since these are public data members, as opposed to private ones.

You can then ensure a Point object is not modified in a function by passing it with const. If the Point object is to be modified, then omit const.

Camera Panning

Move Camera in the MOUSE_MOTION event by applying the traversed x, y coordinates while holding down the right mouse button.

[Feature] Add "level terrain" feature

Add a feature that levels the terrain by clicking (and holding) at a tile to get the source height from the node where the mousebutton down event was triggered), and then drag the mouse over to elevate the terrain beneath the cursor to the source height.

This should not create a preview but instantly elevate the neighboring tiles.

Timer class should be updated from the event handling system

Instead of having a thread running in each timer, the timer should register itself with the EventManager class when it's constructed.

The EventManager class should have a container for timers, and update their time, if active, in each loop.

[Feature] Sprite animations

Implement sprite animations.

Suggestions:

  • Add a list of sprites for animations to resources/data/TileData.json
  • add a tileset with all animation sprites and specify the amount of animated sprites in the tileset to resources/data/TileData.json

Remove tag 0.1

There is tag v0.1.

Remove tag 0.1 or retag as v0.0.1.

[Feature] Allow variations of a tile ID

Add a variations key to the tileData Json file, where alternate images for the same tile ID can be specified.

When creating the terrain (floor tiles), use variations of the "ground" sprite (randomly pick one of the sprites from the variations list)

Store a pointer to neighboring tiles in mapNodes

Instead of providing a function to get a mapNodes neighbors in the map class, the (3x3) neighbors could be stored as pointers in the mapNode itself to avoid having to call the function every time neighbors need to be accessed.

It's probably not worth the effort performance wise, but it'd be cleaner this way and the responsiblity of tracking it's neighbors would go to the mapNode class.

Add Tile class

To manage tiles, a seperate class should be added.
A Mapcell can ask the Tile class, for a tile of type "terrain". The mapclass checks the elevation bitmask of the node and returns the correct texture.

[Style] Consistent styling with clang-format

It would be good to have a tool take care of different style-related things in the code, such as indentation and spacing. clang-format can do this, and you can create a configuration online or use an existing configuration (e.g., LLVM, Google, Chromium, Mozilla, Webkit).

Once a style is decided on, you can then apply it to a file manually or with a shortcut in your IDE. Alternatively, you can create a build target that formats all files at once.

Move settings into its own class

Move settings from the resources class into its own class.

The class should be responsible for

  • reading settings from the json file
  • writing settings into the json file
  • provide access to settings

Add a class that handles UI Layouting for the BuildMenu

Add a class for handling layouting. Maybe different classes for specific tasks.

We need a class, that layouts the menu bar. Following requirements:

  • a container to store UiElement* objects in. (std::vector?) elements should be ordered.
  • Set anchorpoint (top, left, right, bottom)
  • rearrange buttons by their size and padding
  • allow "subgroups" to be layouted too, (clicking a button expands it's submenu buttons)
  • submenu buttons should be restrictable to x elements. if there are more elements, show arrows at the sides to scroll through the elements

hxx extension causes cc1plus warnings

Compiling the application causes warnings for every header file with the extension .hxx. The warnings look like this:

cc1plus: warning: /home/badrmari/personal/software/IsometricEngine/src/engine/cell.hxx: not a directory

I am running Ubuntu 16.04 and using gcc version 6.4.0 with CLion 2018 v1.3 as my IDE.

Refactoring the header files to have a .hpp extension instead of .hxx takes care of the warnings. If you would like, I could submit a pull request with the change. If you agree with the change, you may also want to change cxx to cpp to be consistent, though gcc does not complain about the cxx extension.

[User Interface] Add a class for grouping Buttons

Add a container class for storing Buttons.

  • bool exclusive() - An exclusive button group allow only one button to be clicked at a time. If another button is checked, the other ones get disabled. (radio buttons). The group starts off with no buttons checked. Make sure to check one button you want as default option if this is desired.
  • bool menu() - Similar to exclusive(), only one button can be activated. The difference is, that it is allowed to have no checked button in the group. (Useful for the game menu) Only exclusive() OR menu() can be active at the same time.
  • addButton(UiElement*) / removeButton(UiElement*)
  • getButtons() - return all UiElements ( as a std::vector?)
  • The class should be have it's own signal/slot implementation that emits a pointer to the clicked button if the event is triggered. (For convenience, so there can be one slot function to handle a group of buttons). Consider using integer ids instead of the button pointer for signals, so buttons could be mapped to enums. Maybe both

Add tooltips to the UI

Show tooltips when hovering over a UI element that hast the attribute „Tooltip“ set in the UILayout JSON File.

Split vectormatrix into map class

vectorMatrix should be split into Map class and (if necessary) some template class or typedef for a container

Map class should handle all map related functions. (except procedural terrain generation, this should be handled in an own class)
This includes:
Point Engine::findCellAt(const Point &screenCoordinates)

Support tilemaps and further improve tile management

  • Loading the tiledata from JSON should be moved to the Tile class.
  • TextureManager should accept an ID and a filename to load / store the texture in a map
  • Tileclass should provide a struct with information in a map for each tile ID (Tile Image, Clipping rect, ..)
  • MapNode should access the corresponding tileInfo struct from Tileclass via it's id. (return a ref) including it's render options

Class design suggestion:

image

JSON Structure suggestion:

  {
    "id": "terrain",
    "type": "ground",
    "tiles": {
      "tilemap": "resources/images/terrain/terrain_tiles.png",
      "count": 3,
      "clip_width": 32,
      "clip_height": 16
    },
    "cornerTiles": {
      "tilemap": "resources/images/terrain/terrain_slopes.png",
      "count": 13,
      "clip_width": 32,
      "clip_height": 32
    },
    "title": "Terrain",
    "description": "Terrain tiles",
    "price": 0,
    "upkeep cost": 0,
    "power": 0,
    "water": 0,
    "author": "Kingtut 101",
    "draw ground": false
  }

[User Interface] Make user interface colors configurable

The colors (active / hovered / isclicked) used for drawing certain ui shapes (like frame / button) should be configurable.

Either make that configurable in the UiLayout json per element (and use default values if no values are supplied) or a global setting for UI colors

Texture handling refactoring

TextureManager:

  • Add a struct that contains both SDL_Texture* and SDL_Surface.
  • Change the std::maps to contain the struct instead of keeping them in seperate maps
  • Split the maps to contain textures for each TileMap type instead of having two nested maps with an enum as accessor

[Feature] Map rotation

Implement map rotation.

The mapnode matrix should be rotated in 4 positions (by 90° only).

We need to rotate the iso coordinates of the mapnodes (draw the nodes to another destionation), + the nodes it self (drawing order) and then probably run updateTextures to recalculate the destRect where the nodes are drawn

I've started to work on this at this branch:
https://github.com/JimmySnails/IsometricEngine/tree/rotateMap

My approach was to rotate the whole map cell matrix, which didn't turn out the way it should have.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.