allegrocreategames_robspage2
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.
So how to create the sprites. We could use alphanumeric to represent the enemies (as in the olden days), or we could use actual bitmaps. We could load the bitmaps from a file, or we could create them ourselves. We are going to do the latter. Post edit - I've just decided that's an awful idea, so we are going to use a paint package to create 20*20 sprite bitmaps, and load them into memory here.
In the global variables, add some pointers to sprite bitmaps
atom r1_bmp, r2_bmp, p1_bmp, p2_bmp, exit_bmp, wall_bmp, telep1_bmp, telp2_bmp
In main() add a call to another procedure
create_sprites()
and create another procedure
The robot animation sprites
created with paint shop pro, a very simple graphics editing program
--------------------------------------------------------------- procedure create_sprites() --we are going to allow for some experimentation in here --should only need a one off call, as global pointers --------------------------------------------------------------- integer sprite_size = 20 r1_bmp = load_bitmap("r1.bmp", the_palette) r2_bmp = load_bitmap("r2.bmp", the_palette) pl_bmp = load_bitmap("p1.bmp", the_palette) p2_bmp = load_bitmap("p2.bmp", the_palette) exit_bmp = load_bitmap("exit.bmp", the_palette) wall_bmp = load_bitmap("wall.bmp", the_palette) telp1_bmp = load_bitmap("telp1.bmp", the_palette) --allows for animation telp2_bmp = load_bitmap("telp2.bmp", the_palette) --was going to draw them here, but way too much faff - just drawn bmps in an art package, and loaded. --that's it - ready to be used now. end procedure
We'll also load up a different music track, but hopefully we have enough to start the gameplay loop now.