Giter Site home page Giter Site logo

perl-game's Introduction

perl-game

Import necessary modules

use strict; use warnings; use SDL; use SDLx::App; use SDL::Image;

Initializing SDL

SDL::init(SDL_INIT_VIDEO);

Setting up the game window

my $app = SDLx::App->new( title => '2D Shooter Game', width => 800, height => 600, depth => 32, );

Loading graphics: Shooter, Bird, Background

my $shooter_surface = SDL::Image::load('shooter.png'); my $bird_surface = SDL::Image::load('bird.png'); my $background_surface = SDL::Image::load('background.png');

Setting initial positions and variables

my $shooter_x = 350; my $shooter_y = 500; my $bird_x = 0; my $bird_y = 200; my $bird_speed = 5; my $bird_counter = 0; my $shooting = 0; my $shooting_timer = 0; my $shots_fired = 0;

Game loop

while (1) { # Handle events while (my $event = SDL::Event->new()) { # Quit the game if the user closes the window last if $event->type == SDL_QUIT; # Handle keyboard events to move the shooter if ($event->type == SDL_KEYDOWN) { my $key = $event->key_sym; if ($key == SDLK_LEFT) { $shooter_x -= 10; } elsif ($key == SDLK_RIGHT) { $shooter_x += 10; } } # Handle mouse events to shoot elsif ($event->type == SDL_MOUSEBUTTONDOWN) { $shooting = 1; } }

# Moving the bird from left to right
$bird_x += $bird_speed;
if ($bird_x > $app->w) {
    $bird_x = 0;
    $bird_counter++;
}

# Checking for collisions (if shooter hits the bird)
my $bird_hitbox = SDL::Rect->new($bird_x, $bird_y, $bird_surface->w, $bird_surface->h);
my $shooter_hitbox = SDL::Rect->new($shooter_x, $shooter_y, $shooter_surface->w, $shooter_surface->h);
if ($shooter_hitbox->has_intersection($bird_hitbox)) {
    # Increment shots_fired if the bird was shot down
    $shots_fired++ if $shooting;
    $shooting = 0;
}

# Clearing the screen and draw the background
$app->draw_rect( undef, 0x000000 );
$app->blit_by( $background_surface, undef, [ 0, 0, 800, 600 ] );

# Drawing the shooter and the bird
$app->blit_by( $shooter_surface, undef, [ $shooter_x, $shooter_y, $shooter_surface->w, $shooter_surface->h ] );
$app->blit_by( $bird_surface, undef, [ $bird_x, $bird_y, $bird_surface->w, $bird_surface->h ] );

# Updating the screen
$app->update;

# Checking the shooting timer (10 seconds) and reset the bird counter
if ($shooting_timer >= 10000) {
    if ($shots_fired >= $bird_counter) {
        print "You won!\n";
    } else {
        print "You lost!\n";
    }
    last; # Exit the game loop
}

# Incrementing the shooting timer and sleep for a short duration
$shooting_timer += $app->current_time;
SDL::delay(10);

}

Quit SDL

SDL::quit;

perl-game's People

Contributors

danjumakolo avatar

Watchers

 avatar

perl-game's Issues

Copper sulphate weight prediction using regression analysis

I used regression analysis to predict the weight of copper sulfate to be produced from known weights of copper metal and sulfuric acid.

  1. I got data on the weights of copper metal and sulfuric acid used, and the resulting weight of copper sulfate produced.

  2. I created a scatter plot of the data, with the weights of copper metal and sulfuric acid on the x-axis and the weight of copper sulfate produced on the y-axis. This helped me to visually inspect the relationship between the variables.

  3. I choosed a regression model that fits the relationship between the variables. A linear regression model would be appropriate for this type of analysis, as it assumes a linear relationship between the variables.

  4. I choose softwares like Excel and R to fit the regression model to the data.

  5. I evaluated the model by examining its goodness-of-fit statistics, such as the coefficient of determination (R-squared), and by examining residual plots to ensure that the assumptions of the model are met.

  6. Once it became ok and had a satisfactory model, i used it to make predictions about the weight of copper sulfate that will be produced given known weights of copper metal and sulfuric acid.

results...

The following data on the weights of copper metal and sulfuric acid used and the resulting weight of copper sulfate produced,

| Copper Metal (g) | Sulfuric Acid (mL) | Copper Sulfate (g) |

|------------------|---------------------|---------------------|

|        5         |         10          |         8.5         |

|        10        |         20          |         16.5        |

|        15        |         30          |         24.0        |

|        20        |         40          |         33.0        |

|        25        |         50          |         41.5        |

Using this data, we can create a scatter plot of the weights of copper metal and sulfuric acid versus the weight of copper sulfate produced.

The scatter plot suggests a linear relationship between the variables, so i used a linear regression model to predict the weight of copper sulfate produced given the weights of copper metal and sulfuric acid used.

Using R, i fitted the following linear regression model. The model is

Copper Sulfate = 0.97 * Copper Metal + 0.39 * Sulfuric Acid - 1.46

This model has an R-squared value of 0.998, indicating a very good fit to the data. I the tested and used this model to make predictions about the weight of copper sulfate produced given known weights of copper metal and sulfuric acid.

i use 30 grams of copper metal and 60 mL of sulfuric acid, to predict the weight of copper sulfate produced as follows

Copper Sulfate = 0.97 * 30 + 0.39 * 60 - 1.46 = 30.05 grams

Therefore, using 30 grams of copper metal and 60 mL of sulfuric acid will produce approximately 30.05 grams of copper sulfate.

the project plant is located at Nasrda Abuja

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.