Results 1 to 10 of 87

Thread: Space Shooter Game Editor

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by robert83 View Post
    Hi,

    thank you for the great tips, unfortunately this did not work

    Code:
     BackGround[i, j].ImageIndex = Images.Item[map.data[i,j+Offset]];
    Code:
    Images.Items[map.data[i,j+Offset]]
    is returning a TAspyhreImage result and not Image index.
    Actually you are providing Image index to this line by yourself using:
    Code:
    map.data[i,j+Offset]

    So final code should probably look like this:
    Code:
    BackGround[i, j].Image := Images.Items[map.data[i,j+Offset]];
    asuming that BackGround[i,j].Image is of TAsphyreImage type.


    Quote Originally Posted by robert83 View Post
    Also I was wondering if I could solve my sprite animation possible problems later like this ?

    Code:
    procedure TMain.LoadLevel;
    var i,j : integer;
    begin
      for j := 0 to 14 do
        begin
          for i := 0 to 19 do
            begin
                BackGround[i,j] := TBackGround.Create(SpriteEngine);
                BackGround[i,j].ImageName:= 'Empty.image';
                BackGround[i,j].X:=i*32;
                BackGround[i,j].Y:=j*32;
                BackGround[i,j].Z:=1;
                if BackGround[i,j].PatternCount > 1 then
                    begin
                       BackGround[i,j].AnimPos:=random(3);
                       BackGround[i,j].AnimCount:=3;
                       BackGround[i,j].AnimSpeed:=0.010;
                       BackGround[i,j].AnimLooped:=true;
                       BackGround[i,j].DoAnimate:=true;
                   end;
        end;
    end;
    I belive it should work if PatternCount is automaticly calculated. Try setting a breakpoint inside a if clause to see whether code inside it do executes when needed. If not then probably PatternCount is always returning 1.

    In your program you are using next line:
    Code:
    BackGround[i,j].AnimPos:=random(3);
    This can break animation for continuos tiles like water since neighboring tiles are not synchronized (have different animation position). SO I strongly suggest that you get rid of it. Also you should note that generating random numbers is quite slow so if you call it often it can affect your program performance quite a bit.
    Now I do understand that you would probbably like to have some random animations in case of some animated buildings so that they don't look just like clones of each other. But ass soon as you are dealing with some continuos tiles or contected tiles you need to synchronize their animation ogether.

    Quote Originally Posted by robert83 View Post
    I've found the code on the net, took out some parts I did not need....

    Unfortunately the following did not work with dynamic arrays :
    Code:
     procedure TForm2.Button2Click(Sender: TObject);
    var f:file;
    begin
      if OpenDialog1.Execute then
      begin
        assignFile(f,OpenDialog1.FileName);
        reset(f,1);
        blockread(f,map,sizeof(map)); // load map
        closeFile(f);
        // assign name again
        Edit1.Text:=map.name;
      end;
    end;
    The reason why this probably doesn't work is becouse you would need to first set the size of your arrays manualy by using:
    Code:
    SetLength(Map,Width,Height);
    But I would rather suggest that you make your own map file type which would include all the needed information (width, height, number of layers, map name, etc); Making this would require a bit more code but if done properly would prevent you from having trouble when trying to load unsuported file.
    If you want I can lend you some help in this but I need to know what kinda data structure are you trying to use in your map.

    Also nice work on water texture.
    Last edited by SilverWarior; 31-12-2012 at 07:17 PM.

  2. #2
    Happy new year!!!

    Thank you for the tips, I did remove the random... also in my previous version (probably you did not check my source), I've already managed to save my map data using 2 for cycles, and load it as well.

    Since then I've gone a bit further, I've modified my map record like this :
    Code:
       TMapData=array of array of Integer;
      TMapAnim=array of array of Integer;
      TMap=record
             name:string[20];
             map_length:string[3];
             data:TMapData;
             anim:TMapAnim;
           end;
    It stores the tile index, and it also stores for each tile index if it should be animated or not.

    I'm also saving the data correctly map.name, map.length, map.data, map.anim , and loading correctly as well. But now I have a tiny problem , I don't know how can I make my water tiles get synced, right now if I move fast up or down on this
    map I drew, they get out of sync.

    (yeah I've created the tiles using some tutorials...to see how my map would look like).

    I'm planing to also save into my map file, anim_start, anim_speed so for example if I want to add some light (for example airport lights) to my map, I could specify in which order they would light up, so they would not look like clones of each other.

    I don't know maybe if I add anim_start and anim_speed into my map file , my water tiles will be synced again?

    As for the whole thing I don't know myself what I wanna do... My plan is to make a Space Shooter game...that as you can see will have a lot of terrain in it...with moving stuff. Right now I wanna properly finish layer1 , then I'll add another layer
    for trees, houses, other stuff, some floating on water stuff...., and much much later, I'll probably add another one Layer3 enemy objects, kinda like spawning points for enemy units, enemy buildings that shoot at you etc... but as I said I'm focusing on layer1, I don't want to overcomplicate and get lost, still got very-very-very much to learn about how exactly this sprite_engine works, and Asphyre as well, and game programing in general.

    Attached I give you my latest Editor 0.7 with my tileset, I know it's bad , I will later revise it a few times for the final product... just wanted to see how the final picture would look like.
    I've attached it again, the previous attachment had a nasty bug...

    Greetings
    Robert
    Attached Files Attached Files
    Last edited by robert83; 01-01-2013 at 11:52 PM.

  3. #3
    Hi,

    Meanwhile I've managed to simplify down my DoAnimate yes or no logic.... here is the new code :

    Code:
     procedure TMain.LoadLevel;
    var i,j : integer;
    begin
      for j := 0 to 14 do
        begin
          for i := 0 to 19 do
            begin
                BackGround[i,j] := TBackGround.Create(SpriteEngine);
                BackGround[i,j].ImageName:= 'Empty.image';
                BackGround[i,j].X:=i*32;
                BackGround[i,j].Y:=j*32;
                BackGround[i,j].Z:=1;
                BackGround[i,j].AnimStart:=1;
                BackGround[i,j].AnimCount:=3;
                BackGround[i,j].AnimSpeed:=0.01;
                BackGround[i,j].AnimLooped:=true;
            end;
        end;
    end;
    procedure TMain.DrawLevel;
    var i, j: Integer;
    begin
         for j := 0 to 14 do
            begin
              for i := 0 to 19 do
                begin
                  Used_Tile := Images.Item[map.data[i,j+Offset]];
                  BackGround[i,j].ImageName:= Used_Tile.Name;
                  if BackGround[i,j].PatternCount = 1 then
                    begin
                      BackGround[i,j].DoAnimate:=false;
                    end
                  else
                    begin
                      BackGround[i,j].DoAnimate:=true;
                    end;
                  BackGround[i, j].Draw;
                end;
            end;
    end;
    The problem still persists.... my water tile animation are no longer synced....how can I sync them? It does not matter if all animation would be synced, since I will use the map.anim to specify from which frame to start the animation , and add the map.animspeed to the mix, to make things like lights etc... be "unique" .

    Greetings
    Robert

  4. #4
    Ok,

    I've been thinking about it... and I came to a solution... I created a new procedure SyncAnim, which I right now manualy set using a button on my form... after DrawLevel, I execute it and all my tiles are synced. (later I plan to make the AnimStart variable be read from the map.anim_start[] 2d array.

    Code:
     procedure TMain.SyncAnim;
    var i, j: Integer;
    begin
      for j:= 0 to 14 do
        begin
          for i:=0 to 19 do
            begin
              BackGround[i,j].AnimPos:=0;
            end;
        end;
    end;
    Right now I'm thinking about where to put this code , so that It would execute automagically , each time I go up and down on the level, or add a new tile....

    I'm thinking about using another boolean variable
    Code:
    var something_happened : boolean;
    and if I go up or down, or add a new tile , something_happened :=true ...

    then on AsphyreDevice1Render after DrawLevel I add
    Code:
    if something_happened = true then
        begin
             SyncAnim;
             Something_happened:=false;
        end;

    Right now i don't know if there is a better way to do this? I think this should not slow things down, since I'm not re-drawing twice, I just sync the animpos for all my tiles to 0 right now...

    UPDATE :

    changed my code to see how this works , but it seems this is not the right solution...during scrolling the animpos is always reset to 0, the game will move trough the world by 1 instead of 32 , which will make my water animation along with the rest of the animation still...

    UPDATE2 :

    Code:
      if Update_Anim = true then
        begin
         DrawLevel;
         SyncAnim;
         Update_Anim:=false;
        end;
    Attached is my code with the executable, and a sample level02.map , next step if this is OK, to create a level test sorta thing... that scrolls trough the level smoothly.

    I think I've got it this seems to work quiet good

    Greetings
    Robert
    Attached Files Attached Files
    Last edited by robert83; 02-01-2013 at 12:20 PM.

  5. #5
    The main reason why your sprites are not synchronized is the fact that when you are creating them or modifying them upon map move you are setting their current animation position to 0 but instead you should set animation position to the current animation position.
    So basically you need to keep track of water animation. You can do this by having one Global numerical variable which is increased at the same intervals as animation pictures needs to be changed. And then to find out which is current animation position you calculate using Mod command:
    Code:
    AnimationPos := GlobalAnimCounter mod AnimationCount;
    If you do this you shouldn't forget to reset GlobalAnimCount to 0 after some time othervise you will exceed maximum integer value which can lead to problems.

    Anywhay I'm currently at work so Iall I can give you now is general idea. But when I come home I intend to download Aspyhre eXtreme and SpriteEngine so I would be able to actually compile your source and therefore be able to test some ideas directly by changing your code.
    I have already given some thoughts about how to make map smothly scrolable to be used in your game but I need to check whether it is posible to do this using your sprite engine.
    I was also thinking about how to implement your game map in most eficient way (what would be the best way of storing information for all your needed layers).

    So stay tuned and await more of my suggestions shortly.

  6. #6
    Hi,

    I can't sleep, I've coded a bit, added AnimStart variable to my map data... you can set animstart for each tile, so the latest attached editor can make certain tiles be synced, and other tiles see them lights do their animation from different starting position.
    Also since now I'm only executing my DrawLevel and SyncAnim loop when the map is updated or moved.

    If you execute this one, and load the included level02.map you'll see that water is perfectly synced, the lights which i wanted to be synced are synced, and those 3 lights are using different anim start position, so don't look like exact copies of
    each other.

    Next I'm planing to add for each animated sprite , animation speed, so I can have faster and slower lights, or faster slower water,fire...etc....


    I was thinking myself about the scrooling, unfortunately I cannot simply use BackGround[i,j].WorldX and WorldY , because I'm only drawing as many sprite's as I'm actually using for 1 screen...

    I came up with a solution, which I think could work, I would create 1 more line of Sprite's , that would be beyond the screen height in the direction I'm moving.

    Then I would move WorldY until I would rich the end of this aditional (hidden) line of Sprite's , once I rich the end of it I would move my entire BackGround[i,j].Images in the apropriate directions, and reset my WorldY to the original position.

    My idea is that the redraw of the Sprite Grid would be so fast that the user would not notice it, and would "feel" like it's scrolling trough the map by 1 instead of 32 .

    Greetings
    Robert
    Attached Files Attached Files

  7. #7
    Well, I almost got it I made the smooth scrolling possible like this :

    Code:
     procedure TTools.DOWN_1Execute(Sender: TObject);
    var i,j : integer;
    begin
      if MainForm.Offset < strtoint(LLength.Text)-14 then
        begin
          inc(MainForm.Reset_Grid,1);
          if MainForm.Reset_Grid = 32 then
            begin
              Main.DrawLevel;
              Main.SyncAnim;
              MainForm.Reset_Grid:=1;
              inc(MainForm.Offset,1);
              for j := 0 to 15 do
                begin
                  for i := 0 to 19 do
                    begin
                        BackGround[i,j].WorldY:=0;
                    end;
                end;
            end;
          for j := 0 to 15 do
            begin
              for i := 0 to 19 do
                begin
                    BackGround[i,j].WorldY:=BackGround[i,j].WorldY-1;
                end;
            end;
        end;
    end;
    Currently it only works for down, but has a small problem which I'm trying to fix now, when I start scrolling down with it goes down 32 , then does a jump that I can feel.... but after that I cannot feel that I'm drawing that one additional line , it feels like
    I'm actually scrolling trough a 30 line long map for example....
    Also my animation is reset as I move down .... which is not good...damn, have to find a fix for that to.

    But atleast did some progress on me own.

    UPDATE : if I set RESET_GRID on FormCreate to RESET_GRID:=31 (instead of 0), my scrolling down is as smooth as can be.... only animation remains problem now that it's synced whenever I move....not good will have to
    use you're suggestion to make em synced , hopefully I can make em synced and still keep the uniqueness of invidiual animations by using startpos by tile.

    Greetings
    Robert
    Last edited by robert83; 03-01-2013 at 02:06 AM.

  8. #8
    Quote Originally Posted by robert83 View Post
    Hi,

    I can't sleep, I've coded a bit, added AnimStart variable to my map data... you can set animstart for each tile, so the latest attached editor can make certain tiles be synced, and other tiles see them lights do their animation from different starting position.
    Also since now I'm only executing my DrawLevel and SyncAnim loop when the map is updated or moved.

    If you execute this one, and load the included level02.map you'll see that water is perfectly synced, the lights which i wanted to be synced are synced, and those 3 lights are using different anim start position, so don't look like exact copies of
    each other.
    Nice work on this. But I still think that water animation gets out of sync when scrolling.

    Quote Originally Posted by robert83 View Post
    Next I'm planing to add for each animated sprite , animation speed, so I can have faster and slower lights, or faster slower water,fire...etc....
    Yes this would be nice feature and could come verry handy in future.


    Quote Originally Posted by robert83 View Post
    I was thinking myself about the scrooling, unfortunately I cannot simply use BackGround[i,j].WorldX and WorldY , because I'm only drawing as many sprite's as I'm actually using for 1 screen...

    I came up with a solution, which I think could work, I would create 1 more line of Sprite's , that would be beyond the screen height in the direction I'm moving.

    Then I would move WorldY until I would rich the end of this aditional (hidden) line of Sprite's , once I rich the end of it I would move my entire BackGround[i,j].Images in the apropriate directions, and reset my WorldY to the original position.
    Yes adding a new line of sprites for smoth scrolling is necessary. But I had a bit different idea of how to implement this. Instead of moving WorldY Position I would go and move the sprites instead. Why? If you move sprites instead you won't need to update all visible sprites when you have moved your map for the full line size but instead you go and destroy those sprites that are no longer needed and then make new line of sprites when they would be needed.

    Since you are trying to make SpaceShooter game I presume you will be moving your gameworld downward. So the way how I would implement this scroling is like this.
    1. First you create enough sprites to fill window size (similar as you do now).
    2. Then you create another line of sprites above current ones.
    3. You move all these sprites downward by certain amount of pixels.
    4. Once you have repeted step 3 enough times so that you moved the world for entire line height you destroy botom line of sprites which aren't visible anymore now and then you create another line of spites at the top. After that you go back to step 3.
    5. You repeat step 3 and 4 until you either reach the top of the map or reach a boss ship which temporarily halts your progression through map.
    6. Then you either end the game if it is on end of the map or wait for the boss to be kiled.

    The biggest advantage of this approach is that you are not updating the textures for existing Sprites (unles for animations) but you are just adding necessary new Sprites and killing (destroying) unnecessary ones.

    Offcourse to make this work easier I would change the map structure to someting like this:
    Code:
    TTileData = record
      ImageIndex: Integer; //Stores the index for retriving necessary image from TAspyhreImages
      AnimationCount: Integer //Stores how many pictures does animation contains
      AnimationOffset: Integer; //Stores offset from global animation position
    end;
    
    TMapLine = Array[0..15] of TTileData; //Stores the whole line of cells asuming the map width is 15 tiles.
    
    TMap = record
      Mapname: String;
      MapSize: Integer //Storing the map size in String type could lead to problems during conversion. Also storing in Integer type saves you some memory.
      TLines: Array of TMapLine; //Stores the whole map
    end;
    So with proper file handling routines you can now actually go and read the map data directly from file Line by Line and thus reduce Games memory consumption a lot and you gain the ability to have enourmus maps if needed.
    Ofcourse implementing several Layers would reqjuire aditional change to this maps structure.

    As for Sprites animations you can see that I used AnimationOffset variable in my suggested map code. The reason for this is the fact that I'm still thinking of having some Global variable to progress position of various animations so that when you are making new sprites you just set their proper aniamtion position and then leave your SpriteEngine to take care of your animations.
    To put this in code I need to get my computer set to be ready to compile your program first. Yes I know I sad that I would do this as soon as I come home but the fact is that I came home preaty beat up today so I haven't got much motivation for programing. Tis also means that above code is still just out of my head and might have some syntax errors.

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
  •