Re: Newbie seriously confused.

new topic     » goto parent     » topic index » view thread      » older message » newer message

--Boundary_(ID_hfu5jGS/m2dQ4XdqNpLFFw)

On Thursday 23 August 2001 22:22, mike johnson wrote:

> I have spent a good deal of time using darkbasic, another popular
> game-making language.  I made some simple games on it, but found the 2d
> too slow for my liking.
.....
> If I wanted to paste a picture to the screen, and move it about with the
> arrow keys, how would I? Could anyone give me a very simple example?

Here's about the simplest you can get:

constant instructions =
 "Hit any key to display Bart,\n"&
 "Use arrow keys to move, ESC to quit"

include get.e -- for wait_key()
include image.e -- for bitmap

object coords, oldcoords, size, img, bkgnd
integer key, step
constant PAL = 1, BMP = 2

coords = {100,100} -- initial starting point.

img = read_bitmap("C:\\euphoria\\bart.bmp")
size = {length(img[BMP][1]),length(img[BMP])}
step = 5 -- move by this many pixels each time.

-- Set up graphics mode and display instructions:
if graphics_mode(256) then
   puts(1,"Cannot select graphics mode")
   abort(1)
end if

all_palette(img[PAL]) -- set DOS palette to match bitmap's
bkgnd = save_image(coords,coords+size)
puts(1,instructions)

while 1 do -- check for keypress, move image:
 key = wait_key()
 oldcoords = coords
 if key = 27 then exit
 elsif key = 333 then coords += {step,0}
 elsif key = 336 then coords += {0,step}
 elsif key = 328 then coords -= {0,step}
 elsif key = 331 then coords -= {step,0}
 end if
 display_image(oldcoords,bkgnd)
 display_image(coords,img[BMP])
end while

Regards,
Irv

--Boundary_(ID_hfu5jGS/m2dQ4XdqNpLFFw)
Content-type: image/x-bmp; charset=iso-8859-1; name=bart.bmp
Content-transfer-encoding: base64

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu