Game Maker's Garage Forum

Game Creation => GameMaker => Topic started by: GMG Kurt on March 09, 2011, 04:58:32 PM

Title: imagefile collide
Post by: GMG Kurt on March 09, 2011, 04:58:32 PM
Some of you may know I've been making a remake of TRON.
IF you didn't, well now you know
I've finished the movement, and have hit a road block
yes thats right IMAGEFILE COLLIDE.
I need to find a way to detect if a sprite has hit an imagefile.
so far I tried this:

ON TIMER 20
  xco = x - 5
  xco = xco / 21
  prexco = prex - 5
  prexco = prexco / 21
  yco = y - 5
  yco = yco / 21
  preyco = prey - 5
  preyco = preyco / 21
  string$ = string$ + "( prexco , preyco )"
  IF string$ CONTAINS "( xco , yco )" THEN
    ALERT oh dear your dead
  END IF
OFF TIMER

This doesn't seem to work, when I enter $string$$ it returns as ( prexco , preyco ) repeated over, and over again.
Please help me :'(
Title: Re: imagefile collide
Post by: Zoo on March 09, 2011, 08:20:12 PM
I can't answer your question, but wasn't TRON some kind of an 80's Sci Fi movie? I'm confused.
Title: Re: imagefile collide
Post by: Charlo on March 10, 2011, 06:29:39 PM
If I understand what you're trying to do, I think you have to use the str$ method to convert a numeric value to a string.  Right now, the way you're referencing the prexco/preyco variables, they're being treated as the literal strings "prexco" and "preyco".  
Title: Re: imagefile collide
Post by: Al Staffieri on March 10, 2011, 08:42:27 PM
Can you put the IMAGEFILE as a sprite instead?
Title: Re: imagefile collide
Post by: Al Staffieri on March 11, 2011, 01:30:29 PM
For GameMaker 3.9.95 I just added
bool = SPRITECOLLIDE spriteNum x1 y1 x2 y2

so you can check if a sprite collides with the rectangle area in x, y, x2, y2.
Title: Re: imagefile collide
Post by: GMG Kurt on March 12, 2011, 08:21:21 AM
Quote
I can't answer your question, but wasn't TRON some kind of an 80's Sci Fi movie? I'm confused.
yes, it was also a very popular arcade style game, based on the movie.
If you want to try it out heres a link: http://www.fltron.com/
This is only one of the modes though, most people think that this the only mode, but those people are wrong. The original game had a tank mode, a disc throwing battle, and something about a plane type thing, I think. I've never played the actual version, I only know about the other versions from my dad.
Title: Re: imagefile collide
Post by: GMG Kurt on March 12, 2011, 08:24:53 AM
Quote
Can you put the IMAGEFILE as a sprite instead?
No, I can't. every time the players sprite moves, it also places an imagefile behind him, so that it looks like the light cycle is leaving a trial, of light. Just like in the most famous TRON mode, where you have to box people in with your light cycle, so they hit your trail, and die. There are way over 8 Imagefiles, I can't do it with the current version of gamemaker, plus this seemed like a fine way I could recreate one of my favorite games, and try out this method.
Title: Re: imagefile collide
Post by: GMG Kurt on March 12, 2011, 08:31:00 AM
Quote
If I understand what you're trying to do, I think you have to use the str$ method to convert a numeric value to a string.  Right now, the way you're referencing the prexco/preyco variables, they're being treated as the literal strings "prexco" and "preyco".  

yes exactly, I need a way for the prexco (previous X coordinate) and the preyco (previous Y coordinate) to be added into the string$ as the number it's currently representing. (which would be the coordinate of the imagefile)

Quote
If I understand what you're trying to do, I think you have to use the str$ method to convert a numeric value to a string.  Right now, the way you're referencing the prexco/preyco variables, they're being treated as the literal strings "prexco" and "preyco".  

So tried that like this:


  xco = x - 5
  xco = xco / 21
  xco$ = CHR$ xco
  prexco = prex - 5
  prexco = prexco / 21
  prexco$ = CHR$ prexco
  yco = y - 5
  yco = yco / 21
  yco$ = CHR$ yco
  preyco = prey - 5
  preyco = preyco / 21
  preyco$ = CHR$ preyco
  string$ = string$ + "( $prexco$$ , $preyco$$ )"
  IF string$ CONTAINS "( $xco$$ , $yco$$ )" THEN
    ALERT oh dear you died
    ALERT $string$$
  END IF
END TIMER

IT didn't work ( $prexco$$ , $preyco$$ ) was just repeated over, and over again, but I think your onto something. I'll keep experimenting with this, but I'm not sure if I'm adding to the string$ correctly, are you supposed to surround the variable in '$' marks?
Title: Re: imagefile collide
Post by: GMG Kurt on March 20, 2011, 10:29:00 AM
I re-worked the code, and found
the problem is in the CHR$ variable,
so heres my code, remember that everything here is in TIMER 20, along with other irrelevant code, but I'm only showing you the relevant code:

LET
x = x value on the grid
y = y value on the grid
xco = x-coordinate (a smaller x value which is easier to understand
yco = y-coordinate as the latter
prex = x-value before the last keydown
prey = y-value before the last keydown
precos = prex, and prey coordinates in the form: (prex,prey)
aftcos = xco, and yco in the same form as above

TIMER 20
  xco = x - 5
  xco = xco / 21
  xco$ = CHR$ "xco"
  prexco = prex - 5
  prexco = prexco / 21
  prexco$ = CHR$ "prexco"
  yco = y - 5
  yco = yco / 21
  yco$ = CHR$ "yco"
  preyco = prey - 5
  preyco = preyco / 21
  preyco$ = CHR$ "preyco"
  precos$ = "("
  precos$ = precos$ + "$prexco$$"
  precos$ = precos$ + ","
  precos$ = precos$ + "$preyco$$"
  precos$ = precos$ + ")"
  aftcos$ = "("
  aftcos$ = aftcos$ + "$xco$$"
  aftcos$ = aftcos$ + ","
  aftcos$ = aftcos$ + "$yco$$"
  aftcos$ = aftcos$ + ")"
  string$ = string$ + $precos$$
  IF string$ CONTAINS $aftcos$$ THEN
    ALERT oh dear you died
    ALERT $string$$
  END IF
END TIMER
Title: Re: imagefile collide
Post by: Connors on March 20, 2011, 11:52:30 AM
So what is this code doing exactly? (I'm curious because I made a TRON game in TNT). How does it draw the lines?
Title: Re: imagefile collide
Post by: GMG Kurt on March 20, 2011, 01:50:44 PM
it's kind of hard to explain, the lines are drawn with imagefile, while the box that says 'use IMAGEFILE as an overlay' is selected. The computer finds out how to draw them with the previous keydown, and the current keydown.

The code I selected in the previouse reply controls the variables to log places the cycle has been, and whether it is currently on them. It's the code thats been giving me problems.

here's what I have so far. Its not done. I test codes in card 3, and card 4 has the actual game, and all the stuff we've talked about here.
http://www.mediafire.com/?v6yqwtf9eczyx

The code to draw the lines, is in the KEYDOWN block
Title: Re: imagefile collide
Post by: GMG Kurt on March 22, 2011, 03:46:59 PM
I still have no clue how to correctly use the CHR$ command. Can someone please give me a syntax example?
Title: Re: imagefile collide
Post by: Al Staffieri on March 22, 2011, 06:30:56 PM
Quote
I still have no clue how to correctly use the CHR$ command. Can someone please give me a syntax example?

Leave out the quotes. You have:
preyco$ = CHR$ "preyco"

It should be:
preyco$ = CHR$ preyco
Title: Re: imagefile collide
Post by: Silverwind on March 22, 2011, 06:31:09 PM
Code: [Select]
var1 = 50
var2$ = CHR$ var1

var2$ will now have a value of "50".
Title: Re: imagefile collide
Post by: GMG Kurt on March 27, 2011, 04:36:25 PM
Quote
Code: [Select]
var1 = 50
var2$ = CHR$ var1

var2$ will now have a value of "50".

When I tried this, plus a line that said: ALERT $var2$$
the alert box that came up said that var2$ was '2' so I tried it with another number. when I replaced 50 with a value of 100, and var2$ returned as 'd'  .
Title: Re: imagefile collide
Post by: Silverwind on March 27, 2011, 06:58:08 PM
Sorry, I'd just come back from church and was absolutely knackered when I wrote that. The correct command is of course STR$ (in place of CHR$), using exactly the same syntax.
Title: Re: imagefile collide
Post by: GMG Kurt on March 27, 2011, 07:43:35 PM
Quote
Sorry, I'd just come back from church and was absolutely knackered when I wrote that. The correct command is of course STR$ (in place of CHR$), using exactly the same syntax.
Thanks it worked, perfectly, and if you don't mind me asking. What does CHR$ even do? And how is it useful in a game?

EDIT:
the STR$ variable works fine integrated into my code, and I've encountered another error (oh jeez). It isn't adding the string variables as what they are, just their names.
So my question is: How do you add a string variable to a string variable as it's value.
Here's a link to my game, goto card 4, and you have to start the game by clicking the left arrow

http://www.mediafire.com/?v6yqwtf9eczyx

Thanks again, in advanced, for any help you can give me
P.S. how do I link to a page like most GM users use to let people download their games, all I can get is this one (above)
Title: Re: imagefile collide
Post by: Zoo on March 27, 2011, 08:08:57 PM
How do you download this without pro?
Title: Re: imagefile collide
Post by: Silverwind on March 28, 2011, 05:05:18 AM
Quote
How do you download this without pro?
You can download each file individually, but it would be easier if Kurt compressed the folder housing the game and its resources before uploading it. To do that, highlight the folder and click File in the finder bar and Compress "folder name" in the submenu.

Quote
Thanks it worked, perfectly, and if you don't mind me asking. What does CHR$ even do? And how is it useful in a game?
It's very unlikely that you'll ever use the CHR$ command in a game, and the explanation of what it does is somewhat complicated. Basically, all the standard keys on a keyboard have a number assigned to them (an ASCII value, which stands for "American Standard Code for Information Interchange"), and the ASC command returns the correct ASCII value of a string. For example, the capital J key has an ASCII value of 74, so the following code would result in var2 having a value of 74:

Code: [Select]
var1$ = "J"
var2 = ASC var1$

The CHR$ command does the exact opposite of this; it returns the ASCII character of an integer. The following code will result in var2$ having a value of "J":

Code: [Select]
var1 = 74
var2$ = CHR$ var1

You'll probably never use either commands, but if you do it'll be ASC, not CHR$. I use the ASC command in the Roguesoft RPG Engine to determine whenever a player presses the ESC key, as the ESC key doesn't return a keydown$ value:

Code: [Select]
ON KEYDOWN

  keydownASC = ASC keydown$

  IF keydownASC = 27 THEN
    '--- The ESC key was pressed
  END IF

END KEYDOWN

Quote
the STR$ variable works fine integrated into my code, and I've encountered another error (oh jeez). It isn't adding the string variables as what they are, just their names.
So my question is: How do you add a string variable to a string variable as it's value.
I'm not entirely sure what you mean, but if you're asking how to combine the value of two string variables together, it's easy peasy:

Code: [Select]
var1$ = "Silverwind"
var2$ = " the Great"
var3$ = var1$ + var2$

var3$ will now have a value of "Silverwind the Great". Check out my video tutorials on string manipulation:
http://alstaffieri.com/gmguide.html
Title: Re: imagefile collide
Post by: GMG Kurt on March 28, 2011, 05:55:40 PM
oh thanks you so much ;D  It worked perfectly. When writing this script I didn't really have a clear understanding of how, and when to use quotations, and dollar signs surrounding variables. Re-whatching your video really made it click (good job by the way on the video.)
I was trying to add string to sting like:
  aftcos$ = aftcos$ + "$yco$$"
when I should have added them like:
  aftcos$ = aftcos$ + yco$
Thanks so much. Here's an updated link to the mediafire: http://www.mediafire.com/?elutzm6lrits16b
P.S. how do I get the link to the page that most GameMakers Garage developers use to let people play their games?

EDIT: Never mind when you upload the folder as a ZIP it goes to the screen that I wanted.
Title: Re: imagefile collide
Post by: GMG Kurt on April 15, 2011, 11:30:19 AM
Over break I had a great idea. Different game modes. I'm not getting into that here, but it does require the game to seamlessly pass between cards. I changed the aftcos, and precos block to create an array where every coordinate is showed as marked, or unmarked. It seems to work to an extent, but the IMAGEFILE COLLIDE command started working up again. I found it was a glitch in place from the beginning of the code I didn't notice. here is the Timer block, and (updated) mediafire link. try maneuvering the cycle under a horizontal line, and you'll see the problem. (it kills you)

EDIT: ignore the part at the end about the death animation. It doesn't work, and won't until the is glitch is fixed. It is next on my checklist of this game's development.


http://www.mediafire.com/?by1brdv922mm6at

Thanks in advance for any help you can give

EDIT: the new arrangement of the preycos, and aftcos is because I wanted to make the background and trail carry over to other cards, since I'm running out of room, and thought it would be a good idea to have all of the different AI's in different cards. I'm not quiet sure if i'm going to use all of the 100 lines I have left for AI, so I thought I would at least think ahead this far.

EDIT: I got rid of the timer block, because it was so big and obnoxious, and I found one problem: The new way the preycos and aftcos were set up had a few points with the same value, so I defaulted back to what I had originaly
Title: Re: imagefile collide
Post by: GMG Kurt on April 20, 2011, 05:08:54 PM
I think I might have found the problem, but I'm not sure... at all. I think my string got too long, because it would add 7 more characters every time you move (I'm talking about the 'string$' variable, my death identifier.) So I think that it got too long, and wouldn't add any more of the values. Is this a possibility? Or is it something else that is wrong with my code?Please respond quickly, I'm almost done with these core mechanics.
Title: Re: imagefile collide
Post by: GMG Kurt on April 20, 2011, 05:37:06 PM
 ;D I think I've finally got it. I went into the section of the website called 'Articles and Tutorials' and I saw a document called 'how to fake an array.' Which is by Al Staffieri Jr. by the way, and it hit me how I can fix the bug. I can do it with a fake array. I'll tell you guys how it goes... if it works :-X
Title: Re: imagefile collide
Post by: GMG Kurt on April 28, 2011, 05:59:16 PM
Okay it's been a week since i got the idea to fix the way you lose in TRON formerly (and currently) known as the Precos and Aftcos block. It's been edited to check an array to see what type of trail has been left inside the block. The array posed two problems. One everything beneath the command wouldn't function, and Two it wouldn't register (click the spacebar for an alert window showing it's value.
I fixed the Former by moving it to the bottom of the list, but the later still is a problem.
The mediafire link has been updated:
http://www.mediafire.com/download.php?v7fsvx60tnhexd5

Please help. I think that it should just be a novice mistake, but I can't find anything wrong with it
P.S. if you encounter the other glitch the answer is "Yes I know about it, and it doesn't hamper gameplay testing in any way."
Title: Re: imagefile collide
Post by: GMG Kurt on April 29, 2011, 06:38:07 PM
I think I may cry. :'(
Trying to fix the problem I made it worse... I think
http://www.mediafire.com/download.php?dh2yvv4to95wu6q
check out the least confusion creating a fake array. Now every time I click the space bar to tell me what it equals it keeps saying LEFTARROW >:( This game has utterly spiraled out of control at the third to last core mechanic I need before coming out with a BETA. I hope the three months weren't for nothing :'(
EDIT: if your curious the last two core mechanics, are enemies, and the coveted turbo
Title: Re: imagefile collide
Post by: GMG Kurt on May 03, 2011, 07:28:42 PM
Is there a maximum amount of characters a string can hold? I think the string might be too long, and that might be causing the unexplainable bug.
Title: Re: imagefile collide
Post by: Al Staffieri on May 04, 2011, 10:28:12 AM
Maximum a string can hold is 255 characters.
Title: Re: imagefile collide
Post by: GMG Kurt on May 04, 2011, 09:29:23 PM
well that takes out that theory. I'm just going to make an old fashion array and see if it works.
Title: Re: imagefile collide
Post by: GMG Kurt on May 26, 2011, 05:57:38 PM
I found the error, and I'm going to fix it. Expect a Beta version before tuesday! It might be optimistic, but I think I can finish it fast, and soon. There are two error that I found. One is that a a variable that should've been a string variable didn't have a '$' after the name. The second one is that I'm not using the 'fake array' MID, LEFT, and RIGHT commands correctly. it would log ones and twos depending on whether you were vertical or horizontal, but not the way I wanted. It's kind of hard to explain. Press space for the value of array
http://www.mediafire.com/download.php?8r9cncg98xo2l0s