Hello! I was wonder if you could complete this c++ coding assignment for me? It is the original Mario game, however I only to create the enemies(“Goombas”) Project details: so all i really need done...

1 answer below »

Hello! I was wonder if you could complete this c++ coding assignment for me? It is the original Mario game, however I only to create the enemies(“Goombas”)


Project details:


so all i really need done is creating an automatic movement system in c++ for the "Goombas"(enemies in original mario) and i just need them to pace back and forth (left to right across screen). I would like to be able to customize where on the screen they move so that i can make adjustments later. Also i would like the actual image of the goomba to move. Should be using function/header/.cpp files. For the Goomba, I would like it to look like the original game.


CodeBlocks Configuration -- Settings -> Compiler --> Linker Settings --> (Right Window)put this in the linker settings


//


-lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer


//










sdl plotter-----(Below is the sdl plotter code)


/*



  • SDL_Plotter.h


  • Created on: Jun 13, 2016



*/


#ifndef SDL_PLOTTER_H_
#define SDL_PLOTTER_H_


//Windows Library
#include

#include


#include

#include

#include

#include

#include


using namespace std;


const char UP_ARROW = 1;
const char DOWN_ARROW = 2;
const char LEFT_ARROW = 3;
const char RIGHT_ARROW = 4;
const int RED_SHIFT = 65536;
const int GREEN_SHIFT = 256;
const int BLUE_SHIFT = 1;
const int ALPHA_SHIFT = 16777216;
const int WHITE = 255;
const int MAX_THREAD = 100;


#define MUS_PATH "scratch.wav"


//sample threaded sound function
static int Sound(void *data);


struct param{
bool play;
bool running;
bool pause;
SDL_Thread* threadID;
SDL_cond *cond;
SDL_mutex *mut;
string name;



param(){ play = false; running = false; pause = false; }

};


class SDL_Plotter{
private:
SDL_Texture * texture;
SDL_Renderer * renderer;
SDL_Window * window;



bool leftMouseButtonDown; Uint32 * pixels; const Uint8* currentKeyStates;int row, col; bool quit; SDL_Event event; //Sound Stuff bool SOUND; int soundCount; map soundMap;

public:



SDL_Plotter(int r=480, int c=640, bool WITH_SOUND = true){ row = r; col = c; leftMouseButtonDown = false; quit = false; SOUND = WITH_SOUND; SDL_Init(SDL_INIT_AUDIO); window = SDL_CreateWindow("SDL2 Pixel Drawing", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, col, row, 0); renderer = SDL_CreateRenderer(window, -1, 0); texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, col, row); pixels = new Uint32[col * row]; memset(pixels, WHITE, col * row * sizeof(Uint32)); //SOUND Thread PoolMix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ); soundCount = 0; } ~SDL_Plotter(){ delete[] pixels; SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); } void update(){ SDL_UpdateTexture(texture, NULL, pixels, col * sizeof(Uint32)); SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); } bool getQuit(){ return quit; } bool kbhit(){ bool flag = false; if(SDL_PollEvent(&event)){ if(event.type == SDL_KEYDOWN){ flag = true; } if( event.type == SDL_QUIT ) { quit = true; } } return flag; } char getKey(){ char key = '\0'; currentKeyStates = SDL_GetKeyboardState( NULL ); if(currentKeyStates[SDL_SCANCODE_A]) key = 'A'; if(currentKeyStates[SDL_SCANCODE_B]) key = 'B'; if(currentKeyStates[SDL_SCANCODE_C]) key = 'C'; if(currentKeyStates[SDL_SCANCODE_D]) key = 'D'; if(currentKeyStates[SDL_SCANCODE_E]) key = 'E'; if(currentKeyStates[SDL_SCANCODE_F]) key = 'F'; if(currentKeyStates[SDL_SCANCODE_G]) key = 'G'; if(currentKeyStates[SDL_SCANCODE_H]) key = 'H'; if(currentKeyStates[SDL_SCANCODE_I]) key = 'I'; if(currentKeyStates[SDL_SCANCODE_J]) key = 'J'; if(currentKeyStates[SDL_SCANCODE_K]) key = 'K'; if(currentKeyStates[SDL_SCANCODE_L]) key = 'L'; if(currentKeyStates[SDL_SCANCODE_M]) key = 'M'; if(currentKeyStates[SDL_SCANCODE_N]) key = 'N'; if(currentKeyStates[SDL_SCANCODE_O]) key = 'O'; if(currentKeyStates[SDL_SCANCODE_P]) key = 'P'; if(currentKeyStates[SDL_SCANCODE_Q]) key = 'Q'; if(currentKeyStates[SDL_SCANCODE_R]) key = 'R'; if(currentKeyStates[SDL_SCANCODE_S]) key = 'S'; if(currentKeyStates[SDL_SCANCODE_T]) key = 'T'; if(currentKeyStates[SDL_SCANCODE_U]) key = 'U'; if(currentKeyStates[SDL_SCANCODE_V]) key = 'V'; if(currentKeyStates[SDL_SCANCODE_W]) key = 'W'; if(currentKeyStates[SDL_SCANCODE_X]) key = 'X'; if(currentKeyStates[SDL_SCANCODE_Y]) key = 'Y'; if(currentKeyStates[SDL_SCANCODE_Z]) key = 'Z'; if(currentKeyStates[SDL_SCANCODE_1]) key = '1'; if(currentKeyStates[SDL_SCANCODE_2]) key = '2'; if(currentKeyStates[SDL_SCANCODE_3]) key = '3'; if(currentKeyStates[SDL_SCANCODE_4]) key = '4'; if(currentKeyStates[SDL_SCANCODE_5]) key = '5'; if(currentKeyStates[SDL_SCANCODE_6]) key = '6'; if(currentKeyStates[SDL_SCANCODE_7]) key = '7'; if(currentKeyStates[SDL_SCANCODE_8]) key = '8'; if(currentKeyStates[SDL_SCANCODE_9]) key = '9'; if(currentKeyStates[SDL_SCANCODE_0]) key = '0'; if(currentKeyStates[SDL_SCANCODE_SPACE]) key = ' '; if(currentKeyStates[SDL_SCANCODE_DOWN]) key = DOWN_ARROW; if(currentKeyStates[SDL_SCANCODE_UP]) key = UP_ARROW; if(currentKeyStates[SDL_SCANCODE_LEFT]) key = LEFT_ARROW; if(currentKeyStates[SDL_SCANCODE_RIGHT]) key = RIGHT_ARROW; if(currentKeyStates[SDL_SCANCODE_RETURN]) key = SDL_SCANCODE_RETURN; if(currentKeyStates[SDL_SCANCODE_ESCAPE]) quit = true; return key; } void plotPixel(int x, int y, int r, int g, int b){ pixels[y * col + x] = RED_SHIFT*r + GREEN_SHIFT*g + BLUE_SHIFT*b; } void clear(){ memset(pixels, WHITE, col * row * sizeof(Uint32)); } int getRow(){ return row; } int getCol(){ return col; } void initSound(string sound){ //int *threadReturnValue; if(!soundMap[sound].running){ param* p = &soundMap[sound]; p->name = sound; p->cond = SDL_CreateCond(); p->mut = SDL_CreateMutex(); p->threadID = SDL_CreateThread( Sound, sound.c_str(), (void*)p ); //p->threadID = SDL_CreateThread( Sound, "SoundThread", (void*)p ); //SDL_DetachThread(p->threadID); } }void setQuit(bool flag){ this->quit = flag; } void playSound(string sound){ if(soundMap[sound].running){ SDL_CondSignal(soundMap[sound].cond); } } void quitSound(string sound){ soundMap[sound].running = false; SDL_CondSignal(soundMap[sound].cond); } void Sleep(int ms){ SDL_Delay(ms); }

};


//Threaded Function


static int Sound(void *data){
paramp = (param)data;
p->running = true;
Mix_Chunk *gScratch = NULL;
gScratch = Mix_LoadWAV( p->name.c_str() );



while(p->running){ SDL_mutexP( p->mut ); SDL_CondWait(p->cond, p->mut); Mix_PlayChannel( -1, gScratch, 0 ); p->play = false; SDL_mutexV(p->mut); } Mix_FreeChunk( gScratch ); p->running = false; return 0;

}


#endif /* SDL_PLOTTER_H_ */


Deliverables:



  • header file (.h)

  • main file(.cpp)

  • should output a "Goomba" to the screen and moves it left to right

  • should be using public and private classes




  1. Deadline: 11/27/2018 11:59pm

  2. United Stated, Central Time

  3. C++



Answered Same DayNov 27, 2020

Answer To: Hello! I was wonder if you could complete this c++ coding assignment for me? It is the original...

Snehil answered on Nov 28 2020
146 Votes
My Work/PlotterTest/bin/Debug/goomba.txt
4
0 0 0
101 50 2
216 186 123
50 50 50
16
16
0000001111000000
0000011111100000
0000111111110000
0001111111111000
0013311111133100
0111231111321110
0111231111321110
1111232112321111
1111222112221111
1111111111111111
0111122222211110
0000222222220000
0033222222223300
0333332222333330
0333333003333330
0033333003333300
My Work/PlotterTest/bin/Debug/PlotterTest.exe
My Work/PlotterTest/Goomba.cpp
#include "Goomba.h"
#include
#include
using namespace std;
Goomba::Goomba()
{
readFile("Goomba.txt");
}
void Goomba::readFile(char fileName[])
{
ifstream fin(fileName);
int numColors;
fin>>numColors;
vector> colors;
for(int i=0;i {
int r,g,b;
fin>>r>>g>>b;
vector color={r,g,b};
colors.push_back(color);
}
fin>>width>>height;
char colorVal;
for(int j=0;j {
vector> pixelLine;
for(int i=0;i {
fin>>colorVal;
pixelLine.push_back(colors.at(colorVal-48));
}
pixels.push_back(pixelLine);
}
fin.close();
}
void Goomba::drawAt(int x, int y, SDL_Plotter& p, int scale)
{
for(int j=0; j {
for(int i=0; i {
for (int c = 0; c < scale; c++)
{
for (int c2 = 0; c2 < scale; c2++)
{
p.plotPixel((x + c2) + (i*scale), (y + c)+(j*scale),pixels[j][i][0], pixels[j][i][1], pixels[j][i][2]);
}
}
}
}
}
int Goomba::getWidth()
{
return width;
}
int Goomba::getHeight()
{
return height;
}
My Work/PlotterTest/Goomba.h
#ifndef GOOMBA_H
#define GOOMBA_H
#include"SDL_Plotter.h"
#include
using namespace std;
class Goomba
{
private:
vector>> pixels;
int width;
int height;
public:
Goomba();
void readFile(char fileName[]);
void drawAt(int x, int y,SDL_Plotter& p, int scale=1);
int getWidth();
int getHeight();
};
#endif // GOOMBA_H
My Work/PlotterTest/goomba.txt
4
0 0 0
101 50 2
216 186 123
50 50 50
16
16
0000001111000000
0000011111100000
0000111111110000
0001111111111000
0013311111133100
0111231111321110
0111231111321110
1111232112321111
1111222112221111
1111111111111111
0111122222211110
0000222222220000
0033222222223300
0333332222333330
0333333003333330
0033333003333300
My Work/PlotterTest/main.cpp
My Work/PlotterTest/main.cpp
#include
#include
#include 
#include"SDL_Plotter.h"
#include"Goomba.h"
using namespace std;
void clearBgColor(int screenWidth, int screenHeight, SDL_Plotter& p);
int main(int argc, char ** argv)
{
    const int screenWidth = 800 , screenHeight = 600;
    SDL_Plotter p(screenHeight, screenWidth);
    Goomba goomba;
    //starting x y position of goomba
    int goombaX=10;
    int goombaY=screenHeight/2;
    //Initial movement direction and speed of goomba, +ve means to right, -ve means to left. The higher the value the faster it moves
    int dir=1;
    //size of goomba
    int scale = 7;
    while (!p.getQuit())
    {
        if (p.kbhit())
        {
            p.getKey();
        }
        p.clear();
        clearBgColor(screenWidth, screenHeight, p);
        goomba.drawAt(goombaX,goombaY,p,scale);
        goombaX+=dir;
        if(goombaX+(goomba.getWidth()* scale)>=screenWidth)
        {
            dir*=-1;
            goombaX=screenWidth-1-(goomba.getWidth()* scale);
        }
        else if( goombaX<=0)
        {
            dir*=-1;
            goombaX=0;
        }
        p.update();
        p.Sleep(5);
    }
    return 0;
}
void clearBgColor(int screenWidth, int screenHeight, SDL_Plotter& p)
{
    for (int y = 0; y < screenHeight; y++)
    {
        for (int x = 0; x < screenWidth; x++)
        {
            p.plotPixel(x, y, 0, 0, 0);
        }
    }
}
My Work/PlotterTest/obj/Debug/Goomba.o
My Work/PlotterTest/obj/Debug/main.o
My Work/PlotterTest/PlotterTest.cbp

    
    
        
        
        
        
            
                
                
                
                
                
                    
                
            
            
                
                
                
                
                
                    
                
                
                    
                
            
        
        
            
            
            
            
            
        
        
            
            
        
        
        
        
        
        
            
            
            
            
        
    
My Work/PlotterTest/PlotterTest.depend
# depslib dependency file v1.0
1543389863 source:c:\programming\tfth\35765\my work\plottertest\main.cpp
    
    
    
    "SDL_Plotter.h"
    "Goomba.h"
1543387469 c:\programming\tfth\35765\my work\plottertest\sdl_plotter.h
    
    
    
    
    
    
    
1540998544 c:\programming\sdl2\include\sdl2\sdl.h
    "SDL_main.h"
    "SDL_stdinc.h"
    "SDL_assert.h"
    "SDL_atomic.h"
    "SDL_audio.h"
    "SDL_clipboard.h"
    "SDL_cpuinfo.h"
    "SDL_endian.h"
    "SDL_error.h"
    "SDL_events.h"
    "SDL_filesystem.h"
    "SDL_gamecontroller.h"
    "SDL_haptic.h"
    "SDL_hints.h"
    "SDL_joystick.h"
    "SDL_loadso.h"
    "SDL_log.h"
    "SDL_messagebox.h"
    "SDL_mutex.h"
    "SDL_power.h"
    "SDL_render.h"
    "SDL_rwops.h"
    "SDL_sensor.h"
    "SDL_shape.h"
    "SDL_system.h"
    "SDL_thread.h"
    "SDL_timer.h"
    "SDL_version.h"
    "SDL_video.h"
    "begin_code.h"
    "close_code.h"
1540998544 c:\programming\sdl2\include\sdl2\sdl_main.h
    "SDL_stdinc.h"
    "begin_code.h"
    "close_code.h"
1540998544...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here