-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDraw.c++
85 lines (61 loc) · 2.04 KB
/
TestDraw.c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// TestDraw.c++
// Tech1
//
// Created by Justin Hust on 12/14/13.
// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <cassert>
#include <string>
#include "SDL2/SDL.h"
#include "SDL2_image/SDL_image.h"
#include "SDL2_mixer/SDL_mixer.h"
#include "Clock.h"
#include "Reporter.h"
#include "Resource.h"
const int resWidth = 1136;
const int resHeight = 640;
// -----------------------------------------------------------------
int main(int argc, char *argv[]) {
// --- init ----
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
char err[80];
snprintf(err, 80, "Failed SDL Init: %s.\n", SDL_GetError());
std::cout << err << std::endl;
}
SDL_Window *sdlWindow = NULL;
if((sdlWindow = SDL_CreateWindow("Tech1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
resWidth, resHeight, SDL_WINDOW_SHOWN)) == NULL) {
char err[80];
snprintf(err, 80, "Failed Window Init: %s.\n", SDL_GetError());
std::cout << err << std::endl;
}
SDL_Surface *windowSurf = SDL_GetWindowSurface(sdlWindow);
ResourceMgr rm;
rm.Register("images/space_800x600.png");
rm.Register("images/bomb.png");
rm.Register("images/bullet.png");
ImageResource *imgBack = dynamic_cast<ImageResource *> (rm.get("images/space_800x600.png"));
ImageResource *imgBomb = dynamic_cast<ImageResource *> (rm.get("images/bomb.png"));
ImageResource *imgBullet = dynamic_cast<ImageResource *> (rm.get("images/bullet.png"));
// ----- main code ------
SDLClock c;
while(c.getSecsElapsed() < 3.0f) {
imgBack->draw(resWidth / 2, resHeight/2, windowSurf);
imgBomb->draw(600, 200, windowSurf);
imgBullet->draw(200, 300, windowSurf);
SDL_UpdateWindowSurface(sdlWindow);
c.tick();
}
rm.unregister("images/bullet.png");
rm.unregister("images/bomb.png");
rm.unregister("images/space_800x600.png");
// --- cleanup ----
SDL_FreeSurface(windowSurf);
windowSurf = NULL;
SDL_DestroyWindow(sdlWindow);
sdlWindow = NULL;
SDL_Quit();
return 0;
}