Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- using System.Net;
- using SdlDotNet;
- using SdlDotNet.Core;
- using SdlDotNet.Graphics;
- using SdlDotNet.Graphics.Sprites;
- using SdlDotNet.Input;
- using SdlDotNet.Audio;
- using Newtonsoft.Json;
- namespace ColorCycling
- {
- class Scene
- {
- public Window window;
- Bitmap scenebmp;
- SceneList sceneList;
- System.Drawing.Bitmap bmp;
- public bool blend = false;
- Surface sceneSurface;
- int currentScene;
- long sceneStartTicks;
- int updateTimer = 0;
- public Scene(Window w, SceneList s)
- {
- window = w;
- sceneList = s;
- bmp = new System.Drawing.Bitmap(640, 480);
- }
- public void LoadScene(int sceneindex)
- {
- currentScene = sceneindex;
- string str = "";
- if (File.Exists("scenes/" + sceneList.scenes[sceneindex].jsonpath + ".LBM.JSON"))
- {
- str = File.ReadAllText("scenes/" + sceneList.scenes[sceneindex].jsonpath + ".LBM.JSON");
- }
- else
- {
- string response = GetHTTP("http://www.effectgames.com/demos/canvascycle/image.php?file=" + sceneList.scenes[sceneindex].jsonpath);
- str = response.Substring(1, response.Length - 4);
- File.WriteAllText("scenes/" + sceneList.scenes[sceneindex].jsonpath + ".LBM.JSON", str);
- }
- Music m = new Music("audio/" + sceneList.scenes[sceneindex].soundpath + ".ogg");
- m.Play(true);
- JSONBitmap j = JsonConvert.DeserializeObject<JSONBitmap>(str);
- scenebmp = new Bitmap(this, j);
- sceneStartTicks = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
- scenebmp.render(bmp, false);
- sceneSurface = new Surface(bmp);
- }
- public void NextScene()
- {
- if (currentScene < 34)
- {
- currentScene++;
- }
- else
- {
- currentScene = 0;
- }
- LoadScene(currentScene);
- }
- public void PreviousScene()
- {
- if (currentScene > 0)
- {
- currentScene--;
- }
- else
- {
- currentScene = 34;
- }
- LoadScene(currentScene);
- }
- string GetHTTP(string requeststr)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requeststr);
- request.KeepAlive = false;
- request.Method = "GET";
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- StreamReader sr = new StreamReader(response.GetResponseStream());
- return sr.ReadToEnd();
- }
- public void Update()
- {
- updateTimer++;
- if (updateTimer > 2)
- {
- scenebmp.palette.cycle(scenebmp.palette.baseColors, GetTickCount(), 1, blend);
- scenebmp.render(bmp, false);
- Draw();
- updateTimer = 0;
- }
- else
- {
- }
- }
- long GetTickCount()
- {
- long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
- return milliseconds - sceneStartTicks;
- }
- void Draw()
- {
- sceneSurface = new Surface(bmp);
- window.BlitToScreen(sceneSurface);
- sceneSurface.Dispose();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement