Wiki Diff allegrocreategames, revision #2 to tip

===Creating games with Allegro

Firstly some game theory - there's plenty of stuff written about it out there ([[https://www.google.co.uk/search?dcr=0&q=gameplay+theory&oq=game&gs_l=psy-ab.1.0.35i39k1l2j0i67k1l2.5698730.5699376.0.5701377.4.4.0.0.0.0.103.251.2j1.3.0....0...1.1.64.psy-ab..1.3.250...0.z42ycZUmP8k|google search]]), read away to you heart's content, but this is what it boils down too :-

*if it's too easy it's rubbish
*if it's too hard it's rubbish
*if you're doing the same stuff over and over, and not getting anywhere, it's rubbish

So it's all about the balance, keep testing and retesting and tweaking, until it feels right.

Next, start with an idea, a goal (reward), and challenge (risk) - the harder the challenge, the better the reward, and start putting down your idea - write design goals and ideas as comments on the first page of your code, and keep referring back to it, keep it simple, and if you add stuff, make sure it makes sense.

So let's go through a simple design process, with euallegro as it's foundation. This game has been done probably a hundred times before by the way, but it's a simple enough concept. It's title is 'Revenge of the Robots'.

*Premise - you've escaped blah blah, robots hunting blah blah, can you survive an ever increasing number of bots??
*Player starts in a random spot on the playing field
*Start with a set number of robots
*Random buildings obstacles to avoid
*Get to randomly generated exit point on the map (note could have pre built maps - future idea?)
*When touched by a robot get electrocuted and die - lose a life / restart the level
*power ups - teleport and extra life, kill some robots

Whats shown on the screen
*Lives
*Score (can use simple textouts for this for now)
*Player
*Robots

So that's the basic idea sketched out, now some game mechanics. Blitz Basic has an interesting concept, which works quite well with Euphoria - that of entities. Everything in the program is an entity, so each robot is an entity, and the player is an entity. The entity has properties, that dictate everything about the entity, for instance what it looks like, what it's health is, which direction it's going in, how happy or sad it is, and so on. Let's sketch the player entity

**Player entity**\\
*LIFE\\
*DIRECTION\\
*GRAPHIC\\
*ALIVE\\
*XPOSITION\\
*YPOSITION\\
*SHIELD --anyone guess what happens here?\\

**Robot entity**\\
*ALIVE\\
*DIRECTION\\
*GRAPHIC\\
*SPEED\\
*ANGRY\\
*KILLALL\\
*XPOSITION\\
*YPOSITION\\

So we can create a sequence for the player, and a sequence for the robot. But because we have many robots, all we need to do is copy the sequence as many times as we want for the robot, each robot will be looped through in the game, it properties updated, and it's actions performed. Perhaps you can see there are already some behaviour modifiers in there.


ok, let's get started

Create a new directory, RobotsR, and drop in the following files

{{{
31/08/2017 12:54 62 euallegro.ew stubs to where the real euallegro and others are
10/09/2017 17:43 61 eujgmod.ew not needed in this program
10/09/2017 17:42 61 euppcol.ew not needed in this program
10/09/2017 17:43 62 fmod.ew
11/09/2017 00:41 666 RobotsR.exw the program
08/09/2017 19:26 921,654 RTitle.bmp a bitmap ready to be a title, 640*480
}}}

This is the very basic setup for an allegro program
<eucode>
include euallegro.ew
include fmod.e

--------------------------------------------------------------
--global variables
--------------------------------------------------------------
integer ret, snd
atom the_palette = allocate_palette() --allocates space for the palette


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 = 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 main()
---------------------------------------------------------------

end procedure

main()
allegro_exit()

</eucode>

From this everything else comes.

We now decide on the structure, or flow of the game, as a whole, for instance

{{{
--Game flow
--intro title, music
--game options menu
-- start
-- main game loop
-- options
--exit game
}}}

and how to implement stuff, for instance, the sprites of the main game.

Also we can load and play music, so let's fetch some appropriate music from the mod archive

ok, so first load the bitmap into memory, and keep it there, so only need to call this once

After a little bit of work, go this
<eucode>
---------------------------------------------------------------
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
)

VOID = readkey()

end procedure
</eucode>

but the image on the screen looks awful I tried changing the colour dept of the image to 256, but that didn't work.

Let's try setting the color depth to 32 bit, add set_color_depth(32) to before GFX_AUTODETECT - that works.

Music now - am going to use fmod, so it's dead easy to add, just around the call to the show_title procedure.

Here's the program - starts, displays the intro screen, and plays the intro music

<eucode>
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
)

VOID = readkey()

end procedure


---------------------------------------------------------------
procedure main()
--Game flow
--intro title, music
--game options menu
-- start
-- main game loop
-- options
--exit game
---------------------------------------------------------------
integer fn, cn

--just called once
title_bmp = load_bitmap("Rtitle.bmp", the_palette)

--load intro music
fn = FMUSIC_LoadSong("amplifier.it")
cn = FMUSIC_PlaySong(fn)

--show the title - can call this repeatedly
show_title_bmp()

--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()

</eucode>

[[http://openeuphoria.org/wiki/view/allegrocreategames_robspage2.wc|Next page]] lets make some enemies!


*[[http://openeuphoria.org/wiki/view/allegroCompleteRobot.wc|The complete robot game]]
*[[http://openeuphoria.org/wiki/view/allegro.wc|Allegro home]]

Search



Quick Links

User menu

Not signed in.

Misc Menu