Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Math-O-Spheres

  1. #1

    Math-O-Spheres

    My game, Math-O-Spheres, is a Bejewled-type game where, instead of colored gemstones, you click on spheres with numbers on them. The numbers must add up to ten, and you get a higher score if you chain together more spheres (similar to Tetris Attack or Roof Rats). You also get a higher score for finishing a level faster. Each level has a set time limit, and the time limit gets shorter and shorter as you go along. You have to get a certain number of ten's before the time runs out.

    Right now, the spheres all add together (the feature I'm working on now), but I would eventually like to add subtraction and multiplication spheres, as well. I would also like to add a difficulty system with different grid sizes, but first I'll need a working game.

  2. #2
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Hi sewing and welcome to the PGD forums

    It sounds like a cool game (as far as mechanics go, its more advanced than 2048 after all ). How far have you gotten on the code? Is there a demo to try or are you looking for help?
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  3. #3
    I've designed the interface, loaded the images (via an imagelist), and setup the timer and lives system, but have no idea how to implement the click-then-add mechanics. "Looking for help" would definitely be what I'm doing. I know I want longer chains to generate higher scores, but I'm currently looking for a way to read the image in a cell, then assign the value based on which image it is. My thought is a switch statement with a case for each image, which would be stored in an array until the total value of the array became ten, but again have no idea how to "pick out" the images in the first place. Maybe create the image as part of a spheres class, and draw the object to the grid? I was actually writing a post asking for help in Start with the Basics when I saw your email.

    As far as a demo goes, I could send you what I have.

  4. #4
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    So, it looks like what you need is some 2d array that stores the value of each 'cell'. (reading a texture/image is slow and painful). Then I would write two functions: a FindContiguousBlockScore(X, Y) function that gives me the score for a block of like cells based on the XY co-oridnate of the cell that was clicked in the array. If the score is greater than whatever the minimum score is for a 1x3 or whatever, then I would increment the score by the returned amount before doing something like a EraseContiguousBlock(X, Y) to delete the cells that were just 'cashed in'.

    Then all that remains is the comparatively simple matter of shifting the cells above it downwards and filling the rest with random values.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  5. #5
    I relied to your post, but hit the "Reply to Thread" button by mistake. The response is post #3.

  6. #6
    Would this be easier to do in a TStringGrid component? I just read up on the difference, and realized the stringGrid1.Cells[] property might be useful. I'm honestly not sure how to dsetermine the clicked cell. I know the computer knows already, but how do I associate a value with each image, and how do I tell it to store the information in the clicked cell?

    I apologize for asking so many questions, I'm just feeling a little lost.

  7. #7
    I don't know exactly what you are asking, but you can define 2-dimensional arrays that store any information. Dynamic or static arrays of records.

    Code:
    TSomeCell = record
      someNumber: integer;
      someText: string;
    end;
    ...
    grid: array[0..8, 0..8] of TSomeCell; // Defines a 9x9 grid
    ...
    // Access it easily
    grid[1, 2].someNumber:=1;
    If you need dynamic array it's:
    Code:
    grid: array of array of TSomeCell;
    ...
    setlength(grid, 9, 9); // Defines a 9x9 grid, and you can change it while program runs

  8. #8
    Quote Originally Posted by sewing0109 View Post
    I'm honestly not sure how to dsetermine the clicked cell.
    Well that depends a bit on what components or library you use for drawing your game. So it would be nice if you could share some more information on this.
    But based on the fact that in your posts you are mentioning ImageList and StringGrid I asume that you are using Visual components (VCL in delphi or LCL in Lazarus).
    So I have written you a short example which will show you how to get mouse relative coordinates above TImage and how to caclulate which cell would be selected. I even add a bit of code to render the gridlines on TImage to make it easier for you to understand.
    In order to make this example simply create a new project and put a TImage component on it.
    Then you need to create an OnMouseMove event for TImage and copy the code below into it:
    Code:
    procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    var Line, Row: Integer;
    begin
        //Calculate over which row is mouse cursor positioned
        //Row width is 20 pixels
        Row := X div 20;
        //Calculate ower which line is mouse cursor positioned
        //Line height is 20 pixels
        Line := Y div 20;
        //Show output values instead of form caption
        Form1.Caption := 'X:'+IntToStr(X)+' Y:'+IntToStr(Y)+'  Line:'+IntToStr(Line)+' Row:'+IntToStr(Row);
    end;
    You also need to create an OnCreate even for main form in order to draw gridlines on TImage. Code for this is below:
    Code:
    procedure TForm1.FormCreate(Sender: TObject);
    var X,Y: Integer;
    begin
        //Draw vertical lines
        for X:=0 to 20 do
        begin
            Image1.Canvas.MoveTo(X*20,0);
            Image1.Canvas.LineTo(X*20,400);
        end;
        //Drwa horizontal lines
        for Y:=0 to 20 do
        begin
            Image1.Canvas.MoveTo(0,Y*20);
            Image1.Canvas.LineTo(400,Y*20);
        end;
    end;
    This example reads mouse relative coordinates above TImage component, calculates over which line/row is mouse cursor positioned and displays that instead of default Form caption.

  9. #9
    I'm using Delphi -- RAD Studio XE5. Would it help if I posted the folder with all the files -- the images, exe, dproj, dpr, etc?

    UPDATE: An image of the game running.

    Math-O-Spheres Gameplay Image.jpg

    Each sphere is in a cell, and I want to add functionality so that any two spheres that get clicked are added up.
    Last edited by sewing0109; 12-05-2014 at 07:26 PM. Reason: Adding a reference image

  10. #10
    You can post your project since I do own Delphi XE5 and would therefore be able to check your code in action and then try to give you best suggestion based on your current design.

Page 1 of 2 12 LastLast

Tags for this Thread

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
  •