Created
August 1, 2019 05:56
-
-
Save erspark2002/2ef3d52eba7162a516bf811f97ffbf0a to your computer and use it in GitHub Desktop.
Game Maker Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#___Resources | |
#_Game Maker Programming - Wikibooks, open books for an open world - https://en.wikibooks.org/ | |
https://en.wikibooks.org/wiki/Game_Maker_Programming | |
#_Game Maker Programming/Intro - Wikibooks, open books for an open world - https://en.wikibooks.org/ | |
https://en.wikibooks.org/wiki/Game_Maker_Programming/Intro | |
#_Game Maker Programming/Creating a room - Wikibooks, open books for an open world - https://en.wikibooks.org/ | |
https://en.wikibooks.org/wiki/Game_Maker_Programming/Creating_a_room | |
#_GML Overview - https://docs.yoyogames.com/ | |
https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/ | |
------------------- | |
#___Tutorial - Perfect Top Down Movement - YouTube | |
https://www.youtube.com/watch?v=QtNe7clL9rA&list=PLUQ0xH2XyXgHWa-wC1X1q2sG8lzEuqzGe&index=2 | |
Object | |
name: obj_player | |
add sprite. | |
Add step event | |
> Control tab > Code | |
------------------- | |
#_Keyboard | |
//keyboard_check(vk_right) | |
--- | |
//left right | |
var xDirection, yDirection; | |
xDirection = keyboard_check(ord('D')) - keyboard_check(ord('A')); // 0, 1, -1. ord('key') returns 1 if pressed, 0 otherwise. | |
yDirection = keyboard_check(ord('S')) - keyboard_check(ord('W')); // 1 or -1 | |
x += xDirection; | |
y += yDirection; | |
------------------- | |
#_Bullets | |
obj_bullet | |
move_towards_point(mouse_x,mouse_y,10) | |
------------------- | |
#_HTML5 Export (v1.4) - YouTube - https://www.youtube.com/ | |
https://www.youtube.com/watch?v=GDEMJkeapEU | |
------------------- | |
#_Score on screen | |
#_Controller objects - don't appear on screen, control other things | |
create controller group: r.click Object, create Group, name: Controllers | |
create obj: contr_main | |
View: 0,0 = top left. | |
Room_01: | |
Views > Enable the use of views. | |
Events: | |
Create: | |
//add code: | |
global.score=0; | |
Draw: | |
draw_set_colour(c_lime) | |
draw_text(view_xview[0]+10, view_yview[0]+10, "Score: "+string(global.score)) | |
Add controller to room: | |
room_01 | |
> object > controller > contr_main - click to place. | |
shift + r.click to delete. | |
------------------- | |
tr - ... is a global built-in and cannot be used as an instance variable | |
In Object cont_main, in Event CreateEvent action number 1 at line 1 : "score" is a global built-in and cannot be used as an instance variable | |
In Object cont_main, in Event DrawEvent action number 1 at line 2 : "score" is a global built-in and cannot be used as an instance variable | |
Compile Failed - Please check the Compile window for any additional information | |
global.score=0; | |
//changed to: | |
global.my_score=0; | |
draw_set_colour(c_lime) | |
draw_text(view_xview[0]+10, view_yview[0]+10, "Score: "+string(global.score)) | |
------------------- | |
tr - BSOD - black screen of death | |
"Enable the use of views" was ticked. | |
--- | |
NOTE: These messages are normal: | |
Attempting to set gamepadcount to 12 | |
Unable to find output device "null" defaulting to "AMD HDMI Output (AMD High Definition Audio Device) via DirectSound" | |
Total memory used = 519973(0x0007ef25) bytes | |
Pause event has been registered for this frame | |
Pause event has been unregistered | |
--- | |
Attempting to set gamepadcount to 12 | |
Unable to find output device "null" defaulting to "Speakers (Realtek High Definition Audio) via DirectSound" | |
Total memory used = 518809(0x0007ea99) bytes | |
Pause event has been registered for this frame | |
Pause event has been unregistered | |
--- | |
Attempting to set gamepadcount to 12 | |
Unable to find output device "null" defaulting to "AMD HDMI Output (AMD High Definition Audio Device) via DirectSound" | |
Total memory used = 525485(0x000804ad) bytes | |
Pause event has been registered for this frame | |
Pause event has been unregistered | |
Pause event has been registered for this frame | |
Pause event has been unregistered | |
------------------- | |
#___Keyboard shortcuts | |
search scripts: Ctrl+shift+F | |
------------------- | |
#_room - change start/default room | |
https://docs.yoyogames.com/source/dadiospice/002_reference/rooms/room_goto.html | |
first room in list loads first. | |
Drag room to heading "Rooms". | |
room_goto() | |
------------------- | |
#_collision | |
add event collision object > obj_bullet | |
//destroys the bullet. | |
// "other" - is the object selected when the event was added. eg. Event > collision > player. | |
with(other) instance_destroy(); | |
------------------- | |
#_check if object exists / object_exists() | |
------------------- | |
#_spawn_rate | |
spawn_rate = random_range(60, 180); | |
alarm[0] = spawn_rate; | |
------------------- | |
#_Esoteric Software - https://github.com/ | |
https://github.com/EsotericSoftware | |
#_2D skeletal animation runtimes for Spine. | |
#_Esoteric Software - https://github.com/ | |
https://github.com/EsotericSoftware | |
#_EsotericSoftware/spine-runtimes: 2D skeletal animation runtimes for Spine. - https://github.com/ | |
https://github.com/EsotericSoftware/spine-runtimes | |
------------------- | |
#___SDK - Docs | |
#_point_direction - https://docs.yoyogames.com/ | |
https://docs.yoyogames.com/source/dadiospice/002_reference/maths/vector%20functions/point_direction.html | |
- angle between 2x x&y coordinates. | |
------------------- | |
#_Set angle of 3d viewport | |
move_towards_point(mouse_x,mouse_y,10) | |
angle =(point_direction(x,y,mouse_x,mouse_y)) | |
d3d_transform_set_rotation_axis(angle, angle, angle, angle) | |
------------------- | |
#_rotate sprite | |
image_angle = point_direction(x, y, mouse_x, mouse_y); | |
------------------- | |
#_json examples | |
#_GameMaker Tutorials: Using JSON Data - http://jasonleeelliott.com/ | |
http://jasonleeelliott.com/using-json-data/ | |
var theCard = instance_create(320-CARD_CENTER,32,obj_Card); | |
var theCard = instance_create(320,32,obj_Card); | |
theCard.myID = 1; | |
------------------- | |
#_GM2 - switch between drag and drop and gml | |
r.click code > convert to dnd | |
r.click title bar > convert to GML | |
------------------- | |
#_move enemy/object towards player | |
with (other) { | |
if (hp <= 0) { | |
instance_destroy(); | |
global.my_score += 5; | |
} | |
move_towards_point(global.playerX, global.playerY, global.enemySpeed); | |
if (global.dead) { | |
instance_destroy(); | |
} | |
} | |
--- | |
https://forum.yoyogames.com/index.php?threads/make-an-object-go-towards-an-object.3441/ | |
move_towards_point( player_obj.x, player_obj.y, 4 ); | |
move_towards_point( obj_player.x, obj_player.y, 4 ); | |
direction = point_direction(x,y,obj_player.x,obj_player.y); | |
------------------- | |
#_basic enemy AI | |
#_GameMaker - Basic Enemy AI (cont...) - YouTube - https://www.youtube.com/ | |
https://www.youtube.com/watch?v=MlBt5FU0Eeo&list=PLUQ0xH2XyXgHWa-wC1X1q2sG8lzEuqzGe&index=6 | |
scripts | |
states | |
--- | |
obj_enemy_Create: | |
//globally reference a script | |
state = scr_enemy_static; | |
//Variables | |
hp = 100; | |
enemySpeed = 2; | |
aggroRange = 120; | |
--- | |
#obj enemy step (contain a var called state) | |
//states | |
scipt_execute(state); //all enemies can call this script to control their movement. | |
//move towards player | |
//This function moves an instance towards a point avoiding obstacles. | |
mp_potential_step(obj_player.x,obj_player.y, enemySpeed, true); | |
--- | |
New Script > scr_enemy_static | |
var dis = point_distance(x,y,obj_player.x,obj_player.y); | |
------------------- | |
#_move player - Basic movement of player left right, up, down | |
All versions. | |
sprite | |
room | |
object: create obj_player, select sprite, add obj_player to room. | |
obj_player: add event: Step > Control > Code: | |
--- | |
// Complex code: | |
//left right, up, down | |
var xDirection, yDirection; | |
xDirection = keyboard_check(ord("D")) - keyboard_check(ord("A")); // 0, 1, -1. ord('key') returns 1 if pressed, 0 otherwise. | |
yDirection = keyboard_check(ord("S")) - keyboard_check(ord("W")); // 1 or -1 | |
global.walkingSpeed = 3; | |
x += xDirection * global.walkingSpeed; | |
y += yDirection * global.walkingSpeed; | |
//add these so other scripts know where the player is | |
global.playerX = x | |
global.playerY = y | |
--- | |
Simpler Code: | |
//left right | |
var xDirection, yDirection; | |
xDirection = keyboard_check(ord('D')) - keyboard_check(ord('A')); // 0, 1, -1. ord('key') returns 1 if pressed, 0 otherwise. | |
yDirection = keyboard_check(ord('S')) - keyboard_check(ord('W')); // 1 or -1 | |
x += xDirection; | |
y += yDirection; | |
------------------- | |
tr - Unexpected symbol in expression | |
COMPILATION ERROR in code action | |
Error in code at line 14: | |
var xDirection = 0; | |
^ | |
at position 17: Unexpected symbol in expression. | |
// variable was declared twice | |
var xDirection = 0; | |
var xDirection = 0; | |
--- | |
//ok | |
if (a==0) | |
//wrong | |
if (a===0) | |
--- | |
ERROR in | |
action number 1 | |
of Step Event | |
for object obj_player: | |
Error in code at line 19: | |
x += xDirection; | |
^ | |
at position 7: Unknown variable xDirection | |
--- | |
//ok | |
var xDirection; | |
xDirection = 0; | |
x += xDirection; | |
//wrong - MUST give a variable a value before using it! | |
var xDirection; | |
x += xDirection; | |
------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment