Mappy sucks I hate my life

main
Braydon Kains 6 years ago
parent 2d8714ed26
commit 84527304ae

@ -86,6 +86,10 @@
<Allegro_AddonAcodec>true</Allegro_AddonAcodec> <Allegro_AddonAcodec>true</Allegro_AddonAcodec>
<Allegro_AddonFont>true</Allegro_AddonFont> <Allegro_AddonFont>true</Allegro_AddonFont>
<Allegro_AddonColor>true</Allegro_AddonColor> <Allegro_AddonColor>true</Allegro_AddonColor>
<Allegro_AddonPhysfs>true</Allegro_AddonPhysfs>
<Allegro_AddonDialog>true</Allegro_AddonDialog>
<Allegro_AddonMemfile>true</Allegro_AddonMemfile>
<Allegro_AddonVideo>true</Allegro_AddonVideo>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
@ -101,6 +105,7 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -141,6 +146,7 @@
<ClInclude Include="game.h" /> <ClInclude Include="game.h" />
<ClInclude Include="game_element.h" /> <ClInclude Include="game_element.h" />
<ClInclude Include="game_screen.h" /> <ClInclude Include="game_screen.h" />
<ClInclude Include="mappy_A5.h" />
<ClInclude Include="object_manager.h" /> <ClInclude Include="object_manager.h" />
<ClInclude Include="screen.h" /> <ClInclude Include="screen.h" />
<ClInclude Include="ship.h" /> <ClInclude Include="ship.h" />
@ -152,15 +158,16 @@
<ClCompile Include="game.cpp" /> <ClCompile Include="game.cpp" />
<ClCompile Include="game_screen.cpp" /> <ClCompile Include="game_screen.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="mappy_A5.c" />
<ClCompile Include="object_manager.cpp" /> <ClCompile Include="object_manager.cpp" />
<ClCompile Include="ship.cpp" /> <ClCompile Include="ship.cpp" />
<ClCompile Include="start_screen.cpp" /> <ClCompile Include="start_screen.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <Text Include="enemies.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="enemies.txt" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

@ -63,6 +63,9 @@
<ClInclude Include="object_manager.h"> <ClInclude Include="object_manager.h">
<Filter>Header Files\Engine</Filter> <Filter>Header Files\Engine</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="mappy_A5.h">
<Filter>Header Files\Engine</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
@ -89,13 +92,16 @@
<ClCompile Include="object_manager.cpp"> <ClCompile Include="object_manager.cpp">
<Filter>Source Files\EngineImplement</Filter> <Filter>Source Files\EngineImplement</Filter>
</ClCompile> </ClCompile>
</ItemGroup> <ClCompile Include="mappy_A5.c">
<ItemGroup> <Filter>Source Files\EngineImplement</Filter>
<None Include="packages.config" /> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="enemies.txt"> <Text Include="enemies.txt">
<Filter>Resource Files</Filter> <Filter>Resource Files</Filter>
</Text> </Text>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project> </Project>

@ -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.

@ -1,9 +1,20 @@
#include "bullet.h" #include "bullet.h"
Bullet::Bullet() { Bullet::Bullet(Behavior _behavior) {
speed = 1.0; behavior = _behavior;
height = 20; switch (behavior) {
width = 5; case Enemy:
speed = 1.0;
height = 20;
width = 5;
break;
default:
speed = 1.0;
height = 20;
width = 5;
break;
}
oob = false; oob = false;
} }
@ -19,7 +30,14 @@ void Bullet::draw() {
} }
void Bullet::move(Direction dir) { 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) { if (y_pos < 0 - height) {
oob = true; oob = true;
} }

@ -5,7 +5,7 @@
class Bullet : public GameElement { class Bullet : public GameElement {
public: public:
Bullet(); Bullet(Behavior _behavior);
void reset_pos(float x, float y); void reset_pos(float x, float y);
void draw(); void draw();

@ -2,6 +2,10 @@
#define SCREEN_W 640 #define SCREEN_W 640
#define SCREEN_H 480 #define SCREEN_H 480
#define SCREEN_R_B 600
#define SCREEN_L_B 40
#define TILE_SIZE 40
#define LEVEL_LEN 120
enum State { enum State {
Start, Start,

@ -14,11 +14,9 @@ void Game::init() {
sprites.insert(pair<string, ALLEGRO_BITMAP*>("Ship", al_load_bitmap("placeholder.bmp"))); sprites.insert(pair<string, ALLEGRO_BITMAP*>("Ship", al_load_bitmap("placeholder.bmp")));
//al_reserve_samples(4); al_reserve_samples(4);
//samples.insert(pair<string, ALLEGRO_SAMPLE*>("Theme", al_load_sample("rasputin.wav"))); samples.insert(pair<string, ALLEGRO_SAMPLE*>("Theme", al_load_sample("cheesetheme.wav")));
font = al_create_builtin_font(); font = al_create_builtin_font();
} }

@ -7,10 +7,14 @@ class GameElement {
public: public:
float x_pos; float x_pos;
float y_pos; float y_pos;
float h_bound;
float l_bound;
float r_bound;
float speed; float speed;
float height; float height;
float width; float width;
bool oob; bool oob;
Behavior behavior;
virtual void reset_pos(float x, float y) = 0; virtual void reset_pos(float x, float y) = 0;
virtual void move(Direction dir) = 0; virtual void move(Direction dir) = 0;

@ -9,6 +9,8 @@
#include <map> #include <map>
#include <ctime> #include <ctime>
//#include "mappy_A5.h"
#include "game_screen.h" #include "game_screen.h"
#define FPS 60 #define FPS 60
@ -31,7 +33,7 @@ GameScreen::GameScreen(std::map<std::string, ALLEGRO_BITMAP*> _sprites, std::map
//Resets game to default values, and uses new given values //Resets game to default values, and uses new given values
void GameScreen::reset() { void GameScreen::reset() {
objects.player = new Ship(); objects.player = new Ship(Player);
objects.player->set_sprite(sprites["Ship"]); objects.player->set_sprite(sprites["Ship"]);
objects.player->reset_pos(SCREEN_W / 2, SCREEN_H / 8); objects.player->reset_pos(SCREEN_W / 2, SCREEN_H / 8);
max_bullets = 3; max_bullets = 3;
@ -56,6 +58,10 @@ void GameScreen::run(ALLEGRO_FONT* font) {
timer = al_create_timer(1.0 / FPS); timer = al_create_timer(1.0 / FPS);
al_register_event_source(event_queue, al_get_timer_event_source(timer)); 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); redraw(font);
al_flip_display(); 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 //Global refresh
al_clear_to_color(al_map_rgb(0, 0, 0)); al_clear_to_color(al_map_rgb(0, 0, 0));
redraw(font); redraw(font);
@ -202,12 +215,15 @@ void GameScreen::run(ALLEGRO_FONT* font) {
} }
//Garbage collection //Garbage collection
//MapFreeMem();
al_destroy_event_queue(event_queue); al_destroy_event_queue(event_queue);
al_destroy_timer(timer); al_destroy_timer(timer);
} }
//Redraw all elements of the screen //Redraw all elements of the screen
void GameScreen::redraw(ALLEGRO_FONT* font) { void GameScreen::redraw(ALLEGRO_FONT* font) {
//MapDrawBG(0, map_y, 0, SCREEN_L_B, SCREEN_W - 80, SCREEN_H);
objects.player->draw(); objects.player->draw();
vector<int> unload; vector<int> unload;

@ -16,6 +16,9 @@ public:
int score; int score;
int level; int level;
bool music; bool music;
int map_y;
ObjectManager objects; ObjectManager objects;
unsigned int max_bullets; unsigned int max_bullets;

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Allegro" version="5.2.4.0" targetFramework="native" /> <package id="Allegro" version="5.2.4.0" targetFramework="native" />
<package id="AllegroDeps" version="1.7.0.0" targetFramework="native" /> <package id="AllegroDeps" version="1.7.0.0" targetFramework="native" />
</packages> </packages>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

@ -2,20 +2,20 @@
Ship::Ship(Behavior _behavior) { Ship::Ship(Behavior _behavior) {
switch (_behavior) { switch (_behavior) {
case Player: case Enemy:
speed = 1.0; speed = 1.2;
height = 40; height = 40;
width = 40; width = 40;
break; break;
case Enemy: default:
speed = 1.2; speed = 1.0;
height = 40; height = 40;
width = 40; width = 40;
break; break;
} }
l_bound = 50; l_bound = SCREEN_L_B;
r_bound = 590; r_bound = SCREEN_R_B;
r_bound -= width; r_bound -= width;
h_bound = SCREEN_H; h_bound = SCREEN_H;
h_bound -= height; h_bound -= height;
@ -82,7 +82,7 @@ void Ship::move(Direction dir) {
} }
Bullet Ship::fire() { Bullet Ship::fire() {
Bullet new_bullet; Bullet new_bullet(behavior);
float x = (x_pos) + width / 2.0; float x = (x_pos) + width / 2.0;
float y = y_pos - new_bullet.height; float y = y_pos - new_bullet.height;
new_bullet.reset_pos(x, y); new_bullet.reset_pos(x, y);

@ -9,12 +9,7 @@ public:
ALLEGRO_BITMAP* sprite; ALLEGRO_BITMAP* sprite;
bool fired; bool fired;
float h_bound;
float l_bound;
float r_bound;
Behavior behavior;
Ship(Behavior _behavior); Ship(Behavior _behavior);
void reset_pos(float x, float y); void reset_pos(float x, float y);

Loading…
Cancel
Save