bug fix: initialize last frame timestamp
This commit is contained in:
parent
c71635e5d6
commit
437f2d321c
134
demo/Demo.cpp
134
demo/Demo.cpp
|
@ -109,22 +109,33 @@ void set_framerate_indicator(int frame_count, GLuint id)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
struct Demo : Game
|
||||
Mushroom::Mushroom(Node *parent) : Sprite(parent, "resource/shrooms")
|
||||
{
|
||||
std::cout << "mushroom constructor " << this << std::endl;
|
||||
}
|
||||
|
||||
SDL_Texture *grass_texture;
|
||||
int frame_count = 0, frame_count_timestamp;
|
||||
bool right_active = false, down_active = false, left_active = false,
|
||||
up_active = false;
|
||||
SDL_Event event;
|
||||
GLuint vbo, space_texture_id, mvp_id, framerate_texture_id, flat_program,
|
||||
world_program, fake_texture_id;
|
||||
glm::mat4 projection, view, model = glm::mat4(1.0f), mvp;
|
||||
// Mushroom mushroom = Mushroom(this);
|
||||
// Sprite grass = Sprite(this, "resource/Field.png");
|
||||
|
||||
Demo()
|
||||
void Mushroom::update()
|
||||
{
|
||||
Game *game = get_root();
|
||||
move(direction);
|
||||
int x = location.get_x();
|
||||
if (x > game->sw or x < 0)
|
||||
{
|
||||
direction = -direction;
|
||||
if (x > game->sw)
|
||||
{
|
||||
move(game->sw - x);
|
||||
}
|
||||
else
|
||||
{
|
||||
move(-x);
|
||||
}
|
||||
}
|
||||
Sprite::update();
|
||||
}
|
||||
|
||||
Demo::Demo()
|
||||
{
|
||||
Mix_Music *music = Mix_LoadMUS("resource/Field.mp3");
|
||||
Mix_PlayMusic(music, -1);
|
||||
load_gl_context();
|
||||
|
@ -136,25 +147,20 @@ struct Demo : Game
|
|||
// Input* i = new Input(this);
|
||||
// get_delegate().unsubscribe(i);
|
||||
// delete i;
|
||||
}
|
||||
}
|
||||
|
||||
std::string get_class_name()
|
||||
{
|
||||
return "Demo";
|
||||
}
|
||||
|
||||
void load_sdl_context()
|
||||
{
|
||||
void Demo::load_sdl_context()
|
||||
{
|
||||
Game::load_sdl_context();
|
||||
// grass.load();
|
||||
// mushroom.load();
|
||||
}
|
||||
grass.load();
|
||||
mushroom.load();
|
||||
}
|
||||
|
||||
void load_gl_context()
|
||||
{
|
||||
void Demo::load_gl_context()
|
||||
{
|
||||
Game::load_gl_context();
|
||||
// grass.unload();
|
||||
// mushroom.unload();
|
||||
grass.unload();
|
||||
mushroom.unload();
|
||||
/*
|
||||
v0-v1-v2 (front)
|
||||
v2-v3-v0
|
||||
|
@ -296,10 +302,10 @@ struct Demo : Game
|
|||
frame_count_timestamp = SDL_GetTicks();
|
||||
framerate_texture_id = get_gl_texture_from_surface(
|
||||
get_framerate_indicator_surface(frame_count), GL_LINEAR);
|
||||
}
|
||||
}
|
||||
|
||||
void respond(SDL_Event& event)
|
||||
{
|
||||
void Demo::respond(SDL_Event& event)
|
||||
{
|
||||
if (delegate.compare(event, "context"))
|
||||
{
|
||||
if (is_gl_context)
|
||||
|
@ -311,10 +317,10 @@ struct Demo : Game
|
|||
load_gl_context();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
void Demo::update()
|
||||
{
|
||||
// while (SDL_PollEvent(&event))
|
||||
// {
|
||||
// if (event.type == SDL_KEYDOWN)
|
||||
|
@ -424,24 +430,24 @@ struct Demo : Game
|
|||
roundedBoxColor(renderer, 300, 200, 500, 300, 10, 0x8f8fdfff);
|
||||
aacircleColor(renderer, 300, 200, 30, 0xffef3fff);
|
||||
int speed = 2;
|
||||
// if (up_active)
|
||||
// {
|
||||
// grass.move(0, -speed);
|
||||
// }
|
||||
// if (right_active)
|
||||
// {
|
||||
// grass.move(speed);
|
||||
// }
|
||||
// if (down_active)
|
||||
// {
|
||||
// grass.move(0, speed);
|
||||
// }
|
||||
// if (left_active)
|
||||
// {
|
||||
// grass.move(-speed, 0);
|
||||
// }
|
||||
// grass.update();
|
||||
// mushroom.update();
|
||||
if (up_active)
|
||||
{
|
||||
grass.move(0, -speed);
|
||||
}
|
||||
if (right_active)
|
||||
{
|
||||
grass.move(speed);
|
||||
}
|
||||
if (down_active)
|
||||
{
|
||||
grass.move(0, speed);
|
||||
}
|
||||
if (left_active)
|
||||
{
|
||||
grass.move(-speed, 0);
|
||||
}
|
||||
grass.update();
|
||||
mushroom.update();
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
frame_count++;
|
||||
|
@ -454,30 +460,6 @@ struct Demo : Game
|
|||
}
|
||||
frame_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Mushroom::Mushroom(Node *parent) : Sprite(parent, "resource/shrooms") {}
|
||||
|
||||
void Mushroom::update()
|
||||
{
|
||||
Game *game = get_root();
|
||||
move(direction);
|
||||
int x = location.get_x();
|
||||
if (x > game->sw or x < 0)
|
||||
{
|
||||
direction = -direction;
|
||||
if (x > game->sw)
|
||||
{
|
||||
move(game->sw - x);
|
||||
}
|
||||
else
|
||||
{
|
||||
move(-x);
|
||||
}
|
||||
}
|
||||
Sprite::update();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
#include "glm/gtc/matrix_transform.hpp"
|
||||
|
||||
#include "filesystem.hpp"
|
||||
#include "Game.hpp"
|
||||
#include "Node.hpp"
|
||||
#include "Game.hpp"
|
||||
#include "Location.hpp"
|
||||
#include "Sprite.hpp"
|
||||
#include "Input.hpp"
|
||||
|
@ -42,8 +42,32 @@ struct Mushroom : Sprite
|
|||
|
||||
int direction = 1;
|
||||
|
||||
Mushroom (Node*);
|
||||
Mushroom(Node*);
|
||||
void update();
|
||||
std::string get_class_name() { return "Mushroom"; }
|
||||
|
||||
};
|
||||
|
||||
struct Demo : Game
|
||||
{
|
||||
|
||||
SDL_Texture *grass_texture;
|
||||
int frame_count = 0, frame_count_timestamp;
|
||||
bool right_active = false, down_active = false, left_active = false,
|
||||
up_active = false;
|
||||
SDL_Event event;
|
||||
GLuint vbo, space_texture_id, mvp_id, framerate_texture_id, flat_program,
|
||||
world_program, fake_texture_id;
|
||||
glm::mat4 projection, view, model = glm::mat4(1.0f), mvp;
|
||||
int abc, def, ghi, jkl, mno, pqr, stu, vwx, yz;
|
||||
Mushroom mushroom = Mushroom(this);
|
||||
Sprite grass = Sprite(this, "resource/Field.png");
|
||||
|
||||
Demo();
|
||||
void load_sdl_context();
|
||||
void load_gl_context();
|
||||
void respond(SDL_Event&);
|
||||
void update();
|
||||
std::string get_class_name() { return "Demo"; }
|
||||
|
||||
};
|
||||
|
|
|
@ -57,6 +57,7 @@ Game::Game()
|
|||
{
|
||||
print_sdl_error("Could not set up audio");
|
||||
}
|
||||
last_frame_timestamp = SDL_GetTicks();
|
||||
}
|
||||
|
||||
Game::~Game()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Node.hpp"
|
||||
#include "Game.hpp"
|
||||
#include "Display.hpp"
|
||||
#include "Delegate.hpp"
|
||||
|
||||
Node::Node() : Node(NULL) {}
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
Recorder::Recorder(Node* parent) : Node(parent)
|
||||
{
|
||||
get_delegate().subscribe(&Recorder::respond, this);
|
||||
// in_game_stashes.push_back(Stash());
|
||||
|
||||
animation.play();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue