Spwaning of multiple enemies doesn't work

Here’s the full main.cpp

#include "Core.hpp"
#include "Load.hpp"
#include "Create.hpp"
#include <vector>

int main(int argc, char *argv[]){

  Core core;
  Load load;
  Create* player;
  Create *enemy[10];
  core.init("window", 0, 0, 1080, 720, false);
  float p_x = 1080/2, p_y = 720 - 64 * 2;
  int p_acc = 2;
  player = new Create("../assets/player.png");
  int i = 1;
  for (i = 1; i<=10; i++) {
    enemy[i] = new Create("../assets/enemy.png");
  }
  int j = 1;
  while (core.is_running) {
    player -> update(p_x, p_y);
    core.start_render();
    player -> render();
    while(j <= 10){
      enemy[j] -> update(rand()% 100, rand() % 100);
      enemy[j] -> render();
      std::cout << "loop exits" << i << std::endl;
      j++;
    }
    core.clear_render();
    core.handle_events();
    
    if (core.key[4] == true){
      p_x += 0.5 * p_acc;
      //std::cout << "x pos" << p_x << std::endl;
    }
    if (core.key[3] == true)
      p_x -= 0.5 * p_acc;
    }
    core.update();

  return 0;
}

I tried storing 10 enemy objects in the array.
It all looks ok to me but i can’t see any enemy on the screen (i checked the path to the image)

You’re accessing things past the end of that array of yours. Array indexing starts at 0, not 1. This means that when j == 10, you’re accessing enemy[10] whereas enemy[9] is where its tail end sits. You could decide that you’re not going to use enemy[0] and allocate an array of size 11 instead but I’d encourage you to start 0-indexing things.

You’re also (probably) clearing the screen prior to whatever you’re doing in core.update(). You’re essentially just throwing away everything you just drew. Since you didn’t post all your code, I have no idea what you’re actually calling. You’ll want to clear the screen at the very start of your frame and call a flip at the end of it. Something to the tune of the following pseudo code:

while (alive) {
    process_input();
    update_game_state();

    clear();
    draw_a_bunch_of_things();
    flip();
}

With SDL2/3’s own 2D rendering facility the flipping would be provided via SDL_RenderPresent().

SmashTheState

More like smash the stack.
Sorry, couldn’t resist. :crazy_face: