Search thousands of free JavaScript snippets that you can quickly copy and paste into your web pages. Get free JavaScript tutorials, references, code, menus, calendars, popup windows, games, and much more.
gamemaker fire projectile
obj_source
global left release
projectile=instance_create(x,y,obj_projectile);//create projectile
projectile.direction=point_direction(x,y,mouse_x,mouse_y);//set direction to mouse
projectile.speed=4;//set the speed
gamemaker breakout remake
Information about object:
Sprite: spr_ball
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code: motion_set(random(180),3);//start ball moving
Collision Event with object obj_wall_tlr:
execute code: move_bounce_all(true);//bounce off walls
Collision Event with object obj_wall_bottom:
execute code: show_message("Game Over");//die when hit bottom game_restart();
Collision Event with object obj_player_bat:
execute code: move_bounce_all(true);//bounce off the bat
Collision Event with object obj_stone_blue:
execute code: move_bounce_all(true);//bounce off brick
Information about object: obj_player_bat
Sprite: spr_player_bat Solid: false Visible: true Depth: 0 Persistent: false Parent:Children: Mask: No Physics ObjectStep Event:execute code: //simple movement code if (keyboard_check(vk_left)) {x-=5;} if (keyboard_check(vk_right)) {x+=5;}Information about object: obj_stone_blueSprite: spr_stone_blue Solid: true Visible: true Depth: 0 Persistent: false Parent:Children: Mask: No Physics ObjectCollision Event with object <undefined>:execute code: instance_destroy();Draw Event:execute code: draw_sprite(spr_stone_blue,0,x,y);
Gamemaker Backstab/teleport
obj_player
create event:
spawn_id = 0
step event:
inst = instance_place(x,y,obj_spawn_point)
if inst//create/update spawn point
{
spawn_id = inst
}
if (keyboard_check(ord('T')))//move to last spawn point
{
x=spawn_id.x;
y=spawn_id.y;
}
//movement code
if (keyboard_check(ord('A'))) {x-=5;}
if (keyboard_check(ord('D'))) {x+=5;}
if (keyboard_check(ord('W'))) {y-=5;}
if (keyboard_check(ord('S'))) {y+=5;}
obj_enemy
step event:
x++
create event:
spawn_id = 0
step event:
inst = instance_place(x,y,obj_spawn_point)
if inst//create/update spawn point
{
spawn_id = inst
}
if (keyboard_check(ord('T')))//move to last spawn point
{
x=spawn_id.x;
y=spawn_id.y;
}
//movement code
if (keyboard_check(ord('A'))) {x-=5;}
if (keyboard_check(ord('D'))) {x+=5;}
if (keyboard_check(ord('W'))) {y-=5;}
if (keyboard_check(ord('S'))) {y+=5;}
obj_enemy
step event:
x++
Draw Text with Shadow gamemaker
obj_example:
create event:
text="This is some random text to show a shadow of text.";//set text to draw
draw event:
draw_set_font(font_example);//set the font to use
draw_set_colour(c_black);//set the colour for shadow
draw_text(40-1,40-1,text);//draw text offset
draw_set_colour(c_red);//set draw colour
draw_text(40,40,text);//draw top main text
create event:
text="This is some random text to show a shadow of text.";//set text to draw
draw event:
draw_set_font(font_example);//set the font to use
draw_set_colour(c_black);//set the colour for shadow
draw_text(40-1,40-1,text);//draw text offset
draw_set_colour(c_red);//set draw colour
draw_text(40,40,text);//draw top main text
gamemaker dictionary check
obj_dict
create event:
dictionary=ds_list_create();//create a ds list to hold words
dic_file=file_text_open_read("dictionary.txt"); //open text file with words
while(!file_text_eof(dic_file))//repeat until end of book
{
word=file_text_read_string(dic_file);//get next word
ds_list_add(dictionary,word);//add to ds list
file_text_readln(dic_file);//read to next line
}
create event:
dictionary=ds_list_create();//create a ds list to hold words
dic_file=file_text_open_read("dictionary.txt"); //open text file with words
while(!file_text_eof(dic_file))//repeat until end of book
{
word=file_text_read_string(dic_file);//get next word
ds_list_add(dictionary,word);//add to ds list
file_text_readln(dic_file);//read to next line
}
step event:
word_to_find=get_string("word","");
position = ds_list_find_index(dictionary, word_to_find);
if position>0
{
show_message("Found");
}
else
{
show_message("Not Found");
}
gamemaker Spawn enemies in a random specified location
obj_player
create event:
spawn_x=x;//set initial spawn points
spawn_y=y;
step event:
//movement code
if (keyboard_check(ord('A'))) {x-=5;}
if (keyboard_check(ord('D'))) {x+=5;}
if (keyboard_check(ord('W'))) {y-=5;}
if (keyboard_check(ord('S'))) {y+=5;}
if (keyboard_check(ord('T')))//move to last spawn point
{
x=spawn_x;
y=spawn_y;
}
if place_meeting(x,y,obj_spawn_point)//create/update spawn point
{
spawn_x=other.x;
spawn_y=other.y;
}
GAMEMAKER Save Highscore to INI
OBJ_SCOREHIGHSCORE
CREATE EVENT
ini_open("scores.ini");//open file
global.highscore=ini_read_real("scores","high",0);//load scores high if present, otherwise set as 0
ini_close();//close ini
DRAW EVENT
draw_text(100,100,"Highest Score:="+string(global.highscore));//draw value of global.highscore
OBJ_BUTTON
score= get_integer("Enter A Score:", 0);//get an integer
if score>global.highscore//do this if bigger than current score
{
ini_open("scores.ini");//open ini
ini_write_real("scores","high",score);//write a value
ini_close();//close value
global.highscore=score;//update highscore
show_message("High Score Updated");//message
}
else//do this if not bigger than current score
{
show_message("Score Is Not Bigger Than Current Highscore");//message
}
CREATE EVENT
ini_open("scores.ini");//open file
global.highscore=ini_read_real("scores","high",0);//load scores high if present, otherwise set as 0
ini_close();//close ini
DRAW EVENT
draw_text(100,100,"Highest Score:="+string(global.highscore));//draw value of global.highscore
OBJ_BUTTON
score= get_integer("Enter A Score:", 0);//get an integer
if score>global.highscore//do this if bigger than current score
{
ini_open("scores.ini");//open ini
ini_write_real("scores","high",score);//write a value
ini_close();//close value
global.highscore=score;//update highscore
show_message("High Score Updated");//message
}
else//do this if not bigger than current score
{
show_message("Score Is Not Bigger Than Current Highscore");//message
}
Gamemaker Substitution Cipher
create event:
alpha_src = " 0123456789abcdefghijklmnopqrstuwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//Plain Text
alpha_dst = "tuwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789abcdefghijklmnopqrs";//Encoded Text
text1 = get_string("Source:", "");//Get string to convert
index = 1;//position in Plain text
str = ""; // result
for (var index = 1; index < string_length(text1)+1; index += 1)
{
char = string_char_at(text1, index);//get character at position in string
pos = string_pos(char, alpha_src);//find position of letter in Plain Text
if (pos > 0)
{
// if char occurs in source alphabet, add
// according one from destination alphabet
// to output
str += string_char_at(alpha_dst, pos);//At letter from position in Encoded
}
else
{
// otherwise just add itself
str += char;
}
}
result=str;//result is finished encoded
show_message(result);//show encoded message
alpha_src = " 0123456789abcdefghijklmnopqrstuwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//Plain Text
alpha_dst = "tuwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789abcdefghijklmnopqrs";//Encoded Text
text1 = get_string("Source:", "");//Get string to convert
index = 1;//position in Plain text
str = ""; // result
for (var index = 1; index < string_length(text1)+1; index += 1)
{
char = string_char_at(text1, index);//get character at position in string
pos = string_pos(char, alpha_src);//find position of letter in Plain Text
if (pos > 0)
{
// if char occurs in source alphabet, add
// according one from destination alphabet
// to output
str += string_char_at(alpha_dst, pos);//At letter from position in Encoded
}
else
{
// otherwise just add itself
str += char;
}
}
result=str;//result is finished encoded
show_message(result);//show encoded message
Gamemaker Random Dice Roller
create event:
//set up dice
dice1=0;
dice2=0;
dice3=0;
dice4=0;
dice5=0;
step event:
if position_meeting(mouse_x,mouse_y,id) && mouse_check_button_released(mb_left)//if button press released
{
dice1=irandom_range(1,6);//choose a random value for dice
dice2=irandom_range(1,6);
dice3=irandom_range(1,6);
dice4=irandom_range(1,6);
dice5=irandom_range(1,6);
}
draw event:
draw_self();
draw_sprite(spr_dice,dice1,50,50);//draw choosen sub image
draw_sprite(spr_dice,dice2,150,50);
draw_sprite(spr_dice,dice3,250,50);
draw_sprite(spr_dice,dice4,350,50);
draw_sprite(spr_dice,dice5,450,50);
//set up dice
dice1=0;
dice2=0;
dice3=0;
dice4=0;
dice5=0;
step event:
if position_meeting(mouse_x,mouse_y,id) && mouse_check_button_released(mb_left)//if button press released
{
dice1=irandom_range(1,6);//choose a random value for dice
dice2=irandom_range(1,6);
dice3=irandom_range(1,6);
dice4=irandom_range(1,6);
dice5=irandom_range(1,6);
}
draw event:
draw_self();
draw_sprite(spr_dice,dice1,50,50);//draw choosen sub image
draw_sprite(spr_dice,dice2,150,50);
draw_sprite(spr_dice,dice3,250,50);
draw_sprite(spr_dice,dice4,350,50);
draw_sprite(spr_dice,dice5,450,50);
GAmeMaker Vertical Credits Scrolling
Create Event:
text="(c) Lorem##
Video - Ipsum##
Sound - Dolor##
Stunts - Sit##
Editing - Amet##
";//credits - ## for line break
x=room_width/2;//find middle of room
y=room_height+50;//start 50 pixels off of the room
height=string_height(text);//height of text in pixels
Step Event:
y-=0.5;//move up screen
if y==(0-height) instance_destroy();//if off screen destroy
Draw Event:
draw_set_halign(fa_center);//set allignment
draw_text(x,y,text);
text="(c) Lorem##
Video - Ipsum##
Sound - Dolor##
Stunts - Sit##
Editing - Amet##
";//credits - ## for line break
x=room_width/2;//find middle of room
y=room_height+50;//start 50 pixels off of the room
height=string_height(text);//height of text in pixels
Step Event:
y-=0.5;//move up screen
if y==(0-height) instance_destroy();//if off screen destroy
Draw Event:
draw_set_halign(fa_center);//set allignment
draw_text(x,y,text);
GAME MAKER Create a Shadow
DRAW EVENT:
draw_sprite_ext(spr_duck, 0, x-2, y-2, 1, 1, -5, c_black, 1 );
draw_self();
draw_sprite_ext(spr_duck, 0, x-2, y-2, 1, 1, -5, c_black, 1 );
draw_self();
GAMEMAKER ROOM WRAPPING
OBJ_PLAYER
STEP EVENT:
///keyboard movement
if (keyboard_check(ord('A'))) {x-=5;}
if (keyboard_check(ord('D'))) {x+=5;}
if (keyboard_check(ord('W'))) {y-=5;}
if (keyboard_check(ord('S'))) {y+=5;}
if x>room_width+1 //if off edge of room right
{
x=1; //move to other side
}
if x<-1 //if off edge of room left
{
x=room_width-1; //move to other side
}
if y>room_height+1 //if off edge of room bottom
{
y=1; //move to other side
}
if y<-1 //if off edge of room top
{
y=room_height-1; //move to other side
}
[gamemaker] Pop-Up RPG Style Text Box
obj_message
create_event
global.message=ds_list_create();//create a ds list to hold messages
can_show=true;//set that a message can show
to_draw="";//set text to draw to ""
alarm 0 event
///alarm0 set alarm1
alarm[1]=room_speed*1;//create a short pause
to_draw="";//remove text to show
alarm 1 event:
///set as able to show
can_show=true;//allow message to show
step event:
///check if message waiting
check=ds_list_size(global.message);//get no of messages waiting
if check>0 && can_show//do this if more than one message and can show
{
to_draw=ds_list_find_value(global.message,0);//get message from top of ds list
ds_list_delete(global.message,0);//delete this message
can_show=false;//prevent showing
alarm[0]=room_speed*4;//create a pause
}
draw event:
///draw message
if to_draw!=""//do if there is a message waiting
{
//draw a background box
draw_set_colour(c_blue);
draw_rectangle(100,280,700,320,false);
//draw a message
draw_set_font(font_message);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_colour(c_red);
draw_text(400+1,300+1,to_draw);
draw_set_colour(c_white);
draw_text(400,300,to_draw);
}
obj_player
release event:
//choose an example message and sent to scriptmessage=choose("this is a message","this another message","this is yet another message");
scr_message(message);
scr_message
//add message to a ds list
ds_list_add(global.message,argument0);
[GAMEMAKER] Random Sentence Generator
create event:
sentence="";
draw event:
draw_text(50,50,sentence);
press s event:
name=choose("Edward","Lance","Lorilla");
what=choose("went swimming","ate chocolate");
where=choose("in the park","at the cinema","at the beach");
name2=choose("with Lorem","with Ipsum","With Dolor");
when=choose("on Monday","yesterday","last week");
space=" ";
sentence=name+space+what+space+where+space+name2+space+when;
sentence="";
draw event:
draw_text(50,50,sentence);
press s event:
name=choose("Edward","Lance","Lorilla");
what=choose("went swimming","ate chocolate");
where=choose("in the park","at the cinema","at the beach");
name2=choose("with Lorem","with Ipsum","With Dolor");
when=choose("on Monday","yesterday","last week");
space=" ";
sentence=name+space+what+space+where+space+name2+space+when;
GAMEMAKER Firework Display Using Effects
Step event:
//create firework effect at random position in room,with random size and colour
effect_create_above(ef_firework,random(room_width),random(room_height),irandom(2),choose(c_yellow,c_red,c_blue,c_green));
//create firework effect at random position in room,with random size and colour
effect_create_above(ef_firework,random(room_width),random(room_height),irandom(2),choose(c_yellow,c_red,c_blue,c_green));
[GAMEMAKER] Rotate and Move Object to Mouse Position
player event:
angle=point_direction(x,y,mouse_x,mouse_y);//calculate angle between self and mouse
direction=angle;//set direction to move in
image_angle=angle;//set angle of sprite
speed=2;//set moving speed
angle=point_direction(x,y,mouse_x,mouse_y);//calculate angle between self and mouse
direction=angle;//set direction to move in
image_angle=angle;//set angle of sprite
speed=2;//set moving speed
Subscribe to:
Posts (Atom)
I Quit AeroMedLab
Watch now (2 mins) | Today is my last day at AeroMedLab ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ...
-
code.gs // 1. Enter sheet name where data is to be written below var SHEET_NAME = "Sheet1" ; // 2. Run > setup // // 3....