Skip to content

Commit

Permalink
The source code synced with the Black game development kit 6.4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
PopovEvgeniy committed Feb 6, 2025
1 parent 52a99e5 commit fdd6265
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 12 deletions.
67 changes: 58 additions & 9 deletions documentation/reference.htm
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
<li><a href="#mozTocId904725">Chapter 5. Image kind</a></li>
<li><a href="#mozTocId738557">Chapter 6. Background</a></li>
<li><a href="#mozTocId946803">Chapter 7. Static background</a></li>
<li><a href="#mozTocId309905">Chapter 8. Base sprite subsystem</a></li>
<li><a href="#mozTocId662651">Chapter 9. Ordinary sprites</a></li>
<li><a href="#mozTocId656897">Chapter 10. Static sprites</a></li>
<li><a href="#mozTocId146800">Chapter 11. Sprite sheet</a></li>
<li><a href="#mozTocId946803">Chapter 8. Parallax</a></li>
<li><a href="#mozTocId309905">Chapter 9. Base sprite subsystem</a></li>
<li><a href="#mozTocId662651">Chapter 10. Ordinary sprites</a></li>
<li><a href="#mozTocId656897">Chapter 11. Static sprites</a></li>
<li><a href="#mozTocId146800">Chapter 12. Sprite sheet</a></li>
<li><a href="#mozTocId752257">Chapter 12. Text</a></li>
<li><a href="#mozTocId67980">Chapter 13. Loading images</a></li>
</ul>
Expand Down Expand Up @@ -495,7 +496,54 @@ <h2><a class="mozTocH2" name="mozTocId946803" id="mozTocId946803"></a><big>Chapt
<br>
<span style="text-decoration: underline;">Important notice</span></big></p>
<p><big>Always call the <span style="font-style: italic;">prepare</span> after the background has been loaded.<br></big></p>
<h2><a class="mozTocH2" name="mozTocId309905" id="mozTocId309905"></a><big>Chapter 8. Base sprite subsystem</big></h2>
<h2><a class="mozTocH2" name="mozTocId946803" id="mozTocId946803"></a><big>Chapter 8. Parallax<br></big></h2>
<p><big><span style="text-decoration: underline;">A few words about parallax</span><br>
<br>
The parallax background is a background with scrolling support.</big></p>
<p style="text-decoration: underline;"><big>Speed</big></p>
<p><big>The scrolling speed should be a positive number.</big><br>
<big><br>
<span style="text-decoration: underline;">Work with the background</span><br>
<br>
Just use the <span style="font-style: italic;">Parallax</span> class to work with the parallax background. Let's look at the publicly available methods.<br>
<br>
<span style="font-style: italic;">Parallax *Parallax::get_handle(); -</span> Return the handle to the background object.<br>
<br></big> <big><span style="font-style: italic;">void Parallax::prepare(const Screen *screen); -</span> Prepare for drawing.<br>
<br>
<span style="font-style: italic;">void Parallax::prepare(Screen &amp;screen); -</span> Prepare for drawing.<br>
<br>
<span style="font-style: italic;">void Parallax::prepare(const unsigned int width, const unsigned int height); -</span> Prepare for drawing.<br>
<br>
<span style="font-style: italic;">void Parallax::disable_mirror(); -</span> Disable background mirroring mode.<br>
<br>
<span style="font-style: italic;">void Parallax::horizontal_mirror(); -</span> Set horizontal background mirroring mode.<br>
<br>
<span style="font-style: italic;">void Parallax::vertical_mirror(); -</span> Set vertical background mirroring mode.<br>
<br>
<span style="font-style: italic;">void Parallax::complex_mirror(); -</span> Set both horizontal and vertical background mirroring modes.<br></big> <big><br>
<span style="font-style: italic;">void Parallax::load(Image *background); -</span> Load a background from the buffer.<br>
<br>
<span style="font-style: italic;">void Parallax::load(Image &amp; background); -</span> Load a background</big> <big>from the buffer.</big><big><br>
<br></big> <big><span style="font-style: italic;">void Parallax::load(</span></big><big style="font-style: italic;">const char *name</big><big><span style="font-style: italic;">); -</span> Load a background from the target file.</big><br>
<big><br>
<span style="font-style: italic;">void Parallax::draw(const float horizontal_speed, const vertical_speed); -</span> Draw a background.<br>
<br>
<span style="font-style: italic;">void Parallax::destroy_image(); -</span> Destroy a background image.<br>
<br>
<span style="font-style: italic;">void Parallax::destroy(); -</span> Destroy a background image and destroy the texture.<br>
<br></big> <big><span style="font-style: italic;">bool Parallax::is_load() const; -</span> Return true if a parallax background has already been loaded.</big><br>
<br>
<big><span style="font-style: italic;">unsigned int Parallax::get_width() const; -</span> Return the width of the background.<br>
<br>
<span style="font-style: italic;">unsigned int Parallax::get_height() const; -</span> Return the height of the background.<br>
<br>
<span style="text-decoration: underline;">A background texture</span><br>
<br>
The background doesn't draw if the background texture doesn't exist. It will automatically be created when you load an image.<br>
<br>
<span style="text-decoration: underline;">Important notice</span></big></p>
<p><big>Always call the <span style="font-style: italic;">prepare</span> after the background has been loaded.</big></p>
<h2><a class="mozTocH2" name="mozTocId309905" id="mozTocId309905"></a><big>Chapter 9. Base sprite subsystem</big></h2>
<p><big><span style="text-decoration: underline;">A small, important thing</span><br>
<br>
A sprite is a transparent image. It is useful for many things: enemies, bonuses, etc.<br></big> <big><br>
Expand Down Expand Up @@ -553,7 +601,7 @@ <h2><a class="mozTocH2" name="mozTocId309905" id="mozTocId309905"></a><big>Chapt
<br></big> <big><span style="font-style: italic;">void Billboard::draw(const unsigned int x, const unsigned int y); -</span> Set the sprite position and draw it.<br>
<br></big> <big><em>void Billboard::draw(const bool transparency); -</em> Set the transparent mode and draw a sprite.<br>
<br></big> <big><em>void Billboard::draw(const bool transparency, const unsigned int x, const unsigned int y); -</em> Set the transparent mode and draw a sprite at the target position.</big></p>
<h2><a class="mozTocH2" name="mozTocId662651" id="mozTocId662651"></a><big>Chapter 9. Ordinary sprites</big></h2>
<h2><a class="mozTocH2" name="mozTocId662651" id="mozTocId662651"></a><big>Chapter 10. Ordinary sprites</big></h2>
<p><big><span style="text-decoration: underline;">Sprite types</span><br></big></p>
<p><big>There are two kinds of ordinary sprites: the horizontal strips and the vertical strips. It is a small image with a few frames.<br>
The horizontal strip looks like the horizontal photo ribbon. The vertical strip looks like the vertical photo ribbon.</big></p>
Expand Down Expand Up @@ -581,7 +629,7 @@ <h2><a class="mozTocH2" name="mozTocId662651" id="mozTocId662651"></a><big>Chapt
<span style="text-decoration: underline;">A sprite texture</span><br>
<br>
A sprite doesn't draw if the sprite texture doesn't exist. It will automatically be created when you load or clone a sprite.<br></big></p>
<h2><a class="mozTocH2" name="mozTocId656897" id="mozTocId656897"></a><big>Chapter 10. Static sprites</big></h2>
<h2><a class="mozTocH2" name="mozTocId656897" id="mozTocId656897"></a><big>Chapter 11. Static sprites</big></h2>
<p><big><span style="text-decoration: underline;">A few words about static sprite</span><br>
<br>
The static sprite is a simple kind of sprite. It contains one frame only.<br>
Expand All @@ -602,7 +650,7 @@ <h2><a class="mozTocH2" name="mozTocId656897" id="mozTocId656897"></a><big>Chapt
<span style="text-decoration: underline;">A sprite texture</span><br>
<br>
A sprite doesn't draw if the sprite texture doesn't exist. It will automatically be created when you load or clone a sprite.</big></p>
<h2><a class="mozTocH2" name="mozTocId146800" id="mozTocId146800"></a><big>Chapter 11. Sprite sheet</big></h2>
<h2><a class="mozTocH2" name="mozTocId146800" id="mozTocId146800"></a><big>Chapter 12. Sprite sheet</big></h2>
<p><big><span style="text-decoration: underline;">Some words about a sprite sheet</span><br>
<br>
A sprite sheet is a special kind of animated sprite. Each frame has a fixed size. The sheet is a matrix of frames. Look at this picture to understand it.<br>
Expand Down Expand Up @@ -1791,6 +1839,7 @@ <h1><a class="mozTocH1" name="mozTocId670307" id="mozTocId670307"></a><big>Versi
8.8.1: The source code synced with the Eugene game development kit 9.4.6.<br>
8.8.2: The source code synced with the Eugene game development kit 9.4.7.<br>
8.8.3: The source code synced with the Eugene game development kit 9.4.8.<br>
8.8.4: The source code synced with the Eugene game development kit 9.4.9.<br></big>
8.8.4: The source code synced with the Eugene game development kit 9.4.9.<br>
8.8.5: The source code synced with the Black game development kit 6.4.7.<br></big>
</body>
</html>
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Features
Two render backends: hardware-accelerated OPENGL and software OPENGL.
Easy-to-use object-oriented API.
Animated and static sprites.
Scrollable and static backgrounds.
Animated backgrounds.
Parallax and static backgrounds.
Sprite-sheets.
Tile-maps.
Image transformation: resizing and mirroring.
Expand Down
154 changes: 152 additions & 2 deletions source/SWGF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,8 @@ namespace SWGF
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,buffer);
}

Expand Down Expand Up @@ -3506,6 +3506,156 @@ namespace SWGF
return stage.get_height();
}

Parallax::Parallax()
{
stage.set_size(0,0);
u_offset=0.0f;
v_offset=0.0f;
}

Parallax::~Parallax()
{
stage.destroy();
}

void Parallax::calculate_u_offset(const float speed)
{
if (speed>0.0f)
{
u_offset+=speed;
}

}

void Parallax::calculate_v_offset(const float speed)
{
if (speed>0.0f)
{
v_offset+=speed;
}

}

void Parallax::reset_u_offset()
{
if (u_offset>1.0f)
{
u_offset=0.0f;
}

}

void Parallax::reset_v_offset()
{
if (v_offset>1.0f)
{
v_offset=0.0f;
}

}

void Parallax::set_texture_coordinates()
{
stage.set_texture_coordinates(0,u_offset,1.0f+v_offset);
stage.set_texture_coordinates(1,1.0f+u_offset,1.0f+v_offset);
stage.set_texture_coordinates(2,1.0f+u_offset,v_offset);
stage.set_texture_coordinates(3,u_offset,v_offset);
}

Parallax* Parallax::get_handle()
{
return this;
}

void Parallax::prepare(const Screen *screen)
{
if (screen!=NULL)
{
stage.set_size(screen->get_width(),screen->get_height());
}

}

void Parallax::prepare(const unsigned int width,const unsigned int height)
{
stage.set_size(width,height);
}

void Parallax::prepare(Screen &screen)
{
this->prepare(screen.get_handle());
}

void Parallax::load(Image *background)
{
stage.load(background);
}

void Parallax::load(Image &background)
{
stage.load(background);
}

void Parallax::load(const char *name)
{
stage.load(name);
}

void Parallax::disable_mirror()
{
stage.disable_mirror();
}

void Parallax::horizontal_mirror()
{
stage.horizontal_mirror();
}

void Parallax::vertical_mirror()
{
stage.vertical_mirror();
}

void Parallax::complex_mirror()
{
stage.complex_mirror();
}

void Parallax::destroy_image()
{
stage.destroy_image();
}

void Parallax::draw(const float horizontal_speed,const float vertical_speed)
{
this->calculate_u_offset(horizontal_speed);
this->calculate_v_offset(vertical_speed);
this->reset_u_offset();
this->reset_v_offset();
this->set_texture_coordinates();
stage.draw(false);
}

void Parallax::destroy()
{
stage.destroy();
}

bool Parallax::is_load() const
{
return stage.is_load();
}

unsigned int Parallax::get_width() const
{
return stage.get_width();
}

unsigned int Parallax::get_height() const
{
return stage.get_height();
}

Text::Text()
{
text.set_size(0,0);
Expand Down
33 changes: 33 additions & 0 deletions source/SWGF.h
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,39 @@ typedef enum
unsigned int get_height() const;
};

class Parallax
{
private:
Graphics::Cartoon stage;
float u_offset;
float v_offset;
void calculate_u_offset(const float speed);
void calculate_v_offset(const float speed);
void reset_u_offset();
void reset_v_offset();
void set_texture_coordinates();
public:
Parallax();
~Parallax();
Parallax* get_handle();
void prepare(const Screen *screen);
void prepare(Screen &screen);
void prepare(const unsigned int width,const unsigned int height);
void load(Image *background);
void load(Image &background);
void load(const char *name);
void disable_mirror();
void horizontal_mirror();
void vertical_mirror();
void complex_mirror();
void draw(const float horizontal_speed,const float vertical_speed);
void destroy_image();
void destroy();
bool is_load() const;
unsigned int get_width() const;
unsigned int get_height() const;
};

class Text
{
private:
Expand Down
56 changes: 56 additions & 0 deletions source/parallax.cbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="parallax" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="32 bit">
<Option output="bin/Release/parallax" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m32" />
</Compiler>
<Linker>
<Add option="-m32" />
</Linker>
</Target>
<Target title="64 bit">
<Option output="bin/Release/parallax64" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m64" />
</Compiler>
<Linker>
<Add option="-m64" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-std=c++98" />
<Add option="-fexceptions" />
</Compiler>
<Linker>
<Add option="-static-libstdc++" />
<Add option="-static-libgcc" />
<Add option="-static" />
<Add library="user32" />
<Add library="kernel32" />
<Add library="gdi32" />
<Add library="opengl32" />
<Add library="ole32" />
<Add library="strmiids" />
<Add library="xinput" />
</Linker>
<Unit filename="SWGF.cpp" />
<Unit filename="SWGF.h" />
<Unit filename="parallax.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>
Loading

0 comments on commit fdd6265

Please sign in to comment.