gamecreator Posted February 13, 2015 Share Posted February 13, 2015 Here you go Recoils14. I added some comments to hopefully help. Just replace your App.cpp with the following. Also, don't forget that this code uses a bullet.tex and a ship.tex from the Models folder so you'll need those there so the code doesn't crash. It also assumes that the bullet texture is 16x16 and the ship is 128x128, as that is hard coded (but it would be easy to change to detect it). #include "App.h" using namespace Leadwerks; #define NUMBEROFBULLETS 1000 App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Texture *bullettexture = NULL; Texture *shiptexture = NULL; float shipx, shipy; float fps; struct bulletinfo { float x, y, vx, vy; } bullet[NUMBEROFBULLETS]; bool App::Start() { window = Leadwerks::Window::Create("BulletHell", 0, 0, 1728, 972, Leadwerks::Window::Titlebar|Leadwerks::Window::Center); context = Context::Create(window); world = World::Create(); camera = Camera::Create(); camera->Move(0, 2, -5); window->HideMouse(); bullettexture = Texture::Load("Models/bullet.tex"); shiptexture = Texture::Load("Models/ship.tex"); // Generate random bullet position for(int i=0; i<NUMBEROFBULLETS; i++) { bullet[i].x=Math::Random(0, 1700); bullet[i].y=Math::Random(0, 950); bullet[i].vx=Math::Random(-2, 2); bullet[i].vy=Math::Random(-2, 2); } // Generate random ship position and velocities shipx=Math::Random(0, 1650); shipy=Math::Random(0, 900); return true; } bool App::Loop() { // Exit program if window is closed or Escape button is hit if(window->Closed() || window->KeyHit(Key::Escape)) { printf("\n\nfps: %f\n", fps); return false; } Leadwerks::Time::Update(); world->Update(); world->Render(); // Move ship with arrow keys if(window->KeyDown(Key::Left)) shipx-=Time::GetSpeed()*3.0; if(window->KeyDown(Key::Right)) shipx+=Time::GetSpeed()*3.0; if(window->KeyDown(Key::Up)) shipy-=Time::GetSpeed()*3.0; if(window->KeyDown(Key::Down)) shipy+=Time::GetSpeed()*3.0; context->SetBlendMode(Blend::Alpha); // Go through all of the bullets, one by one for(int i=0; i<NUMBEROFBULLETS; i++) { // If bullet is at the edge of the screen, turn it around if(bullet[i].x>1700 && bullet[i].vx>0) bullet[i].vx*=-1; if(bullet[i].x<0 && bullet[i].vx<0) bullet[i].vx*=-1; if(bullet[i].y>970 && bullet[i].vy>0) bullet[i].vy*=-1; if(bullet[i].y<0 && bullet[i].vy<0) bullet[i].vy*=-1; // Move bullet bullet[i].x+=bullet[i].vx*Time::GetSpeed(); bullet[i].y+=bullet[i].vy*Time::GetSpeed(); // If bullet is by the ship, turn it blue if(bullet[i].x>shipx-8 && bullet[i].x<shipx+136 && bullet[i].y>shipy-8 && bullet[i].y<shipy+136) context->SetColor(0,0,1); else context->SetColor(1, 1, 1); // Draw bullet context->DrawImage(bullettexture, bullet[i].x, bullet[i].y); } // Draw ship context->DrawImage(shiptexture, shipx, shipy); // Get frames per second and show it fps=Time::UPS(); context->DrawText("FPS: "+String(fps), 10, 10); context->Sync(false); return true; } Quote Link to comment Share on other sites More sharing options...
Recoils14 Posted February 14, 2015 Author Share Posted February 14, 2015 Thanks! That's a bit overwhelming for me at this point, but it will give me a good reference so base some of reading off of! Quote Link to comment Share on other sites More sharing options...
gamecreator Posted February 14, 2015 Share Posted February 14, 2015 Definitely understandable. It's not complex but it's also not for beginners. Definitely start elsewhere to get a handle on things. Happy to help either way. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.