Page 7 of 9 FirstFirst ... 56789 LastLast
Results 61 to 70 of 87

Thread: Space Shooter Game Editor

  1. #61
    I tend to put:
    Code:
    DecimalSeparator:='.';
    Then it's dot always and on everything, ignoring whatever language settings are.

    I mean, wouldn't you just hate it if this application would on some computers write '.' and sometimes ','?
    Code:
    var d: single; F: TextFile;
    begin
      d:=1.001;
      assignfile(F, 'test.txt');
      rewrite(F);
      writeln(F, d);
      closefile(F);
    end;
    That would be very bad if you would want to send such files to others, with different language settings.
    Last edited by User137; 11-02-2013 at 01:09 AM.

  2. #62
    Quote Originally Posted by User137 View Post
    I tend to put:
    Code:
    DecimalSeparator:='.';
    Then it's dot always and on everything, ignoring whatever language settings are.
    Yes and when someone who comes from country where "." is used as thousand seperator and sees 1.001 thinks that this actually means thousand and one and not one point zero zero one.
    The reason why Language settings are available to any application is so that each of theese aplaication can use proper settings when formating strings.

    Quote Originally Posted by User137 View Post
    I mean, wouldn't you just hate it if this application would on some computers write '.' and sometimes ','?
    Code:
    var d: single; F: TextFile;
    begin
      d:=1.001;
      assignfile(F, 'test.txt');
      rewrite(F);
      writeln(F, d);
      closefile(F);
    end;
    That would be very bad if you would want to send such files to others, with different language settings.
    Why would you like to write any numerical number as Text? Writing the number 1.001 as text would require 5 * 8 = 40 bits of data or 5 bytes of data. Writing the same number as Single would require 4 * 8 = 32 bits od data or 4 bytes of data.
    Also writing this number in numerical form makes sure that number isn't afected by computer language settings.

  3. #63
    Floating point values are written as text in many file formats, for example OBJ, INI, various XML formats and so on. Text files are easier to debug. I don't think there is anyone in this world who actually reads with thousand-separators, at least when it comes to programming. Something like MS Office may print such separators though, and even then it could internally be stored as number, not string.

  4. #64
    I must admit that lots of programs stores numerical values in textual form but I can't understand why. Sure it is good to be able to see some of theese values outside the program sometimes but in most times you wouldn't want those values to be so easy accsesible since changing any of those can have huge impact on your program.
    Also converting values from textual form and back is quite slow process. Textual representation of theese values usually takes more space to store. And finally the sligthest data corruption (one letter inserted in the value) and you get that nasty "String conversion fail" Exception which would deffinitly scare many customers away from using your programs. Nobody likes seeing Exception windows poping up in your applications.

    So personally I avoid storing any numerical value in textual form.
    I also try avoiding the use of XML files. Sure the original idea of XML is to make filetype which would alow sharing information stored in it between different applications and even systems. But reality is that XML is far from that. If you are monitoring other general programing forums you can see that quite some peepole are having problems of extracting the data from XML files they got somwhere around the web. Finally many of them solves their problem by hardcoding the data structure of XML file into their program despite the fact that every XML should already contain the necessary information to get the data structure out of it automaticly.

  5. #65
    Hello,

    I'm stuck... I just dont know how to solve this :
    Code:
    procedure TMain.ScrollMap;
    var x,y,z,i,j : integer;
    begin
      if RanOnce = false then
        begin
          for z:=0 to 3 do
            SetLength(AnimTable.Layer[z].TileAnim, Map.MapLength);
          if MapOffset in [0..15] then
            begin
              MapOffset:=Map.MapLength-15;
            end;
          LineHeight:=0;
          GameDrawGrid;
          RanOnce:=true;
        end;
     
      if MapOffset > 0 then
        begin
          i:=-1;
          LineHeight:=LineHeight+ScrollSpeed;
          if LineHeight = 32 then
            begin
              Dec(MapOffset,1);
              OffsetEdit.Value:=MapOffset;
              LineHeight:=0;
            end;
    // Background : Layers [0..3], Tiles [0..19], Lines [0..15] of TBackGround;
    // Map.Record : Layers [0..3], Lines [0..Map.Length-1] , Tiles [0..19]
          for y:=0 to 15 do
              for x:=0 to 19 do
                begin
                  // move existing sprites down
                  if BackGround[0,x,y] <> nil then
                    begin
                      if LineHeight = 32 then i:=y;
                      BackGround[0,x,y].Y:=BackGround[0,x,y].Y+ScrollSpeed;
                      if BackGround[0,x,y].Y = 480 then
                        begin
                          i:=y;
                          BackGround[0,x,y].Dead;
                          BackGround[0,x,y]:=nil;
                        end;
                    end;
                end; // X loop
          for j:=0 to 19 do
            begin
              if (i <> -1) and (Map.Layer[0].Lines[MapOffset-1,j].ImageIndex <> 0) then
                begin
                  BackGround[0,j,i] := TBackGround.Create(SpriteEngine);
                  BackGround[0,j,i].ImageName:= Images.Item[1].Name;
                  BackGround[0,j,i].X:=j*32;
                  BackGround[0,j,i].Y:=-32;
                  BackGround[0,j,i].Z:=0;
                end;
            end;
     
        end; // if Offset
    What I've tried to do here is, move every AVAILABLE sprite in the BackGround sprite array down, and then kill it off, when one of them Lines is killed a new line should be created in it's place. The above "almost" works perfectly if there is a Sprite on the beggining of each line, but won't do a thing when there is none, I ...damn... I just can't figure it out. Also for some reason when it reaches the end of the map there is a difference in Sprites between the EditorMode and the GameMode, to be exact the difference is 7 . The code above is probably pretty sh*tty, I've tried to combine things, move code around...the thing is I don't understand this at all.

    Original code which I think is the only part that is clean, and I understand what it does and it does that to is this :
    Code:
      if MapOffset > 0 then
        begin
          LineHeight:=LineHeight+ScrollSpeed;
          if LineHeight = 32 then
            begin
              Dec(MapOffset,1);
              OffsetEdit.Value:=MapOffset;
              LineHeight:=0;
            end;
     
          for y:=0 to 15 do
              for x:=0 to 19 do
                begin
                  // move existing sprites down
                  if BackGround[0,x,y] <> nil then
                    begin
                      BackGround[0,x,y].Y:=BackGround[0,x,y].Y+ScrollSpeed;
                      if BackGround[0,x,y].Y = 480 then
                        begin
                          BackGround[0,x,y].Dead;
                          BackGround[0,x,y]:=nil;
                        end;
                    end;
                end; // X loop
    end;
    I know what I must do , but I dont know how to tell the machine to do it.
    1. Move every available sprite inside SpriteArray
    2. When a sprite reaches the bottom it is killed
    ---- problem zone here ----- I'm not sure what to do....
    since there are empty spaces, and EMPTY lines as well my logic is stuck here
    3. I should create a new line of Sprites inside the array but : ( I'm seriously confused here )
    -- do I need to take into account from which line of the SpriteArray did I previously destroy the Sprites , which reached the end of level . I think yes (the first code does that, altought not very clean)
    -- I don't know how to check which line of the SpriteArray was destroyed if there are Lines with NO Sprites at all

    I'm also attaching my code , with 2 maps , I'm so confused that you'll probably understand better if you load the two maps and see the problem .

    Greetings
    Robert


    Attached is a PDF file with a drawing showing what is happening , or atleast I think it goes like that...
    Attached Images Attached Images
    Attached Files Attached Files

  6. #66
    The way I have solved this in the Editor rewrite I'm doing for you is that I instead of checking by sprites position I'm actually checking by the map offset position.
    Since you know that each line has certain position on the map (Line.YPos := LineIndex * LineHeight). But this approach requires you to threat your map a bit differently.

    Easiest way to add this into your code would be so that before you create line of sprites you also create TObject list which would hold pointers to the sprites you would create for that specific line. So when it comes time to remove sprites from this certain line you just iterate through TObject list items and cal Dead procedure for each of theese sprites.


    As for the my progress on Editor I had to rewrite most of my code so that now I have posibilty to include some aditional functionality I hadn't plan before.
    Features that I currently plan to include are:
    1. Multilayer support -offcourse
    2. Two layer types:
    - grid based layer type is verry similar to the one you use now. Tiles are positioned on the grid
    - section based layer is a bit different. This layer alows positioning Sprites ony any position. You would probbably use this one for enemy units and such.
    Each of the layers would have its own procedure for taking care of Sprite creation and destruction.
    3. Tiles are now declared as classes to alow data sharing. For instance you create a water Tile data, and then simply reuse this data for creating WaterTiles on different parts of map Tiles can also have pointers to AnimationData class and Entity class.
    4. AnimationData class would serve for controlling Sprites animations. It contains all the needed data for animations like number of frames animation has, animatiomn speed, animation start position. I also plan to improve this by adding ability to stop or start animation at any time. And this woulld be posible to do instantly or by speeding up or slowig down the animation (gradually stopping the windmill for instance). And since you can share dataq from AnimationData class between different tiles it serves as perfect way for tile animation synchronization.
    5. Entity class would be used for things like buildings, units, etc. This would be mostly used in game as an easy way to figure ut which unit or structures health should be lowered when you do colision detection between different sprites.

    Main reasony why I use classes rather than records are class properties. Why? Class property can actually automaticly return you a value which is calculation of several class internal properties or in our case to actually forward the values of conected classes. In layman terms this means that you would be able to acces all required values from connected AnimationData and Entity classes just as these values would be saved in Tile class. And if you Tile class is not conected to AnimatioData or Entity class properties would still return some predefined values.

    Anywhay there is still quite some work to be done but I'm progressing gradually.

    Now I would ask you if you could either found diferent shore graphics which doesn't contain any water are compleetly transparent on the place where water should be. This way I could test water and shore layering.
    I would also be glad if you could provide me your textures in native format as files so I can also try some of my ideas (ability to place whole tree with one click for instance).

  7. #67
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Quote Originally Posted by SilverWarior View Post
    Main reasony why I use classes rather than records are class properties. Why? Class property can actually automaticly return you a value which is calculation of several class internal properties
    I Use them a lot too, although I've started to favour public setter procedures over writable properties simply to make my classes easier to read, no need to check properties in a class to see what they do. I've found it's a great time-saver as it removes any element of ambiguity that arises from writable properties, which is good when you're working on a code-base so big that you can't possibly remember everything you did and why
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  8. #68
    I did it


    Scrolling works now, and I've tested it in multiple scenarios , and I understand why it works now , so simple (now...)

    1. I move every available sprite down in the BackGround array
    2. Once I reach 32 with my LineHeight counter (that means I went trough 1 line of Map data) , i do the following :
    a) locate empty line inside BackGround array
    b) read next line of MapData and put it inside of this empty line inside the BackGround array

    Code:
    procedure TMain.ScrollMap;
    var x,y,z : integer;
        i : integer;
        a,b,c : integer;
    begin
      if RanOnce = false then
        begin
          for z:=0 to 3 do
            SetLength(AnimTable.Layer[z].TileAnim, Map.MapLength);
          if MapOffset in [0..15] then
            begin
              MapOffset:=Map.MapLength-15;
            end;
          LineHeight:=0;
          GameDrawGrid;
          RanOnce:=true;
        end;
     
      if MapOffset > 0 then
        begin
          LineHeight:=LineHeight+ScrollSpeed;
    // Background : Layers [0..3], Tiles [0..19], Lines [0..15] of TBackGround;
    // Map.Record : Layers [0..3], Lines [0..Map.Length-1] , Tiles [0..19]
          // move available sprites down
          for z:=0 to 3 do
            for y:=0 to 15 do
              for x:=0 to 19 do
                begin
                  if BackGround[z,x,y] <> nil then
                    begin
                      BackGround[z,x,y].Y:=BackGround[z,x,y].Y+ScrollSpeed;
                      if BackGround[z,x,y].Y = 480 then
                        begin
                          BackGround[z,x,y].Dead;
                          BackGround[z,x,y]:=nil;
                        end;
                    end;
                end; // X loop
          // screen scrolled down one line
          if LineHeight = 32 then
            begin
              Dec(MapOffset,1);
              OffsetEdit.Value:=MapOffset;
              LineHeight:=0;
              // locate an empty line in the BackGround array
              if MapOffset > 0 then
                begin
                  a:=0;
                  y:=0;
                  c:=0;
                  repeat
                    for z:=0 to 3 do
                      for x:=0 to 19 do
                        if BackGround[z,x,y] <> nil then
                          a:=-1;
                    if a = -1 then
                      begin
                        inc(y);
                        a:=0;
                      end
                    else
                      begin
                        b:=y;
                        c:=-1;
                      end;
                  until c = -1;
                  // get next line of tiles and put into free line in background array
                  for z:=0 to 3 do
                  for i:=0 to 19 do
                    if Map.Layer[z].Lines[MapOffset-1,i].ImageIndex <> 0 then
                      begin
                        BackGround[z,i,b] := TBackGround.Create(SpriteEngine);
                        BackGround[z,i,b].ImageName:= Images.Item[map.Layer[z].Lines[MapOffset-1,i].ImageIndex].Name;
                        BackGround[z,i,b].X:=i*32;
                        BackGround[z,i,b].Y:=-32;
                        BackGround[z,i,b].Z:=z;
                        // animation properties
                        if BackGround[z,i,b].PatternCount = 1 then
                          begin
                            BackGround[z,i,b].DoAnimate:=false;
                          end
                        else
                          begin
                            BackGround[z,i,b].AnimStart:=0;
                            BackGround[z,i,b].AnimCount:=map.Layer[z].Lines[MapOffset-1,i].AnimCount;
                            BackGround[z,i,b].AnimSpeed:=map.Layer[z].Lines[MapOffset-1,i].AnimSpeed;
                            BackGround[z,i,b].AnimPos:=AnimTable.Layer[z].TileAnim[MapOffset-1,i];
                            BackGround[z,i,b].DoAnimate:=true;
                            BackGround[z,i,b].AnimLooped:=true;
                          end;
                      end;
                end;
            end;
        end // if Offset
      else
        begin
          // Destroy sprites
          for x:=0 to SpriteEngine.Count-1 do
            SpriteEngine.Items[x].Dead;
          // Clear dynamic array
          for z:=0 to 3 do
            for y:=0 to 15 do
              for x:= 0 to 19 do
                BackGround[z,x,y]:=nil;
          // Start again
          RanOnce:=false;
        end;
    
    end;

    SilverWarrior :

    -I'll get the art in my next post, I'll reasemble the tree, cause I've cut it out into parts from a larger image
    -I'll also give you the shore tiles which are transparent

    If you can then please move this thread to myprojects as you've suggested and name it Space Shooter Game Editor . (think by the end it will be more then just a simple Level Editor)

    Next in plan :
    a) speed set by map position
    b) add snow (perhaps rain, but rain makes me depressed so i'll probably wont do that),
    when game reaches a part of map for example I have a special tile that triggers snow , till another special tile stops it, I planed to make it snow like this :
    -- snow would start faling at line 0 and be destroyed at line 2, next instance of snow would start falling at line 1 and be destroyed at line 3, etc (2,4,3,5,4,6...)
    hopefully with this I would achive a sense of depth, that the snow is actually falling down. This way I could do this without Collision detection, which would probably slow it down pretty much.





    ----
    As for the Object things, there was a reason I've used arrays, I must confess that I'll need to go back to reading and practicing object oriented programing, while I do understand the basics how it works , I did not write code at all in an object oriented way (excluding the Delphi 7 graphichs interface part , but that is automatic, so it doesn't count)
    I've started reading Mastering Delphi7 , that is why I updated my variable, procedure etc...names, as well as why I started commenting in a different way.
    ----

    Greetings
    Robert
    Attached Files Attached Files
    Last edited by robert83; 20-02-2013 at 10:20 AM.

  9. #69
    Quote Originally Posted by robert83 View Post
    SilverWarrior :

    -I'll get the art in my next post, I'll reasemble the tree, cause I've cut it out into parts from a larger image
    -I'll also give you the shore tiles which are transparent
    About the tree do also leave the pices that you have now.
    What I have in plan is only to show tree preview (replacing default selection sprite and snaping its position to grid) when you are placing it and then programaticly place tree pices into proper tiles.

    Quote Originally Posted by robert83 View Post
    If you can then please move this thread to myprojects as you've suggested and name it Space Shooter Game Editor . (think by the end it will be more then just a simple Level Editor)
    Done already

    Quote Originally Posted by robert83 View Post
    Next in plan :
    a) speed set by map position
    b) add snow (perhaps rain, but rain makes me depressed so i'll probably wont do that),
    when game reaches a part of map for example I have a special tile that triggers snow , till another special tile stops it, I planed to make it snow like this :
    -- snow would start faling at line 0 and be destroyed at line 2, next instance of snow would start falling at line 1 and be destroyed at line 3, etc (2,4,3,5,4,6...)
    hopefully with this I would achive a sense of depth, that the snow is actually falling down. This way I could do this without Collision detection, which would probably slow it down pretty much.
    Why not just use a good snow animation tiles which you then move when moving the map.

    Quote Originally Posted by robert83 View Post
    As for the Object things, there was a reason I've used arrays, I must confess that I'll need to go back to reading and practicing object oriented programing, while I do understand the basics how it works , I did not write code at all in an object oriented way (excluding the Delphi 7 graphichs interface part , but that is automatic, so it doesn't count)
    I've started reading Mastering Delphi7 , that is why I updated my variable, procedure etc...names, as well as why I started commenting in a different way.
    Since you are reading Mastering Delphi 7 do pay close atention to the chapter about making your own components as it covers some concepts that you will need for understanding my code.
    But since I have used some more advanced concepts that aren't presented there (data sharing between classes) I'm writing my own tutorial about that.

    Also if all goes wel I will ask Primož Gabrijelčič for opinion wheter my aproach is thread safe or not (I'm atending a Multithreading course tomorow) so pepole could easily use it in multithreading applications.

  10. #70
    Here it is , see attachment.

    Yep about the snow, you are right, for that I'll need a Animated Snow tile , that is two tiles in Height, and I'll get the same depth effect and it will be much less expensive....


    A few questions about this Editor / code :

    1. I've tried it on multiple machines, and there is a strange thing (I'll try to explain) . The map scrolling even though it says 60FPS always , does not seem smooth... it feels like its going down at a variable speed (which is impossible since I'm moving it by 4 always....) Any ideas why?

    2. Also on one machine Amd Sempron 7100GS , it hangs at random places , the computer itself freezes completely... need to reboot. But on my computer, and another one ( I have a few of them, for them LanParty's) it goes without a problem. In fact yesterday I left it to run all night to see if I have a memory leak, or some other bug somewhere. I guess the 7100GS is overheating and that is why it hangs.... anyway if you could take a moment to look at my Scrollmap
    procedure to see if there is some potentialy dangerous code in there...that under certain circumstances might be problematic.

    Anyway what anoys me the most is problem number 1 , maybe it's because I'm not fullscreen ? Maybe because I'm using Panel as renderingsurface? Is this because VSYNC ? I'm not sure if I've set MaxFPS correclty and SPEED, is there a magic ratio between the two that should be input ?


    3. A side-side question :
    I've got a Celeron 2000, GeForce 2GTS can only push out 30FPS max... , what is the culprit here ? My code ? Asphyre / SpriteEngine combo? I'm asking this because (and now I'm probably comparing apples to oranges) for example Tyrian 2000
    runs smoothly on ever lower specs... am I limited here by the programing language itself ? ( or by my knowledge to write fast code ) - I'm asking this because I always think it's my falt, but not 100% sure, I just want to make this 100% clear, so that I don't expect it to run as fast on older hardware ...when it's simply not possible ... (cause it uses some modern DirectX stuff that is even though my sprites themselves are not complex , it still taxes older generation gpu's more... )
    Greetings
    Robert
    Attached Files Attached Files

Page 7 of 9 FirstFirst ... 56789 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •