Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Billy2600

Pages: [1]
1
SFML projects / Re: Bazoik - A clone of the arcade game Berzerk
« on: July 23, 2020, 11:01:08 pm »
Oh man, it'd almost be easier to explain where I didn't use SFML. This code takes advantage of the SFML features you'd expect, like window handling, input handling, sprite drawing, etc. But also, the SFML data types were used quite a bit. Positions are stored as Vector2s, hitboxes are FloatRects, etc. Only a couple other libraries were used, like one to perform line clipping for testing the robots' line of sight, and another to parse XML files.

I have added link to a video to the first post, showing a little over a minute of gameplay. I didn't see a way to embed a video from YouTube.

2
SFML projects / Bazoik - A clone of the arcade game Berzerk
« on: July 23, 2020, 07:11:59 pm »
Bazoik is a free and open source clone of the 80's arcade game Berzerk. I actually created this in 2018, with a couple friends doing everything that wasn't code. If you do take a look at the code, please know that it's not up to my current standards and doesn't really take advantage of C++11 features, etc. Currently Windows only.

I'd love see hear what you think of the game.



Itch.io

Github



3
General / Re: Error while capturing resized window?
« on: June 24, 2017, 04:09:43 am »
Sorry, I thought "resize" would be self-explanatory. I did experiment with the MCVE, but you definitely pointed me toward the solution:

txTrans.create( window.getSize().x, window.getSize().y );
sf::View view;
view = window.getDefaultView();
view.setSize( window.getSize().x, window.getSize().y );
view.setCenter( window.getSize().x / 2, window.getSize().y / 2 );
window.setView( view );
txTrans.update( window );
sprTrans.setTexture( txTrans, true );
 

And then after the transition is done, reset the view (because my intention is to keep the image stretched, not increase the viewport):

window.setView( window.getDefaultView() );
 

I'm sure there's optimizations I can do. Regardless, thank you all for your input.

4
General / Re: Error while capturing resized window?
« on: June 21, 2017, 01:20:44 am »
Sorry for the delay, here's a proper MCVE that's exhibiting the same issue.
#include <SFML/Graphics.hpp>
#include <cstdlib>

#define WIN_WIDTH 640
#define WIN_HEIGHT 480
#define NUM_SHAPES 5
#define MOVE_SPEED 0.05f
#define TRANS_SPEED 0.05f
#define TRANS_DELAY 2000

sf::RenderWindow window( sf::VideoMode( WIN_WIDTH, WIN_HEIGHT ), "SFML Capture MCVE" );
sf::RectangleShape shapes[NUM_SHAPES];
sf::RectangleShape player;
bool transition = false;
bool captured = false;
sf::Int8 lastMove = 0;
sf::Texture txTrans;
sf::Sprite sprTrans;
sf::Clock clkTrans;

void ScreenTransition( const sf::Int8 lastMove ) // 0 = N, 1 = E, 2 = S, 3 = W
{
        if ( !captured )
        {
                // Capture the screen
                txTrans.create( window.getSize().x, window.getSize().y );
                txTrans.update( window );
                sprTrans.setTexture( txTrans, true );
                captured = true;
                clkTrans.restart();
        }
        else
        {
                sf::Vector2f move;
                switch ( lastMove )
                {
                case 0:
                        move = sf::Vector2f( 0, -TRANS_SPEED );
                        break;
                case 1:
                        move = sf::Vector2f( TRANS_SPEED, 0 );
                        break;
                case 2:
                        move = sf::Vector2f( 0, TRANS_SPEED );
                        break;
                case 3:
                        move = sf::Vector2f( -TRANS_SPEED, 0 );
                        break;
                }

                sprTrans.move( move );

                // Fake resetting state
                if ( clkTrans.getElapsedTime().asMilliseconds() > TRANS_DELAY )
                {
                        transition = false;
                        captured = false;
                        player.setPosition( 10, 10 );
                        sprTrans.setPosition( 0, 0 );
                }
        }
}

int main()
{
        for ( int i = 0; i < NUM_SHAPES; i++ )
        {
                shapes[i].setFillColor( sf::Color::Blue );
                shapes[i].setPosition( rand() % WIN_WIDTH, rand() % WIN_HEIGHT );
                shapes[i].setSize( sf::Vector2f( rand() % 1 + 100, rand() % 1 + 100 ) );
        }
        player.setSize( sf::Vector2f( 50, 50 ) );
        player.setPosition( sf::Vector2f( 10, 10 ) );
        player.setFillColor( sf::Color::Red );
        sprTrans.setPosition( sf::Vector2f( 0, 0 ) );

        while ( window.isOpen() )
        {
                sf::Event event;
                while ( window.pollEvent( event ) )
                {
                        if ( event.type == sf::Event::Closed )
                                window.close();
                }

                if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::D ) )
                        player.move( MOVE_SPEED, 0 );
                else if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::A ) )
                        player.move( -MOVE_SPEED, 0 );
                else if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::W ) )
                        player.move( 0, -MOVE_SPEED );
                else if ( sf::Keyboard::isKeyPressed( sf::Keyboard::Key::S ) )
                        player.move( 0, MOVE_SPEED );

                if ( player.getPosition().x < 0 )
                {
                        transition = true;
                        lastMove = 3;
                }
                else if ( player.getPosition().x + 50 > WIN_WIDTH )
                {
                        transition = true;
                        lastMove = 1;
                }
                else if ( player.getPosition().y < 0 )
                {
                        transition = true;
                        lastMove = 0;
                }
                else if ( player.getPosition().y + 50 > WIN_HEIGHT )
                {
                        transition = true;
                        lastMove = 2;
                }

                if ( transition )
                {
                        ScreenTransition( lastMove );
                }

                window.clear();
                if ( transition && captured )
                {
                        window.draw( sprTrans );
                }
                else
                {
                        for ( int i = 0; i < NUM_SHAPES; i++ )
                        {
                                window.draw( shapes[i] );
                        }
                        window.draw( player );
                }
               
                window.display();
        }

        return 0;
}
 

5
General / Re: Error while capturing resized window?
« on: June 16, 2017, 04:11:39 am »
Okay, hopefully this will show you what you need to know. Anything you don't see defined is a member variable or a #define (defines are all caps). Both of these functions run every frame.

void StateGameplay::ScreenTransition( const float dt )
{
        if( !captured )
        {
                // Capture the screen
                txTrans.create( game->window.getSize().x, game->window.getSize().y );
                txTrans.update( game->window );
                sprTrans.setTexture( txTrans, true );
                captured = true;
        }
        else
        {
                sf::Vector2f move;
                switch( lastMove )
                {
                case Directions::N:
                        move = sf::Vector2f( 0, -TRANS_SPEED );
                        break;
                case Directions::E:
                        move = sf::Vector2f( TRANS_SPEED, 0 );
                        break;
                case Directions::S:
                        move = sf::Vector2f( 0, TRANS_SPEED );
                        break;
                case Directions::W:
                        move = sf::Vector2f( -TRANS_SPEED, 0 );
                        break;
                }

                sprTrans.move( move * dt );

                // State gets switched here
}

void StateGameplay::Draw() const
{
        if( transition && captured )
        {
                game->window.draw( sprTrans );
                return; // Don't draw anything else
        }
       
        // etc
}
 

6
General / Re: Error while capturing resized window?
« on: June 15, 2017, 02:53:06 pm »
It displays incorrectly whether being captured by external software or not. By "capture", I meant the built-in function to apply the window's contents to a texture.

7
General / Re: Error while capturing resized window?
« on: June 15, 2017, 03:11:44 am »
Nope. The only things I'm calling from the sprite are setTexture, move, and getGlobalBounds.

8
General / Re: Error while capturing resized window?
« on: June 15, 2017, 01:49:45 am »
Thank you for your reply, but that didn't seem to solve the problem, even after rebuilding.

9
General / Error while capturing resized window?
« on: June 14, 2017, 03:42:37 am »
I'm trying to capture the window in order to do a sort of transition effect, but when I capture a resized window it seems to only capture a portion of the screen or display it incorrectly. There are other ways to do the effect I'm looking for, but I'm hoping to get this method working. I am currently developing on Win10 with VS2015. See the following webms:

Default window size: https://webmshare.com/play/Zro60

Resized window: https://webmshare.com/play/jzxXa

This is the code I'm using to capture the window:
txTrans.create( game->window.getSize().x, game->window.getSize().y );
txTrans.update( game->window );
sprTrans.setTexture( txTrans );
 

Pages: [1]
anything