2022-02-07 05:15:50 +00:00
# define SDL_MAIN_HANDLED // needs to be here or linker fucking dies
2022-02-11 00:48:03 +00:00
# define SDL_STBIMAGE_IMPLEMENTATION
2022-02-07 05:15:50 +00:00
# undef _HAS_STD_BYTE
# include <iostream>
# include "SDL2/SDL.h"
# include "Render.hpp"
# include <cmath>
# include <Windows.h>
using namespace std ;
using namespace Render ;
class MainState : public State {
2022-02-07 07:14:52 +00:00
AnimatedObject objs ;
2022-02-07 07:59:38 +00:00
TextObject text ;
2022-02-08 02:23:57 +00:00
// objects need to be outside the function to work
2022-02-07 05:15:50 +00:00
Object title ;
2022-02-08 02:20:45 +00:00
Object title2 ;
Object title3 ;
Object title4 ;
2022-02-08 05:54:19 +00:00
// cameras are rects
2022-02-08 02:20:45 +00:00
SDL_Rect camera = { 0 , 0 , WINDOW_WIDTH , WINDOW_HEIGHT } ;
2022-02-08 05:54:19 +00:00
// to override a function, just state back the name of it with a virtual keyword
// before it
2022-02-07 05:15:50 +00:00
virtual void Create ( ) {
2022-02-11 00:48:03 +00:00
// SPEAK("eyeyeyayeyayeyaeyaeyayeayeyaeyaeyayeyaeyayeyayeyayeyayeaye", 3000.0f, 5.0f);
2022-02-09 05:03:49 +00:00
playModPlug ( " data/canyon.mid " ) ;
2022-02-08 05:54:19 +00:00
// i know that this isnt the best idea to do this
// yeah, im just lazy
2022-02-07 05:15:50 +00:00
title . create ( 0 , 0 , " data/bg.png " ) ;
2022-02-08 05:54:19 +00:00
AddObject ( & title ) ;
2022-02-08 02:20:45 +00:00
title2 . create ( 640 , 0 , " data/bg.png " ) ;
2022-02-08 05:54:19 +00:00
AddObject ( & title2 ) ;
2022-02-08 02:20:45 +00:00
title3 . create ( 640 , 480 , " data/bg.png " ) ;
AddObject ( & title3 ) ;
title4 . create ( 0 , 480 , " data/bg.png " ) ;
AddObject ( & title4 ) ;
2022-02-08 05:54:19 +00:00
// example of animated object
2022-02-08 02:20:45 +00:00
objs . create ( 0 , 0 , " data/smile.png " ) ;
2022-02-07 05:15:50 +00:00
AddObject ( & objs ) ;
2022-02-07 07:14:52 +00:00
objs . AddAnimation ( " idle " , { { 0 , 0 , 50 , 50 } , { 50 , 0 , 50 , 50 } } ) ;
objs . PlayAnimation ( " idle " ) ;
objs . framerate = 1 ;
2022-02-08 05:54:19 +00:00
// set cameras :)
2022-02-08 02:20:45 +00:00
objs . setCamera ( & camera ) ;
title . setCamera ( & camera ) ;
title2 . setCamera ( & camera ) ;
title3 . setCamera ( & camera ) ;
title4 . setCamera ( & camera ) ;
2022-02-07 05:15:50 +00:00
title . scale . y = 0 ;
2022-02-07 07:23:33 +00:00
2022-02-08 05:54:19 +00:00
// center object
2022-02-08 02:20:45 +00:00
objs . centerSelf ( ) ;
2022-02-08 05:54:19 +00:00
// offsets :)
2022-02-08 02:23:57 +00:00
title2 . offset . x = 640 ;
title3 . offset = { 640 , 480 } ;
title4 . offset . y = 480 ;
2022-02-08 05:54:19 +00:00
// example of a text object
2022-02-08 02:20:45 +00:00
text . create ( 50 , 480 - 100 , " Welcome to the funny application \n Make yourself at home :) \n - haya " , " data/monogram.ttf " , { 255 , 255 , 255 , 255 } , TTF_STYLE_NORMAL , 40 ) ;
2022-02-07 07:59:38 +00:00
AddObject ( & text ) ;
2022-02-07 05:15:50 +00:00
}
int yvel = 0 ;
int xvel = 0 ;
float elaped = 0 ;
2022-02-08 05:54:19 +00:00
// update
2022-02-07 05:15:50 +00:00
virtual void Update ( float dt ) {
2022-02-08 05:54:19 +00:00
// to get current keyboard input, use SDL_GetKeyboardState
2022-02-07 05:15:50 +00:00
const Uint8 * kb = SDL_GetKeyboardState ( NULL ) ;
2022-02-08 05:54:19 +00:00
// :)
2022-02-07 05:15:50 +00:00
yvel = - kb [ SDL_SCANCODE_UP ] + kb [ SDL_SCANCODE_DOWN ] ;
xvel = - kb [ SDL_SCANCODE_LEFT ] + kb [ SDL_SCANCODE_RIGHT ] ;
objs . x = objs . x + xvel * 2 ;
objs . y = objs . y + yvel * 2 ;
2022-02-08 05:54:19 +00:00
// cool scaling
title . scale . y = sin ( elaped / 100 ) ;
title . scale . x = cos ( elaped / 100 ) ;
title2 . scale . y = cos ( elaped / 100 ) ;
title2 . scale . x = sin ( elaped / 100 ) ;
title3 . scale . y = sin ( elaped / 100 ) ;
title3 . scale . x = sin ( elaped / 100 ) ;
title4 . scale . y = cos ( elaped / 100 ) ;
title4 . scale . x = cos ( elaped / 100 ) ;
// make camera point to an object
2022-02-08 02:20:45 +00:00
pointTo ( & camera , objs ) ;
2022-02-08 05:54:19 +00:00
// center shit
2022-02-07 05:44:09 +00:00
title . centerSelf ( ) ;
2022-02-08 02:23:57 +00:00
title2 . centerSelf ( ) ;
title3 . centerSelf ( ) ;
title4 . centerSelf ( ) ;
2022-02-08 01:36:23 +00:00
text . centerSelf ( ) ;
2022-02-08 05:54:19 +00:00
// :)
text . scale . y = cos ( elaped / 10 ) * 2 ;
2022-02-08 01:36:23 +00:00
text . offset . y = - 240 / 2 ;
2022-02-07 05:15:50 +00:00
2022-02-08 05:54:19 +00:00
// for the sin and cos shit
elaped + = 1 ;
2022-02-07 05:15:50 +00:00
}
} ;
2022-02-08 05:54:19 +00:00
MainState m2 ;
class SplashScreen : public State {
Object bg ;
Object black ;
virtual void Create ( ) {
bg . create ( 0 , 0 , " data/powered.png " ) ;
AddObject ( & bg ) ;
black . create ( 0 , 0 , " data/black.png " ) ;
AddObject ( & black ) ;
black . alpha = 0 ;
2022-02-08 09:08:05 +00:00
Timer time ;
Timer time2 ;
time2 . start ( 1.0 , [ this ] ( int dummy ) { black . alpha + = 1 ; return 0 ; } , true ) ;
time . start ( 3.0 , [ ] ( int dummy ) { SwitchState ( & m2 ) ; return 0 ; } ) ;
2022-02-08 05:54:19 +00:00
2022-02-08 09:08:05 +00:00
playSound ( " data/flixel.ogg " ) ;
2022-02-08 05:54:19 +00:00
//SDL_SetRenderDrawColor( renderer, 0xFF, 0xFF, 0xFF, 0xFF );
}
} ;
SplashScreen m ;
2022-02-07 05:15:50 +00:00
int main ( ) {
2022-02-09 03:01:45 +00:00
if ( ! Init ( " SDLflixel :))))) " ) ) {
return ERROR_CODE ;
}
2022-02-07 05:15:50 +00:00
SwitchState ( & m ) ;
if ( ! Update ( ) ) {
2022-02-09 03:01:45 +00:00
return NO_ERROR_CODE ;
2022-02-07 05:15:50 +00:00
}
}