Game Maker oddity

A place for people with an interest in developing new shmups.
Post Reply
User avatar
STG~PASI
Posts: 32
Joined: Fri Oct 08, 2010 5:46 am

Game Maker oddity

Post by STG~PASI »

I've been trying to make an enemy shoot towards me.
I remember being able to do this before, but setting the
bullets direction in create moving instance to "x,y,ship.x,ship.y" doesnt seem to work.

Halp.

EDIT

Oh, forgot to mention. Moving around does affect the
direction of enemy fire, yet its still not going anywhere near "ship".
"Use a bomb when it comes to a pinch. It is wasteful to die before using bomb."
User avatar
S20-TBL
Posts: 440
Joined: Mon Jan 18, 2010 6:48 am
Location: Frying over a jungle and saving the nature
Contact:

Re: Game Maker oddity

Post by S20-TBL »

Put this in the bullet's Create event:

Code: Select all

move_towards_point(ship.x,ship.y,<speed>);
Just replace <speed> with any value you like. This will make a bullet that moves towards the player's last known (x,y) coordinate upon creation.
--Papilio v0.9 Beta now on itch.io! (development thread)--
Xyga wrote:Blondest eyelashes ever.
User avatar
STG~PASI
Posts: 32
Joined: Fri Oct 08, 2010 5:46 am

Re: Game Maker oddity

Post by STG~PASI »

S20-TBL wrote:Put this in the bullet's Create event:

Code: Select all

move_towards_point(ship.x,ship.y,<speed>);
Just replace <speed> with any value you like. This will make a bullet that moves towards the player's last known (x,y) coordinate upon creation.
The problem there is making bullet patterns, it becomes much more complicated as every bullet would always just move towards the player.

point_direction(x,y,ship.x,ship.y) did the trick !
"Use a bomb when it comes to a pinch. It is wasteful to die before using bomb."
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: Game Maker oddity

Post by Rozyrg »

I don' t know how much experience you have with scripting in GM; but if you don't, this would be a good time to get your feet wet. It makes handling things like bullet patterns much, MUCH easier.

I actually learned my first bit of GML (basic bullet making scripts) from a few forumers here. :)
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Game Maker oddity

Post by BPzeBanshee »

While we're on the subject of bullets in Game Maker, what would be the best method for one to create a good bullet pattern? Ive been using timelines myself and trying to put the direction-based stuff into the enemy itself to pass to the child bullet, but I'm certain there's gotta be an easier way with scripts.
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: Game Maker oddity

Post by Rozyrg »

There was a pretty good thread on it awhile back... I'll have to see if I can find it.

What I do:

- All the basic stats for different patterns (speed, number of bullets per burst, spread, etc) are kept in a single script.
- The enemy is given a few variables (one for basic type - spread, homing, etc., the other to call the specific pattern's stats)
- Once the firing conditions are met, the enemy creates a bullet generator object, which calls the pattern 'list', produces the pattern, then destroys itself. (The point of creating a separate object is so that a pattern will not 'warp' as the enemy moves, nor will killing an enemy before it finishes firing create an incomplete pattern.)

Basic bullet creation script:

Code: Select all

bullet=instance_create(argument0,argument1,bullet_object)
bullet.speed=argument2
bullet.direction=argument3
All the more complex firing scripts (for spreads, etc.) use this basic one, so all the same stuff applies. The hierarchy goes something like:

Enemy>Bullet generator>Pattern type script(Spread,Homing,etc.)>Basic bullet script

As for making the actual patterns, I just use timers in the generator's step event:

Code: Select all

//bullet_burst_spacing,bullet_speed,bullet_direction would all be loaded by the stat script

burst_timer+=1

if (burst_timer=bullet_burst_spacing)
{
burst_timer=0

if (burst<bullet_burst_number)
{bulletscript(x,y,bullet_speed,bullet_direction)}
 else {instance_destroy()} //destroys obj. once pattern is completed
}
Spreads and other effects you can do fairly easily by tweaking the direction and x,y position variables as the script runs. It takes a little figuring out; but once you grasp the basic idea, you can do all kinds of neat stuff. :3
EddyMRA
Posts: 798
Joined: Wed Jan 26, 2005 9:36 am
Location: San Diego, CA, USA

Re: Game Maker oddity

Post by EddyMRA »

This is the aimed spread shot script I use for Xeno Fighters R:

Code: Select all

/*
    Aimed bullet spread shot script
    by Alluro
    
    Function:
        Shoots an arc of bullets aimed at the player.
    
    Usage:
        aimedspreadshot (origin_x, origin_y, bullettype, shootsound, arc, numbullets)
        
    Arguments:
        originx,     : the x/y location where the shot will originate
        originy
        bullettype   : the bullet OBJECT to shoot
        shootsound   : the sound to play when shooting (-1 plays no sound)
        arc          : arc (in degrees) the spread will cover
        numbullets   : the number of bullets in the spread
        bulletspeed  : the speed the bullets will travel
        
    Returns:
        none

*/

//Variables from arguments
origin_x    = argument0
origin_y    = argument1
bullettype  = argument2
shootsound  = argument3
arc         = argument4
numbullets  = argument5
bulletspeed = argument6

//Get direction to shoot (from origin to player)
shootdir   = point_direction (origin_x, origin_y, obj_playerhitbox.x, obj_playerhitbox.y)

if numbullets > 1
    arcstart   = (shootdir - (arc / 2))
else
    arcstart   = shootdir
    
//play shoot sound (-1 plays no sound)
if shootsound >= 0
{
    sound_stop (shootsound)
    sound_play (shootsound)
}

for (bulletloop = 0; bulletloop < numbullets; bulletloop += 1)
{
    mybullet = instance_create (origin_x, origin_y, bullettype)
    mybullet.direction = arcstart
    mybullet.speed = bulletspeed
    if numbullets > 1
        arcstart += arc / (numbullets - 1)
}
The downside is that you cannot easily set angles between each bullet in the spread (i.e. make a 5-way spread with each bullet 10 degrees apart). In this script, you need to do the math in your head, so that example spread would result in this script call:

Code: Select all

aimedspreadshot (enemy.x, enemy.y, obj_bullet, shoot_sound, 50, 5, bulletspeed)
The age of Alluro and JudgeSpear is over.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Game Maker oddity

Post by BPzeBanshee »

Hope yous dont mind me making use of your code, cause I spent a few hours making this work tonight:

A Bullet Engine Example.

It makes use of the Game Maker code snippets seen here and uses them. I made it because I had trouble imagining how it'd work from looking at the code and because I was bored. I'm also used to precise commenting in case I forget how I've made something before (Ive had this happen before as seen within the file itself for Draw functions in GML) and to use as examples for people getting used to Game Maker and GML in general, so it's not some kind of making people seem stupid at all.

/tiredrant

Should I work on this more? I'd like to see a open-source Shmup engine template people can use for Game Maker and I may just make it myself once I get some sleep and work on my own game project and figure out how to use Game Maker to the full extent of the jam. Duke Nukem Forever may come sooner though. :lol:
User avatar
S20-TBL
Posts: 440
Joined: Mon Jan 18, 2010 6:48 am
Location: Frying over a jungle and saving the nature
Contact:

Re: Game Maker oddity

Post by S20-TBL »

BPzeBanshee wrote:Should I work on this more? I'd like to see a open-source Shmup engine template people can use for Game Maker and I may just make it myself once I get some sleep and work on my own game project and figure out how to use Game Maker to the full extent of the jam. Duke Nukem Forever may come sooner though.
Forget Duke Nukem Forever, just make the full extent of the jam. 8)

I remember Pixel_Outlaw made a similar code sample a while back, albeit with a slightly more complicated angle calculation algorithm. [url=http://s_a_2_d.sitesled.com/bullet%20Hell%20EngineGM5.gmd]Here's a GM5 version of his code[/url], which is designed more to create a...rather familiar-looking bullet hell pattern.

I'd like to study and use your spreadshot algorithm in my own game BTW, if it's OK with you. :) Right now my own script is a bit unwieldy.

EDIT: Oh, it's Alluro's code. JudgeSpear for president! (or the next JSF candidate, whichever you prefer...)

EDIT 2: I decided to throw in my own code into the mix. An open source shmup engine is too good to pass up.

This is a script for a basic bullet ring that changes aim depending on the player's position.

Code: Select all

density = argument0;  // controls the density of the circle pattern, in degrees
origin_x = argument1; // x coordinate of the bullet's origin
origin_y = argument2; // y coordinate of the bullet's origin
obj_dist = argument3; // distance from object at which bullet will be created
b_type = argument4;   // bullet object to be created
target = argument5;   // target object the bullet is supposed to aim at
b_speed = argument6;  // bullet speed

var _x, _y, bullet;
for (i=0; i<360; i+=density)   // controls the density of the bullet ring; smaller numbers mean tighter patterns
{
        _x = origin_x + lengthdir_x(obj_dist, i);   // distance from the origin at which the bullet will spawn
        _y = origin_y + lengthdir_y(obj_dist, i);
        _bullet = instance_create(_x, _y, b_type);
        _bullet.direction=point_direction(x, y, argument5.x, argument5.y)+i;
        _bullet.speed=2;   // a negative value will make the bullet go towards the origin of the object firing it
}
That last bit can create a nifty Mushihime-sama TLB-like appearance, if you cause the bullets to manifest a certain radius away from the object generating them (hence the use of lengthdir).

Credit goes to GodHand from the Game Maker forums, from which I originally got the base for this code a couple years back.
--Papilio v0.9 Beta now on itch.io! (development thread)--
Xyga wrote:Blondest eyelashes ever.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Game Maker oddity

Post by BPzeBanshee »

That stuff looks quite interesting S20, if I can get hold of a way to open the GM5 file (I couldve sworn I had a Pro GM6 lying around somewhere....) I'll ask Pixel_Outlaw for using some of the stuff in the engine example too. I will be quite busy over the next few days for purposes of being online but I seem to have plenty of spare time later on at night so I can code stuff with a purpose then.

Eventually I'll figure out how to create multiple scripts for different purposes myself and maybe be able to make a Shmup stage in this thing using Timelines and a basic looping background.

Also, what do you think about the whole mouse-controlled thing? I have a similar thing going on for my main game project but I use WSAD for controls and currently the way the weapons are coded for random spread is not to my liking (I somehow managed to fix the variable spread based on mouse position in this demo actually). All stuff I put into this demonstration will find its way into my main game project in one form or another.
User avatar
Rozyrg
Posts: 918
Joined: Wed Feb 11, 2009 12:03 am
Location: Southeast USA

Re: Game Maker oddity

Post by Rozyrg »

The way I do bullet 'rings' is just borrowing the same simple code I use for making spread patterns... something like:

(bulletscript)

Code: Select all

bullet=instance_create(argument0,argument1,bullet_object)
bullet.speed=argument2
bullet.direction=argument3
dividing half of 360 (since it will produce bullets on both sides) by the density you want (angle_adjust)

Code: Select all

var spread_number,n;
spread_number= 180/angle_adjust

repeat (spread_number)
{
n+=1
 switch (n)
 {
 //first set has a 'center' bullet moving at direction 'default_angle', which could target the player or  just be the angle the enemy is currently facing

 case 1:

  bulletscript(x,y,default_speed,default_angle) 
  bulletscript(x,y,default_speed,default_angle+angle_adjust) 
  bulletscript(x,y,default_speed,default_angle-angle_adjust) 
  ;break;

//subsequent sets lack the center aimed bullet

 default:

  bulletscript(x,y,default_speed,default_angle+(angle_adjust*n)) 
  bulletscript(x,y,default_speed,default_angle-(angle_adjust*n)) 
 ;break;
 }
}


You could obviously add extra repeats to make longer strings or bursts of bullets. I personally prefer to use timers for that. (this *may* produce some unwanted gaps, though... just doing this off the top of my head.)

Anyways, it is cool to see some slightly different approaches with all this stuff though. Also, for the looping backgrounds...if you don't use the GM's stock looping effect (which is painfully limited if I remember correctly), that can be a bit of a beginner's snag, too... so feel free to ask about that if you run into trouble. Took me forever to get right. :D
User avatar
S20-TBL
Posts: 440
Joined: Mon Jan 18, 2010 6:48 am
Location: Frying over a jungle and saving the nature
Contact:

Re: Game Maker oddity

Post by S20-TBL »

BPzeBanshee wrote:That stuff looks quite interesting S20, if I can get hold of a way to open the GM5 file (I couldve sworn I had a Pro GM6 lying around somewhere....) I'll ask Pixel_Outlaw for using some of the stuff in the engine example too.
GM8 is capable of running GM5 files, I tried it myself last night and it works properly. :)

Took me a while to locate it though. The original file IIRC was either a GM7 or GM6 one. Here's the Shmup-Dev thread from which I got the download, but all the other download links in it are broken except for the one I gave you.
--Papilio v0.9 Beta now on itch.io! (development thread)--
Xyga wrote:Blondest eyelashes ever.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Game Maker oddity

Post by BPzeBanshee »

S20-TBL wrote:
BPzeBanshee wrote:That stuff looks quite interesting S20, if I can get hold of a way to open the GM5 file (I couldve sworn I had a Pro GM6 lying around somewhere....) I'll ask Pixel_Outlaw for using some of the stuff in the engine example too.
GM8 is capable of running GM5 files, I tried it myself last night and it works properly. :)

Took me a while to locate it though. The original file IIRC was either a GM7 or GM6 one. Here's the Shmup-Dev thread from which I got the download, but all the other download links in it are broken except for the one I gave you.
Cool, thanks, tried the file shortly after I posted and found it worked. :roll:
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Game Maker oddity

Post by BPzeBanshee »

Well I made some use of your circle code S20, and somehow I created something vaguely similar to Dodonpachi's first boss spinning attack. I'll work on it more, put the shot into a script more (since currently its locked in as a User Defined Event and the circle attack that follows uses your script) and at the moment it's all heavily fiddling around with variable timers though. Gets me lost frequently.

When I get time I'll work on it more and maybe post an EXE (or GMK if you're really interested in my hacky code).
User avatar
S20-TBL
Posts: 440
Joined: Mon Jan 18, 2010 6:48 am
Location: Frying over a jungle and saving the nature
Contact:

Re: Game Maker oddity

Post by S20-TBL »

BPzeBanshee: No prob, glad you found a use for it. :)

I've been thinking though. Since the original question has already been answered, why don't we have the thread renamed to "Open-Source Game Maker Shmup Engine WIP"?

Also, regarding your question about the mouse-controlled ship...Fraxy perhaps? :P Coupled with a WASD movement scheme it would work well with a free-roaming shmup along the lines of Sprite's old work ZugyA DX.
--Papilio v0.9 Beta now on itch.io! (development thread)--
Xyga wrote:Blondest eyelashes ever.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Game Maker oddity

Post by BPzeBanshee »

S20-TBL wrote:BPzeBanshee: No prob, glad you found a use for it. :)

I've been thinking though. Since the original question has already been answered, why don't we have the thread renamed to "Open-Source Game Maker Shmup Engine WIP"?

Also, regarding your question about the mouse-controlled ship...Fraxy perhaps? :P Coupled with a WASD movement scheme it would work well with a free-roaming shmup along the lines of Sprite's old work ZugyA DX.
I can make a separate thread if the mods want it.

My main game project used WSAD for movements and was vertically-scrolling but omnidirectional aiming. Since I originally started it just as I was learning GM7 in school I left it at 30 FPS at 800x600 resolution. Starting from scratch I've been keeping it at 800x600 though it'll be 60 FPS and geared around being that size.

And as much as I see stuff like Fraxy and Danmakfu (I think that's what it's called, Sasupoika remade Evacaneer DOOM on it and I saw a YouTube vid for it the other day), I'd rather stick with Game Maker as if this thing actually kicks off and I can do stuff with it it can be used and potentially ported.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Game Maker oddity

Post by BPzeBanshee »

Well its taken me two full days but I built another GMK from scratch and then imported the resources from the one I posted earlier, and to make things easier in the long run I made a separate thread for it here. :D
Getting closer and closer to the goal of the 'full extent of the jam' now. :lol:
User avatar
S20-TBL
Posts: 440
Joined: Mon Jan 18, 2010 6:48 am
Location: Frying over a jungle and saving the nature
Contact:

Re: Game Maker oddity

Post by S20-TBL »

I'm reviving this thread. Maybe we need to give it a new title, though. Something like "Game Maker Developer Thread".

Anyway, I have a question regarding option/helper movement. What types of techniques are available for recreating the multiple movement in Gradius?

So far I have this method (taken from the GMC forums):

Code: Select all

//CREATE CODE
//CODE
qqx=ds_queue_create() 
qqy=ds_queue_create()

//BEGIN STEP CODE
//CODE
if global.morto = 1 {exit}

    length = 10*number
    if global.movim = 1
         {
         ds_queue_enqueue(qqx,obj_ship.x)
         ds_queue_enqueue( qqy,obj_ship.y)
         size += 1
         }
  
    if size > length
         {
         x = ds_queue_head(qqx)
         y = ds_queue_head(qqy)
         ds_queue_dequeue(qqx) 
        ds_queue_dequeue( qqy)
         size -= 1
         }
This method works by queueing the player ship's (x,y) coords into a datastructure, then calculating the distance between the ship and the multiple. If the ship is moving (global.movim) and the distance between the two objects exceeds the maximum allotted, the multiple will then call up the queued ship coordinate variables and adjust its own coordinates accordingly.

Normally, this method works like a dream when using a room that is the same the size as the viewport. HOWEVER. If you use a large room with an automatically scrolling view, and your ship scrolls along with that viewport, what happens is that the multiples will fall back by several pixels whenever you move, depending on where you stopped and how long you remained idle.

One way I dealt with this is by removing the "if" statement that checks whether the ship is moving or not, and just allowed the multiple to queue and de-queue its coordinates continously. However, this always caused it to center itself on the ship's origin when you aren't moving, since the multiple was always checking its coordinates.

The current method I use is simply to check for the distance between the multiple and the ship, and cause the multiple to move towards the ship at a fixed speed whenever that distance is exceeded. However, the obvious downside is that it causes the multiple to not accurately trail the ship's last position, instead stopping cold whenever it lies within the distance threshold and only moving when you're far enough from it.
--Papilio v0.9 Beta now on itch.io! (development thread)--
Xyga wrote:Blondest eyelashes ever.
User avatar
BPzeBanshee
Posts: 4859
Joined: Sun Feb 08, 2009 3:59 am

Re: Game Maker oddity

Post by BPzeBanshee »

I have no idea how I'd go about doing that but with that normal code, wouldnt priority queues be better? I'm sure there was something of the kind in GM when I last looked at it but that may be my memory playing up.

Now that you've brought up this thread however, I've got a problem of my own:

Here's my code example of my issue.

I feel like an idiot for not immediately seeing an easier way to do this but as it stands I have no idea why it plays up.

I came up with pretty much this for adding a configurable Deadzone function into GMOSSE. I swear I've done it exactly the same as the other functions that are there in the options menu but for some reason moving left and right a certain amount of times results in the dz variable not being modified and as a result the thing reverts to the default text "WTF". In GMOSSE this made the game come up with an error because I had no default event in my case-switch-break for deciding what 'dz' would be according to 'global.deadzone'.

I suspect it's because I'm using decimal numbers, since that's the only thing that's different from the other options, but why would it work a certain amount of times moving left and right and then play up?
And why can't I add variables in whatever order I want after "anymessagehere" in the draw_text function?
That second percentage that comes up when WTF appears is how I finally managed to figure out a workaround by drawing the % sign separately from the number and then one of the lines disappearing and the other saying "Exact" when global.deadzone = 0.

Really, strange brainfuck. I'm sure there's a logical explanation for it but I'm clearly missing it.
User avatar
S20-TBL
Posts: 440
Joined: Mon Jan 18, 2010 6:48 am
Location: Frying over a jungle and saving the nature
Contact:

Re: Game Maker oddity

Post by S20-TBL »

I saw that adding a second object caused more problems than was initially thought--press Left and Right enough times and the message handling will eventually become confused. Try this:

http://www.mediafire.com/?3p8e2uwbckko7nb

I got rid of the extensive switch-case loop in the Step event and just calculated dz using round(global.LOL*100) to get rid of the decimals, added a second variable that would trigger a message in the draw event if dz exceeds 60, then disabled the second object entirely. I tested it in Debug mode and all the variables work fine, but I don't know if that's what you need.

As for priority queues, I'll look into it, thanks. :D
--Papilio v0.9 Beta now on itch.io! (development thread)--
Xyga wrote:Blondest eyelashes ever.
Post Reply