This material is Copyright 2007 Sheldon Allen
This material is intended for your personal use only.You do not have permission to copy it, redistribute it or profit from it in anyway without written permission from the author.Any included files and their content, may be used for any non-commercial purpose.Contact the author for information regarding commercial use.Emotions RTS Tutorial - 1
Quote:
selected = 0 // Whether the unit is selected or notdirection = 270 //The direction the unit is facingimage_index = direction/360*image_number //Display the correct sub-image
Quote:
image_index = direction/360*image_number //Display the correct sub-image
Quote:
if selected{ draw_set_color(c_red) draw_ellipse(x,y,x+50,y+25,false) // Draw an Ellipse under the unit (looks better than a circle) //draw_circle(x,y,50,false) // Draw a circle under the unit}draw_sprite(sprite_index,-1,x,y)
Quote:
// Initialize all constants for the gamescr_constants() //Setup Constantsinstance_create(-1000,-1000,obj_input_controller) //Create other objects in code so the room doesn't look a mess //Unit Listfor (i=0;i<10+1;i+=1){ global.unit_list = ds_list_create()}
Quote:
//————————————Constants——————————-// Mouse global.pressed = 1global.released = 2// Hotkeysglobal.shift = 0global.control = 0global.alt = 0
Quote:
// Initialize mouse// Buttonsglobal.mouse_left = 0 //Left Button Stateglobal.mouse_right = 0 //Right Button State//Draggingglobal.mouse_drag = 0 global.mouse_drag_x = mouse_x //The starting x coordinate for a dragglobal.mouse_drag_y = mouse_y //The starting y coordinate for a drag// Clicking-Hoveringglobal.click = 0 // Whether the mouse has been clickedglobal.click_id = -1 //The id of the instance last-clicked by the mouseglobal.mouse_over = - 1 //The id of the instance the mouse is hovering over//Double-Clickingglobal.double_click = 0 //Whether the mosue has been double-clickedglobal.double_click_time = 200 //Time allowed for double-clickglobal.mouse_click_timer = current_time + global.double_click_time // Tracks time left to double-click
Quote:
scr_get_input()scr_check_selection()scr_check_hotkeys()
Quote:
// Clear out old mouse statesglobal.double_click = false //Clear double-click stateif global.mouse_drag = 2{ //Released Drag global.mouse_drag = 0 //Clear drag state}if current_time > global.mouse_click_timer{ // Clear Double-Click State (too slow) global.click = 0}if global.mouse_left = global.released{ // Clear Release State global.mouse_left = 0 global.mouse_click_timer = current_time + global.double_click_time}if global.mouse_right = global.released{ // Clear Release State global.mouse_right = 0}global.mouse_over = collision_point(mouse_x,mouse_y,all,true,false) // Object Mouse Hovers Over//Clicking - Left Buttonif mouse_check_button_pressed(mb_left) && global.mouse_left !=global.pressed{ // First Press global.mouse_left = global.pressed // Set mouse state global.mouse_drag_x = mouse_x // Set Drag X global.mouse_drag_y = mouse_y // Set Drag Y if global.click = 0 and global.double_click = false{ // Single-Click global.click = 1 //Set click state to single-click global.click_id = global.mouse_over // Instance receiving click global.mouse_click_timer = current_time + global.double_click_time //Start timer for double-click }else if global.click = 1{ //Test For Double-Click global.click = 0 if current_time < global.mouse_click_timer && global.mouse_over = global.click_id{ // Double-Click global.double_click = true } }}//Clicking - Right Buttonif mouse_check_button_pressed(mb_right) && global.mouse_right !=global.pressed{ global.mouse_right = global.pressed}//Draggingif global.mouse_left = global.pressed && global.mouse_drag = 0 && point_distance(global.mouse_drag_x,global.mouse_drag_y,mouse_x,mouse_y) > 5{ //Test for drag global.mouse_drag = 1}//Releasingif !mouse_check_button(mb_left) && global.mouse_left = global.pressed{ // Releasing Left Mouse Button global.mouse_left = global.released if global.mouse_drag = 1{ global.mouse_drag = 2 }}if !mouse_check_button(mb_right) && global.mouse_right = global.pressed{ //Releasing Right Mouse Button global.mouse_right = global.released}if global.double_click = true{ // Clear the mouse after a double-click mouse_clear(mb_left)}
Quote:
if global.mouse_over{ // If the mouse is over anything if object_get_parent(global.mouse_over.object_index) = obj_unit and global.mouse_left = global.pressed and !global.mouse_drag{ // If the left mouse button is pressed and over a unit unit_id = global.mouse_over // Set the unit_id to global.mouse_over global.unit_type = unit_id.object_index // Get the type/class of the unit if !global.double_click{ // Single-Click if global.shift{ //Shift-key held if !unit_id.selected{ //If the unit hasn't already been selected unit_id.selected = 1 ds_list_add(global.unit_list[0],unit_id) //Add it to the list } }else if global.control{ if unit_id.selected{ unit_id.selected = 0 ds_list_delete(global.unit_list[0],ds_list_find_index(global.unit_list[0],unit_id)) } }else{ ds_list_clear(global.unit_list[0]) // Clear out the unit list with(obj_unit){ selected = 0 } unit_id.selected = 1 ds_list_add(global.unit_list[0],unit_id) } }else{ // Double-Click if global.shift{ // Add units to Selection List with(obj_unit){ if !selected and object_index = global.unit_type{ ds_list_add(global.unit_list[0],id) selected = 1 } } }else if global.control{ //Remove Units from Selection List with(obj_unit){ if object_index = global.unit_type and selected = 1{ selected = 0 ds_list_delete(global.unit_list[0],ds_list_find_index(global.unit_list[0],id)) } } }else if !global.control and !global.shift{ // Clear List and add new Units //mouse_clear(mb_left) ds_list_clear(global.unit_list[0]) // Clear out the unit list with(obj_unit){ selected = 0 } with(obj_unit){ //Reset all units selected variable to zero. Should actually run through list if object_index = global.unit_type{ ds_list_add(global.unit_list[0],id) selected = 1 } } } } }}else if global.mouse_left = global.released and global.mouse_drag = 0{ ds_list_clear(global.unit_list[0]) // Clear out the unit list with(obj_unit){ selected = 0 } global.click = 0}if global.mouse_drag = 2 and global.mouse_drag_x !=mouse_x and global.mouse_drag_y !=mouse_y{ //Released x1 = min(global.mouse_drag_x,mouse_x) y1 = min(global.mouse_drag_y,mouse_y) x2 = max(global.mouse_drag_x,mouse_x) y2 = max(global.mouse_drag_y,mouse_y) // Check for units // Any objects belonging to player get selected if global.shift{ instance_deactivate_region(x1,y1,x2-x1,y2-y1,false,true) with(obj_unit){ selected = 1 ds_list_add(global.unit_list[0],id) } }else if global.control{ //Remove object instance_deactivate_region(x1,y1,x2-x1,y2-y1,false,true) with(obj_unit){ selected = 0 ds_list_delete(global.unit_list[0],ds_list_find_index(global.unit_list[0],id)) } }else{ with(obj_unit){ selected = 0 } instance_deactivate_region(x1,y1,x2-x1,y2-y1,false,true) ds_list_clear(global.unit_list[0]) with(obj_unit){ selected = !selected ds_list_add(global.unit_list[0],id) } } instance_activate_all() }
Quote:
var j,iid;//Hot-Keys//048-057if keyboard_key >=048 && keyboard_key <=057{ global.group = 9 - (57 - keyboard_key) + 1 // Number of Hotkey pressed. Add one to amount because '0' is default list if keyboard_check(vk_control){ //Create Group ds_list_clear(global.unit_list[global.group]) for (j=0;j<ds_list_size(global.unit_list[0]);j+=1){ //Loop through current list ds_list_add(global.unit_list[global.group],ds_list_find_value(global.unit_list[0],j)) // Add selected unit to specified list } }else{ //Select group if !keyboard_check(vk_shift){ with (obj_unit){ //Reset Selection to 0 selected = 0 } } ds_list_clear(global.unit_list[0]) for (j=0;j<ds_list_size(global.unit_list[global.group]);j+=1){ //Loop through List iid = ds_list_find_value(global.unit_list[global.group],j) //Pull Id from list ds_list_add(global.unit_list[0],iid) //Add unit to default list (0) iid.selected = 1 } }}
Quote:
if keyboard_check(vk_left){ //Spin left with (obj_unit){ if selected{ direction -=10 } }}if keyboard_check(vk_right){ //Spin left with (obj_unit){ if selected{ direction +=10 } }}
Quote:
if global.mouse_drag{ draw_set_color(c_blue) draw_rectangle(global.mouse_drag_x,global.mouse_drag_y,mouse_x,mouse_y,1)}
Sorry everyone had trouble with the formatting.
Had to useDoesn't the
No,
Wall of text
Polystyrene Man
Thanks! [GRIN]Does anyone know of anything off-hand that can parse GML code to BBcode? OR even RTF to BBcode?I'd rather use something that's already out there than make my own…TwistyWristy