Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - BdR

#41
Hi all, I have a question. I want to have a bullet follow a path from a start position to a goal position in a certain nr of steps. And when it reaches the goal position, it should do a hit check etc. But I can't get the compare of 2 floating point values to work. Here is an example code.
Code (glbasic) Select

SEEDRND GETTIMERALL()
WHILE (KEY(0) = FALSE)
  DEBUG " -- start test --\n"
  Test()
WEND

FUNCTION Test:

  // variables
  LOCAL iStep%, iCount%
  LOCAL x#, y#, xGoal#, yGoal#, xSpeed#, ySpeed#

  // start at bottom of screen
  x = 320
  y = 480
 
  // goal is random position at top of screen
  xGoal = RND(640)
  yGoal = RND(100)

  // set speed so that block moves from start to end in exactly 60 steps
  xSpeed = (xGoal - x) / 60.0
  ySpeed = (yGoal - y) / 60.0

  // do the steps
  iCount = 0
  WHILE (iCount < 100)

    // draw block and goal
    DRAWRECT xGoal, yGoal, 4, 4, RGB(192, 255, 0)
    DRAWRECT x, y, 8, 8, RGB(0, 192, 255)
    SHOWSCREEN

    // update all
    x = x + xSpeed
    y = y + ySpeed
   
    IF (x = xGoal) AND (y = yGoal)
      DEBUG "GOAL REACHED!\n"
    ELSE
      // goal not reached, check if close to goal
      IF (ABS(x - xGoal) < 10) AND (ABS(y - yGoal) < 10)
        DEBUG "Positions are NOT equal. x=" + x + " y=" + y + " <> xGoal=" + xGoal + " yGoal=" + yGoal + "\n"
      ENDIF
    ENDIF

    iCount = iCount + 1 // to stop WHILE loop
  WEND

ENDFUNCTION

So the code does the following:
1) divide length of path into 60 steps
2) increment start position with steps of divided length
3) check if goal position is reached

The check if x=xGoal and y=yGoal is almost never true (on rare occasions it is). I guess this is due to limited precision of floating points, causing the end result to being slightly off. For example the goal position is (123, 456) but the incremented result is (123.0003, 456.0001) or something like that. So I think you will run into the same problem when working with C or Java etc. not just GLBasic.

But it's strange because the debug output is for example this
Positions are NOT equal. x=116 y=34 <> xGoal=116 yGoal=34

I can add an iSteps variable and simply count the nr of steps. But my question is, what is the best way to check if the goal is reached using float variables?
#42
I have a question for the iPhone developers, where did you find the graphics artist for your games? Looking at some of the games such as Birdie In Trouble (by Ozden79) or Exodus (by fjsantosb) or DefCon Z (by kaotiklabs), they've got some nice artwork.

I'm nearing completion with one of my game projects and I've started looking for cartoonists/illustrators in the area of my hometown, but I'm not sure this is the best way to go.

I guess I could try to contact someone through a website like deviantart, they've got some GREAT artwork on there :nw: But working via e-mail/chat, never meeting face-to-face seems kind of weird to me. Also, what would be an estimated price range for, let's say, three A4-size drawing/illustrations with or without color?

Any thoughts on this?
#43
I'm having trouble erasing a section from an ini-file.

I save the current gamestate to an inifile, so I can reload it at next startup. After it has been reloaded it needs to be removed from the file. So wanted to erase my "savestate" section using the INIPUT command. But this doesn't seem to work properly, it looks like a bug.

For example, my settings.ini file contains this:

[gamesettings]
x=4
y=4
[customsettings]
sound=off
[savestate]
level=2
time=831
moves=4


And when I run the following GLBasic code, the section is not removed from the ini-file. The filedate of the ini-file isn't even changed, so it looks like it's actually not doing anything.

Code (glbasic) Select

  INIOPEN PLATFORMINFO$("DOCUMENTS") + "/settings.ini"
  INIPUT "savestate", "", ""
  INIOPEN ""
  // nothing has happened, savestate section still exists


However, when I first change one of the values in the section and then erase it, then it does work. For example like this:

Code (glbasic) Select

  INIOPEN PLATFORMINFO$("DOCUMENTS") + "/settings.ini"
  INIPUT "savestate", "level", "1" // <- change one value
  INIPUT "savestate", "", ""
  INIOPEN ""
  // this works, savestate section is now removed


Some of my system info, maybe it will help:
Windows XP
GLBasic IDE, Version: 7.341
Configuration: WIN32
GPC - GLBasic Precompiler V.6.922 SN:******** - 3D, NET
#44
Hi all :good: I have a question about array of types, and assignment of these array elements.

If you have an array of a custom type, you can assign the values of an element with a variable, if the variable is of the same type. See code example below, it works fine and as expected.

Code (glbasic) Select

TYPE TLevel
  Tiles[5][5]
  Difficulty
  Description$
ENDTYPE

GLOBAL LevelSet[] AS TLevel

DIM LevelSet[3]

LOCAL i, x, y
LOCAL tmpLevel AS TLevel

// initialise dummie test levels
FOR i = 0 TO 2
  LevelSet[i].Description$ = "Level "+i
  FOR y = 0 TO 4
    FOR x = 0 TO 4
      LevelSet[i].Tiles[x][y] = i
    NEXT //y
  NEXT //x
NEXT //i

// now move the items array around
tmpLevel = LevelSet[0]
LevelSet[0] = LevelSet[1]
LevelSet[1] = LevelSet[2]
LevelSet[2] = tmpLevel

// draw dummie levels
FOR i = 0 TO 2
  PRINT LevelSet[i].Description$, (i*80), 0
  FOR y = 0 TO 4
    FOR x = 0 TO 4
      PRINT LevelSet[i].Tiles[x][y], (i*80) + x*8, 32+y*8
    NEXT //y
  NEXT //x
NEXT //i

// display the results
SHOWSCREEN
KEYWAIT

My question is, does it actually do the assignment of all array elements (each integer in Tiles[][] etc.) or are the pointers switched around? Or are there are any other potential pitfalls I need to be aware of, when assigning typed-array elements this way?

I'd like to know, before I use this "trick" extensivly in my game code.
#45
I'm working on a puzzle game for the iphone using GLBasic and it will have a level editor so players can make their to own puzzles. A level is simply a grid with items, similar to Sokoban levels (but my game is not Sokoban ;))

But I also want to be able to send these user created levels to a website or server. Is it possible in GLBasic to send files to a server? What would be the best way to do this. I guess you could use PHP scripts, similar to the php script to send and recieve online-highscores.. But I don't know that much about it, how would you send an entire file using php? :doubt:

On the news page it says that Wumbo's Adventure will have an online level library so I guess it is possible. Will the next version of GLBasic have added features or commands to do these kind of things?
#46
I saw "Life", the latest showroom entry and I thought it was pretty cool.. :good:
http://www.glbasic.com/showroom.php?site=games&game=life&lang=en

Unfortunately, it always starts with a random pattern, so I've written a little function to read in *.lif files. These are relatively simple files (plain-text) used to describe and exchange Life pattern. You can download these kind of files from many websites, for example here. I've also created a glbasic.lif, it display the GLBasic logo. 8) (see attachment)
Code (glbasic) Select
FUNCTION lifload: filename$
// load and interpret a Game of Life pattern file (*.lif)

LOCAL str$, px$, py$
LOCAL i
LOCAL x%, y%, scrx%, scry%

// clear
FOR y%=0 TO heigt%-1
FOR x%=0 TO width%-1
pl%[x%][y%] = 0
NEXT
NEXT

// get middle of screen
GETSCREENSIZE scrx%, scry%

generatie%=0

// open and read file
IF OPENFILE(1, filename$, 1)
WHILE (ENDOFFILE(1) = FALSE)
// read next line
READLINE 1, str$
str$ = str$ + "\n"
// command
IF (MID$(str$, 0, 1) = "#")
// P = position command, for example "#P -3 -1"
IF (MID$(str$, 1, 1) = "P")
str$ = MID$(str$, 3)
i = INSTR(str$, " ")
IF (i <> -1)
// get positions
px$ = MID$(str$, 0, i)
py$ = MID$(str$, i+1)
// string to int
    x% = INTEGER(px$) + (scrx% / 2)
y% = INTEGER(py$) + (scry% / 2)
ENDIF
ENDIF
// TODO: display comment lines on screen? "#D blah bla"
//IF (MID$(str$, 1, 1) = "D")
//ENDIF
ELSE
// cells, for example "*...***"
FOR i = 0 TO LEN(str$)
IF (MID$(str$, i, 1) = "*")
// not out of bounds
IF (x%+i >= 0) AND (y% >= 0) AND (x%+i < scrx%) AND (y% < scry%)
pl%[x%+i][y%] = 1
ENDIF
ENDIF
NEXT //i
y% = y% + 1
ENDIF
WEND
ENDIF

ENDFUNCTION

and in the sourcecode (provided in showroom download) you can replace "GOSUB rrand" with "lifload("glbasic.lif")"

It was written by someone only known as Goos (who is dutch I think, looking at some of the code), no e-mail or anything, so I hope he will read this topic.

[attachment deleted by admin]
#47
I'm new to GLBasic and just started to check it out, but I'm very impressed. Easy coding with awesome game results. :) I tried the Quantum game and looked at the code, and it runs great. I especially like the built in net-support for online highscore tables, and with only a few lines of code.

My question, will GLBasic have MacOS support at some point? Or is this not planned? I currently program in BlitzMax (newest BlitzBasic IDE) which has MacOS support. No MacOS support is for me the main reason not to use GLBasic. :|

Don't get me wrong, I know this is not a small thing to do, adding a completely new architecture/OS support to a compiler. But MacOS has a large userbase, most people play games on their mac. And Linux and GP2X seem, at least to me, relatively obscure platforms.