diff --git a/Assignment3Project/Assignment3Project/Assignment3Project.vcxproj b/Assignment3Project/Assignment3Project/Assignment3Project.vcxproj index 2505e79..5f5ccd1 100644 --- a/Assignment3Project/Assignment3Project/Assignment3Project.vcxproj +++ b/Assignment3Project/Assignment3Project/Assignment3Project.vcxproj @@ -86,6 +86,10 @@ true true true + true + true + true + true @@ -101,6 +105,7 @@ Disabled true true + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) Windows @@ -141,6 +146,7 @@ + @@ -152,15 +158,16 @@ + - + - + diff --git a/Assignment3Project/Assignment3Project/Assignment3Project.vcxproj.filters b/Assignment3Project/Assignment3Project/Assignment3Project.vcxproj.filters index 943c9ba..dfbe102 100644 --- a/Assignment3Project/Assignment3Project/Assignment3Project.vcxproj.filters +++ b/Assignment3Project/Assignment3Project/Assignment3Project.vcxproj.filters @@ -63,6 +63,9 @@ Header Files\Engine + + Header Files\Engine + @@ -89,13 +92,16 @@ Source Files\EngineImplement - - - + + Source Files\EngineImplement + Resource Files + + + \ No newline at end of file diff --git a/Assignment3Project/Assignment3Project/README.TXT b/Assignment3Project/Assignment3Project/README.TXT new file mode 100644 index 0000000..2792538 --- /dev/null +++ b/Assignment3Project/Assignment3Project/README.TXT @@ -0,0 +1,255 @@ +A5 Allegro, version 1 + +DISCLAIMER: + + This software and associated files are provided 'as is' +with no warranty or guarantees of any kind, you use them +at your own risk and in doing so agree that the author is +in no way liable and cannot be held responsible for any +loss of time/data/hair or anything else that may occur +either directly or indirectly from the use of this +software or associated files. + +============================================== +http://www.tilemap.co.uk + +Allegro 5 converted by Neil Walker + +C++ notes: MappyAL will work fine with C++, but the file 'mappyal.c' +must be compiled as 'C'. With MSVC there is no problem as it uses +the filename extension (.c/.cpp) to determine how to compile, but +IDE's like DevC++ and VIDE don't do this with C++ projects, so +instead of adding mappyal.c to your list of sourcefiles (like with +MSVC) be sure you have mappyal.o by manually compiling with: + +gcc mappy_A5.c -O2 -Wall -c -o mappy_A5.o + +then adding mappy_A5.o to the compiler + +Please report any bugs! + + +Function reference: +------------------------------------------------- +IMPORTANT: You must have initialised allegro first. See the demo. + +Quick list: +MAPS + MapLoad : load a map from file + MapDecode : load a map from memory + MapFreeMem : frees up all memory. must be called on exit + MapMakeParallaxBitmap : make a parallax bitmap for the map + MapChangeLayer : change map layer. mappy supports 8 different layers + MapUpdateAnims: update map animations + +DRAWING: + MapDrawBG : draw the background tile from the current map layer + MapDrawFG : draw foreground tiles (layer 1,2,3) from the current map layer + MapDrawParallax: draw the parallax layer (call this first before BG and FG!) + +BLOCKS/TILES: + MapGetBlock/MapGetBlockInPixels: get a block/tile from a given location + MapSetBlock/MapSetBlockInPixels: set a block at a given position to be a new block type + +OTHER STUFF + MapRestore: regenerate bitmaps (in case of loss through video switching in windows) + MapLoadMAR: load a .mar file (cut-down map file) + MapDrawRow: row by row drawing, needed for isometric + MapGetXOffset/MapGetYOffset: handy for translating pixel to block co-ordinates + +------------------------------------------------- + +int MapLoad (char * mapname, int converttoalpha); + +mapname: filename, e.g. "test.fmp" +converttoalpha: if 8bpp then 'magic pink' or index 0 will be converted to alpha + if any other resolution then black or 'magic pink' will be converted to alpha + +Uses allegro file functions so physfs is supported. + +Default uses default allegro bitmaps, i.e. video. If the call fails you need to set new bitmaps to MEMORY then load + +The array abmTiles is available and points to each tile graphic, +eg. if you want to get at the third BITMAP, use abmTiles[2]. + +------------------------------------------------- +int MapDecode (unsigned char * mapmempt,int converttoalpha); + +Same as MapLoad, but loads from an area of memory containing an FMP file. +(Useful if your maps are stored compressed, just uncompress to memory and +call MapDecode). + +------------------------------------------------- +void MapRestore (void); + +Restores the graphics to video bitmaps in hardware rendering. +Useful in Windows that loses video memory on app switching. +However A5 attempts to recover these for you so the function may not be that useful + +------------------------------------------------- +void MapFreeMem (void); + +When you've had enough of the map, this frees all the memory mappypb +has used.MapLoad and MapDecode call this so no need if loading a new map. + +------------------------------------------------- +int MapLoadMAR (char * filename, int layer); +int MapDecodeMAR (unsigned char * marmemory, int layer); + +Loads a .MAR file into a specified layer. Decode does it from memory, +you can dealloc that memory afterwards. If you called MapGenerateYLookup, +call it again after this function. Returns -1 on error, 0 on success. + +MAR files are like FMP map files but without the graphics, animation, etc. +i.e. they are simple boxed arrays storing tile numbers + +------------------------------------------------- +void MapDrawBG (int mapxo, int mapyo, int mapx, int mapy, + int mapw, int maph); + +Draws the blocks referenced in bgoff. Will clip the map to the specified area. +Note: the normal clipping on the bitmap is ignored, so trying to draw off the +edges of a bitmap will crash your programme. + +Draws to the current target bitmap, i.e. you need to set this, or just leave it alone +if using standard backbuffer + +Refer to mapload for drawing of transparent areas (i.e. alpha channels) + +int mapxo offset, in pixels, from left edge of map, this is + the first visible column of pixels you are drawing +int mapyo offset, in pixels, from top edge of map, this is + the first visible row of pixels you are drawing +int mapx offset, in pixels, from left edge of bitmap +int mapy offset, in pixels, from top edge of bitmap +int mapw width of area you want to draw +int maph height of area you want to draw + +------------------------------------------------- +void MapDrawFG (int mapxo, int mapyo, int mapx, int mapy, + int mapw, int maph, int mapfg); + +Same as MapDrawBG, except: + +int mapfg The foreground layer you want to draw, 0, 1, or 2 + +------------------------------------------------- +void MapDrawRow (int mapxo, int mapyo, int mapx, int mapy, + int mapw, int maph, int maprw, void (*cellcall) (int cx, int cy, int dx, int dy)) + +Same as MapDrawBG, except: + +int maprw is the row to draw +cellcall is a callback function for each cell, pass NULL if you are doing your +own depth sorting, or using another system +see demo for an example of this in ISOMETRIC test + +------------------------------------------------- +BITMAP * MapMakeParallaxBitmap (BITMAP * sourcebm); + +Only on regular rectangular maps. +Pass a bitmap you would like to use for the parallax bitmap. + +You must use this function to make the bitmap you pass to MapDrawParallax. +The source bitmap MUST be a multiple of your block size (ie if you are +using 32*32 blocks, 128*128 and 96*64 are valid, but 100*100 is not). + +------------------------------------------------- +void MapDrawParallax (BITMAP * parbm, int mapxo, int mapyo, int mapx, int mapy, + int mapw, int maph); + +This behaves like MapDrawBG etc, except the 'parbm' bitmap is created +with 'MapMakeParallaxBitmap' and this is tiled in the transparent +regions of the map. + +This is more efficient than drawing the whole screen as it only draws +in areas not obscured by higher layers, there is minimal overdraw +(pixels aren't overwritten by higher layers where possible). + +------------------------------------------------- +int MapChangeLayer (int) + +This changes to a different map layer, returns -1 if failed, or the new +layer number if success. See mpgame.c + +------------------------------------------------- +int MapGetXOffset (int x, int y) +int MapGetYOffset (int x, int y) + +These functions are handy for translating a pixel coordinate to block +coordinates, especially for non-rectangular blocks (see mousecrd.c). + +------------------------------------------------- +BLKSTR * MapGetBlockInPixels (int x, int y) + +Returns a BLKSTR pointer, useful for collision detection and examining a +blockstructure. This is more useful on non-rectangular maps as it is pixel +perfect. + +------------------------------------------------- +BLKSTR * MapGetBlock (int x, int y); + +Returns a BLKSTR pointer, useful for collision detection and examining a +blockstructure. Note: the x and y paramaters are the offset from the left +and top of the map in _BLOCKS_ NOT pixels. See mpgame.c for an example. + +------------------------------------------------- +void MapSetBlockInPixels (int x, int y, int strvalue) + +The x and y paramaters are the offset from the left and top of the map +in pixels. If strvalue is positive, the cell is set to that block structure. +If strvalue is negative the cell is set to that anim structure-1 (ie if +you want to put anim 3 in, strvalue would be -4). + +------------------------------------------------- +void MapSetBlock (int x, int y, int strvalue); + +The x and y paramaters are the offset from the left and top of the map +in _BLOCKS_ NOT pixels. See mpgame.c for an example. If strvalue is +positive, the cell is set to that block structure. If strvalue is +negative the cell is set to that anim structure-1 (ie if you want to +put anim 3 in, strvalue would be -4). +------------------------------------------------- +int MapGenerateYLookup (void); + +This is now called for you on MapLoad and is not required, however for an explanation: + +It will generate a lookup table that _may_ slightly speed up the functions +MapGetBlock and MapSetBlock, and allows you to use the maparraypt. If you +use this, you _must_ use MapChangeLayer if you want to swap between layers. +Another advantage is you can access block or anim offsets simply with: +maparraypt[y][x]; +Where x is the offset from the left in _BLOCKS_, and y is the offset from +the top in _BLOCKS_. Note you can get the actual block structure with the +functions MapGetBlock and MapSetBlock. +The memory allocated is freed when either MapFreeMem is called, or another +map is loaded. + +------------------------------------------------- +int MapGetBlockID (int blid, int usernum) + +returns the number of the first block that matches 'blid' in the field +specified with usernum (1 to 7, user1 to user7). If no match, returns -1 + + + +------------------------------------------------- +void MapInitAnims (void); + +Call to reset the animated blocks to their defaults +Called on loading of a map for you + +------------------------------------------------- +void MapUpdateAnims (void); + +Animation control. Call from your game loop, moves blocks to next anim +Animations are set up in the map editor + + +Don't forget to look at the example source code, I've documented them. + + +Version Changes: +================ + +version 1. \ No newline at end of file diff --git a/Assignment3Project/Assignment3Project/bullet.cpp b/Assignment3Project/Assignment3Project/bullet.cpp index d60d256..e38d885 100644 --- a/Assignment3Project/Assignment3Project/bullet.cpp +++ b/Assignment3Project/Assignment3Project/bullet.cpp @@ -1,9 +1,20 @@ #include "bullet.h" -Bullet::Bullet() { - speed = 1.0; - height = 20; - width = 5; +Bullet::Bullet(Behavior _behavior) { + behavior = _behavior; + switch (behavior) { + case Enemy: + speed = 1.0; + height = 20; + width = 5; + break; + default: + speed = 1.0; + height = 20; + width = 5; + break; + } + oob = false; } @@ -19,7 +30,14 @@ void Bullet::draw() { } void Bullet::move(Direction dir) { - y_pos -= 6; + switch (dir) { + case U: + y_pos -= 6; + break; + case D: + y_pos += 6; + break; + } if (y_pos < 0 - height) { oob = true; } diff --git a/Assignment3Project/Assignment3Project/bullet.h b/Assignment3Project/Assignment3Project/bullet.h index 37d6c35..3ecfdd0 100644 --- a/Assignment3Project/Assignment3Project/bullet.h +++ b/Assignment3Project/Assignment3Project/bullet.h @@ -5,7 +5,7 @@ class Bullet : public GameElement { public: - Bullet(); + Bullet(Behavior _behavior); void reset_pos(float x, float y); void draw(); diff --git a/Assignment3Project/Assignment3Project/cheesetheme.wav b/Assignment3Project/Assignment3Project/cheesetheme.wav new file mode 100644 index 0000000..32a1e3b Binary files /dev/null and b/Assignment3Project/Assignment3Project/cheesetheme.wav differ diff --git a/Assignment3Project/Assignment3Project/enums.h b/Assignment3Project/Assignment3Project/enums.h index 8cbc602..37e3494 100644 --- a/Assignment3Project/Assignment3Project/enums.h +++ b/Assignment3Project/Assignment3Project/enums.h @@ -2,6 +2,10 @@ #define SCREEN_W 640 #define SCREEN_H 480 +#define SCREEN_R_B 600 +#define SCREEN_L_B 40 +#define TILE_SIZE 40 +#define LEVEL_LEN 120 enum State { Start, diff --git a/Assignment3Project/Assignment3Project/font.tga b/Assignment3Project/Assignment3Project/font.tga new file mode 100644 index 0000000..552cd9a Binary files /dev/null and b/Assignment3Project/Assignment3Project/font.tga differ diff --git a/Assignment3Project/Assignment3Project/game.cpp b/Assignment3Project/Assignment3Project/game.cpp index 7cefbca..79771d1 100644 --- a/Assignment3Project/Assignment3Project/game.cpp +++ b/Assignment3Project/Assignment3Project/game.cpp @@ -14,11 +14,9 @@ void Game::init() { sprites.insert(pair("Ship", al_load_bitmap("placeholder.bmp"))); - //al_reserve_samples(4); - //samples.insert(pair("Theme", al_load_sample("rasputin.wav"))); - + al_reserve_samples(4); + samples.insert(pair("Theme", al_load_sample("cheesetheme.wav"))); - font = al_create_builtin_font(); } diff --git a/Assignment3Project/Assignment3Project/game_element.h b/Assignment3Project/Assignment3Project/game_element.h index 853f06e..05e0ffb 100644 --- a/Assignment3Project/Assignment3Project/game_element.h +++ b/Assignment3Project/Assignment3Project/game_element.h @@ -7,10 +7,14 @@ class GameElement { public: float x_pos; float y_pos; + float h_bound; + float l_bound; + float r_bound; float speed; float height; float width; bool oob; + Behavior behavior; virtual void reset_pos(float x, float y) = 0; virtual void move(Direction dir) = 0; diff --git a/Assignment3Project/Assignment3Project/game_screen.cpp b/Assignment3Project/Assignment3Project/game_screen.cpp index 31c649a..63a227a 100644 --- a/Assignment3Project/Assignment3Project/game_screen.cpp +++ b/Assignment3Project/Assignment3Project/game_screen.cpp @@ -9,6 +9,8 @@ #include #include +//#include "mappy_A5.h" + #include "game_screen.h" #define FPS 60 @@ -31,7 +33,7 @@ GameScreen::GameScreen(std::map _sprites, std::map //Resets game to default values, and uses new given values void GameScreen::reset() { - objects.player = new Ship(); + objects.player = new Ship(Player); objects.player->set_sprite(sprites["Ship"]); objects.player->reset_pos(SCREEN_W / 2, SCREEN_H / 8); max_bullets = 3; @@ -56,6 +58,10 @@ void GameScreen::run(ALLEGRO_FONT* font) { timer = al_create_timer(1.0 / FPS); al_register_event_source(event_queue, al_get_timer_event_source(timer)); + //MapLoad((char*)"level.fmp", 1); + + map_y = TILE_SIZE * LEVEL_LEN; + redraw(font); al_flip_display(); @@ -119,6 +125,13 @@ void GameScreen::run(ALLEGRO_FONT* font) { } } + if (map_y > 0) { + map_y -= 10; + } + else { + next_state = Exit; + } + //Global refresh al_clear_to_color(al_map_rgb(0, 0, 0)); redraw(font); @@ -202,12 +215,15 @@ void GameScreen::run(ALLEGRO_FONT* font) { } //Garbage collection + //MapFreeMem(); al_destroy_event_queue(event_queue); al_destroy_timer(timer); } //Redraw all elements of the screen void GameScreen::redraw(ALLEGRO_FONT* font) { + //MapDrawBG(0, map_y, 0, SCREEN_L_B, SCREEN_W - 80, SCREEN_H); + objects.player->draw(); vector unload; diff --git a/Assignment3Project/Assignment3Project/game_screen.h b/Assignment3Project/Assignment3Project/game_screen.h index 4598866..80c4e3f 100644 --- a/Assignment3Project/Assignment3Project/game_screen.h +++ b/Assignment3Project/Assignment3Project/game_screen.h @@ -16,6 +16,9 @@ public: int score; int level; bool music; + + int map_y; + ObjectManager objects; unsigned int max_bullets; diff --git a/Assignment3Project/Assignment3Project/level.fmp b/Assignment3Project/Assignment3Project/level.fmp new file mode 100644 index 0000000..3a44cd3 Binary files /dev/null and b/Assignment3Project/Assignment3Project/level.fmp differ diff --git a/Assignment3Project/Assignment3Project/mappy.exe b/Assignment3Project/Assignment3Project/mappy.exe new file mode 100644 index 0000000..999b6a1 Binary files /dev/null and b/Assignment3Project/Assignment3Project/mappy.exe differ diff --git a/Assignment3Project/Assignment3Project/packages.config b/Assignment3Project/Assignment3Project/packages.config index 1ed61ed..0c6bbd7 100644 --- a/Assignment3Project/Assignment3Project/packages.config +++ b/Assignment3Project/Assignment3Project/packages.config @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file diff --git a/Assignment3Project/Assignment3Project/parallax.bmp b/Assignment3Project/Assignment3Project/parallax.bmp new file mode 100644 index 0000000..5d634e9 Binary files /dev/null and b/Assignment3Project/Assignment3Project/parallax.bmp differ diff --git a/Assignment3Project/Assignment3Project/ship.cpp b/Assignment3Project/Assignment3Project/ship.cpp index 4e564af..60aeb96 100644 --- a/Assignment3Project/Assignment3Project/ship.cpp +++ b/Assignment3Project/Assignment3Project/ship.cpp @@ -2,20 +2,20 @@ Ship::Ship(Behavior _behavior) { switch (_behavior) { - case Player: - speed = 1.0; + case Enemy: + speed = 1.2; height = 40; width = 40; break; - case Enemy: - speed = 1.2; + default: + speed = 1.0; height = 40; width = 40; break; } - l_bound = 50; - r_bound = 590; + l_bound = SCREEN_L_B; + r_bound = SCREEN_R_B; r_bound -= width; h_bound = SCREEN_H; h_bound -= height; @@ -82,7 +82,7 @@ void Ship::move(Direction dir) { } Bullet Ship::fire() { - Bullet new_bullet; + Bullet new_bullet(behavior); float x = (x_pos) + width / 2.0; float y = y_pos - new_bullet.height; new_bullet.reset_pos(x, y); diff --git a/Assignment3Project/Assignment3Project/ship.h b/Assignment3Project/Assignment3Project/ship.h index 5b16220..4ac5510 100644 --- a/Assignment3Project/Assignment3Project/ship.h +++ b/Assignment3Project/Assignment3Project/ship.h @@ -9,12 +9,7 @@ public: ALLEGRO_BITMAP* sprite; bool fired; - float h_bound; - float l_bound; - float r_bound; - - Behavior behavior; - + Ship(Behavior _behavior); void reset_pos(float x, float y); diff --git a/Assignment3Project/Assignment3Project/test32bpp.fmp b/Assignment3Project/Assignment3Project/test32bpp.fmp new file mode 100644 index 0000000..47a8691 Binary files /dev/null and b/Assignment3Project/Assignment3Project/test32bpp.fmp differ diff --git a/Assignment3Project/Assignment3Project/test8bpp.fmp b/Assignment3Project/Assignment3Project/test8bpp.fmp new file mode 100644 index 0000000..92a9a72 Binary files /dev/null and b/Assignment3Project/Assignment3Project/test8bpp.fmp differ diff --git a/Assignment3Project/Assignment3Project/testhex.fmp b/Assignment3Project/Assignment3Project/testhex.fmp new file mode 100644 index 0000000..add2a79 Binary files /dev/null and b/Assignment3Project/Assignment3Project/testhex.fmp differ diff --git a/Assignment3Project/Assignment3Project/testiso.fmp b/Assignment3Project/Assignment3Project/testiso.fmp new file mode 100644 index 0000000..4624609 Binary files /dev/null and b/Assignment3Project/Assignment3Project/testiso.fmp differ