-- *********************************************************************** -- * * -- * FRONTEND.E The Happy Hippy (C) 1998 * -- * * -- *********************************************************************** constant VERSION = 1.06 -- DO NOT CHANGE THIS VALUE OR CODE WON'T RUN ! -- *********************************************************************** -- * * -- * Description : A Euphoria Pixel Bot Project Graphical Interface * -- * Version : 1.06 - 26th November 1998 * -- * * -- * Filename : frontend.e * -- * Source Code : Euphoria 2.00 * -- * * -- * Author : The Happy Hippy * -- * Copyright : The Happy Hippy (C) 1998 * -- * Contact : hippy@psynet.net * -- * * -- * Licence : You are granted the free right to use the code * -- * within this file as the basis of any Pixel Bot * -- * Project graphical interface that you are designing * -- * providing that you do not use the code exactly as * -- * it is without including all comments in their * -- * original format. * -- * * -- * You may modify this code and comments as you wish * -- * and may use it as the basis of any Pixel Bot * -- * graphical interface that you develop free of * -- * charge and royalties. * -- * * -- * Trademarks : See http://www.psynet.net/hippy/pixelbot.htm for * -- * details of Copyright and Trademark assignments. * -- * * -- * Y2K Issues : This code does not use dates for any purpose and * -- * is therefore, by default, millennium compliant. * -- * * -- * For further information about the Euphoria Pixel Bot project * -- * please look at http://www.psynet.net/hippy/pixelbot.htm * -- * * -- * For further information about the Euphoria language please look * -- * at http://members.aol.com/FilesEu * -- * * -- *********************************************************************** -- *********************************************************************** -- * * -- * KNOWN BUGS * -- * * -- * None * -- * * -- *********************************************************************** -- *********************************************************************** -- * * -- * RELEASE HISTORY * -- * * -- * * -- * 1.06 30 Nov 1998 Remove trail when Pixel Bot dies. * -- * * -- * 1.05 26 Nov 1998 Corrected bug in Winning_Pixel_Bot_At() * -- * where Row and Col was swapped. * -- * * -- * 1.04 16 Nov 1998 Added Graphical Interface API routines * -- * to show winning and losing Pixel Bots. * -- * * -- * 1.03 14 Nov 1998 Fail-safe code added to GUI_Enquiry(). * -- * * -- * Added Create_Pixel_Bot() and colour * -- * assignment using Group * -- * * -- * Tail handling for non-clone pixels also * -- * included. * -- * * -- * 1.02 13 Nov 1998 Added identifier for particular Pixel * -- * Bot related actions. Added extra API * -- * routine Make_Pixel_Bot_Face() routine. * -- * * -- * 1.01 12 Nov 1998 Reduced public Graphical Interface API * -- * connection into arena.e so that there * -- * is less chance of a user hacking the * -- * source code of arena for information * -- * to accidentally use something in the * -- * Pixel Bot program that they shouldn't. * -- * * -- * Note : The intention is not to stop * -- * hacking, which is still encouraged, * -- * but to prevent misinformation being * -- * spread about what may or may not be * -- * of possible use to a Pixel Bot program. * -- * * -- * The code format has been changed so it * -- * is easier to find the code amongst the * -- * comments. * -- * * -- * Version control added. * -- * * -- * 1.00 10 Nov 1998 First public release * -- * * -- *********************************************************************** -- *********************************************************************** -- * * -- * NOTES * -- * * -- * 1) Don't modify this code whilst it is still a version 1.XX; * -- * there are likely to be a lot of day-to-day changes and it * -- * will be difficult to keep up with changes that are happening * -- * in the Arena program. * -- * * -- * 2) Don't declare and constants, variables or functions as * -- * global other than the GUI_Enquiry() function and the GUI() * -- * routine. * -- * * -- *********************************************************************** -- Some constants have been commented out to stop warnings appearing -- because those constants are not used in this Arena program. constant BLACK = 0 -- Arena floor / Invisible wall constant BLUE = 1 constant GREEN = 2 -- Teleporter constant CYAN = 3 constant RED = 4 -- Damaged Pixel Bot constant MAGENTA = 5 constant BROWN = 6 constant WHITE = 7 constant GRAY = 8 -- Walls constant BRIGHT_BLUE = 9 constant BRIGHT_GREEN = 10 -- Exit point for maze constant BRIGHT_CYAN = 11 -- constant BRIGHT_RED = 12 -- Laser constant BRIGHT_MAGENTA = 13 constant YELLOW = 14 constant BRIGHT_WHITE = 15 -- Give objects a colour constant FLOOR_COLOUR = BLACK -- Floor constant WALL_COLOUR = GRAY -- Wall constant DAMAGED_PIXEL_BOT_COLOUR = RED -- Damaged Bot constant TELEPORT_COLOUR = GREEN -- Teleporter constant EXIT_POINT_COLOUR = BRIGHT_GREEN -- Exit Point -- constant LASER_COLOUR = BRIGHT_RED -- Laser shot -- constant LANDMINE = -- Landmine -- constant MEDI_PACK = -- Medical pack -- constant LASER_CHARGE = -- Extra laser charge -- constant ARMOUR = -- Armour constant WINNING_COLOUR = BRIGHT_GREEN constant LOSING_COLOUR = GREEN constant PIXEL_BOT_COLOURS = { BRIGHT_CYAN , CYAN , BRIGHT_MAGENTA , MAGENTA , YELLOW , BROWN , BRIGHT_WHITE , WHITE , BRIGHT_BLUE , BLUE } -- *********************************************************************** -- * * -- * DATA USED BY GRAPHICAL INTERFACE * -- * * -- *********************************************************************** integer Dummy sequence Pixel_Bot_Colour_List sequence Tail sequence Tail_Flag integer Tail_Trigger_Count Pixel_Bot_Colour_List = {} Tail = {} Tail_Flag = {} Tail_Trigger_Count = 1 constant MAX_TAIL_LENGTH = 40 -- *********************************************************************** -- * * -- * UTILITY FUNCTIONS * -- * * -- *********************************************************************** function Degrees(atom Radians) -- Convert Radians to Degrees return (180 * Radians) / (4 * arctan(1)) end function function Radians(atom Degrees) -- Convert Degrees to Radians return (4 * arctan(1) * Degrees) / 180 end function constant KEY_BUFFER = 1054 constant FIRST_INDEX = 1050 constant LAST_INDEX = 1052 procedure Flush_Funny_Keys() integer scan_code integer key_code integer Kludge if peek(FIRST_INDEX) != peek(LAST_INDEX) then scan_code = peek(KEY_BUFFER+peek(FIRST_INDEX)-29) key_code = peek(KEY_BUFFER+peek(FIRST_INDEX)-30) Kludge = FALSE if scan_code = 46 and key_code = 3 then Kludge = TRUE -- Ctrl-C elsif scan_code = 31 and key_code = 19 then Kludge = TRUE -- Ctrl-S elsif scan_code = 25 and key_code = 16 then Kludge = TRUE -- Ctrl-P end if if Kludge then poke(KEY_BUFFER+peek(FIRST_INDEX)-29,0) poke(KEY_BUFFER+peek(FIRST_INDEX)-30,255) -- poke(FIRST_INDEX,peek(LAST_INDEX)) end if end if end procedure -- *********************************************************************** -- * * -- * SCREEN HANDLING FUNCTIONS * -- * * -- *********************************************************************** procedure Enter_Graphics_Mode() if machine_func(5,18) != 0 then puts(1,"Cannot select 640x480 16-colour mode") abort(1) end if end procedure procedure Leave_Graphics_Mode() integer Dummy Dummy = machine_func(5,-1) end procedure procedure Set_Pixel(integer Row, integer Col, integer Colour) Flush_Funny_Keys() pixel(Colour, { Col-1 , Row-1 } ) end procedure function Get_Pixel(integer Row, integer Col) Flush_Funny_Keys() return get_pixel( { Col-1 , Row-1 } ) end function procedure Create_Wall(integer Row,integer Col) Set_Pixel(Row,Col,WALL_COLOUR) end procedure procedure Create_Exit_Point(integer Row,integer Col) Set_Pixel(Row,Col,EXIT_POINT_COLOUR) end procedure procedure Create_Teleport(integer Row,integer Col) Set_Pixel(Row,Col,TELEPORT_COLOUR) end procedure -- Tail_Trigger_Count is used so that different Pixel Bots update their -- tails on different goes so we can reduce the processing overhead per go. procedure Create_Pixel_Bot(integer Row, integer Col,integer Pixel_Bot, integer Group) integer Colour while Pixel_Bot > length(Pixel_Bot_Colour_List) do Pixel_Bot_Colour_List = Pixel_Bot_Colour_List & 0 Tail = append(Tail , { } ) if remainder(Group,2)=0 then Tail_Flag = append(Tail_Flag , Tail_Trigger_Count ) Tail_Trigger_Count = Tail_Trigger_Count + 1 if Tail_Trigger_Count > 3 then Tail_Trigger_Count = 1 end if else Tail_Flag = append(Tail_Flag , 0 ) end if end while Colour = PIXEL_BOT_COLOURS[remainder(Group,length(PIXEL_BOT_COLOURS))+1] Pixel_Bot_Colour_List[Pixel_Bot] = Colour Set_Pixel(Row,Col,Colour) end procedure procedure Make_Pixel_Bot_Face(integer Pixel_Bot, integer Direction) Dummy = Pixel_Bot --// INCOMPLETE Dummy = Direction --// INCOMPLETE end procedure procedure Move_Pixel_Bot_From(integer Row,integer Col, integer Pixel_Bot) integer t t = Tail_Flag[Pixel_Bot] if t = 0 then Set_Pixel(Row,Col,FLOOR_COLOUR) else if t = 1 then Set_Pixel(Row,Col,WALL_COLOUR) Tail[Pixel_Bot] = append(Tail[Pixel_Bot] , { Row , Col } ) if length(Tail[Pixel_Bot]) > MAX_TAIL_LENGTH then Row = Tail[Pixel_Bot][1][1] Col = Tail[Pixel_Bot][1][2] if Get_Pixel(Row,Col) = WALL_COLOUR then Set_Pixel(Row,Col,FLOOR_COLOUR) end if Tail[Pixel_Bot] = Tail[Pixel_Bot][2..length(Tail[Pixel_Bot])] end if t = 3 else Set_Pixel(Row,Col,FLOOR_COLOUR) t = t - 1 end if Tail_Flag[Pixel_Bot] = t end if end procedure procedure Move_Pixel_Bot_To(integer Row,integer Col, integer Pixel_Bot) Dummy = Pixel_Bot --// INCOMPLETE Set_Pixel(Row,Col,Pixel_Bot_Colour_List[Pixel_Bot]) end procedure procedure Damage_Pixel_Bot_At(integer Row,integer Col, integer Pixel_Bot) Dummy = Pixel_Bot --// INCOMPLETE Set_Pixel(Row,Col,DAMAGED_PIXEL_BOT_COLOUR) end procedure procedure Destroy_Pixel_Bot_At(integer Row,integer Col, integer Pixel_Bot) integer XRow integer XCol Dummy = Pixel_Bot --// INCOMPLETE Set_Pixel(Row,Col,FLOOR_COLOUR) if length(Tail[Pixel_Bot]) > 0 then for i = 1 to length(Tail[Pixel_Bot]) do XRow = Tail[Pixel_Bot][i][1] XCol = Tail[Pixel_Bot][i][2] if Get_Pixel(XRow,XCol) = WALL_COLOUR then Set_Pixel(XRow,XCol,FLOOR_COLOUR) end if end for Tail[Pixel_Bot] = {} end if end procedure procedure Winning_Pixel_Bot_At(integer Row,integer Col, integer Pixel_Bot) integer XRow integer XCol integer k atom r sequence Polygon Polygon = {} for d = 0 to 360 by 20 do r = Radians(d) if remainder(d,40)=0 then k = 14 else k = 8 end if XRow = floor(sin(r)*k) XCol = floor(cos(r)*k) Polygon = append(Polygon, { Col+XCol , Row+XRow } ) end for machine_proc(11, {WINNING_COLOUR, FALSE, Polygon }) end procedure procedure Losing_Pixel_Bot_At(integer Row,integer Col, integer Pixel_Bot) machine_proc(18, {LOSING_COLOUR, FALSE, {Col-10,Row-10}, {Col+10,Row+10 } }) end procedure procedure Synchronise_Front_End() end procedure procedure Kick_Front_End() end procedure procedure Fired_Laser(integer Row_From,integer Col_From,integer Row_To,integer Col_To) Dummy = Row_From --// INCOMPLETE Dummy = Col_From --// INCOMPLETE Dummy = Row_To --// INCOMPLETE Dummy = Col_To --// INCOMPLETE end procedure -- *********************************************************************** -- * * -- * INTERFACE TO / FROM ARENA PROGRAM * -- * * -- *********************************************************************** -- This function is called to return an identifying number of the routines -- that are available in the Graphical Interface. Only available routines -- must be requested. -- The identifying numbers are then used by the arena program by calling -- the GUI() routine to activate the relevant routine call indirectly. -- This means that the arena program ( and consequently Pixel Bots ) will -- only be able to refer to GUI_Enquiry() and GUI() as all other routines -- remain local to the frontend. -- Of course, it goes without saying that, a Pixel Bot should never call -- the GUI_Enquiry() or GUI() routines directly. global function GUI_Enquiry(sequence Proc_Name) if compare(Proc_Name,"Version")=0 then return VERSION else if routine_id(Proc_Name) < 0 then puts(1,"\n\nGUI_Enquiry(" & Proc_Name & ")\n\n") abort(1) end if return routine_id(Proc_Name) end if end function -- The GUI() routine is used to direct a call from the arena program to -- the actual Graphical Interface routine that will do the job that has -- been requested. global procedure GUI(integer Proc_Id,sequence Proc_Args) call_proc(Proc_Id,Proc_Args) end procedure -- *********************************************************************** -- * * -- * END OF THE GRAPHICAL INTERFACE * -- * * -- ***********************************************************************