Jump to content
  • Advertisement

Flandria4

Member
  • Content Count

    16
  • Joined

  • Last visited

Everything posted by Flandria4

  1. Hello!   I want to make a basic 2D map editor like this:   I can currently load images to a position on the canvas, without making use of any form of grid. At first I was looking to create a dynamic grid with variable amount rows/columns and bind the position (index) of each sprite to a grid column/row but I quickly figured that isn't what a grid is meant to do.   After looking further into this my best bet is to use a datagrid and I'm now wondering if this the best fit for the job, whether it will work and how to do this with a MVVM approach.   I want to dynamically set the size of each 'cell' (32x32, 64x64) at runtime (or maybe just for a new project) I want every sprite to have a (bound) grid position. I want to zoom in/out on the grid. I want an overview of my loaded sprites in a container such as in the above example 'terrains'. I want to draw with these terrains on a visible (solid..) line grid, with every sprite snapping into place. I want to drag and drop (move) sprites within the datagrid and spawn click the selected sprite from the 'spritecontainer'. I want a undo/redo option.   Is this all possible with a datagrid? Is a datagrid the way to go or are there better ways? How long will this take me? Are some points too ambitious? How should I approach this?     Thanks in advance!        
  2. Flandria4

    WPF - Presenting 2D sprites (2D map editor)

    Allright!!   This: <ItemsControl.ItemTemplate> <DataTemplate> <Image Source="{Binding MapTileImage}" Stretch="Fill" Width="{Binding Width}" Height="{Binding Height}"> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseEnter"> <command:EventToCommand Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ChangeTilesCommand}" CommandParameter="{Binding .}" /> </i:EventTrigger> <i:EventTrigger EventName="MouseLeftButtonDown"> <command:EventToCommand Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.DrawingCommand}" PassEventArgsToCommand="True"/> <command:EventToCommand Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ChangeTilesCommand}" CommandParameter="{Binding .}"/> </i:EventTrigger> <i:EventTrigger EventName="MouseLeftButtonUp"> <command:EventToCommand Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.DrawingCommand}" PassEventArgsToCommand="True"/> </i:EventTrigger> </i:Interaction.Triggers> </Image> </DataTemplate> </ItemsControl.ItemTemplate> in combination with: private RelayCommand<BitmapModel> _changeTileCommand; public RelayCommand<BitmapModel> ChangeTilesCommand { get { return _changeTileCommand ?? (_changeTileCommand = new RelayCommand<BitmapModel>(UpdateTile, CanDraw)); } } private RelayCommand<MouseEventArgs> _drawingCommand; public RelayCommand<MouseEventArgs> DrawingCommand { get { return _drawingCommand ?? (_drawingCommand = new RelayCommand<MouseEventArgs>(MouseDown)); } } void MouseDown(MouseEventArgs mouse) { if (mouse.LeftButton == MouseButtonState.Pressed) _mouseDown = true; else if (mouse.LeftButton == MouseButtonState.Released) _mouseDown = false; } bool CanDraw(BitmapModel tile) { return _mouseDown; } Made it work! Thanks for your input!       Additional info: "MouseDown" and other events didn't work because of my Image.InputBinding I figured, had to get rid of it. Working with MouseEventArgs did the trick.
  3. Flandria4

    WPF - Presenting 2D sprites (2D map editor)

    Thanks for checking in on me!       Made quite some progress in the meantime, however, I just hit another speed bump and have been spending most of my day on it.   As visible in the screenshot, I manage to draw on the canvas with my mouse but either only through single clicks (tedious) or with a MouseEnter event (drawing always on..)   Neither are what I wished for and I tried to work with a MouseDown event, which doesn't work. After some research I figured PreviewMouseDown should do the trick where MouseDown doesn't, but this doesn't work as well.   How can I make 'click dragging' work to paint with tiles?   This is my xaml part: <DataTemplate> <Image Source="{Binding MapTileImage}" Stretch="Fill" Width="{Binding Width}" Height="{Binding Height}"> <Image.InputBindings> <MouseBinding MouseAction="LeftClick" Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ChangeTilesCommand}" CommandParameter="{Binding .}"/> </Image.InputBindings> <i:Interaction.Triggers> <i:EventTrigger EventName="MouseEnter"> <command:EventToCommand Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ChangeTilesCommand}" CommandParameter="{Binding .}" /> </i:EventTrigger> </i:Interaction.Triggers> </Image> </DataTemplate> And in MainViewModel private RelayCommand<BitmapModel> _changeTileCommand; public RelayCommand<BitmapModel> ChangeTilesCommand { get { return _changeTileCommand ?? (_changeTileCommand = new RelayCommand<BitmapModel>(UpdateTile)); } } with void UpdateTile(BitmapModel tile) { if (tile == null) return; if (SelectedMapTile == null) return; tile.MapTileImage = SelectedMapTile.MapTileImage; } Of course, the MouseAction is redundant with the introduction of Event "MouseEnter", but MouseEnter works regardless of the button state, which is my problem. No other event seems to work from MSDN. What can I do?
  4. Flandria4

    WPF - Presenting 2D sprites (2D map editor)

    I've incorporated some of your code into my application:       I create a grid of 8x8 with the first sprite extracted from a spritesheet. The UniformGrid just scales as it wishes   Edit: Since I initialized the entire grid anyway, I just added positions to the tiles and threw them in a canvas under scrollview. Works splendid!
  5. Flandria4

    WPF - Presenting 2D sprites (2D map editor)

    Digging further into this, it seems like a UniformGrid (kinda like a datagrid) only shows populated cells.   My issue is that cells are empty until filled. I need to find some way to bind (spawn) items to existing visible empty row/columns.
  6. Flandria4

    WPF - Presenting 2D sprites (2D map editor)

    I think UniformGrid is what I was looking for, thanks!
  7. Flandria4

    WPF - Presenting 2D sprites (2D map editor)

    Digging a bit deeper into this, it looks like a datagrid can't be an empty grid and is solely used for displaying existing data.     How should I create a grid, ready for displaying images at a certain index?
  8. Flandria4

    WPF - Presenting 2D sprites (2D map editor)

    Yes indeed, I know, I was using Tiled as reference here :)   I'm doing this is purely for learning purposes.
  9. Hello     I have similar / follow up question from this topic: http://www.gamedev.net/topic/666703-how-to-use-geometry-shader-instances-to-divide-the-output-data/     Currently I'm subdividing a regular plane into smaller quads to create a rectangular footprint for small cubes. This is done successfully in the geometry shader. However, when I want to add the the other faces of the cube I'm going over the maxvertexcount (100). This limits me to only a few subdivisions of a regular plane with a maximum of 2 cubes per triangle.   Here is the result of 4 subdivisions of the ground triangles, outputting 64 vertices on its own:   [attachment=27254:pipeline.png]     I've read in the post linked above that subdividing a mesh should be done in the tessellation shader but I'm not familiar with this and don't know how to approach it. The msdn page leaves me no wiser: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476340%28v=vs.85%29.aspx   If I manage to initialize the tessellator stage, can/ should I reuse my code? How do I get a similar result as I currently have with the GS? Do I need a Hull / Domain shader? How do I pass this data to the GS? I'm kinda puzzled here :s       My code: http://pastebin.com/HzYPMWUY
  10. I ended up doing it the easy way. Since I already had the code to create cubes I decided to stick with it and only generate 4 cubes for each triangle. To solve the division problem I just went into 3ds max and made another plane with more divisions. Problem (kinda :)) solved!
  11. Thanks for your input unbird!   You've convinced me the vertex shader might be the way to go. I used the GS because it was pretty straight forward getting fed triangle per triangle, however, In the vertex shader there is no coherence between separate vertices and neither something like a totalVertices counter to deduce anything from. I've looked a bit around on the SV_VertexID and as far as figured out this is an counter which increments each execution and resets on Draw(). I kinda fail to see how this could be of any use in my occasion :s. Also, as far as I know, you can only transform vertices in the vertex shader, not add them. How would you propose I tackle this in the VS?
  12. Hey   I'm making a brute force string / (password, if you want to) cracker for fun/learning purposes. To keep things short and interesting I tried my own way of implementing it, but little luck so far.   The code works as follows: Enter a string in console. The code starts in a 'while' loop and iterates over a given string with unique characters, generating different combinations up to 8 characters long.   For example:   string = ""0123456789abcdefghijklmnopqrstuvwxyz" Counter 1: result 0 Counter 10: result 9 Counter 36: result z Counter 37: result 00 Counter 38: result 01 Counter 100: result  1u = 1 + u = (35 * 2 = 1.) + (30 = u) Counter  1296: result  zz  Counter  1297: result  000   string: "abc" Counter  14256 gives a00 (pos 11 * 36 * 36) 0 for illustration purposes as placeholder Counter  432     gives b0 Counter  13       gives c -> "abc" = 14701   I may have made mistakes here but hopefully this makes sense.     Now for the part where it goes wrong and need your help:   My code SKIPS the entire leading 0's part, it goes from (counter/result) 36/z to 37/10 (instead of 37/00) and continues normally 38/11 until 1296/zz. This is where the second and final bug comes in, something similar as before. Next counter skips leading 0 again (like 000) and does this instead: 1297/100 then goes like 1298/111 1299/122 up to 1332/1zz, gives 1332/100 and 1334/111 one more time before giving up on me and trowing a debug assertion failure. For clarity, what should happen is 1297/000, 1298/001, 1299/002, etc.. YES, I've spend a lot of time trying different things, adding magic numbers, removing equal signs, adding modulo's and other useless things resulting in shifting or mutation of the problem.   My code probably says more than my rambling, so without further ado: #include <iostream> #include <string> #include <ctime> const std::string BruteForce(const std::string strPassword, int &intTries){     const std::string         strNumbers = "0123456789",         strLetters = "abcdefghijklmnopqrstuvwxyz",         strLettersU = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",         strIncChar = strNumbers + strLetters; //included characters, bool based (later)     const int MAX_LENGTH = (int)strIncChar.length();          std::string strTest;     int intLength = 0, intRemainder = 0;     if (strPassword.length() > 8) return "Password too long, max 8 characters"; //passwords are max 8 characters     while (strTest != strPassword){             intLength = 0;             intRemainder = intTries;             while (intRemainder >= MAX_LENGTH){                 intRemainder = intRemainder / MAX_LENGTH;                 ++intLength; //determine current length password             }             strTest = strIncChar[intRemainder % MAX_LENGTH]; //set first part 14256    a00 (pos 11 * 36 * 36)             for (int i = 0; i < intLength; ++i) {                 intRemainder = (intTries - ((intRemainder) * std::pow(MAX_LENGTH, intLength - i))); //password abc = 14701 minus first part 14256 = a00 (pos 11 * 36 * 36) OR (pos 11 * 36^2)                 strTest += strIncChar[intRemainder % MAX_LENGTH];             }                                      std::cout << ++intTries << ": " << strTest << "\n";     }          return strTest; } int main(){     std::string strPassword;     do {         int intTries = 0;         std::clock_t tStart = clock(), tEnd;         std::cout << "Enter string:" << std::endl;         std::cin >> strPassword;         std::cout << "\nResult: " << BruteForce(strPassword, intTries) << std::endl;         tEnd = clock();         double tTaken = static_cast<double>(tEnd - tStart) / CLOCKS_PER_SEC;         std::cout << "Time: " << tTaken << " ms" << "        Combinations: " << intTries << "\n\n";     } while (std::getline(std::cin, strPassword));     return 0; } I really hope my approach and/or coding style doesn't throw you off, I never had feedback on my code before and I'm not really experienced.   Thanks in advance!
  13. Hey   I'm experimenting a bit and was wondering if it is possible to make (something alike) a method/function that accepts derived classes as argument instead of a base class.   To illustrate my (poorly worded?) question:     I have 2 base classes: Items.cpp and Enemies.cpp. Both have several derived classes.   I have made a DeleteAll() method with several overloads as following: void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Box* boxPtr[]); void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Coin* coinPtr[]); void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Diamond* diamondPtr[]); void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Heart* heartPtr[]); void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Unit1* unit1Ptr[]); void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Unit2* unit2Ptr[]); void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Frog* frogPtr[]); But this doesn't feel like it's the correct way.  I only have to execute for (int i = 0; i < arrLength; i++){ if(itemPtr[i]!=nullptr){ delete itemPtr[i]; itemPtr[i] = nullptr; } if(hitRegion[i]!=nullptr){ delete hitRegion[i]; hitRegion[i] = nullptr; } } every method and I could just copy this for every derived class in one big method without arguments that takes care of all of it.   But still, I love experimenting and I'm wondering if it would it be possible to do something like: void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Items* itemPtr[]); void DeleteAll(static const int arrLength, HitRegion *hitRegion[], Enemies* ememyPtr[]); and put the derived classes instead of the base class as argument, like this: DeleteAll(ITEMS_BOX, m_HitBoxPtr, m_BoxPtr); I know it doesn't work like this, but is there an alternate/similar/professional approach? I'm just trying to improve my coding skills. I'm sorry if this is a weird question, I couldn't find anything on this on the interwebz.     Thanks in advance!
  14. I didn't know about templates before, thank you! Also, I just learned about vectors a week ago, I'll use those for my next project. Way better than arrays.   About the pointers, how can my separate class not be a pointer/object?
  15. Flandria4

    Basic console project

    Thanks for your replies,   The cin >> get1 operation waits on an input and puts the entered number in get1 and checks if the operation was valid.   The problem was indeed that after entering an non integral number this code did not jump back to the "else"  but it waits on  cin >> get1 (again!) before concluding the statement is false anyway, because get1==0 is should be false at this point.   The solution is: do { if(get1==0){ cout << "Enter first operand (integer): >"; if (!(cin >> get1)) { cout << "Did you even try?" << endl; cin.clear(); cin.ignore(1000, '\n'); } } else { if(get2==0)cout << "Enter second operand (integer): >"; if (!(cin >> get2)){ cout << "Cmon! You can do it!" << endl; cin.clear(); cin.ignore(1000, '\n'); } else cout << "Good boy! Press ENTER to continue" << endl; } } while (get1==0 || get2==0);   Thanks a lot!
  16. Flandria4

    Basic console project

    Hey   I'm trying to make a simple calculator, at this point I can't even get the input right. I know my code is kinda ugly but afaik it should work. int _tmain(int argc, _TCHAR* argv[]) { int get1=0, get2=0; cout << "Binary operation" << endl; //cin.get(); do { if(get1==0)cout << "Enter first operand (integer): >"; if (!(cin >> get1) && get1==0) { cout << "Did you even try?" << endl; cin.clear(); cin.ignore(1000, '\n'); } else { if(get2==0)cout << "Enter second operand (integer): >"; if (!(cin >> get2)){ cout << "Cmon! You can do it!" << endl; cin.clear(); cin.ignore(1000, '\n'); } else cout << "Good boy! Press ENTER to continue" << endl; } } while (get1==0 || get2==0); return 0; } This is how the console responds:    Why do I get an blanc line on the end instead of the line "Enter second operand (integer): >" ? What should I change?   Thanks in advance!
  • 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!