Re: Shooting Multiple Bullets
- Posted by Icy_Viking Feb 08, 2020
- 1041 views
Thank you. However I had to fix a couple of things. Like putting the for loop in between the begin and end drawing functions. Also, when the last bullet of the array is done, there is a subscript value out of bounds error.
Value 1 is out of bounds, reading from a sequence length of 0 in subscript #1 of "bullets"
without warning include std/machine.e include std/get.e include std/convert.e include EuRaylib.ew include flags.e atom Width=1024 atom Height=720 constant TRUE=1 constant FALSE=0 InitWindow(Width,Height,"Shump") SetTargetFPS(60) atom black = bytes_to_int({0,0,0,0}) atom red = bytes_to_int({255,0,0,255}) atom bullet_speed = 5.0 integer bullet_visible = FALSE constant X=1,Y=2 sequence bullets = {} while not WindowShouldClose() do if IsKeyPressed(KEY_SPACE) then atom bullet_x = GetScreenWidth() / 2 atom bullet_y = GetScreenHeight() / 2 bullets = append(bullets,{bullet_x,bullet_y}) end if BeginDrawing() ClearBackground(black) for i = length(bullets) to 1 by -1 do bullets[i][X] += bullet_speed if (bullets[i][X] >= GetScreenWidth()) then bullets = remove(bullets,i) end if DrawCircleV(bullets[i][X],bullets[i][Y],20,red) end for EndDrawing() end while CloseWindow()