Jump to content
  • Advertisement

AlexanderBladh

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

118 Neutral

About AlexanderBladh

  • Rank
    Newbie

Personal Information

  1. 3.de plats på nordic extreme running.
  2. AlexanderBladh

    Practical help on making a simple bullet hell

    Thank you. Ultra late reply, but i have been working on the game ever since you replied. The command idea worked well, the only problem is that ifstream whont work on xcode So i cant load the commands from a file, instead i store them in a string :   std::string line = "Begin 10 2 100 0 5 5" "N 70 2 700 0 5 5" "N 120 2 100 0 5 5" "N 130 3 200 0 2 50" "N 130 3 550 0 2 50" "Cos(v) 140 100 550 0 5 4" "N 190 100 550 0 5 4" "N 250 3 200 0 1 0" "N 250 3 550 0 1 0" "v=t 260 101 550 0 60 1" "N 300 3 500 0 1 0" "N 300 3 350 0 1 0" "N 300 3 150 0 1 0" "sin(y) 330 102 550 0 40 1" .....; The Polymorfism also worked great for the first time i understand how abstract classes and pointers work together.   Her is a samall gif of the game:    
  3. Hi gamedev,  I have been bored on the programming lessons recently, so i decided to make a bullet hell in c++ with sdl2.   The problem is, I don't know how to structure the code so that it would work properly. Problems such as how to control the bullets, how to spawn a enemy at the right time needs to be solved. Here is what i have come up with so far (psudoish); class player { SDL_Texture * P_Texture; SDL_Texture * Col_texture; double mx; //x,y movement double my; SDL_Rect P_pos; int hp; int power; int points; void loop(double delta_time); void render(SDL_Renderer * renderer); }; class Enemy { int type; SDL_Texture * texture; int helth; SDL_Rect pos; SDL_Rect col; void loop(); void render(SDL_Renderer * renderer); }; struct Bullet { int type; SDL_Texture * texture; float rotation; int helth; SDL_Rect pos; SDL_Rect col; void render(SDL_Renderer * renderer); void loop(double delta_time); }; class game { player Player; std::vector<Enemy> enemies; std::vector<Bullet> bullets; void even(SDL_Event * event) { // Handle events and // Pass on events to underlaying code } void render(SDL_Renderer * renderer) { //Render } void loop() { /* Update positions Handle collisions */ } }; So where do I go from here? I would like to be able to control the bullets using different equations and spawn allot of them. The game doesn't have to be advanced at all just spawn a bunch of enemies and bullets flying in different directions.     Thanks for any help and sorry for my bad English  
  4. Bilder på bästa födelsedagen
  5. AlexanderBladh

    [Sdl] sdl opengl alph problem

    ok so this problem might be hard to picture but anyway what im trying to do is bliting a blended text onto a sdl_surface and then convert it the surface to a oglsurface. the problem is when i render the fixed ogltexture it still looks like a solid rendered text. so hers my code: surfaceFixed = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, surface->w, surface->h, 32 , R_Mask, G_Mask, B_Mask, A_Mask); saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); saved_alpha = surface->format->alpha; if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { SDL_SetAlpha(surface, 0, 0); } SDL_BlitSurface(surface, NULL, surfaceFixed, NULL); if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { SDL_SetAlpha(surfaceFixed, saved_flags, saved_alpha); } text = TTF_RenderText_Blended(ButtonsFont, buttonText, textColor); rect.x = (w / 2) - (text->w / 2); rect.y = (h / 2 + 1) - (text->h / 2); SDL_BlitSurface(text, 0, surfaceFixed, &rect); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glGenTextures( 1, &OGL_Texture ); glBindTexture( GL_TEXTURE_2D, OGL_Texture ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D( GL_TEXTURE_2D, 0, numberOfColors, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surfaceFixed->pixels );
  6. AlexanderBladh

    Sdl basic chess game networking

    sorry for posting this stupid question. found this grate tutorial
  7. hello, [color="#1c2837"]so i made a small 2d chess game everything[color="#1c2837"] works fine but network i relay don't know how to make it work. [color="#1c2837"]so at firs i thougt about sending the hole chessboard array over network but that whatnot[color="#1c2837"] such good idea due to size. so i tried sending the coordinates and the dest [color="#1c2837"]coordinates, [color="#1c2837"]but i kept getting wrong numbers. [color="#1c2837"]i hope you can give me a start at sending data over sockets. [color="#1c2837"]so my code is written for the sdl_net library im using the tcp socket because its more "safe" i heard. the code is used as both server and client the player can press start server or join game. [color="#1c2837"]so here's my code [color="#1c2837"]network.cpp [color="#1c2837"]#include "stdafx.h" #include "network.h" //------------------------------------------------------------------------------------------------- Network::Network() { initialized = false; } Network::~Network() { initialized = false; } //------------------------------------------------------------------------------------------------- bool Network::init(char *host) { if(host == NULL) { server = true; } else { server = false; } if (SDLNet_Init() < 0) { fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError()); return false; } /* Resolving the host using NULL make network interface to listen */ if (SDLNet_ResolveHost(&ip, host, Port) < 0) { fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError()); return false; } /* Open a connection with the IP provided (listen on the host's port) */ if (!(sd = SDLNet_TCP_Open(&ip))) { fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError()); return false; } sockset = SDLNet_AllocSocketSet(4); SDLNet_TCP_AddSocket(sockset,sd); initialized = true; return true; } //------------------------------------------------------------------------------------------------- void Network::exit() { SDLNet_TCP_Close(sd); if (server) { SDLNet_TCP_Close(csd); } SDLNet_FreeSocketSet(sockset); SDLNet_Quit(); initialized = false; } //------------------------------------------------------------------------------------------------- bool Network::waitforconection() { if ((csd = SDLNet_TCP_Accept(sd))) { /* Now we can communicate with the client using csd socket * sd will remain opened waiting other connections */ /* Get the remote address */ if ((remoteIP = SDLNet_TCP_GetPeerAddress(csd))) { /* Print the address, converting in the host format */ printf("Host connected: %x %d\n", SDLNet_Read32(&remoteIP->host), SDLNet_Read16(&remoteIP->port)); return true; } else fprintf(stderr, "SDLNet_TCP_GetPeerAddress: %s\n", SDLNet_GetError()); } return false; } //------------------------------------------------------------------------------------------------- bool Network::send(const char * buf) { len = strlen(buf) + 1; if (server) { if (SDLNet_TCP_Send(csd, (void *)buf, len) < len) { fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError()); return false; } }else { if (SDLNet_TCP_Send(sd, (void *)buffer, len) < len) { fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError()); return false; } } return true; } //------------------------------------------------------------------------------------------------- bool Network::getactivety() { /* Wait for events */ SDLNet_CheckSockets(sockset, 0); /* Check for new connections */ if (server) { if ( SDLNet_SocketReady(csd)) if (SDLNet_TCP_Recv(csd, buffer, 512) > 0) return true; }else { if ( SDLNet_SocketReady(sd)) if (SDLNet_TCP_Recv(sd, buffer, 512) > 0) return true; } return false; } //------------------------------------------------------------------------------------------------- bool Network::waitforactivety() { /* Wait for events */ SDLNet_CheckSockets(sockset, ~0); /* Check for new connections */ if (server) { if ( SDLNet_SocketReady(csd)) if (SDLNet_TCP_Recv(csd, buffer, 512) > 0) return true; }else { if ( SDLNet_SocketReady(sd)) if (SDLNet_TCP_Recv(sd, buffer, 512) > 0) return true; } return false; } //------------------------------------------------------------------------------------------------ [color="#1c2837"]network.h [color="#1c2837"]#ifndef network_h__ #define network_h__ #include <sdl.h> #include <SDL_net.h> #ifndef Max_iplength #define Max_iplength 15 #endif #ifndef Port #define Port 2000 #endif class Network { public: Network(); virtual ~Network(); bool init(char *host = NULL); void exit(); bool waitforconection(); bool send(const char *); bool getactivety(); bool waitforactivety(); bool initialized; bool server; char buffer[512]; private: TCPsocket sd, csd; /* Socket descriptor, Client socket descriptor */ IPaddress ip, *remoteIP; SDLNet_SocketSet sockset; int len; }; #endif // network_h__ [color="#1c2837"]game_network.cpp [color="#1c2837"]void CGame::Network_Events() { if (network->getactivety()) { if (strcmp(network->buffer, "move") == 0) network_recivemove(); else if (strcmp(network->buffer, "next player") == 0) next_player(); else if (strcmp(network->buffer, "quit") == 0) { quit();screens->signtext = "opponent quited";screens->DisplaySign(); } } } void CGame::network_sendmove(int x, int y , int desty,int destx) { char c[10]; network->send("sending move"); itoa(x,c,10); network->send(c); itoa(y,c,10); network->send(c); itoa(destx,c,10); network->send(c); itoa(desty,c,10); network->send(c); } void CGame::network_recivemove() { network->waitforactivety(); int x,y,dx,dy; network->waitforactivety(); x =(int) network->buffer; network->waitforactivety(); y =(int) network->buffer; network->waitforactivety(); dx =(int) network->buffer; network->waitforactivety(); dy =(int) network->buffer; pices->Move(x,y,dx,dy,Chessboard); } [color="#1c2837"]thanks in advice [color="#1c2837"]/alex [color="#1c2837"]oh if you find spelling mistakes please don't point em out.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!