Fangames > Game Design
Post your Code Snippets
zaphod77:
This is for I wanna Be The Studio Engine YoYoYo Edition.
I've created a cherry that will after a number of ticks that you can assign after creation, aim itself at the player, and that will repeat the action a defined number of times. It can optionally change speed when it does this, and then change speed again each time after.
(click to show/hide)Information about object: objCherryRetargetPlayer
Sprite: sprCherry
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: objCherry
Children:
Mask:
No Physics Object
Create Event:
execute code:
event_inherited();
/// this cherry will aim itself at the player a certain time AFTER it's spawned.
homedelay=0; ///number of ticks to wait before each direction change.
homeretargets=0; /// how many times to change directions
hometimer=0; ///internal variable
changespeed=false; /// whether or not it should change speed when it changes direction.
newspeed=16; /// speed after first direction change, if changespeed=true.
speeddelta=0; /// amount to add or subtract from the speed above after each change, if changespeed=true. use negative values to slow it down.
Step Event:
execute code:
hometimer+=1;
if (hometimer>homedelay && homeretargets>0 && homedelay>0)
{
homeretargets-=1;
hometimer=0;
if (instance_exists(objPlayer)) /// only aim for Kid if he's alive.
{
direction=point_direction(x,y,objPlayer.x,objPlayer.y); ///aim for kid
}
if (changespeed=true)
{
speed=newspeed; ///change the speed
newspeed=newspeed+speeddelta; ///and adjust the speed for the next change
}
}
I modifed scrCreateShapes for testing this. you can, of course, make colored versions of this object easily enough.
There are many things you can do with this object.
1) make a shape that expands, then aims all it's cherries at you.
2) make a shot that curves towards you for a bit and accelerates
3) place a mine that speeds off in your direction a while later.
making versions of other/random colors is left as an exercise to the reader.
WetWookie:
Someone asked me for my water droplet code so here ya go. Object drips down blocks and slides along the edges of spikes.
(click to show/hide)
--- Code: ---Stat = 0; // 0 = flowing, 1 = falling
VSpd = 0.5;
HSpd = 0;
LastVC = 0;
LastHC = 0;
HStep = 0
NotPlaced = 0;
--- End code ---
(click to show/hide)
--- Code: ---if NotPlaced == 1
{
NotPlaced = 0;
bnum = irandom_range(1,instance_number(objBlock)-2);
cnt = 0;
with objBlock
{
other.cnt = other.cnt + 1;
if other.cnt == other.bnum
{
other.x = x + 16;
other.y = y + 16;
}
}
visible = true;
}
if Stat == 0
{
x = x + HSpd;
y = y + VSpd;
if place_empty(x,y)
{
VSpd = 0;
if place_empty(x - 1,y) == false {x -= 1;}
if place_empty(x + 1,y) == false {x += 1;}
HSpd = 0;
}
if place_empty(x,y)
{
VSpd = 0;
if place_empty(x - 2,y) == false {x -= 2;}
if place_empty(x + 2,y) == false {x += 2;}
HSpd = 0;
}
if place_empty(x,y)
{
Stat = 1;
HSpd = 0;
} else {
LastVC = choose(-VSpd,-VSpd / 2, LastVC, LastVC,0.05,0.1);
VSpd += LastVC;
if HStep <= 0
{
HStep = irandom_range(25,150);
HSpd = random_range(-0.05,0.05);
} else {
HStep -= 1;
}
if VSpd > 10
{
HSpd = 0;
VSpd = choose(0,1);
}
if VSpd < 0 {VSpd = 0;}
}
} else {
VSpd += 0.3;
y += VSpd;
x += HSpd;
if place_meeting(x, y, objBlock) || place_meeting(x, y, objPlayerKiller) || place_meeting(x, y, objPlayer)
{
VSpd = VSpd / 4;
HSpd = 0;
Stat = 0;
HStep = 0;
}
}
--- End code ---
(click to show/hide)
--- Code: ---y = 1;
x = irandom_range(100,room_width - 100);
--- End code ---
Smartkin:
People probably already made this thousands of times but decided to write this myself. This is a code that let's you make the object fade in and out, or just fade in, or just fade out - scrAlphaFade
Oh, yeah if you work in Studio you should have currentFade variable defined in the creation code of every object that will use this script.
Edit: I decided to go even further and created a script that will let you mess with fading any variable you want to - scrValFade
MrSlick:
https://klazen.com/gm/AjN
All credit goes to YoYo for this script. I only added too it.
The description says what it does and all the arguments are documented. :)
ADMIN EDIT: snippet edit panel was showing, be more careful next time.
patrickgh3:
I made a pretty nice pushable block that feels smooth, drops into 32px gaps, and is configurable. PM if you find any issues.
https://klazen.com/gm/eEq
EDIT: Updated version here: https://tinyurl.com/zx9ra6h
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version