rotierendes Spielfeld

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

maximilian

Betreff: rotierendes Spielfeld

BeitragSo, Nov 20, 2005 15:32
Antworten mit Zitat
Benutzer-Profile anzeigen
Eigentlich sollte ich an meinem Spiel für den Weihnachtscontest weitermachen, aber irgendwie habe ich momentan nicht so viel Lust und habe mich mal wieder mit etwas anderem beschäftigt. Confused

Dieser Code stammt von jemandem aus dem englischen C/Allegro-Board. Er schrieb einen exzellen Artikel über Sin & Cos. Ich habe einmal ein Beispiel-Programm von ihm nach BB portiert und durch Banks etwas beschleunigt (läuft hier auf einem 550er mit ATI Rage Turbo AGP 2x 8 MB eigentlich relativ ok.)

Hier der Artikel (Beispiel-Downloadlink ist im ersten Text-Abschnitt):
http://amarillion.bafsoft.net/...sincos.htm

Und hier der BB-Source:
Code: [AUSKLAPPEN]
;
;   CIRCLE 9
;   Written by Amarillion (amarillion@yahoo.com)
;   BlitzBasic port by LordChaos
;
;   This program demonstrates how a sprite rotation Function
;   works.
;


; initialize gfx mode
Graphics 320, 240, 16, 0
SetBuffer BackBuffer()

; call the example function
test_rotate_sprite ()

End



; my_rotate_sprite will draw src_bmp on to dest_bmp
; rotated by angle degrees and scaled by the scale factor.
; The width and height of the src bitmap must be
; powers of 2 (e.g. 32, 64, 128).
Function my_rotate_sprite (src_bmp, angle#, scale#)

    ; current position in the source bitmap
    Local src_x#, src_y#

    ; current position in the destination bitmap
    Local dest_x, dest_y

    ; src_x And src_y will change Each time by dx And dy
    Local dx#, dy#

    ; src_x and src_y will be initialized To start_x and start_y
    ; at the beginning of each new Line
    Local start_x# = 0, start_y# = 0

    ; calculate increments For the coordinates in the source bitmap
    ; For when we move Right one pixel on the destination bitmap
    dx# = Cos(angle#) * scale#
    dy# = Sin(angle#) * scale#

    LockBuffer BackBuffer()

    For dest_y = 0 To GraphicsHeight()-1

        ; set the position in the source bitmap to the
        ; beginning of this line
        src_x# = start_x
        src_y# = start_y

        For dest_x = 0 To GraphicsWidth()-1

            ; Copy a pixel.
            WritePixelFast(dest_x, dest_y, PeekInt(src_bmp, ((src_x And 63)+(src_y And 63)*63)*4))

            ; advance the position in the source bitmap
            src_x# = src_x# + dx#
            src_y# = src_y# + dy#
       
        Next

        ; for the next line we have a different starting position
        start_x = start_x - dy
        start_y = start_y + dx

    Next

    UnlockBuffer BackBuffer()

End Function

; This function is just a small demo of my_rotate_sprite
Function test_rotate_sprite ()

    Local bmp
    Local angle# = 0
    Local scale# = 0
    Local angle_stepsize# = 1

    Local i, j

    ; create a bitmap of size 64x64 and fill it with something
    bmp = CreateImage(64, 64)

    For i = 0 To 31
     For j = i To 31
       WritePixel(i, j, i*4, ImageBuffer(bmp))
       WritePixel(i, 63-j, i*4, ImageBuffer(bmp))
       WritePixel(63-i, j, i*4, ImageBuffer(bmp))
       WritePixel(63-i, 63-j, i*4, ImageBuffer(bmp))
       WritePixel(j, i, i*4, ImageBuffer(bmp))
       WritePixel(j, 63-i, i*4, ImageBuffer(bmp))
       WritePixel(63-j, i, i*4, ImageBuffer(bmp))
       WritePixel(63-j, 63-i, i*4, ImageBuffer(bmp))
     Next
    Next

    bnk_bmp = CreateBank(ImageWidth(bmp)*ImageHeight(bmp)*4)

    For i = 0 To 63
     For j = 0 To 63
       PokeInt(bnk_bmp, (i+j*63)*4, ReadPixel(i, j, ImageBuffer(bmp)))
     Next
    Next

    While Not KeyHit(1)

        angle = angle + angle_stepsize
        scale = Sin(angle) + 1.5
        my_rotate_sprite(bnk_bmp, angle, scale)

        Flip

    Wend

    FreeImage(bmp)

End Function
Variety is the spice of life. One day ignore people, next day annoy them.

Triton

BeitragFr, Nov 25, 2005 20:16
Antworten mit Zitat
Benutzer-Profile anzeigen
Schöner Effekt. Sieht gut aus.
Coding: silizium-net.de | Portfolio: Triton.ch.vu

soli

BeitragSa, Nov 26, 2005 6:11
Antworten mit Zitat
Benutzer-Profile anzeigen
*wow*
solitaire

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group