Historical allegrocreategames_robspage2, Revision 3
The robots revenge game, page 2
Ok, so things have moved on a tad, we've now got a functioning menu, the sound plays and stops, now it's time to create our robots. This is what we have so far
include euallegro.ew include fmod.e -------------------------------------------------------------- --global variables -------------------------------------------------------------- integer ret, snd atom the_palette = allocate_palette() --allocates space for the palette atom title_bmp --the title bitmap pointer object VOID ret = allegro_init() ret = install_timer() ret = install_keyboard() if install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, "") = 0 then snd = 1 else snd = 0 allegro_message("Playing without sound ....",{}) end if ret = FSOUND_Init(44100, 32, 0) if ret = 0 then puts(1, "Could not init fmod") abort(1) end if set_color_depth(32) ret = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640,480, 0, 0) if ret = -1 then --switch to a safe mode instead ret = set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) end if --------------------------------------------------------------- procedure show_title_bmp() --------------------------------------------------------------- --the bitmap is loaded into memory, with a pointer to it, title_bmp --let's blast it to the screen blit(title_bmp, screen, --source, dest 0,0, --source co ords 0,0, --dest co ords bitmap_w(title_bmp), bitmap_h(title_bmp) --the bitmap size to blit ) end procedure --------------------------------------------------------------- procedure main_menu_default(atom menu_buffer ) --------------------------------------------------------------- --copy section of title_bmp to menu_buffer blit(title_bmp, menu_buffer, --source, dest floor(640/3), floor(480/3)*2 - 20, --source coords 0,0, --dest coords floor(640/3), floor(480/3)) --size to blit --add on the menu options textout_centre_ex(menu_buffer, font, --dest, font "Start game", --string floor(640/3/2),20, --position makecol(10,10,10), -1 --colour, transparent back ground ) textout_centre_ex(menu_buffer, font, --dest, font "Options", --string floor(640/3/2),60, --position makecol(10,10,10), -1 --colour, transparent back ground ) textout_centre_ex(menu_buffer, font, --dest, font "Exit", --string floor(640/3/2),100, --position makecol(10,10,10), -1 --colour, transparent back ground ) --blit that bit of memory back to the screen blit(menu_buffer, screen, --source, dest 0,0, --source coords floor(640/3), floor(480/3)*2 - 20, --dest coords bitmap_w(menu_buffer), bitmap_h(menu_buffer)) --all of it end procedure --------------------------------------------------------------- procedure set_menu_option(integer item_no, atom menu_buffer) --------------------------------------------------------------- --add on the menu options if item_no = 1 then textout_centre_ex(menu_buffer, font, --dest, font "Start game", --string floor(640/3/2)-2,20-2, --position makecol(244,238,66), -1 --colour, transparent back ground ) elsif item_no = 2 then textout_centre_ex(menu_buffer, font, --dest, font "Options", --string floor(640/3/2)-2 ,60-2, --position makecol(244,238,66), -1 --colour, transparent back ground ) elsif item_no = 3 then textout_centre_ex(menu_buffer, font, --dest, font "Exit", --string floor(640/3/2)-2,100-2, --position makecol(244,238,66), -1 --colour, transparent back ground ) end if --blit that bit of memory back to the screen blit(menu_buffer, screen, --source, dest 0,0, --source coords floor(640/3), floor(480/3)*2 - 20, --dest coords bitmap_w(menu_buffer), bitmap_h(menu_buffer)) --all of it end procedure --------------------------------------------------------------- procedure main() --Game flow --intro title, music --game options menu -- start -- main game loop -- options --exit game --------------------------------------------------------------- integer fn, cn atom menu_buffer integer current_item = 1, prev_item = 1 --just called once title_bmp = load_bitmap("Rtitle.bmp", the_palette) --show the title - can call this repeatedly show_title_bmp() --load intro music fn = FMUSIC_LoadSong("amplifier.it") cn = FMUSIC_PlaySong(fn) --grab a section of the background to act as buffer for the menu menu_buffer = create_bitmap(floor(640/3), floor(480/3)) clear_bitmap(menu_buffer) main_menu_default(menu_buffer) set_menu_option(current_item, menu_buffer) --main menu while 1 do VOID = readkey() --just slows down that menu change if key(KEY_UP) then current_item -= 1 if current_item = 0 then current_item = 1 end if elsif key(KEY_DOWN) then current_item += 1 if current_item > 3 then current_item = 3 end if elsif key(KEY_ENTER) then if current_item = 3 then exit elsif current_item = 1 then VOID = FMUSIC_StopSong(fn) --playgame VOID = FMUSIC_PlaySong(fn) elsif current_item = 2 then --options VOID = FMUSIC_StopSong(fn) VOID = FMUSIC_PlaySong(fn) end if end if if current_item != prev_item then main_menu_default(menu_buffer) set_menu_option(current_item, menu_buffer) prev_item = current_item end if --wait a little - moves too fast! rest(100) end while --stop the music VOID = FMUSIC_StopSong(fn) VOID = FMUSIC_FreeSong(fn) end procedure main() set_color_depth(8) --just need this because of a little graphic quirk ret = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640,480, 0, 0) allegro_exit()
So we need a sprite for the robot, and a sprite for the player. Let's go overboard and create 2 sprites for the player, and 2 for the robots. We can put as many of the robot sprites down as we want, and this can be used to vary the hardness of the game.
- diff to current revision, view current revision history, backlinks
- Last modified Sep 11, 2017 by ChrisB