问题
I have obtained an assignment where I need to create a game using emu8086.
But the problem is I don't know how to draw a sprite.
Can anyone help me by explaining sprite creation to me?
回答1:
Can you tell me how to draw on emu8086 ?
First you setup a graphics video mode. Next code selects the 320x200 256-color mode:
mov ax, 0013h ; AH=00h is BIOS.SetVideoMode, AL=13h is 320x200 mode
int 10h
Now you can plot any pixel you like. Below is an example that plots a single pixel in the center of the screen:
mov dx, 100 ; Y = 200 / 2
mov cx, 160 ; X = 320 / 2
mov bh, 0 ; DisplayPage
mov ax, 0C02h ; AH=0Ch is BIOS.WritePixel, AL=2 is color green
int 10h
To draw a line you repeat plotting a pixel while changing one or both coordinates. Below is an example that draws the vertical line (100,50) - (100,150). This line has 101 pixels (150 - 50 + 1):
mov bh, 0 ; DisplayPage doesn't change
mov cx, 100 ; X is fixed for a vertical line
mov dx, 50 ; Y to start
More:
mov ax, 0C04h ; AH=0Ch is BIOS.WritePixel, AL=4 is color red
int 10h
inc dx ; Next Y
cmp dx, 150
jbe More
To plot an area you use a couple of nested loops. Below is an example that plots the rectangle between (200,33) - (209,35). This area has 30 pixels (209 - 200 + 1) * (35 - 33 + 1):
mov si, Bitmap
mov bh, 0 ; DisplayPage doesn't change
mov dx, 33 ; Y to start
OuterLoop:
mov cx, 200 ; X to start
InnerLoop:
lodsb ; Fetch color for this pixel
mov ah, 0Ch ; AH=0Ch is BIOS.WritePixel
int 10h
inc cx ; Next X
cmp cx, 209
jbe InnerLoop
inc dx ; Next Y
cmp dx, 35
jbe OuterLoop
...
Bitmap: ; Just some blue and cyan pixels
db 1, 3, 1, 3, 1, 3, 1, 3, 1, 3
db 3, 1, 3, 1, 3, 1, 3, 1, 3, 1
db 1, 3, 1, 3, 1, 3, 1, 3, 1, 3
来源:https://stackoverflow.com/questions/54937822/how-to-create-and-draw-sprites-in-emu8086