Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

154 Neutral

About tristan1333

  • Rank

Personal Information

  • Interests
  1. When using SDL_setlogicalsize to have the screen be resizable, it works fine. Using SDL_GetMouseState(&x, &y); to poll the mouse position, it's based on the position of the screen, I'm using 640x480 for the base screen size to resize from. I'm wondering how to convert it down to what I need?
  2. tristan1333

    Box2D collisions

    I fixed it, thank you very much, it was an issue on my point not converting from radians oops.
  3. tristan1333

    Box2D collisions

    That's a very, very good point, I changed it to 20x10, and the other to 2x2, alas, still the same result Edit: However rather than tripping out, it slides to the left a bit on landing and then freezes
  4. tristan1333

    Box2D collisions

    I'm really new to using Box2D. I've setup a small thing with a Dynamic body that falls onto a static one. When the box hits the body, it begins "vibrating" for a bit and shaking, then suddenly stops. If anyone has used it or might know what is happening I'd appreciate it, That's the setup of the boxes. b2BodyDef groundBodyDef; groundBodyDef.position.Set(100.0f, 400.0f); b2Body* groundBody = world.CreateBody(&groundBodyDef); b2PolygonShape groundBox; groundBox.SetAsBox(240, 20); groundBody->CreateFixture(&groundBox, 0.0f); b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(100.0f, 0.0f); b2Body* body = world.CreateBody(&bodyDef); b2PolygonShape dynamicBox; dynamicBox.SetAsBox(32.0f, 32.0f); b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicBox; fixtureDef.density = 1.0f; fixtureDef.friction = 0.3f; body->CreateFixture(&fixtureDef); body->SetAngularVelocity(20); int32 velocityIterations = 8; int32 positionIterations = 4; world.Step(ticks_per_frame, velocityIterations, positionIterations); b2Vec2 position = body->GetPosition(); float32 angle = body->GetAngle(); std::cout << angle<< "\n"; SDL_Rect rect = {position.x, position.y, 32, 32}; //SDL_Point point = {32, 0}; SDL_RenderCopyEx(mainren, textures[0], NULL, &rect, angle, NULL, SDL_FLIP_NONE);
  5. Thanks a tonne, I'm working on reworking it all and it's looking wonderful so far. Huge improvement! I'd say this is solved
  6. I'll work on fixing the gameloop tomorrow, though I am partly confused on how you get this_frame_time_in_seconds.  double lastTime = getCurrentTime(); while (true) { double current = getCurrentTime(); double elapsed = current - lastTime; processInput(); update(elapsed); render(); lastTime = current; } Do I literally just times it by the number that comes out from elapsed if the velocity is 1? Or is there something else to be done there? Appreciate your answers.
  7. while(!quit) //if(currentKeyStates[SDL_SCANCODE_UP]) function[SDL_DEFINED_KEYCODE] { switch(GAME_STATE) { case MENU: main_menu(&e,currentKeyStates); break; case CHARACTERS: character_menu(&e,currentKeyStates); break; case GAME: menu_game(&e,currentKeyStates); break; } SDL_RenderClear(mainren); SDL_PollEvent(&e); if(TARGET_FPS > (SDL_GetTicks() - fps_time)) { SDL_Delay(TARGET_FPS - (SDL_GetTicks() - fps_time)); } } That's the current main game loop. I can show you any other parts if you like. And yeah I understand it should be running slowly of course, but rather that it shouldn't change stuff like arrows speeds.  if(last_travel + travel_rate < SDL_GetTicks()) { last_travel = SDL_GetTicks(); x += velocity; } //This is arrow timers that change it's velocity. Arrows travel at a snail pace. //EDIT: On low tier machines. Menu_Game handles all of the actual game processing. It has an SDL_RenderPresent(mainren) at the end of it. I appreciate the comments. EDIT EDIT: I don't have any evidence and can't collect it tonight sorry. Will try that when I can change my code tomorrow. And I believe that would be the rest of my problem more than likely. The jumping works by increasing the y value until the timer reaches a certain limit. While that's definitely a hacky way to do it, it's definitely to do with timers. 
  8. I'm currently working on a game which relies on SDL_GetTicks(). However, on lower tier computers (My home computer), the game runs at a very high FPS. What is happening however, is it hogs all the CPU and so the thread that is handling the SDL_GetTicks() is slowed down I believe. This effectively means arrows that are firing for example, are slowed down. On faster machines, an archer can fire and only have 1 arrow on the screen at once. However, on my computer an archer can fire three times before the arrow leaves the screen. The jumping relies on a SDL_GetTicks() as well, and is also affected meaning you jump lower. I'm wondering on how to fix this issue? I think I should do a timer inside of the application however I'm not quite sure on how to go about this.
  9. tristan1333

    School Project Game

    Heya, I taught myself to code in year 8 and am currently in year 12, working on this project for class. It's a project I've worked on for a few months now, and thought I'd share. It's currently not completed. On low spec computers (Such as my own) it struggles to run, I'm not certain why. Maybe poor optimization. In any case I've had fun working on it.  I am aware I need to replace the sprites, but I want to make it run before I try to make it pretty. I made it in C++ using SDL. Known issues: Occasionally you spawn in a piece of terrain at the start, also effectively freezing the game. Restart if this happens. Occasionally the terrain at the start is a bit uhh... Funky. Everything past it works however. The characters button on the loading screen doesn't actually do anything.   There are melee warriors as well, they are disabled in the spawning right now.   Controls:  Spacebar to stab WAS to move Left and Right arrow keys effectively pause the game and allow you to look around. Press enter on the start menu to play. EDIT: If anyone wants I'm willing to privately message them the source code if they really want to see it. 
  10. tristan1333

    Handling Projectiles in SDL C++

    I should mention this is sloppy BUT wip so ehhh yeah. void handle_projectiles() { for(int i = 0;i < P_List.size();i++) { if(P_List[i].x > cam.x + 1000 || P_List[i].x < cam.x - 1000) { P_List.erase(P_List.begin() + i); i--; continue; } P_List[i].travel(); int renderx,rendery; if(P_List[i].x > cam.x) { renderx = SCREEN_WIDTH/2 + (P_List[i].x - cam.x); } else { renderx = SCREEN_WIDTH/2 - (cam.x - P_List[i].x); } if(P_List[i].y > cam.y) { rendery = SCREEN_HEIGHT/2 + (P_List[i].y - cam.y); } else { rendery = SCREEN_HEIGHT/2 - (cam.y - P_List[i].y); } SDL_Rect position_rect; P_List[i].collbox.x = renderx; P_List[i].collbox.y = rendery; P_List[i].collbox.w = P_List[i].w; P_List[i].collbox.h = P_List[i].h; SDL_RenderCopyEx(mainren,P_List[i].display,NULL,&P_List[i].collbox, 0,NULL,P_List[i].flip); //renderTexture(P_List[i].display,mainren,renderx,rendery); } } for(int a = 0; a < P_List.size();a++) { if(SDL_HasIntersection(&P_List[a].collbox,&mainchar.pos_rect)) { if(mainchar.last_hit + mainchar.hit_timer > SDL_GetTicks()) { continue; } int x_pw = 2; int y_pw = -2; if(P_List[a].velocity < 0) { x_pw = -x_pw; } mainchar.set_knockback(x_pw,y_pw,50,20); P_List.erase(P_List.begin() + a); a--; continue; } } //Checks the intersection between projectiles. There's alot to sort through, but I think that's the most relevant. 
  11. I'm making a game currently, it's a 2d platformer. I've got characters working and recently implemented a projectile system for archers. However, when there's about 50-100 projectiles on screen, the performance is majorly hit. I tried it on my home computer, and it isn't really playable at all. On other computers it's fine and works mostly perfectly, but my friend said his fan got louder so uhh... There's obviously a few minor optimization issues. The way it currently works is, (this is not a particularly good way to do it I know but it's temporary) check against the players rectangle and the projectile in questions rectangle (This is a for loop against a vector containing all of the projectiles). If there's a collision, hit the player and delete the projectile. I've thought about making it that it only checks when a certain x value away, however, that would lead to the issue of nuking the persons fps when they come close to the projectiles. Is there a proper way to handle these projectiles, or is my pc just terribly, terribly awful?
  12. tristan1333

    Handling game objects

    Thanks heaps guys, informative stuff!  @Servant of the Lord - Yeah, not going to bruteforce stuff into an abstract system if there's a more viable way to go about it! @Randy Gaul - I had an idea somewhat similar, this is good stuff thanks! Time to die and regret my choice of hobbies!
  13.  It's pretty cool, though one thing I noticed: I pressed x while I was in a level, it closed, however I checked my processes upload jpg That's definitely not good. The game wasn't open on my taskbar, but the process itself didn't die, meaning it was running in the background. 
  14. I'm working on a tile game currently, but I'm not quite certain on how I'm going to handle objects. My current plan is to make a base "thing" type, which everything, from npc's to objects are derived from. If it can be seen/interacted with, it's a thing. Is this a good approach to handling this? Or are there any other ways which to handle this? 
  15. tristan1333

    Got any wish list for 2017?

    I would like my grades to skyrocket, but that's a longshot. 
  • 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!