Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //including libraries
- //Cpu.score < 2000 || (Cpu.score > 2500 && Cpu.score < 15000) || (Cpu.score > 18000 && Cpu.score < 60000)
- #include "SDL/SDL.h"
- #include "SDL/SDL_ttf.h"
- #include "SDL/SDL_mixer.h";
- #include <ctime>
- #include <stdlib.h>
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <sstream>
- #include "cpu.h"
- #include "player.cpp"
- #include "monster.cpp"
- #define BLACK {0, 0, 0}
- using namespace std;
- //Surfaces
- SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
- SDL_Surface *background = SDL_LoadBMP("data/images/background.bmp");
- SDL_Surface *tileset = SDL_LoadBMP("data/images/tileset.bmp");
- void apply_text(SDL_Surface *destination, string msg, int x, int y, int size, SDL_Color color) {
- TTF_Font *font;
- font = TTF_OpenFont("data/font.ttf", size);
- SDL_Rect rect;
- rect.x = x;
- rect.y = y;
- SDL_Surface *message = NULL;
- message = TTF_RenderText_Solid(font, msg.c_str(), color);
- SDL_BlitSurface(message, NULL, destination, &rect);
- TTF_CloseFont(font);
- SDL_FreeSurface(message);
- }
- void apply_int(SDL_Surface* destination, int number, int x, int y, int size, SDL_Color color) {
- TTF_Font *font;
- font = TTF_OpenFont("data/font.ttf", size);
- string s;
- stringstream out;
- out << number;
- s = out.str();
- SDL_Rect rect;
- rect.x = x;
- rect.y = y;
- SDL_Surface *message = NULL;
- message = TTF_RenderText_Solid(font, s.c_str(), color);
- SDL_BlitSurface(message, NULL, destination, &rect);
- TTF_CloseFont(font);
- SDL_FreeSurface(message);
- }
- void checkCpu() {
- Cpu.gameLoop = true;
- Cpu.fps = 30;
- Cpu.currentTick = SDL_GetTicks();
- Cpu.score = 0;
- Cpu.time = 10;
- Cpu.lvl = 1;
- Cpu.kill = 0;
- Cpu.shoot = 0;
- Cpu.bossfight = false;
- }
- void load_sprite(int x, int y, SDL_Surface *source, SDL_Surface *destination, int bx, int by, int width, int height) {
- SDL_Rect rect;
- SDL_Rect offset;
- offset.x = x;
- offset.y = y;
- rect.x = bx;
- rect.y = by;
- rect.w = width;
- rect.h = height;
- SDL_BlitSurface(source, &rect, destination, &offset);
- }
- void load_sound() {
- Mix_Music *songName = songName = Mix_LoadMUS("data/sound.mp3");
- Mix_VolumeMusic(25);
- Mix_PlayMusic(songName, -1);
- }
- void game() {
- SDL_Init(SDL_INIT_EVERYTHING);
- SDL_WM_SetCaption("Bullshoo - V 0.7.4 - BETA!", NULL);
- TTF_Init();
- Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);
- srand(time(NULL));
- SDL_Rect player;
- SDL_Rect monster1[10];
- SDL_Rect monster2[5];
- SDL_Rect monster3[8];
- SDL_Rect monster4[15];
- SDL_Rect boss1;
- SDL_Rect boss2;
- SDL_Rect bullet[100];
- checkCpu();
- cPlayer.checkVars();
- checkBullet();
- for(int i=0; i<10; i++) {
- cMonster1[i].checkMonster1();
- }
- for(int i=0; i<5; i++) {
- cMonster2[i].checkMonster2();
- }
- for(int i=0; i<8; i++) {
- cMonster3[i].checkMonster3();
- }
- for(int i=0; i<15; i++) {
- cMonster4[i].checkMonster4();
- }
- cBoss1.checkBoss1();
- cBoss2.checkBoss2();
- Uint32 colorkey = SDL_MapRGB(tileset -> format, 255, 0, 255);
- SDL_SetColorKey(tileset, SDL_SRCCOLORKEY, colorkey);
- load_sound();
- //Runs the game
- while(Cpu.gameLoop) {
- if(Cpu.time>0) {
- Cpu.time--;
- }
- //player_rect
- player.x = cPlayer.x;
- player.y = cPlayer.y;
- player.w = cPlayer.w;
- player.h = cPlayer.h;
- //boss1_rect
- boss1.x = cBoss1.x;
- boss1.y = cBoss1.y;
- boss1.w = cBoss1.w;
- boss1.h = cBoss1.h;
- boss2.x = cBoss2.x;
- boss2.y = cBoss2.y;
- boss2.w = cBoss2.w;
- boss2.h = cBoss2.h;
- //monster1_rect
- for(int i=0; i<10; i++) {
- monster1[i].x = cMonster1[i].x;
- monster1[i].y = cMonster1[i].y;
- monster1[i].w = 32;
- monster1[i].h = 32;
- }
- //monster2_rect
- for(int i=0; i<5; i++) {
- monster2[i].x = cMonster2[i].x;
- monster2[i].y = cMonster2[i].y;
- monster2[i].w = cMonster2[i].w;
- monster2[i].h = cMonster2[i].h;
- }
- //monster3_rect
- for(int i=0; i<8; i++) {
- monster3[i].x = cMonster3[i].x;
- monster3[i].y = cMonster3[i].y;
- monster3[i].w = cMonster3[i].w;
- monster3[i].h = cMonster3[i].h;
- }
- //monster4_rect
- for(int i=0; i<15; i++) {
- monster4[i].x = cMonster4[i].x;
- monster4[i].y = cMonster4[i].y;
- monster4[i].w = cMonster4[i].w;
- monster4[i].h = cMonster4[i].h;
- }
- //bullet_rect
- for(int i=0; i<100; i++) {
- bullet[i].x = cBullet[i].A.x;
- bullet[i].y = cBullet[i].A.y;
- bullet[i].w = cBullet[i].w;
- bullet[i].h = cBullet[i].h;
- }
- Cpu.currentTick = SDL_GetTicks();
- cPlayer.input();
- //MoveMonsters
- if(Cpu.bossfight == false) {
- for(int i=0; i<10; i++) {
- cMonster1[i].moveMonster();
- }
- if(Cpu.score >= 250) {
- for(int i=0; i<5; i++) {
- cMonster2[i].moveMonster2();
- }
- }
- if(Cpu.score >= 800) {
- for(int i=0; i<8; i++) {
- cMonster3[i].moveMonster3();
- }
- }
- if(Cpu.score >= 1500) {
- for(int i=0; i<15; i++) {
- cMonster4[i].moveMonster4();
- }
- }
- }
- //checks if player is hit by monsters
- if(Cpu.bossfight == false) {
- for(int i=0; i<10; i++) {
- if(cPlayer.collision(player, monster1[i])) {
- Cpu.gameLoop = false;
- }
- }
- for(int i=0; i<5; i++) {
- if(cPlayer.collision(player, monster2[i])) {
- Cpu.gameLoop = false;
- }
- }
- for(int i=0; i<8; i++) {
- if(cPlayer.collision(player, monster3[i])) {
- Cpu.gameLoop = false;
- }
- }
- for(int i=0; i<15; i++) {
- if(cPlayer.collision(player, monster4[i])) {
- Cpu.gameLoop = false;
- }
- }
- }
- //if player is hit by boss1
- if(cPlayer.collision(player, boss1)) {
- Cpu.gameLoop = false;
- }
- //if player is hit by boss2
- if(cPlayer.collision(player, boss2)) {
- Cpu.gameLoop = false;
- }
- //checks if monster is hit by bullet
- //monster1
- if(Cpu.bossfight == false) {
- for(int i=0; i<10; i++) {
- for(int i2=0; i2<100; i2++) {
- if(cPlayer.collision(monster1[i], bullet[i2])) {
- cMonster1[i].x = rand() % 1500 + 640;
- cMonster1[i].x = rand() % 1230 + 640;
- Cpu.score += 10;
- Cpu.kill += 1;
- cBullet[i2].alive = false;
- cBullet[i2].A.x = 0;
- cBullet[i2].A.y = 0;
- }
- }
- }
- }
- //boss1
- for(int i2=0; i2<100; i2++) {
- if(Cpu.score >= 2000 && Cpu.score <= 10000) {
- if(cPlayer.collision(boss1, bullet[i2])) {
- cBoss1.life--;
- cBullet[i2].alive = false;
- cBullet[i2].A.x = 0;
- cBullet[i2].A.y = 0;
- }
- }
- }
- //boss2
- for(int i2=0; i2<100; i2++) {
- if(Cpu.score >= 15000 && Cpu.score <= 20000) {
- if(cPlayer.collision(boss2, bullet[i2])) {
- cBoss2.life--;
- cBullet[i2].alive = false;
- cBullet[i2].A.x = 0;
- cBullet[i2].A.y = 0;
- }
- }
- }
- if(Cpu.bossfight == false) {
- if(Cpu.score >= 250) {
- for(int i=0; i<5; i++) {
- for(int i2=0; i2<100; i2++) {
- if(cPlayer.collision(monster2[i], bullet[i2])) {
- cMonster2[i].x = rand() % 1300 + 640;
- cMonster2[i].y = rand() % 1430 + 640;
- Cpu.score += 15;
- Cpu.kill+=1;
- cBullet[i2].alive = false;
- cBullet[i2].A.x = 0;
- cBullet[i2].A.y = 0;
- }
- }
- }
- }
- for(int i=0; i<8; i++) {
- for(int i2=0; i2<100; i2++) {
- if(Cpu.score >= 800) {
- if(cPlayer.collision(monster3[i], bullet[i2])) {
- cMonster3[i].life--;
- cBullet[i2].alive = false;
- cBullet[i2].A.x = 0;
- cBullet[i2].A.y = 0;
- }
- }
- }
- }
- if(Cpu.score >= 1500) {
- for(int i=0; i<15; i++) {
- for(int i2=0; i2<100; i2++) {
- if(cPlayer.collision(monster4[i], bullet[i2])) {
- cMonster4[i].life--;
- cBullet[i2].alive = false;
- cBullet[i2].A.x = 0;
- cBullet[i2].A.y = 0;
- }
- }
- }
- }
- }
- for(int i=0; i<8; i++) {
- if(cMonster3[i].life<=0) {
- cMonster3[i].x = rand() % 1150 + 640;
- cMonster3[i].x = rand() % 1005 + 480;
- Cpu.score += 20;
- Cpu.kill+=1;
- cMonster3[i].life = 3;
- }
- }
- for(int i=0; i<15; i++) {
- if(cMonster4[i].life<=0) {
- cMonster4[i].x = rand() % 2000 + 640;
- cMonster4[i].y = rand() % (480-50) + 10;
- cMonster4[i].life = 2;
- Cpu.score += 50;
- Cpu.kill+=1;
- }
- }
- load_sprite(0, 0, background, screen, 0, 0, 640, 480);
- //print out bullet and stuff for it
- for(int i=0; i<100; i++) {
- if(cBullet[i].alive == true) {
- cBullet[i].A.x += 5;
- cBullet[i].A.w = cBullet[i].w;
- cBullet[i].A.h = cBullet[i].h;
- SDL_FillRect(screen, &cBullet[i].A, 0xFFFF66);
- if(cBullet[i].A.x > 640) {
- cBullet[i].alive = false;
- }
- }
- }
- //Print out things to screen
- //player
- load_sprite(cPlayer.x, cPlayer.y, tileset, screen, cPlayer.bx, cPlayer.by, cPlayer.w, cPlayer.h);
- if(Cpu.bossfight == false) {
- //monster1
- for(int i=0; i<10; i++) {
- load_sprite(cMonster1[i].x, cMonster1[i].y, tileset, screen, cMonster1[i].bx, cMonster1[i].by, cMonster1[i].w, cMonster1[i].h);
- }
- //monster2
- if(Cpu.score >= 250) {
- for(int i=0; i<5; i++) {
- load_sprite(cMonster2[i].x, cMonster2[i].y, tileset, screen, cMonster2[i].bx, cMonster2[i].by, cMonster2[i].w, cMonster2[i].h);
- }
- }
- //monster3
- if(Cpu.score >= 800) {
- for(int i=0; i<8; i++) {
- load_sprite(cMonster3[i].x, cMonster3[i].y, tileset, screen, cMonster3[i].bx, cMonster3[i].by, cMonster3[i].w, cMonster3[i].h);
- }
- }
- //monster 4
- if(Cpu.score >= 1500) {
- for(int i=0; i<15; i++) {
- load_sprite(cMonster4[i].x, cMonster4[i].y, tileset, screen, cMonster4[i].bx, cMonster4[i].by, cMonster4[i].w, cMonster4[i].h);
- }
- }
- }
- if((Cpu.bossfight == true && (Cpu.score >= 2000 && Cpu.score <= 2100)) || (Cpu.bossfight == true && (Cpu.score >= 15000 && Cpu.score <= 15100))) {
- for(int i=0; i<10; i++) {
- cMonster1[i].moveBack1();
- }
- for(int i=0; i<5; i++) {
- cMonster2[i].moveBack2();
- }
- for(int i=0; i<8; i++) {
- cMonster3[i].moveBack3();
- }
- for(int i=0; i<15; i++) {
- cMonster4[i].moveBack4();
- }
- }
- //boss1
- if(Cpu.score >= 2000 && cBoss1.life >= 1) {
- cBoss1.moveBoss1();
- Cpu.bossfight = true;
- apply_int(screen, cBoss1.life, cBoss1.x, cBoss1.y-55, 50, BLACK);
- load_sprite(cBoss1.x, cBoss1.y, tileset, screen, cBoss1.bx, cBoss1.by, cBoss1.w, cBoss1.h);
- }else if(Cpu.score >= 15000 && cBoss2.life >= 1) {
- cBoss2.moveBoss2();
- Cpu.bossfight = true;
- apply_int(screen, cBoss2.life, cBoss2.x, cBoss2.y-55, 50, BLACK);
- load_sprite(cBoss2.x, cBoss2.y, tileset, screen, cBoss2.bx, cBoss2.by, cBoss2.w, cBoss2.h);
- } else {
- Cpu.bossfight = false;
- }
- //if bosses is dead
- if(cBoss1.life <= 0 || cBoss2.life <= 0) {
- Cpu.bossfight = false;
- } else {
- Cpu.bossfight = true;
- }
- //checks so the boss is dead and then move it out of the game
- if(cBoss1.life <= 0 && cBoss1.life >= -2) {
- cBoss1.x = 640+100;
- Cpu.score += 10000;
- cBoss1.life = -5;
- }
- if(cBoss2.life <= 0 && cBoss2.life >= -2) {
- cBoss2.x = 640+100;
- Cpu.score += 50000;
- cBoss2.life = -5;
- }
- //check wich level it is!
- if(Cpu.score >= 100) {
- Cpu.lvl = 2;
- }
- if(Cpu.score >= 250) {
- Cpu.lvl = 3;
- }
- if(Cpu.score >= 12000) {
- Cpu.lvl = 4;
- }
- if(Cpu.score >= 60000) {
- Cpu.lvl = 5;
- }
- apply_text(screen, "Score: ", 0, 0, 50, BLACK);
- apply_int(screen, Cpu.score, 65, 0, 50, BLACK);
- apply_text(screen, "Level: ", 0, 40, 50, BLACK);
- apply_int(screen, Cpu.lvl, 65, 40, 50, BLACK);
- apply_text(screen, "Kills: ", 0, 80, 50, BLACK);
- apply_int(screen, Cpu.kill, 65, 80, 50, BLACK);
- apply_text(screen, "Bullet: ", 0, 120, 50, BLACK);
- apply_int(screen, Cpu.shoot, 65, 120, 50, BLACK);
- apply_text(screen, "Life: ", 0, 160, 50, BLACK);
- apply_int(screen, cPlayer.life, 65, 160, 50, BLACK);
- if(SDL_GetTicks() - Cpu.currentTick < 1000 / Cpu.fps) {
- SDL_Delay(((1000/Cpu.fps)-(SDL_GetTicks() - Cpu.currentTick)));
- }
- SDL_Flip(screen);
- }
- SDL_CloseAudio();
- }
Advertisement
Add Comment
Please, Sign In to add comment