Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Anonymous
unregistriert
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
void loop() { if (!MapLoad("maps/lvl1.FMP")) MapSetPal8(); float x = 50, y = 300; scroll = create_sub_bitmap(doubleBuffer, 0, 0, SCREEN_W*2, SCREEN_H); mario2 = load_video_bitmap("sprites/mario/mariorun2.bmp"); FrameSource frames2 = FrameSource(mario2, 4); Animation anim2(&frames2); anim2.addFrame(0, 7); Sprite sprite2(&anim2); sprite2.setPos(x, y); sprite2.setSpeed(0, 0); int needsRepaint = TRUE; syncTimer(&timerCounter); while(!key[KEY_ESC]) { if (timerCounter) { do { if(key[KEY_D]) { x += 1.5; anim2.addFrame(0, 7); anim2.addFrame(1, 7); anim2.addFrame(2, 7); anim2.addFrame(3, 7); } clear_keybuf(); sprite2.setPos(x, y); MapDrawBGT (doubleBuffer, 0, 0, 0, 0, 1280, 480); sprite2.tick(); sprite2.draw(doubleBuffer); --timerCounter; } while (timerCounter >0); needsRepaint = true; } if (needsRepaint) { needsRepaint = false; show(); } } } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
FrameSource::FrameSource(BITMAP *bmp, int cnt) : frames(bmp), count(cnt) { if (frames && count > 0) { w = frames->w / count; h = frames->h; } } // Gibt die bitmap bei explizitem Aufruf // frei. void FrameSource::destroy() { if (frames != NULL) { destroy_bitmap(frames); frames = NULL; } } // Zeigt Frame <index> an der Position (x,y) an void FrameSource::render(BITMAP *dst, int index, int x, int y) { masked_blit(frames, dst, w * index, 0, x, y, w, h); } // Ausmasse eines Frames int FrameSource::getWidth() { return w; } int FrameSource::getHeight() { return h; } Animation::Animation(FrameSource *src) : source(src), ticks(0), curFrame(0), count(0) { } Animation::~Animation() { } void Animation::addFrame(int index, int delay, int dx, int dy) { FrameInfo info(index, delay, dx, dy); addFrame(info); ++count; } void Animation::addFrame(FrameInfo &info) { frames.push_back(info); } void Animation::tick() { if (count >0) { ++ticks; if (ticks >= frames[curFrame].delay) { ++curFrame; if (curFrame >= count) { curFrame = 0; } ticks = 0; } } } void Animation::render(BITMAP *dst, int x, int y) { source->render(dst,frames[curFrame].frame, x + frames[curFrame].dx, y + frames[curFrame].dy); } FrameSource* Animation::getFrameSource() { return source; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#ifndef SPRITES_HEADER #define SPRITES_HEADER #include <allegro.h> #include <list> #include "util.h" #include "animation.h" using namespace std; struct Sprite { float x, y, dx, dy; Animation *anim; Sprite(Animation *ani) { anim = ani; } void draw(BITMAP *dest) { anim->render(dest, (int) x, (int) y); } void setPos(float x, float y) { this->x = x; this->y = y; } void setSpeed(float dx, float dy) { this->dx = dx; this->dy = dy; } virtual void tick() { x += dx; y += dy; if (x > SCREEN_W) { x = -anim->getFrameSource()->getWidth(); } if (y > SCREEN_H) { y = -anim->getFrameSource()->getHeight(); } anim->tick(); } }; typedef list<Sprite*> SpriteList; typedef SpriteList::iterator SpriteIterator; BITMAP* load_video_bitmap(const char* name) { BITMAP* bmp = load_bitmap(name, NULL); if (!bmp) { return NULL; } BITMAP *vid = create_video_bitmap(bmp->w, bmp->h); if (vid) { blit(bmp, vid, 0, 0, 0, 0, bmp->w, bmp->h); destroy_bitmap(bmp); return vid; } return bmp; } #endif |
Anonymous
unregistriert
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 |
if((getKeyState2(KEY_W) == KEY_PRESSED) && (getKeyState(KEY_D) != KEY_PRESSED)) { y2 = y; y2 -= 30; while(y > y2) { masked_blit(mariojump, doubleBuffer, 0, 0, x, y, mariojump->w, mariojump->h); y -= 1; } } |
Anonymous
unregistriert
Werbeanzeige